is_mimetype()) { continue; } foreach($types as $type) { $derivative = new DerivativeImage($type, $src_image); if ($type != $derivative->get_type()) { continue; } if (@filemtime($derivative->get_path())===false) { $urls[] = $derivative->get_url().$uid; } } if (count($urls)>=$max_urls and !$is_last) { break; } } if ($is_last) { $start_id = 0; } } while (count($urls)<$max_urls and $start_id); $ret = array(); if ($start_id) { $ret['next_page'] = $start_id; } $ret['urls'] = $urls; return $ret; } /** * API method * Returns Piwigo version * @param mixed[] $params */ function ws_getVersion($params, &$service) { return PHPWG_VERSION; } /** * API method * Returns general informations about the installation * @param mixed[] $params */ function ws_getInfos($params, &$service) { $infos['version'] = PHPWG_VERSION; $query = 'SELECT COUNT(*) FROM '.IMAGES_TABLE.';'; list($infos['nb_elements']) = pwg_db_fetch_row(pwg_query($query)); $query = 'SELECT COUNT(*) FROM '.CATEGORIES_TABLE.';'; list($infos['nb_categories']) = pwg_db_fetch_row(pwg_query($query)); $query = 'SELECT COUNT(*) FROM '.CATEGORIES_TABLE.' WHERE dir IS NULL;'; list($infos['nb_virtual']) = pwg_db_fetch_row(pwg_query($query)); $query = 'SELECT COUNT(*) FROM '.CATEGORIES_TABLE.' WHERE dir IS NOT NULL;'; list($infos['nb_physical']) = pwg_db_fetch_row(pwg_query($query)); $query = 'SELECT COUNT(*) FROM '.IMAGE_CATEGORY_TABLE.';'; list($infos['nb_image_category']) = pwg_db_fetch_row(pwg_query($query)); $query = 'SELECT COUNT(*) FROM '.TAGS_TABLE.';'; list($infos['nb_tags']) = pwg_db_fetch_row(pwg_query($query)); $query = 'SELECT COUNT(*) FROM '.IMAGE_TAG_TABLE.';'; list($infos['nb_image_tag']) = pwg_db_fetch_row(pwg_query($query)); $query = 'SELECT COUNT(*) FROM '.USERS_TABLE.';'; list($infos['nb_users']) = pwg_db_fetch_row(pwg_query($query)); $query = 'SELECT COUNT(*) FROM `'.GROUPS_TABLE.'`;'; list($infos['nb_groups']) = pwg_db_fetch_row(pwg_query($query)); $query = 'SELECT COUNT(*) FROM '.COMMENTS_TABLE.';'; list($infos['nb_comments']) = pwg_db_fetch_row(pwg_query($query)); // first element if ($infos['nb_elements'] > 0) { $query = 'SELECT MIN(date_available) FROM '.IMAGES_TABLE.';'; list($infos['first_date']) = pwg_db_fetch_row(pwg_query($query)); } // unvalidated comments if ($infos['nb_comments'] > 0) { $query = 'SELECT COUNT(*) FROM '.COMMENTS_TABLE.' WHERE validated=\'false\';'; list($infos['nb_unvalidated_comments']) = pwg_db_fetch_row(pwg_query($query)); } // Cache size // TODO for real later $infos['cache_size'] = 4242; foreach ($infos as $name => $value) { $output[] = array( 'name' => $name, 'value' => $value, ); } return array('infos' => new PwgNamedArray($output, 'item')); } /** * API method * Calculates and returns the size of the cache * @param mixed[] $params */ function ws_getCacheSize($params, &$service) { // Cache size $infos['cache_size'] = 4444; /* Multiples sizes */ $custom = 1; $huge = 2; $extra_large = 3; $large = 4; $medium = 5; $small = 6; $extra_small = 7; $tiny = 8; $thumbnail = 9; $squarre = 10; $all = $squarre + $thumbnail + $tiny + $extra_small + $small + $medium + $large + $extra_large + $huge + $custom; $infos['msizes'] = [$all, $squarre, $thumbnail, $tiny, $extra_small, $small, $medium, $large, $extra_large, $huge, $custom]; $infos['last_time_calc'] = "now"; foreach ($infos as $name => $value) { $output[] = array( 'name' => $name, 'value' => $value, ); } return array('infos' => new PwgNamedArray($output, 'item')); } /** * API method * Adds images to the caddie * @param mixed[] $params * @option int[] image_id */ function ws_caddie_add($params, &$service) { global $user; $query = ' SELECT id FROM '. IMAGES_TABLE .' LEFT JOIN '. CADDIE_TABLE .' ON id=element_id AND user_id='. $user['id'] .' WHERE id IN ('. implode(',',$params['image_id']) .') AND element_id IS NULL ;'; $result = array_from_query($query, 'id'); $datas = array(); foreach ($result as $id) { $datas[] = array( 'element_id' => $id, 'user_id' => $user['id'], ); } if (count($datas)) { mass_inserts( CADDIE_TABLE, array('element_id','user_id'), $datas ); } return count($datas); } /** * API method * Deletes rates of an user * @param mixed[] $params * @option int user_id * @option string anonymous_id (optional) */ function ws_rates_delete($params, &$service) { $query = ' DELETE FROM '. RATE_TABLE .' WHERE user_id='. $params['user_id']; if (!empty($params['anonymous_id'])) { $query .= ' AND anonymous_id=\''.$params['anonymous_id'].'\''; } if (!empty($params['image_id'])) { $query .= ' AND element_id='.$params['image_id']; } $changes = pwg_db_changes(pwg_query($query)); if ($changes) { include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php'); update_rating_score(); } return $changes; } /** * API method * Performs a login * @param mixed[] $params * @option string username * @option string password */ function ws_session_login($params, &$service) { if (try_log_user($params['username'], $params['password'], false)) { return true; } return new PwgError(999, 'Invalid username/password'); } /** * API method * Performs a logout * @param mixed[] $params */ function ws_session_logout($params, &$service) { if (!is_a_guest()) { logout_user(); } return true; } /** * API method * Returns info about the current user * @param mixed[] $params */ function ws_session_getStatus($params, &$service) { global $user, $conf; $res['username'] = is_a_guest() ? 'guest' : stripslashes($user['username']); foreach ( array('status', 'theme', 'language') as $k ) { $res[$k] = $user[$k]; } $res['pwg_token'] = get_pwg_token(); $res['charset'] = get_pwg_charset(); list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); $res['current_datetime'] = $dbnow; $res['version'] = PHPWG_VERSION; // Piwigo Remote Sync does not support receiving the available sizes $piwigo_remote_sync_agent = 'Apache-HttpClient/'; if (!isset($_SERVER['HTTP_USER_AGENT']) or substr($_SERVER['HTTP_USER_AGENT'], 0, strlen($piwigo_remote_sync_agent)) !== $piwigo_remote_sync_agent) { $res['available_sizes'] = array_keys(ImageStdParams::get_defined_type_map()); } if (is_admin()) { $res['upload_file_types'] = implode( ',', array_unique( array_map( 'strtolower', $conf['upload_form_all_types'] ? $conf['file_ext'] : $conf['picture_ext'] ) ) ); $res['upload_form_chunk_size'] = $conf['upload_form_chunk_size']; } return $res; } /** * API method * Returns lines of users activity */ function ws_getActivityList($param, &$service) { global $conf; /* Test Lantency */ // sleep(1); $output_lines = array(); $current_key = ''; $query = ' SELECT activity_id, performed_by, object, action, session_idx, ip_address, occured_on, details, '.$conf['user_fields']['username'].' AS username FROM '.ACTIVITY_TABLE.' JOIN '.USERS_TABLE.' AS u ON performed_by = u.'.$conf['user_fields']['id'].' ORDER BY activity_id DESC ;'; $line_id = 0; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { $row['details'] = str_replace('`groups`', 'groups', $row['details']); $row['details'] = str_replace('`rank`', 'rank', $row['details']); $details = unserialize($row['details']); if (isset($details['method'])) { $detailsType = 'method'; } if (isset($details['script'])) { $detailsType = 'script'; } $line_key = $row['session_idx'].'~'.$row['object'].'~'.$row['action'].'~'; // idx~photo~add if ($line_key === $current_key) { // j'incrémente le counter de la ligne précédente $output_lines[count($output_lines)-1]['counter']++; } else { list($date, $hour) = explode(' ', $row['occured_on']); // New line $output_lines[] = array( 'id' => $line_id, 'object' => $row['object'], 'action' => $row['action'], 'ip_address' => $row['ip_address'], 'date' => format_date($date), 'hour' => $hour, 'username' => $row['username'], 'user_id' => $row['performed_by'], 'detailsType' => $detailsType, 'details' => $details, 'counter' => 1, ); $current_key = $line_key; $line_id++; } } return $output_lines; } /** * API method * Returns lines of users activity */ function ws_activity_downloadLog($param, &$service) { global $conf; $output_lines = array(); $query = ' SELECT activity_id, performed_by, object, object_id, action, ip_address, occured_on, details, '.$conf['user_fields']['username'].' AS username FROM '.ACTIVITY_TABLE.' JOIN '.USERS_TABLE.' AS u ON performed_by = u.'.$conf['user_fields']['id'].' ORDER BY activity_id DESC ;'; $result = pwg_query($query); array_push($output_lines, ['User', 'ID_User', 'Object', 'Object_ID', 'Action', 'Date', 'Hour', 'IP_Address', 'Details']); while ($row = pwg_db_fetch_assoc($result)) { $row['details'] = str_replace('`groups`', 'groups', $row['details']); $row['details'] = str_replace('`rank`', 'rank', $row['details']); list($date, $hour) = explode(' ', $row['occured_on']); $output_lines[] = array( 'username' => $row['username'], 'user_id' => $row['performed_by'], 'object' => $row['object'], 'object_id' => $row['object_id'], 'action' => $row['action'], 'date' => $date, 'hour' => $hour, 'ip_address' => $row['ip_address'], 'details' => $row['details'], ); } header('Content-type: application/csv'); header('Content-Disposition: attachment; filename='.date('YmdGis').'piwigo_activity_log.csv'); header("Content-Transfer-Encoding: UTF-8"); $f = fopen('php://output', 'w'); foreach ($output_lines as $line) { fputcsv($f, $line, ";"); } fclose($f); } ?>