@@ -5,42 +5,46 @@ function urluploader_ws_add_methods($arr)
55{
66 global $ conf ;
77 $ service = &$ arr [0 ];
8-
8+
99 $ service ->addMethod (
1010 'pwg.images.addRemote ' ,
1111 'ws_images_addRemote ' ,
1212 array (
1313 'file_url ' => array (),
14- 'category ' => array (),
14+ 'category ' => array (' type ' => WS_TYPE_ID ),
1515 'name ' => array ('default ' => null ),
1616 'level ' => array (
1717 'default ' => 0 ,
18- 'maxValue ' => $ conf ['available_permission_levels ' ]
19- ),
20- 'url_in_comment ' => array ('default ' => true ),
18+ 'maxValue ' => $ conf ['available_permission_levels ' ],
19+ 'type ' => WS_TYPE_INT | WS_TYPE_POSITIVE ,
20+ ),
21+ 'url_in_comment ' => array (
22+ 'default ' => true ,
23+ 'type ' => WS_TYPE_BOOL ,
2124 ),
25+ ),
2226 'Add image from remote URL. ' ,
2327 null ,
24- array ('admin_only ' => true )
25- );
28+ array ('admin_only ' => true )
29+ );
2630}
2731
2832function ws_images_addRemote ($ params , &$ service )
2933{
3034 global $ conf ;
31-
35+
3236 if (!is_admin ())
3337 {
3438 return new PwgError (401 , 'Access denied ' );
3539 }
36-
40+
3741 load_language ('plugin.lang ' , URLUPLOADER_PATH );
38-
42+
3943 $ params = array_map ('trim ' , $ params );
40-
41- $ allowed_extensions = array ('jpg ' ,'jpeg ' ,'png ' ,'gif ' );
44+
45+ $ allowed_extensions = array ('jpg ' , 'jpeg ' , 'png ' , 'gif ' );
4246 $ allowed_mimes = array ('image/jpeg ' , 'image/png ' , 'image/gif ' );
43-
47+
4448 // check empty url
4549 if (empty ($ params ['file_url ' ]))
4650 {
@@ -58,84 +62,86 @@ function ws_images_addRemote($params, &$service)
5862 }
5963
6064 // download file
61- include_once (PHPWG_ROOT_PATH . 'admin/include/functions.php ' );
62-
63- $ temp_filename = $ conf ['data_location ' ]. basename ($ params ['file_url ' ]);
65+ include_once (PHPWG_ROOT_PATH . 'admin/include/functions.php ' );
66+
67+ $ temp_filename = $ conf ['data_location ' ] . basename ($ params ['file_url ' ]);
6468 $ file = fopen ($ temp_filename , 'w+ ' );
6569 $ result = fetchRemote ($ params ['file_url ' ], $ file );
6670 fclose ($ file );
67-
71+
6872 // download failed ?
6973 if (!$ result )
7074 {
7175 @unlink ($ temp_filename );
76+
7277 return new PwgError (WS_ERR_INVALID_PARAM , l10n ('Unable to download file ' ));
7378 }
7479 // check mime-type
7580 if (!in_array (get_mime ($ temp_filename , $ allowed_mimes [0 ]), $ allowed_mimes ))
7681 {
7782 @unlink ($ temp_filename );
83+
7884 return new PwgError (WS_ERR_INVALID_PARAM , l10n ('Invalid file type ' ));
7985 }
8086
8187 // add photo
82- include_once (PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php ' );
83-
88+ include_once (PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php ' );
89+
8490 $ image_id = add_uploaded_file (
85- $ temp_filename ,
86- basename ($ temp_filename ),
87- array ($ params ['category ' ]),
91+ $ temp_filename ,
92+ basename ($ temp_filename ),
93+ array ($ params ['category ' ]),
8894 $ params ['level ' ]
89- );
90-
95+ );
96+
9197 $ updates = array ();
9298 if (!empty ($ params ['name ' ]))
9399 {
94100 $ updates ['name ' ] = $ params ['name ' ];
95101 }
96- if ($ params ['url_in_comment ' ]== 'true ' )
102+ if ($ params ['url_in_comment ' ] == 'true ' )
97103 {
98104 $ url = parse_url ($ params ['file_url ' ]);
99- $ url = $ url ['scheme ' ]. ':// ' . $ url ['host ' ];
100- $ updates ['comment ' ] = '<a href=" ' . $ url . '"> ' . $ url .'</a> ' ;
105+ $ url = $ url ['scheme ' ] . ':// ' . $ url ['host ' ];
106+ $ updates ['comment ' ] = '<a href=" ' . $ url . '"> ' . $ url . '</a> ' ;
101107 }
102-
108+
103109 single_update (
104110 IMAGES_TABLE ,
105111 $ updates ,
106112 array ('id ' => $ image_id )
107- );
108-
109-
113+ );
114+
115+
110116 // return infos
111117 $ query = '
112118SELECT id, name, permalink
113- FROM '. CATEGORIES_TABLE . '
114- WHERE id = '. $ params ['category ' ]. '
119+ FROM ' . CATEGORIES_TABLE . '
120+ WHERE id = ' . $ params ['category ' ] . '
115121; ' ;
116122 $ category = pwg_db_fetch_assoc (pwg_query ($ query ));
117123
118124 $ url_params = array (
119125 'image_id ' => $ image_id ,
120126 'section ' => 'categories ' ,
121127 'category ' => $ category ,
122- );
123-
128+ );
129+
124130 $ query = '
125131SELECT id, path, name
126- FROM '. IMAGES_TABLE . '
127- WHERE id = '. $ image_id. '
132+ FROM ' . IMAGES_TABLE . '
133+ WHERE id = ' . $ image_id . '
128134; ' ;
129135 $ image_infos = pwg_db_fetch_assoc (pwg_query ($ query ));
130-
136+
131137 $ query = '
132138SELECT
133139 COUNT(*) AS nb_photos
134- FROM '. IMAGE_CATEGORY_TABLE . '
135- WHERE category_id = '. $ params ['category ' ]. '
140+ FROM ' . IMAGE_CATEGORY_TABLE . '
141+ WHERE category_id = ' . $ params ['category ' ] . '
136142; ' ;
137143 $ category_infos = pwg_db_fetch_assoc (pwg_query ($ query ));
138-
144+
139145 $ category_name = get_cat_display_name_from_id ($ params ['category ' ], null );
140146
141147 return array (
@@ -147,6 +153,6 @@ function ws_images_addRemote($params, &$service)
147153 'id ' => $ params ['category ' ],
148154 'nb_photos ' => $ category_infos ['nb_photos ' ],
149155 'label ' => $ category_name ,
150- ),
151- );
156+ ),
157+ );
152158}
0 commit comments