function ws_images_addFlickr($photo, &$service) { if (!is_admin()) { return new PwgError(403, 'Forbidden'); } global $conf; if (empty($conf['flickr2piwigo']['api_key']) or empty($conf['flickr2piwigo']['secret_key'])) { return new PwgError(null, l10n('Please fill your API keys on the configuration tab')); } include_once PHPWG_ROOT_PATH . 'admin/include/functions.php'; include_once PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php'; include_once FLICKR_PATH . 'include/functions.inc.php'; if (test_remote_download() === false) { return new PwgError(null, l10n('No download method available')); } // init flickr API include_once FLICKR_PATH . 'include/phpFlickr/phpFlickr.php'; $flickr = new phpFlickr($conf['flickr2piwigo']['api_key'], $conf['flickr2piwigo']['secret_key']); $flickr->enableCache('fs', FLICKR_FS_CACHE); // user $u = $flickr->test_login(); if ($u === false or empty($_SESSION['phpFlickr_auth_token'])) { return new PwgError(403, l10n('API not authenticated')); } // photos infos $photo_f = $flickr->photos_getInfo($photo['id']); $photo = array_merge($photo, $photo_f['photo']); $photo['url'] = $flickr->get_biggest_size($photo['id'], 'original'); $photo['path'] = FLICKR_FS_CACHE . 'flickr-' . $u['username'] . '-' . $photo['id'] . '.' . get_extension($photo['url']); // copy file if (download_remote_file($photo['url'], $photo['path']) == false) { return new PwgError(null, l10n('Can\'t download file')); } // category if (!preg_match('#^[0-9]+$#', $photo['category'])) { $categories_names = explode(',', $photo['category']); $photo['category'] = array(); foreach ($categories_names as $category_name) { $query = ' SELECT id FROM ' . CATEGORIES_TABLE . ' WHERE LOWER(name) = "' . strtolower($category_name) . '" ;'; $result = pwg_query($query); if (pwg_db_num_rows($result)) { list($cat_id) = pwg_db_fetch_row($result); $photo['category'][] = $cat_id; } else { $cat = create_virtual_category($category_name); $photo['category'][] = $cat['id']; } } } else { $photo['category'] = array($photo['category']); } // add photo $photo['image_id'] = add_uploaded_file($photo['path'], basename($photo['path']), $photo['category']); // do some updates if (!empty($photo['fills'])) { $photo['fills'] = rtrim($photo['fills'], ','); $photo['fills'] = explode(',', $photo['fills']); $updates = array(); if (in_array('fill_name', $photo['fills'])) { $updates['name'] = pwg_db_real_escape_string($photo['title']); } if (in_array('fill_posted', $photo['fills'])) { $updates['date_available'] = date('Y-m-d H:i:s', $photo['dates']['posted']); } if (in_array('fill_taken', $photo['fills'])) { $updates['date_creation'] = $photo['dates']['taken']; } if (in_array('fill_author', $photo['fills'])) { $updates['author'] = pwg_db_real_escape_string($photo['owner']['username']); } if (in_array('fill_description', $photo['fills'])) { $updates['comment'] = pwg_db_real_escape_string(@$photo['description']); } if (in_array('fill_geotag', $photo['fills']) and !empty($photo['location'])) { $updates['latitude'] = pwg_db_real_escape_string($photo['location']['latitude']); $updates['longitude'] = pwg_db_real_escape_string($photo['location']['longitude']); } if (in_array('level', $photo['fills']) && !$photo['visibility']['ispublic']) { $updates['level'] = 8; if ($photo['visibility']['isfamily']) { $updates['level'] = 4; } if ($photo['visibility']['isfriend']) { $updates['level'] = 2; } } if (count($updates)) { single_update(IMAGES_TABLE, $updates, array('id' => $photo['image_id'])); } if (!empty($photo['tags']['tag']) and in_array('fill_tags', $photo['fills'])) { $raw_tags = array_map(create_function('$t', 'return $t["_content"];'), $photo['tags']['tag']); $raw_tags = implode(',', $raw_tags); set_tags(get_tag_ids($raw_tags), $photo['image_id']); } } return l10n('Photo "%s" imported', $photo['title']); }
function plugin_install($id, $version, &$errors) { global $conf; /* ****************************************************************** */ /* **************** BEGIN - Data preparation in vars **************** */ /* ****************************************************************** */ $defaultPH = array(); // Set current plugin version in config table $plugin = PHInfos(PH_PATH); $version = $plugin['version']; // Default global parameters for Prune History conf // ------------------------------------------------- $defaultPH = array('PHVersion' => $version, 'AUTOPRUNE' => 'false', 'RANGEVALUE' => '0', 'RANGE' => '0'); // Create Prune History conf if not already exists // ------------------------------------------------ $query = ' SELECT param FROM ' . CONFIG_TABLE . ' WHERE param = "PruneHistory" ;'; $count = pwg_db_num_rows(pwg_query($query)); if ($count == 0) { $q = ' INSERT INTO ' . CONFIG_TABLE . ' (param, value, comment) VALUES ("PruneHistory","' . pwg_db_real_escape_string(serialize($defaultPH)) . '","Prune History parameters") ;'; pwg_query($q); } }
function install($plugin_version, &$errors = array()) { global $conf, $prefixeTable; $query = ' CREATE TABLE IF NOT EXISTS ' . $prefixeTable . 'pfemail_mailboxes ( id int(11) NOT NULL AUTO_INCREMENT, path varchar(255) NOT NULL, login varchar(255) NOT NULL, password varchar(255) NOT NULL, category_id smallint(5) unsigned DEFAULT NULL, moderated enum(\'true\',\'false\') NOT NULL DEFAULT \'true\', PRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;'; pwg_query($query); $query = ' CREATE TABLE IF NOT EXISTS ' . $prefixeTable . 'pfemail_pendings ( image_id mediumint(8) unsigned NOT NULL, state varchar(255) NOT NULL, added_on datetime NOT NULL, validated_by mediumint(8) unsigned DEFAULT NULL, from_name varchar(255) DEFAULT NULL, from_address varchar(255) DEFAULT NULL, subject varchar(255) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;'; pwg_query($query); $result = pwg_query('SHOW COLUMNS FROM `' . GROUPS_TABLE . '` LIKE "pfemail_notify";'); if (!pwg_db_num_rows($result)) { pwg_query('ALTER TABLE ' . GROUPS_TABLE . ' ADD pfemail_notify enum(\'true\', \'false\') DEFAULT \'false\';'); } $this->installed = true; }
function NBMS_Save_Profile() { global $conf, $user; include_once PHPWG_ROOT_PATH . 'admin/include/functions_notification_by_mail.inc.php'; $query = ' SELECT * FROM ' . USER_MAIL_NOTIFICATION_TABLE . ' WHERE user_id = \'' . $user['id'] . '\' '; $count = pwg_db_num_rows(pwg_query($query)); if ($count == 0) { $inserts = array(); $check_key_list = array(); // Calculate key $nbm_user['check_key'] = find_available_check_key(); // Save key array_push($check_key_list, $nbm_user['check_key']); // Insert new nbm_users array_push($inserts, array('user_id' => $user['id'], 'check_key' => $nbm_user['check_key'], 'enabled' => $_POST['NBM_Subscription'])); mass_inserts(USER_MAIL_NOTIFICATION_TABLE, array('user_id', 'check_key', 'enabled'), $inserts); } elseif ($count != 0 and !empty($_POST['NBM_Subscription']) && in_array($_POST['NBM_Subscription'], array('true', 'false'))) { $query = ' UPDATE ' . USER_MAIL_NOTIFICATION_TABLE . ' SET enabled = \'' . $_POST['NBM_Subscription'] . '\' WHERE user_id = \'' . $user['id'] . '\';'; pwg_query($query); } }
function install($plugin_version, &$errors = array()) { // create categories.downloadable (true/false) $result = pwg_query('SHOW COLUMNS FROM `' . CATEGORIES_TABLE . '` LIKE "external_reference";'); if (!pwg_db_num_rows($result)) { pwg_query('ALTER TABLE `' . CATEGORIES_TABLE . '` ADD `external_reference` varchar(255) DEFAULT NULL;'); } $this->installed = true; }
function osm_items_have_latlon($items) { $query = ' SELECT id FROM ' . IMAGES_TABLE . ' WHERE latitude IS NOT NULL AND id IN (' . implode(',', $items) . ') ORDER BY NULL LIMIT 0,1'; if (pwg_db_num_rows(pwg_query($query)) > 0) { return true; } return false; }
function install($plugin_version, &$errors = array()) { global $conf, $prefixeTable; $result = pwg_query('SHOW COLUMNS FROM `' . IMAGES_TABLE . '` LIKE "pqv_validated";'); if (!pwg_db_num_rows($result)) { pwg_query('ALTER TABLE ' . IMAGES_TABLE . ' ADD pqv_validated enum(\'true\', \'false\') DEFAULT NULL;'); } $result = pwg_query('SHOW COLUMNS FROM `' . GROUPS_TABLE . '` LIKE "pqv_enabled";'); if (!pwg_db_num_rows($result)) { pwg_query('ALTER TABLE ' . GROUPS_TABLE . ' ADD pqv_enabled enum(\'true\', \'false\') DEFAULT \'false\';'); } $this->installed = true; }
function get_oauth_id($user_id) { $query = ' SELECT oauth_id FROM ' . USER_INFOS_TABLE . ' WHERE user_id = ' . $user_id . ' AND oauth_id != "" ;'; $result = pwg_query($query); if (!pwg_db_num_rows($result)) { return null; } else { list($oauth_id) = pwg_db_fetch_row($result); return $oauth_id; } }
/** deletes the permalink associated with a category * returns true on success * @param int cat_id the target category id * @param boolean save if true, the current category-permalink association * is saved in the old permalinks table in case external links hit it */ function delete_cat_permalink($cat_id, $save) { global $page, $cache; $query = ' SELECT permalink FROM ' . CATEGORIES_TABLE . ' WHERE id=\'' . $cat_id . '\' ;'; $result = pwg_query($query); if (pwg_db_num_rows($result)) { list($permalink) = pwg_db_fetch_row($result); } if (!isset($permalink)) { // no permalink; nothing to do return true; } if ($save) { $old_cat_id = get_cat_id_from_old_permalink($permalink); if (isset($old_cat_id) and $old_cat_id != $cat_id) { $page['errors'][] = sprintf(l10n('Permalink %s has been previously used by album %s. Delete from the permalink history first'), $permalink, $old_cat_id); return false; } } $query = ' UPDATE ' . CATEGORIES_TABLE . ' SET permalink=NULL WHERE id=' . $cat_id . ' LIMIT 1'; pwg_query($query); unset($cache['cat_names']); //force regeneration if ($save) { if (isset($old_cat_id)) { $query = ' UPDATE ' . OLD_PERMALINKS_TABLE . ' SET date_deleted=NOW() WHERE cat_id=' . $cat_id . ' AND permalink=\'' . $permalink . '\''; } else { $query = ' INSERT INTO ' . OLD_PERMALINKS_TABLE . ' (permalink, cat_id, date_deleted) VALUES ( \'' . $permalink . '\',' . $cat_id . ',NOW() )'; } pwg_query($query); } return true; }
function vjs_add_tab($sheets, $id) { if ($id == 'photo') { $query = "SELECT id FROM " . IMAGES_TABLE . " WHERE " . SQL_VIDEOS . " AND id = " . $_GET['image_id'] . ";"; $result = pwg_query($query); if (!pwg_db_num_rows($result)) { return $sheets; } $sheets['videojs'] = array('caption' => 'VideoJS', 'url' => get_root_url() . 'admin.php?page=plugin&section=piwigo-videojs/admin/admin_photo.php&image_id=' . $_GET['image_id']); unset($sheets['coi'], $sheets['update']); unset($sheets['rotate'], $sheets['update']); /* Replace the RotateImage by a our own */ $sheets['rotate'] = array('caption' => 'Rotate', 'url' => get_root_url() . 'admin.php?page=plugin&section=piwigo-videojs/admin/admin_rotate.php&image_id=' . $_GET['image_id']); } return $sheets; }
function install($plugin_version, &$errors = array()) { global $conf; if (empty($conf['oauth'])) { conf_update_param('oauth', $this->default_conf, true); } else { $conf['oauth'] = safe_unserialize($conf['oauth']); if (!isset($conf['oauth']['allow_merge_accounts'])) { $conf['oauth']['allow_merge_accounts'] = true; conf_update_param('oauth', $conf['oauth']); } } $result = pwg_query('SHOW COLUMNS FROM `' . USER_INFOS_TABLE . '` LIKE "oauth_id";'); if (!pwg_db_num_rows($result)) { pwg_query('ALTER TABLE `' . USER_INFOS_TABLE . '` ADD `oauth_id` VARCHAR(255) DEFAULT NULL;'); } // move field from users table to user_infos $result = pwg_query('SHOW COLUMNS FROM `' . USERS_TABLE . '` LIKE "oauth_id";'); if (pwg_db_num_rows($result)) { $query = ' UPDATE `' . USER_INFOS_TABLE . '` AS i SET oauth_id = ( SELECT oauth_id FROM `' . USERS_TABLE . '` AS u WHERE u.' . $conf['user_fields']['id'] . ' = i.user_id ) ;'; pwg_query($query); pwg_query('ALTER TABLE `' . USERS_TABLE . '` DROP `oauth_id`;'); } // add 'total' and 'enabled' fields in hybridauth conf file if (file_exists($this->file)) { $hybridauth_conf = (include $this->file); if (!isset($hybridauth_conf['total'])) { $enabled = array_filter($hybridauth_conf['providers'], create_function('$p', 'return $p["enabled"];')); $hybridauth_conf['total'] = count($hybridauth_conf['providers']); $hybridauth_conf['enabled'] = count($enabled); $content = "<?php\ndefined('PHPWG_ROOT_PATH') or die('Hacking attempt!');\n\nreturn "; $content .= var_export($hybridauth_conf, true); $content .= ";\n?>"; file_put_contents($this->file, $content); } } }
function install($plugin_version, &$errors = array()) { global $conf; // add a new column to existing table $result = pwg_query('SHOW COLUMNS FROM `' . CATEGORIES_TABLE . '` LIKE "polaroid_active";'); if (!pwg_db_num_rows($result)) { pwg_query('ALTER TABLE `' . CATEGORIES_TABLE . '` ADD `polaroid_active` enum(\'true\', \'false\') default \'false\';'); } $config = array('apply_to_albums' => 'all'); // load existing config parameters if (!empty($conf['polaroid'])) { $conf['polaroid'] = safe_unserialize($conf['polaroid']); foreach ($conf['polaroid'] as $key => $value) { $config[$key] = $value; } } conf_update_param('polaroid', $config, true); $this->installed = true; }
function install($plugin_version, &$errors = array()) { global $conf, $prefixeTable; $query = ' CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'pshare_keys` ( `pshare_key_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `uuid` varchar(255) NOT NULL, `user_id` mediumint(8) unsigned NOT NULL, `image_id` mediumint(8) unsigned NOT NULL, `sent_to` varchar(255) NOT NULL, `created_on` datetime NOT NULL, `duration` int(10) unsigned DEFAULT NULL, `expire_on` datetime NOT NULL, `is_valid` enum(\'true\',\'false\') NOT NULL DEFAULT \'true\', PRIMARY KEY (`pshare_key_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;'; pwg_query($query); $query = ' CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'pshare_log` ( `pshare_log_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `pshare_key_idx` int(10) unsigned NOT NULL, `occured_on` datetime NOT NULL, `type` enum(\'download\',\'visit\') NOT NULL DEFAULT \'visit\', `ip_address` varchar(15) NOT NULL DEFAULT \'\', `user_id` mediumint(8) unsigned NOT NULL, `format_id` int(11) unsigned default NULL, PRIMARY KEY (`pshare_log_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;'; pwg_query($query); $result = pwg_query('SHOW COLUMNS FROM `' . GROUPS_TABLE . '` LIKE "pshare_enabled";'); if (!pwg_db_num_rows($result)) { pwg_query('ALTER TABLE ' . GROUPS_TABLE . ' ADD pshare_enabled enum(\'true\', \'false\') DEFAULT \'false\';'); } $result = pwg_query('SHOW COLUMNS FROM `' . $prefixeTable . 'pshare_log` LIKE "format_id";'); if (!pwg_db_num_rows($result)) { pwg_query('ALTER TABLE ' . $prefixeTable . 'pshare_log ADD format_id int(11) DEFAULT NULL;'); } $this->installed = true; }
function plugin_install($id, $version, &$errors) { global $conf; // Set current plugin version in config table $plugin = CM_Infos(CM_PATH); $version = $plugin['version']; $default = array('CMVersion' => $version, 'CM_No_Comment_Anonymous' => 'false', 'CM_GROUPCOMM' => 'false', 'CM_ALLOWCOMM_GROUP' => -1, 'CM_GROUPVALID1' => 'false', 'CM_VALIDCOMM1_GROUP' => -1, 'CM_GROUPVALID2' => 'false', 'CM_VALIDCOMM2_GROUP' => -1); $query = ' SELECT param FROM ' . CONFIG_TABLE . ' WHERE param = "CommentsManager" ;'; $count = pwg_db_num_rows(pwg_query($query)); if ($count == 0) { $q = ' INSERT INTO ' . CONFIG_TABLE . ' (param, value, comment) VALUES ("CommentsManager","' . pwg_db_real_escape_string(serialize($default)) . '","Comments Access Manager parameters") ;'; pwg_query($q); } }
/** * interrupt normal login if corresponding to an oauth user */ function oauth_try_log_user($success, $username) { global $conf, $redirect_to; $query = ' SELECT oauth_id FROM ' . USER_INFOS_TABLE . ' AS i INNER JOIN ' . USERS_TABLE . ' AS u ON i.user_id = u.' . $conf['user_fields']['id'] . ' WHERE ' . $conf['user_fields']['username'] . ' = "' . pwg_db_real_escape_string($username) . '" AND oauth_id != "" ;'; $result = pwg_query($query); if (pwg_db_num_rows($result)) { list($oauth_id) = pwg_db_fetch_row($result); list($provider) = explode('---', $oauth_id, 2); $_SESSION['page_errors'][] = l10n('You registered with a %s account, please sign in with the same account.', $provider); $redirect_to = get_root_url() . 'identification.php'; // variable used by identification.php return true; } return false; }
function plugin_activate($id, $version, &$errors) { global $conf; include_once HIPE_PATH . 'include/dbupgrade.inc.php'; /* Check for upgrade from 2.0.0 to 2.0.1 */ /* *************************************** */ $query = ' SELECT param FROM ' . CONFIG_TABLE . ' WHERE param = "nbc_HistoryIPExcluder" ;'; $count = pwg_db_num_rows(pwg_query($query)); if ($count == 1) { /* upgrade from version 2.0.0 to 2.0.1 */ /* ************************************ */ upgrade_200(); } $query = ' SELECT param FROM ' . CONFIG_TABLE . ' WHERE param = "HistoryIPConfig" ;'; $count = pwg_db_num_rows(pwg_query($query)); if ($count == 0) { /* upgrade from version 2.1.0 to 2.1.1 */ /* ************************************ */ upgrade_210(); } /* upgrade from version 2.1.1 to 2.2.0 */ /* *********************************** */ $HIPE_Config = unserialize($conf['HistoryIPConfig']); if ($HIPE_Config['Version'] == '2.1.1') { upgrade_211(); } /* Global version number upgrade */ /* ***************************** */ global_version_update(); }
function plugin_install($id, $version, &$errors) { global $prefixeTable, $conf; // Set current plugin version in config table $plugin = RegFluxBB_Infos(REGFLUXBB_PATH); $version = $plugin['version']; // Default global parameters for RegisterFluxBB conf // ------------------------------------------------- $defaultRegFluxBB = array('REGFLUXBB_VERSION' => $version, 'FLUXBB_PREFIX' => '', 'FLUXBB_ADMIN' => '', 'FLUXBB_GUEST' => '', 'FLUXBB_DEL_PT' => 'false', 'FLUXBB_CONFIRM' => 'false', 'FLUXBB_DETAIL' => 'false', 'FLUXBB_UAM_LINK' => 'false', 'FLUXBB_GROUP' => ''); // Create RegisterFluxBB conf if not already exists // ------------------------------------------------ $query = ' SELECT param FROM ' . CONFIG_TABLE . ' WHERE param = "Register_FluxBB" ;'; $count = pwg_db_num_rows(pwg_query($query)); if ($count == 0) { $q = ' INSERT INTO ' . CONFIG_TABLE . ' (param, value, comment) VALUES ("Register_FluxBB","' . pwg_db_real_escape_string(serialize($defaultRegFluxBB)) . '","Register_FluxBB parameters") ;'; pwg_query($q); } // Create relation table between FluxBB and Piwigo // ----------------------------------------------- $q = ' CREATE TABLE IF NOT EXISTS ' . Register_FluxBB_ID_TABLE . ' ( id_user_pwg smallint(5) NOT NULL default "0", id_user_FluxBB int(10) NOT NULL default "0", PwdSynch varchar(3) default NULL, PRIMARY KEY (id_user_pwg), KEY id_user_pwg (id_user_pwg, id_user_FluxBB, PwdSynch) ) ;'; pwg_query($q); }
if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } $upgrade_description = 'add "latitude" and "longitude" fields'; // add fields $query = ' ALTER TABLE ' . IMAGES_TABLE . ' ADD `latitude` DOUBLE(8, 6) DEFAULT NULL, ADD `longitude` DOUBLE(9, 6) DEFAULT NULL ;'; pwg_query($query); // add index $query = ' ALTER TABLE ' . IMAGES_TABLE . ' ADD INDEX `images_i6` (`latitude`) ;'; pwg_query($query); // search for old "lat" field $query = 'SHOW COLUMNS FROM ' . IMAGES_TABLE . ' LIKE "lat";'; if (pwg_db_num_rows(pwg_query($query))) { // duplicate non-null values $query = ' UPDATE ' . IMAGES_TABLE . ' SET latitude = lat, longitude = lon WHERE lat IS NOT NULL AND lon IS NOT NULL ;'; pwg_query($query); } echo "\n" . $upgrade_description . "\n";
} elseif ($conf['allow_random_representative']) { // searching a random representant among elements in sub-categories $image_id = get_random_image_in_category($row); } elseif ($row['count_categories'] > 0 and $row['count_images'] > 0) { // searching a random representant among representant of sub-categories $query = ' SELECT representative_picture_id FROM ' . CATEGORIES_TABLE . ' INNER JOIN ' . USER_CACHE_CATEGORIES_TABLE . ' ON id = cat_id and user_id = ' . $user['id'] . ' WHERE uppercats LIKE \'' . $row['uppercats'] . ',%\' AND representative_picture_id IS NOT NULL' . get_sql_condition_FandF(array('visible_categories' => 'id'), "\n AND") . ' ORDER BY ' . DB_RANDOM_FUNCTION . '() LIMIT 1 ;'; $subresult = pwg_query($query); if (pwg_db_num_rows($subresult) > 0) { list($image_id) = pwg_db_fetch_row($subresult); } } if (isset($image_id)) { if ($conf['representative_cache_on_subcats'] and $row['user_representative_picture_id'] != $image_id) { $user_representative_updates_for[$row['id']] = $image_id; } $row['representative_picture_id'] = $image_id; $image_ids[] = $image_id; $categories[] = $row; $category_ids[] = $row['id']; } unset($image_id); } if ($conf['display_fromto']) {
, ROUND(AVG(rate),2) AS average FROM ' . RATE_TABLE . ' WHERE element_id = ' . $picture['current']['id'] . ' ;'; list($rate_summary['count'], $rate_summary['average']) = pwg_db_fetch_row(pwg_query($query)); } $template->assign('rate_summary', $rate_summary); $user_rate = null; if ($conf['rate_anonymous'] or is_autorize_status(ACCESS_CLASSIC)) { if ($rate_summary['count'] > 0) { $query = 'SELECT rate FROM ' . RATE_TABLE . ' WHERE element_id = ' . $page['image_id'] . ' AND user_id = ' . $user['id']; if (!is_autorize_status(ACCESS_CLASSIC)) { $ip_components = explode('.', $_SERVER['REMOTE_ADDR']); if (count($ip_components) > 3) { array_pop($ip_components); } $anonymous_id = implode('.', $ip_components); $query .= ' AND anonymous_id = \'' . $anonymous_id . '\''; } $result = pwg_query($query); if (pwg_db_num_rows($result) > 0) { $row = pwg_db_fetch_assoc($result); $user_rate = $row['rate']; } } $template->assign('rating', array('F_ACTION' => add_url_params($url_self, array('action' => 'rate')), 'USER_RATE' => $user_rate, 'marks' => $conf['rate_items'])); } }
} $uid = '&b=' . time(); global $conf; $conf['question_mark_in_urls'] = $conf['php_extension_in_urls'] = true; $conf['derivative_url_style'] = 2; //script $qlimit = min(5000, ceil(max($image_count / 500, $max_urls))); $query_model = 'SELECT * FROM ' . IMAGES_TABLE . ' WHERE id < start_id ORDER BY id DESC LIMIT ' . $qlimit; $urls = array(); do { $result = pwg_query(str_replace('start_id', $start_id, $query_model)); $is_last = pwg_db_num_rows($result) < $qlimit; while ($row = pwg_db_fetch_assoc($result)) { $start_id = $row['id']; $src_image = new SrcImage($row); if ($src_image->is_mimetype()) { continue; } $derivative = new DerivativeImage(ImageStdParams::get_custom(9999, $conf['GThumb']['height']), $src_image); if (@filemtime($derivative->get_path()) === false) { $urls[] = $derivative->get_url() . $uid; } if (count($urls) >= $max_urls && !$is_last) { break; } } if ($is_last) {
/** * Add main toolbar to current page * @trigger loc_after_page_header */ function admintools_add_public_controller() { global $MultiView, $conf, $template, $page, $user, $picture; if (script_basename() == 'picture' and empty($picture['current'])) { return; } $url_root = get_root_url(); $tpl_vars = array(); if ($MultiView->is_admin()) { // full options for admin $tpl_vars['U_SITE_ADMIN'] = $url_root . 'admin.php?page='; $tpl_vars['MULTIVIEW'] = $MultiView->get_data(); $tpl_vars['USER'] = $MultiView->get_user(); $tpl_vars['CURRENT_USERNAME'] = $user['id'] == $conf['guest_id'] ? l10n('guest') : $user['username']; $tpl_vars['DELETE_CACHE'] = isset($conf['multiview_invalidate_cache']); if (($admin_lang = $MultiView->get_user_language()) !== false) { include_once PHPWG_ROOT_PATH . 'include/functions_mail.inc.php'; switch_lang_to($admin_lang); } } else { if ($conf['AdminTools']['public_quick_edit'] and script_basename() == 'picture' and $picture['current']['added_by'] == $user['id']) { // only "edit" button for photo owner } else { return; } } $tpl_vars['POSITION'] = $conf['AdminTools']['closed_position']; $tpl_vars['DEFAULT_OPEN'] = $conf['AdminTools']['default_open']; $tpl_vars['U_SELF'] = $MultiView->get_clean_url(true); // photo page if (script_basename() == 'picture') { $url_self = duplicate_picture_url(); $tpl_vars['IS_PICTURE'] = true; // admin can add to caddie and set representattive if ($MultiView->is_admin()) { $template->clear_assign(array('U_SET_AS_REPRESENTATIVE', 'U_PHOTO_ADMIN', 'U_CADDIE')); $template->set_prefilter('picture', 'admintools_remove_privacy'); $tpl_vars['U_CADDIE'] = add_url_params($url_self, array('action' => 'add_to_caddie')); $query = ' SELECT element_id FROM ' . CADDIE_TABLE . ' WHERE element_id = ' . $page['image_id'] . ' ;'; $tpl_vars['IS_IN_CADDIE'] = pwg_db_num_rows(pwg_query($query)) > 0; if (isset($page['category'])) { $tpl_vars['CATEGORY_ID'] = $page['category']['id']; $tpl_vars['U_SET_REPRESENTATIVE'] = add_url_params($url_self, array('action' => 'set_as_representative')); $tpl_vars['IS_REPRESENTATIVE'] = $page['category']['representative_picture_id'] == $page['image_id']; } $tpl_vars['U_ADMIN_EDIT'] = $url_root . 'admin.php?page=photo-' . $page['image_id'] . (isset($page['category']) ? '&cat_id=' . $page['category']['id'] : ''); } $tpl_vars['U_DELETE'] = add_url_params($url_self, array('delete' => '', 'pwg_token' => get_pwg_token())); // gets tags (full available list is loaded in ajax) include_once PHPWG_ROOT_PATH . 'admin/include/functions.php'; $query = ' SELECT id, name FROM ' . IMAGE_TAG_TABLE . ' AS it JOIN ' . TAGS_TABLE . ' AS t ON t.id = it.tag_id WHERE image_id = ' . $page['image_id'] . ' ;'; $tag_selection = get_taglist($query); $tpl_vars['QUICK_EDIT'] = array('img' => $picture['current']['derivatives']['square']->get_url(), 'name' => $picture['current']['name'], 'comment' => $picture['current']['comment'], 'author' => $picture['current']['author'], 'level' => $picture['current']['level'], 'date_creation' => substr($picture['current']['date_creation'], 0, 10), 'date_creation_time' => substr($picture['current']['date_creation'], 11, 5), 'tag_selection' => $tag_selection); } else { if ($MultiView->is_admin() and @$page['section'] == 'categories' and isset($page['category'])) { $url_self = duplicate_index_url(); $tpl_vars['IS_CATEGORY'] = true; $tpl_vars['CATEGORY_ID'] = $page['category']['id']; $template->clear_assign(array('U_EDIT', 'U_CADDIE')); $tpl_vars['U_ADMIN_EDIT'] = $url_root . 'admin.php?page=album-' . $page['category']['id']; if (!empty($page['items'])) { $tpl_vars['U_CADDIE'] = add_url_params($url_self, array('caddie' => 1)); } $tpl_vars['QUICK_EDIT'] = array('img' => null, 'name' => $page['category']['name'], 'comment' => $page['category']['comment']); if (!empty($page['category']['representative_picture_id'])) { $query = ' SELECT * FROM ' . IMAGES_TABLE . ' WHERE id = ' . $page['category']['representative_picture_id'] . ' ;'; $image_infos = pwg_db_fetch_assoc(pwg_query($query)); $tpl_vars['QUICK_EDIT']['img'] = DerivativeImage::get_one(IMG_SQUARE, $image_infos)->get_url(); } } } $template->assign(array('ADMINTOOLS_PATH' => './plugins/' . ADMINTOOLS_ID . '/', 'ato' => $tpl_vars)); $template->set_filename('ato_public_controller', realpath(ADMINTOOLS_PATH . 'template/public_controller.tpl')); $template->parse('ato_public_controller'); if ($MultiView->is_admin() && @$admin_lang !== false) { switch_lang_back(); } }
/** * Add configuration parameters from database to global $conf array * * @param string $condition SQL condition * @return void */ function load_conf_from_db($condition = '') { global $conf; $query = ' SELECT param, value FROM ' . CONFIG_TABLE . ' ' . (!empty($condition) ? 'WHERE ' . $condition : '') . ' ;'; $result = pwg_query($query); if (pwg_db_num_rows($result) == 0 and !empty($condition)) { fatal_error('No configuration data'); } while ($row = pwg_db_fetch_assoc($result)) { $val = isset($row['value']) ? $row['value'] : ''; // If the field is true or false, the variable is transformed into a boolean value. if ($val == 'true') { $val = true; } elseif ($val == 'false') { $val = false; } $conf[$row['param']] = $val; } trigger_notify('load_conf', $condition); }
$charset = 'iso-8859-1'; } $all_langs[$language] = array('count' => $row['count'], 'new_lang' => $new_lang, 'charset' => $charset); $upgrade_log .= ">>user_lang\t" . $language . "\t" . $row['count'] . "\n"; } $upgrade_log .= "\n"; // +-----------------------------------------------------------------------+ // get admin charset include PHPWG_ROOT_PATH . 'include/config_default.inc.php'; @(include PHPWG_ROOT_PATH . 'local/config/config.inc.php'); $admin_charset = 'iso-8859-1'; $query = ' SELECT language FROM ' . USER_INFOS_TABLE . ' WHERE user_id=' . $conf['webmaster_id']; $result = pwg_query($query); if (pwg_db_num_rows($result) == 0) { $query = ' SELECT language FROM ' . USER_INFOS_TABLE . ' WHERE status="webmaster" and adviser="false" LIMIT 1'; $result = pwg_query($query); } if ($row = pwg_db_fetch_assoc($result)) { $admin_charset = $all_langs[$row['language']]['charset']; } $upgrade_log .= ">>admin_charset\t" . $admin_charset . "\n"; // +-----------------------------------------------------------------------+ // get mysql version and structure of tables $mysql_version = mysql_get_server_info(); $upgrade_log .= ">>mysql_ver\t" . $mysql_version . "\n"; $all_tables = array();
/** * API method * Returns a list of missing derivatives (not generated yet) * @param mixed[] $params * @option string types (optional) * @option int[] ids * @option int max_urls * @option int prev_page (optional) */ function ws_getMissingDerivatives($params, &$service) { global $conf; if (empty($params['types'])) { $types = array_keys(ImageStdParams::get_defined_type_map()); } else { $types = array_intersect(array_keys(ImageStdParams::get_defined_type_map()), $params['types']); if (count($types) == 0) { return new PwgError(WS_ERR_INVALID_PARAM, "Invalid types"); } } $max_urls = $params['max_urls']; $query = 'SELECT MAX(id)+1, COUNT(*) FROM ' . IMAGES_TABLE . ';'; list($max_id, $image_count) = pwg_db_fetch_row(pwg_query($query)); if (0 == $image_count) { return array(); } $start_id = $params['prev_page']; if ($start_id <= 0) { $start_id = $max_id; } $uid = '&b=' . time(); $conf['question_mark_in_urls'] = $conf['php_extension_in_urls'] = true; $conf['derivative_url_style'] = 2; //script $qlimit = min(5000, ceil(max($image_count / 500, $max_urls / count($types)))); $where_clauses = ws_std_image_sql_filter($params, ''); $where_clauses[] = 'id<start_id'; if (!empty($params['ids'])) { $where_clauses[] = 'id IN (' . implode(',', $params['ids']) . ')'; } $query_model = ' SELECT id, path, representative_ext, width, height, rotation FROM ' . IMAGES_TABLE . ' WHERE ' . implode(' AND ', $where_clauses) . ' ORDER BY id DESC LIMIT ' . $qlimit . ' ;'; $urls = array(); do { $result = pwg_query(str_replace('start_id', $start_id, $query_model)); $is_last = pwg_db_num_rows($result) < $qlimit; while ($row = pwg_db_fetch_assoc($result)) { $start_id = $row['id']; $src_image = new SrcImage($row); if ($src_image->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; }
/** * Returns the auto login key for an user or false if the user is not found. * * @param int $user_id * @param int $time * @param string &$username fille with corresponding username * @return string|false */ function calculate_auto_login_key($user_id, $time, &$username) { global $conf; $query = ' SELECT ' . $conf['user_fields']['username'] . ' AS username , ' . $conf['user_fields']['password'] . ' AS password FROM ' . USERS_TABLE . ' WHERE ' . $conf['user_fields']['id'] . ' = ' . $user_id; $result = pwg_query($query); if (pwg_db_num_rows($result) > 0) { $row = pwg_db_fetch_assoc($result); $username = stripslashes($row['username']); $data = $time . $user_id . $username; $key = base64_encode(hash_hmac('sha1', $data, $conf['secret_key'] . $row['password'], true)); return $key; } return false; }
/** * API method * Returns a list of categories * @param mixed[] $params * @option int cat_id (optional) * @option bool recursive * @option bool public * @option bool tree_output * @option bool fullname */ function ws_categories_getList($params, &$service) { global $user, $conf; $where = array('1=1'); $join_type = 'INNER'; $join_user = $user['id']; if (!$params['recursive']) { if ($params['cat_id'] > 0) { $where[] = '( id_uppercat = ' . (int) $params['cat_id'] . ' OR id=' . (int) $params['cat_id'] . ' )'; } else { $where[] = 'id_uppercat IS NULL'; } } else { if ($params['cat_id'] > 0) { $where[] = 'uppercats ' . DB_REGEX_OPERATOR . ' \'(^|,)' . (int) $params['cat_id'] . '(,|$)\''; } } if ($params['public']) { $where[] = 'status = "public"'; $where[] = 'visible = "true"'; $join_user = $conf['guest_id']; } else { if (is_admin()) { // in this very specific case, we don't want to hide empty // categories. Function calculate_permissions will only return // categories that are either locked or private and not permitted // // calculate_permissions does not consider empty categories as forbidden $forbidden_categories = calculate_permissions($user['id'], $user['status']); $where[] = 'id NOT IN (' . $forbidden_categories . ')'; $join_type = 'LEFT'; } } $query = ' SELECT id, name, comment, permalink, uppercats, global_rank, id_uppercat, nb_images, count_images AS total_nb_images, representative_picture_id, user_representative_picture_id, count_images, count_categories, date_last, max_date_last, count_categories AS nb_categories FROM ' . CATEGORIES_TABLE . ' ' . $join_type . ' JOIN ' . USER_CACHE_CATEGORIES_TABLE . ' ON id=cat_id AND user_id=' . $join_user . ' WHERE ' . implode("\n AND ", $where) . ' ;'; $result = pwg_query($query); // management of the album thumbnail -- starts here $image_ids = array(); $categories = array(); $user_representative_updates_for = array(); // management of the album thumbnail -- stops here $cats = array(); while ($row = pwg_db_fetch_assoc($result)) { $row['url'] = make_index_url(array('category' => $row)); foreach (array('id', 'nb_images', 'total_nb_images', 'nb_categories') as $key) { $row[$key] = (int) $row[$key]; } if ($params['fullname']) { $row['name'] = strip_tags(get_cat_display_name_cache($row['uppercats'], null)); } else { $row['name'] = strip_tags(trigger_change('render_category_name', $row['name'], 'ws_categories_getList')); } $row['comment'] = strip_tags(trigger_change('render_category_description', $row['comment'], 'ws_categories_getList')); // management of the album thumbnail -- starts here // // on branch 2.3, the algorithm is duplicated from // include/category_cats, but we should use a common code for Piwigo 2.4 // // warning : if the API method is called with $params['public'], the // album thumbnail may be not accurate. The thumbnail can be viewed by // the connected user, but maybe not by the guest. Changing the // filtering method would be too complicated for now. We will simply // avoid to persist the user_representative_picture_id in the database // if $params['public'] if (!empty($row['user_representative_picture_id'])) { $image_id = $row['user_representative_picture_id']; } else { if (!empty($row['representative_picture_id'])) { // if a representative picture is set, it has priority $image_id = $row['representative_picture_id']; } else { if ($conf['allow_random_representative']) { // searching a random representant among elements in sub-categories $image_id = get_random_image_in_category($row); } else { // searching a random representant among representant of sub-categories if ($row['count_categories'] > 0 and $row['count_images'] > 0) { $query = ' SELECT representative_picture_id FROM ' . CATEGORIES_TABLE . ' INNER JOIN ' . USER_CACHE_CATEGORIES_TABLE . ' ON id=cat_id AND user_id=' . $user['id'] . ' WHERE uppercats LIKE \'' . $row['uppercats'] . ',%\' AND representative_picture_id IS NOT NULL ' . get_sql_condition_FandF(array('visible_categories' => 'id'), "\n AND") . ' ORDER BY ' . DB_RANDOM_FUNCTION . '() LIMIT 1 ;'; $subresult = pwg_query($query); if (pwg_db_num_rows($subresult) > 0) { list($image_id) = pwg_db_fetch_row($subresult); } } } } } if (isset($image_id)) { if ($conf['representative_cache_on_subcats'] and $row['user_representative_picture_id'] != $image_id) { $user_representative_updates_for[$row['id']] = $image_id; } $row['representative_picture_id'] = $image_id; $image_ids[] = $image_id; $categories[] = $row; } unset($image_id); // management of the album thumbnail -- stops here $cats[] = $row; } usort($cats, 'global_rank_compare'); // management of the album thumbnail -- starts here if (count($categories) > 0) { $thumbnail_src_of = array(); $new_image_ids = array(); $query = ' SELECT id, path, representative_ext, level FROM ' . IMAGES_TABLE . ' WHERE id IN (' . implode(',', $image_ids) . ') ;'; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { if ($row['level'] <= $user['level']) { $thumbnail_src_of[$row['id']] = DerivativeImage::thumb_url($row); } else { // problem: we must not display the thumbnail of a photo which has a // higher privacy level than user privacy level // // * what is the represented category? // * find a random photo matching user permissions // * register it at user_representative_picture_id // * set it as the representative_picture_id for the category foreach ($categories as &$category) { if ($row['id'] == $category['representative_picture_id']) { // searching a random representant among elements in sub-categories $image_id = get_random_image_in_category($category); if (isset($image_id) and !in_array($image_id, $image_ids)) { $new_image_ids[] = $image_id; } if ($conf['representative_cache_on_level']) { $user_representative_updates_for[$category['id']] = $image_id; } $category['representative_picture_id'] = $image_id; } } unset($category); } } if (count($new_image_ids) > 0) { $query = ' SELECT id, path, representative_ext FROM ' . IMAGES_TABLE . ' WHERE id IN (' . implode(',', $new_image_ids) . ') ;'; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { $thumbnail_src_of[$row['id']] = DerivativeImage::thumb_url($row); } } } // compared to code in include/category_cats, we only persist the new // user_representative if we have used $user['id'] and not the guest id, // or else the real guest may see thumbnail that he should not if (!$params['public'] and count($user_representative_updates_for)) { $updates = array(); foreach ($user_representative_updates_for as $cat_id => $image_id) { $updates[] = array('user_id' => $user['id'], 'cat_id' => $cat_id, 'user_representative_picture_id' => $image_id); } mass_updates(USER_CACHE_CATEGORIES_TABLE, array('primary' => array('user_id', 'cat_id'), 'update' => array('user_representative_picture_id')), $updates); } foreach ($cats as &$cat) { foreach ($categories as $category) { if ($category['id'] == $cat['id'] and isset($category['representative_picture_id'])) { $cat['tn_url'] = $thumbnail_src_of[$category['representative_picture_id']]; } } // we don't want them in the output unset($cat['user_representative_picture_id'], $cat['count_images'], $cat['count_categories']); } unset($cat); // management of the album thumbnail -- stops here if ($params['tree_output']) { return categories_flatlist_to_tree($cats); } return array('categories' => new PwgNamedArray($cats, 'category', ws_std_get_category_xml_attributes())); }
if (isset($redirect)) { redirect($admin_album_base_url . '-properties'); } // nullable fields foreach (array('comment', 'dir', 'site_id', 'id_uppercat') as $nullable) { if (!isset($category[$nullable])) { $category[$nullable] = ''; } } $category['is_virtual'] = empty($category['dir']) ? true : false; $query = 'SELECT DISTINCT category_id FROM ' . IMAGE_CATEGORY_TABLE . ' WHERE category_id = ' . $_GET['cat_id'] . ' LIMIT 1'; $result = pwg_query($query); $category['has_images'] = pwg_db_num_rows($result) > 0 ? true : false; // Navigation path $navigation = get_cat_display_name_cache($category['uppercats'], get_root_url() . 'admin.php?page=album-'); $form_action = $admin_album_base_url . '-properties'; //----------------------------------------------------- template initialization $template->set_filename('album_properties', 'cat_modify.tpl'); $base_url = get_root_url() . 'admin.php?page='; $cat_list_url = $base_url . 'cat_list'; $self_url = $cat_list_url; if (!empty($category['id_uppercat'])) { $self_url .= '&parent_id=' . $category['id_uppercat']; } $template->assign(array('CATEGORIES_NAV' => $navigation, 'CAT_ID' => $category['id'], 'CAT_NAME' => @htmlspecialchars($category['name']), 'CAT_COMMENT' => @htmlspecialchars($category['comment']), 'CAT_VISIBLE' => boolean_to_string($category['visible']), 'U_JUMPTO' => make_index_url(array('category' => $category)), 'U_ADD_PHOTOS_ALBUM' => $base_url . 'photos_add&album=' . $category['id'], 'U_CHILDREN' => $cat_list_url . '&parent_id=' . $category['id'], 'U_HELP' => get_root_url() . 'admin/popuphelp.php?page=cat_modify', 'F_ACTION' => $form_action)); if ($conf['activate_comments']) { $template->assign('CAT_COMMENTABLE', boolean_to_string($category['commentable'])); }
function get_comment_author_id_guestbook($comment_id, $die_on_error = true) { $query = ' SELECT author_id FROM ' . GUESTBOOK_TABLE . ' WHERE id = ' . $comment_id . ' ;'; $result = pwg_query($query); if (pwg_db_num_rows($result) == 0) { if ($die_on_error) { fatal_error('Unknown comment identifier'); } else { return false; } } list($author_id) = pwg_db_fetch_row($result); return $author_id; }
/** * Find a random photo among all photos inside an album (including sub-albums) * * @param array $category (at least id,uppercats,count_images) * @param bool $recursive * @return int|null */ function get_random_image_in_category($category, $recursive = true) { $image_id = null; if ($category['count_images'] > 0) { $query = ' SELECT image_id FROM ' . CATEGORIES_TABLE . ' AS c INNER JOIN ' . IMAGE_CATEGORY_TABLE . ' AS ic ON ic.category_id = c.id WHERE '; if ($recursive) { $query .= ' (c.id=' . $category['id'] . ' OR uppercats LIKE \'' . $category['uppercats'] . ',%\')'; } else { $query .= ' c.id=' . $category['id']; } $query .= ' ' . get_sql_condition_FandF(array('forbidden_categories' => 'c.id', 'visible_categories' => 'c.id', 'visible_images' => 'image_id'), "\n AND") . ' ORDER BY ' . DB_RANDOM_FUNCTION . '() LIMIT 1 ;'; $result = pwg_query($query); if (pwg_db_num_rows($result) > 0) { list($image_id) = pwg_db_fetch_row($result); } } return $image_id; }