| | 1341 | } |
| | 1342 | |
| | 1343 | function ws_images_addSimple($params, &$service) |
| | 1344 | { |
| | 1345 | global $conf; |
| | 1346 | if (!is_admin()) |
| | 1347 | { |
| | 1348 | return new PwgError(401, 'Access denied'); |
| | 1349 | } |
| | 1350 | |
| | 1351 | if (!$service->isPost()) |
| | 1352 | { |
| | 1353 | return new PwgError(405, "This method requires HTTP POST"); |
| | 1354 | } |
| | 1355 | |
| | 1356 | $params['image_id'] = (int)$params['image_id']; |
| | 1357 | if ($params['image_id'] > 0) |
| | 1358 | { |
| | 1359 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
| | 1360 | |
| | 1361 | $query=' |
| | 1362 | SELECT * |
| | 1363 | FROM '.IMAGES_TABLE.' |
| | 1364 | WHERE id = '.$params['image_id'].' |
| | 1365 | ;'; |
| | 1366 | |
| | 1367 | $image_row = pwg_db_fetch_assoc(pwg_query($query)); |
| | 1368 | if ($image_row == null) |
| | 1369 | { |
| | 1370 | return new PwgError(404, "image_id not found"); |
| | 1371 | } |
| | 1372 | } |
| | 1373 | |
| | 1374 | // category |
| | 1375 | $params['category'] = (int)$params['category']; |
| | 1376 | if ($params['category'] <= 0 and $params['image_id'] <= 0) |
| | 1377 | { |
| | 1378 | return new PwgError(WS_ERR_INVALID_PARAM, "Invalid category_id"); |
| | 1379 | } |
| | 1380 | |
| | 1381 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); |
| | 1382 | prepare_upload_configuration(); |
| | 1383 | |
| | 1384 | $image_id = add_uploaded_file( |
| | 1385 | $_FILES['image']['tmp_name'], |
| | 1386 | $_FILES['image']['name'], |
| | 1387 | $params['category'] > 0 ? array($params['category']) : null, |
| | 1388 | 8, |
| | 1389 | $params['image_id'] > 0 ? $params['image_id'] : null |
| | 1390 | ); |
| | 1391 | |
| | 1392 | $info_columns = array( |
| | 1393 | 'name', |
| | 1394 | 'author', |
| | 1395 | 'comment', |
| | 1396 | 'level', |
| | 1397 | 'date_creation', |
| | 1398 | ); |
| | 1399 | |
| | 1400 | foreach ($info_columns as $key) |
| | 1401 | { |
| | 1402 | if (isset($params[$key])) |
| | 1403 | { |
| | 1404 | $update[$key] = $params[$key]; |
| | 1405 | } |
| | 1406 | } |
| | 1407 | |
| | 1408 | if (count(array_keys($update)) > 0) |
| | 1409 | { |
| | 1410 | $update['id'] = $image_id; |
| | 1411 | |
| | 1412 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
| | 1413 | mass_updates( |
| | 1414 | IMAGES_TABLE, |
| | 1415 | array( |
| | 1416 | 'primary' => array('id'), |
| | 1417 | 'update' => array_diff(array_keys($update), array('id')) |
| | 1418 | ), |
| | 1419 | array($update) |
| | 1420 | ); |
| | 1421 | } |
| | 1422 | |
| | 1423 | |
| | 1424 | if (isset($params['tags']) and !empty($params['tags'])) |
| | 1425 | { |
| | 1426 | $tag_ids = array(); |
| | 1427 | $tag_names = explode(',', $params['tags']); |
| | 1428 | foreach ($tag_names as $tag_name) |
| | 1429 | { |
| | 1430 | $tag_id = tag_id_from_tag_name($tag_name); |
| | 1431 | array_push($tag_ids, $tag_id); |
| | 1432 | } |
| | 1433 | |
| | 1434 | add_tags($tag_ids, array($image_id)); |
| | 1435 | } |
| | 1436 | |
| | 1437 | $url_params = array('image_id' => $image_id); |
| | 1438 | |
| | 1439 | if ($params['category'] > 0) |
| | 1440 | { |
| | 1441 | $query = ' |
| | 1442 | SELECT id, name, permalink |
| | 1443 | FROM '.CATEGORIES_TABLE.' |
| | 1444 | WHERE id = '.$params['category'].' |
| | 1445 | ;'; |
| | 1446 | $result = pwg_query($query); |
| | 1447 | $category = pwg_db_fetch_assoc($result); |
| | 1448 | |
| | 1449 | $url_params['section'] = 'categories'; |
| | 1450 | $url_params['category'] = $category; |
| | 1451 | } |
| | 1452 | |
| | 1453 | return array( |
| | 1454 | 'image_id' => $image_id, |
| | 1455 | 'url' => make_picture_url($url_params), |
| | 1456 | ); |
| 1490 | | if ( !empty($image_ids)) |
| 1491 | | { |
| 1492 | | $where_clauses = ws_std_image_sql_filter($params); |
| 1493 | | $where_clauses[] = get_sql_condition_FandF( |
| 1494 | | array |
| 1495 | | ( |
| 1496 | | 'forbidden_categories' => 'category_id', |
| 1497 | | 'visible_categories' => 'category_id', |
| 1498 | | 'visible_images' => 'i.id' |
| 1499 | | ), |
| 1500 | | '', true |
| 1501 | | ); |
| 1502 | | $where_clauses[] = 'id IN ('.implode(',',$image_ids).')'; |
| 1503 | | |
| 1504 | | $order_by = ws_std_image_sql_order($params); |
| 1505 | | if (empty($order_by)) |
| 1506 | | { |
| 1507 | | $order_by = $conf['order_by']; |
| 1508 | | } |
| 1509 | | else |
| 1510 | | { |
| 1511 | | $order_by = 'ORDER BY '.$order_by; |
| 1512 | | } |
| 1513 | | |
| 1514 | | $query = ' |
| 1515 | | SELECT DISTINCT i.* FROM '.IMAGES_TABLE.' i |
| 1516 | | INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON i.id=image_id |
| 1517 | | WHERE '. implode(' |
| 1518 | | AND ', $where_clauses).' |
| 1519 | | '.$order_by.' |
| 1520 | | LIMIT '.(int)$params['per_page'].' OFFSET '.(int)($params['per_page']*$params['page']); |
| 1521 | | |
| 1522 | | $result = pwg_query($query); |
| | 1614 | if (!empty($image_ids)) |
| | 1615 | { |
| | 1616 | $rank_of = array_flip($image_ids); |
| | 1617 | $result = pwg_query(' |
| | 1618 | SELECT * FROM '.IMAGES_TABLE.' |
| | 1619 | WHERE id IN ('.implode(',',$image_ids).')'); |
| | 2246 | function ws_categories_delete($params, &$service) |
| | 2247 | { |
| | 2248 | global $conf; |
| | 2249 | if (!is_admin()) |
| | 2250 | { |
| | 2251 | return new PwgError(401, 'Access denied'); |
| | 2252 | } |
| | 2253 | |
| | 2254 | if (!$service->isPost()) |
| | 2255 | { |
| | 2256 | return new PwgError(405, "This method requires HTTP POST"); |
| | 2257 | } |
| | 2258 | |
| | 2259 | if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token']) |
| | 2260 | { |
| | 2261 | return new PwgError(403, 'Invalid security token'); |
| | 2262 | } |
| | 2263 | |
| | 2264 | $modes = array('no_delete', 'delete_orphans', 'force_delete'); |
| | 2265 | if (!in_array($params['photo_deletion_mode'], $modes)) |
| | 2266 | { |
| | 2267 | return new PwgError( |
| | 2268 | 500, |
| | 2269 | '[ws_categories_delete]' |
| | 2270 | .' invalid parameter photo_deletion_mode "'.$params['photo_deletion_mode'].'"' |
| | 2271 | .', possible values are {'.implode(', ', $modes).'}.' |
| | 2272 | ); |
| | 2273 | } |
| | 2274 | |
| | 2275 | $params['category_id'] = preg_split( |
| | 2276 | '/[\s,;\|]/', |
| | 2277 | $params['category_id'], |
| | 2278 | -1, |
| | 2279 | PREG_SPLIT_NO_EMPTY |
| | 2280 | ); |
| | 2281 | $params['category_id'] = array_map('intval', $params['category_id']); |
| | 2282 | |
| | 2283 | $category_ids = array(); |
| | 2284 | foreach ($params['category_id'] as $category_id) |
| | 2285 | { |
| | 2286 | if ($category_id > 0) |
| | 2287 | { |
| | 2288 | array_push($category_ids, $category_id); |
| | 2289 | } |
| | 2290 | } |
| | 2291 | |
| | 2292 | if (count($category_ids) == 0) |
| | 2293 | { |
| | 2294 | return; |
| | 2295 | } |
| | 2296 | |
| | 2297 | $query = ' |
| | 2298 | SELECT id |
| | 2299 | FROM '.CATEGORIES_TABLE.' |
| | 2300 | WHERE id IN ('.implode(',', $category_ids).') |
| | 2301 | ;'; |
| | 2302 | $category_ids = array_from_query($query, 'id'); |
| | 2303 | |
| | 2304 | if (count($category_ids) == 0) |
| | 2305 | { |
| | 2306 | return; |
| | 2307 | } |
| | 2308 | |
| | 2309 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
| | 2310 | delete_categories($category_ids, $params['photo_deletion_mode']); |
| | 2311 | update_global_rank(); |
| | 2312 | } |
| | 2313 | |
| | 2314 | function ws_categories_move($params, &$service) |
| | 2315 | { |
| | 2316 | global $conf, $page; |
| | 2317 | |
| | 2318 | if (!is_admin()) |
| | 2319 | { |
| | 2320 | return new PwgError(401, 'Access denied'); |
| | 2321 | } |
| | 2322 | |
| | 2323 | if (!$service->isPost()) |
| | 2324 | { |
| | 2325 | return new PwgError(405, "This method requires HTTP POST"); |
| | 2326 | } |
| | 2327 | |
| | 2328 | if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token']) |
| | 2329 | { |
| | 2330 | return new PwgError(403, 'Invalid security token'); |
| | 2331 | } |
| | 2332 | |
| | 2333 | $params['category_id'] = preg_split( |
| | 2334 | '/[\s,;\|]/', |
| | 2335 | $params['category_id'], |
| | 2336 | -1, |
| | 2337 | PREG_SPLIT_NO_EMPTY |
| | 2338 | ); |
| | 2339 | $params['category_id'] = array_map('intval', $params['category_id']); |
| | 2340 | |
| | 2341 | $category_ids = array(); |
| | 2342 | foreach ($params['category_id'] as $category_id) |
| | 2343 | { |
| | 2344 | if ($category_id > 0) |
| | 2345 | { |
| | 2346 | array_push($category_ids, $category_id); |
| | 2347 | } |
| | 2348 | } |
| | 2349 | |
| | 2350 | if (count($category_ids) == 0) |
| | 2351 | { |
| | 2352 | return new PwgError(403, 'Invalid category_id input parameter, no category to move'); |
| | 2353 | } |
| | 2354 | |
| | 2355 | // we can't move physical categories |
| | 2356 | $categories_in_db = array(); |
| | 2357 | |
| | 2358 | $query = ' |
| | 2359 | SELECT |
| | 2360 | id, |
| | 2361 | name, |
| | 2362 | dir |
| | 2363 | FROM '.CATEGORIES_TABLE.' |
| | 2364 | WHERE id IN ('.implode(',', $category_ids).') |
| | 2365 | ;'; |
| | 2366 | $result = pwg_query($query); |
| | 2367 | while ($row = pwg_db_fetch_assoc($result)) |
| | 2368 | { |
| | 2369 | $categories_in_db[$row['id']] = $row; |
| | 2370 | // we break on error at first physical category detected |
| | 2371 | if (!empty($row['dir'])) |
| | 2372 | { |
| | 2373 | $row['name'] = strip_tags( |
| | 2374 | trigger_event( |
| | 2375 | 'render_category_name', |
| | 2376 | $row['name'], |
| | 2377 | 'ws_categories_move' |
| | 2378 | ) |
| | 2379 | ); |
| | 2380 | |
| | 2381 | return new PwgError( |
| | 2382 | 403, |
| | 2383 | sprintf( |
| | 2384 | 'Category %s (%u) is not a virtual category, you cannot move it', |
| | 2385 | $row['name'], |
| | 2386 | $row['id'] |
| | 2387 | ) |
| | 2388 | ); |
| | 2389 | } |
| | 2390 | } |
| | 2391 | |
| | 2392 | if (count($categories_in_db) != count($category_ids)) |
| | 2393 | { |
| | 2394 | $unknown_category_ids = array_diff($category_ids, array_keys($categories_in_db)); |
| | 2395 | |
| | 2396 | return new PwgError( |
| | 2397 | 403, |
| | 2398 | sprintf( |
| | 2399 | 'Category %u does not exist', |
| | 2400 | $unknown_category_ids[0] |
| | 2401 | ) |
| | 2402 | ); |
| | 2403 | } |
| | 2404 | |
| | 2405 | // does this parent exists? This check should be made in the |
| | 2406 | // move_categories function, not here |
| | 2407 | // |
| | 2408 | // 0 as parent means "move categories at gallery root" |
| | 2409 | if (!is_numeric($params['parent'])) |
| | 2410 | { |
| | 2411 | return new PwgError(403, 'Invalid parent input parameter'); |
| | 2412 | } |
| | 2413 | |
| | 2414 | if (0 != $params['parent']) { |
| | 2415 | $params['parent'] = intval($params['parent']); |
| | 2416 | $subcat_ids = get_subcat_ids(array($params['parent'])); |
| | 2417 | if (count($subcat_ids) == 0) |
| | 2418 | { |
| | 2419 | return new PwgError(403, 'Unknown parent category id'); |
| | 2420 | } |
| | 2421 | } |
| | 2422 | |
| | 2423 | $page['infos'] = array(); |
| | 2424 | $page['errors'] = array(); |
| | 2425 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
| | 2426 | move_categories($category_ids, $params['parent']); |
| | 2427 | invalidate_user_cache(); |
| | 2428 | |
| | 2429 | if (count($page['errors']) != 0) |
| | 2430 | { |
| | 2431 | return new PwgError(403, implode('; ', $page['errors'])); |
| | 2432 | } |
| | 2433 | } |
| | 2434 | |
| 2169 | | |
| 2170 | | $relative_dir = preg_replace('#^'.PHPWG_ROOT_PATH.'#', '', $conf['upload_dir']); |
| 2171 | | |
| 2172 | | if (!is_dir($conf['upload_dir'])) |
| 2173 | | { |
| 2174 | | if (!is_writable(dirname($conf['upload_dir']))) |
| 2175 | | { |
| 2176 | | return sprintf( |
| 2177 | | l10n('Create the "%s" directory at the root of your Piwigo installation'), |
| 2178 | | $relative_dir |
| 2179 | | ); |
| 2180 | | } |
| | 2474 | |
| | 2475 | if (!is_admin()) |
| | 2476 | { |
| | 2477 | return new PwgError(401, 'Access denied'); |
| | 2478 | } |
| | 2479 | |
| | 2480 | include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php'); |
| | 2481 | $plugins = new plugins(); |
| | 2482 | $plugins->sort_fs_plugins('name'); |
| | 2483 | $plugin_list = array(); |
| | 2484 | |
| | 2485 | foreach($plugins->fs_plugins as $plugin_id => $fs_plugin) |
| | 2486 | { |
| | 2487 | if (isset($plugins->db_plugins_by_id[$plugin_id])) |
| | 2488 | { |
| | 2489 | $state = $plugins->db_plugins_by_id[$plugin_id]['state']; |
| | 2490 | } |
| | 2491 | else |
| | 2492 | { |
| | 2493 | $state = 'uninstalled'; |
| | 2494 | } |
| | 2495 | |
| | 2496 | array_push( |
| | 2497 | $plugin_list, |
| | 2498 | array( |
| | 2499 | 'id' => $plugin_id, |
| | 2500 | 'name' => $fs_plugin['name'], |
| | 2501 | 'version' => $fs_plugin['version'], |
| | 2502 | 'state' => $state, |
| | 2503 | 'description' => $fs_plugin['description'], |
| | 2504 | ) |
| | 2505 | ); |
| | 2506 | } |
| | 2507 | |
| | 2508 | return $plugin_list; |
| | 2509 | } |
| | 2510 | |
| | 2511 | function ws_plugins_performAction($params, &$service) |
| | 2512 | { |
| | 2513 | global $template; |
| | 2514 | |
| | 2515 | if (!is_admin()) |
| | 2516 | { |
| | 2517 | return new PwgError(401, 'Access denied'); |
| | 2518 | } |
| | 2519 | |
| | 2520 | if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token']) |
| | 2521 | { |
| | 2522 | return new PwgError(403, 'Invalid security token'); |
| | 2523 | } |
| | 2524 | |
| | 2525 | define('IN_ADMIN', true); |
| | 2526 | include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php'); |
| | 2527 | $plugins = new plugins(); |
| | 2528 | $errors = $plugins->perform_action($params['action'], $params['plugin']); |
| | 2529 | |
| | 2530 | |
| | 2531 | if (!empty($errors)) |
| | 2532 | { |
| | 2533 | return new PwgError(500, $errors); |
| 2184 | | if (!is_writable($conf['upload_dir'])) |
| 2185 | | { |
| 2186 | | @chmod($conf['upload_dir'], 0777); |
| 2187 | | |
| 2188 | | if (!is_writable($conf['upload_dir'])) |
| 2189 | | { |
| 2190 | | return sprintf( |
| 2191 | | l10n('Give write access (chmod 777) to "%s" directory at the root of your Piwigo installation'), |
| 2192 | | $relative_dir |
| 2193 | | ); |
| 2194 | | } |
| 2195 | | } |
| 2196 | | } |
| 2197 | | |
| 2198 | | return null; |
| | 2537 | if (in_array($params['action'], array('activate', 'deactivate'))) |
| | 2538 | { |
| | 2539 | $template->delete_compiled_templates(); |
| | 2540 | } |
| | 2541 | return true; |
| | 2542 | } |
| | 2543 | } |
| | 2544 | |
| | 2545 | function ws_themes_performAction($params, &$service) |
| | 2546 | { |
| | 2547 | global $template; |
| | 2548 | |
| | 2549 | if (!is_admin()) |
| | 2550 | { |
| | 2551 | return new PwgError(401, 'Access denied'); |
| | 2552 | } |
| | 2553 | |
| | 2554 | if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token']) |
| | 2555 | { |
| | 2556 | return new PwgError(403, 'Invalid security token'); |
| | 2557 | } |
| | 2558 | |
| | 2559 | define('IN_ADMIN', true); |
| | 2560 | include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php'); |
| | 2561 | $themes = new themes(); |
| | 2562 | $errors = $themes->perform_action($params['action'], $params['theme']); |
| | 2563 | |
| | 2564 | if (!empty($errors)) |
| | 2565 | { |
| | 2566 | return new PwgError(500, $errors); |
| | 2567 | } |
| | 2568 | else |
| | 2569 | { |
| | 2570 | if (in_array($params['action'], array('activate', 'deactivate'))) |
| | 2571 | { |
| | 2572 | $template->delete_compiled_templates(); |
| | 2573 | } |
| | 2574 | return true; |
| | 2575 | } |