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 PhpBB_Linkuser($pwg_id, $bb_id) { $query = "\nSELECT pwg.id as pwg_id, bb.user_id as bb_id\nFROM " . USERS_TABLE . " pwg, " . PhpBB_USERS_TABLE . " bb\nWHERE pwg.id = " . $pwg_id . "\nAND bb.user_id = " . $bb_id . "\nAND pwg.username = bb.username\n;"; $data = pwg_db_fetch_row(pwg_query($query)); if (!empty($data)) { $subquery = "\nDELETE FROM " . Register_PhpBB_ID_TABLE . "\nWHERE id_user_pwg = '" . $pwg_id . "'\nOR id_user_PhpBB = '" . $bb_id . "'\n;"; $subresult = pwg_query($subquery); $subquery = "\nINSERT INTO " . Register_PhpBB_ID_TABLE . "\n (id_user_pwg, id_user_PhpBB)\nVALUES (" . $pwg_id . ", " . $bb_id . ")\n;"; $subresult = pwg_query($subquery); } }
/** * Returns search rules stored into a serialized array in "search" * table. Each search rules set is numericaly identified. * * @param int $search_id * @return array */ function get_search_array($search_id) { if (!is_numeric($search_id)) { die('Search id must be an integer'); } $query = ' SELECT rules FROM ' . SEARCH_TABLE . ' WHERE id = ' . $search_id . ' ;'; list($serialized_rules) = pwg_db_fetch_row(pwg_query($query)); return unserialize($serialized_rules); }
/** * checks the validity of input parameters, fills $page['errors'] and * $page['infos'] and send an email with confirmation link * * @return bool (true if email was sent, false otherwise) */ function process_password_request() { global $page, $conf; if (empty($_POST['username_or_email'])) { $page['errors'][] = l10n('Invalid username or email'); return false; } $user_id = get_userid_by_email($_POST['username_or_email']); if (!is_numeric($user_id)) { $user_id = get_userid($_POST['username_or_email']); } if (!is_numeric($user_id)) { $page['errors'][] = l10n('Invalid username or email'); return false; } $userdata = getuserdata($user_id, false); // password request is not possible for guest/generic users $status = $userdata['status']; if (is_a_guest($status) or is_generic($status)) { $page['errors'][] = l10n('Password reset is not allowed for this user'); return false; } if (empty($userdata['email'])) { $page['errors'][] = l10n('User "%s" has no email address, password reset is not possible', $userdata['username']); return false; } $activation_key = generate_key(20); list($expire) = pwg_db_fetch_row(pwg_query('SELECT ADDDATE(NOW(), INTERVAL 1 HOUR)')); single_update(USER_INFOS_TABLE, array('activation_key' => pwg_password_hash($activation_key), 'activation_key_expire' => $expire), array('user_id' => $user_id)); $userdata['activation_key'] = $activation_key; set_make_full_url(); $message = l10n('Someone requested that the password be reset for the following user account:') . "\r\n\r\n"; $message .= l10n('Username "%s" on gallery %s', $userdata['username'], get_gallery_home_url()); $message .= "\r\n\r\n"; $message .= l10n('To reset your password, visit the following address:') . "\r\n"; $message .= get_gallery_home_url() . '/password.php?key=' . $activation_key . '-' . urlencode($userdata['email']); $message .= "\r\n\r\n"; $message .= l10n('If this was a mistake, just ignore this email and nothing will happen.') . "\r\n"; unset_make_full_url(); $message = trigger_change('render_lost_password_mail_content', $message); $email_params = array('subject' => '[' . $conf['gallery_title'] . '] ' . l10n('Password Reset'), 'content' => $message, 'email_format' => 'text/plain'); if (pwg_mail($userdata['email'], $email_params)) { $page['infos'][] = l10n('Check your email for the confirmation link'); return true; } else { $page['errors'][] = l10n('Error sending email'); return false; } }
function ws_extref_categories_set($params, &$service) { // does the category really exist? $query = ' SELECT COUNT(*) FROM ' . CATEGORIES_TABLE . ' WHERE id = ' . $params['category_id'] . ' ;'; list($count) = pwg_db_fetch_row(pwg_query($query)); if ($count == 0) { return new PwgError(404, 'category_id not found'); } single_update(CATEGORIES_TABLE, array('external_reference' => $params['external_reference']), array('id' => $params['category_id'])); return true; }
/** * list all columns of each given table * * @return array of array */ function get_columns_of($tables) { $columns_of = array(); foreach ($tables as $table) { $query = ' DESC ' . $table . ' ;'; $result = pwg_query($query); $columns_of[$table] = array(); while ($row = pwg_db_fetch_row($result)) { $columns_of[$table][] = $row[0]; } } return $columns_of; }
/** * search an available feed_id * * @return string feed identifier */ function find_available_feed_id() { while (true) { $key = generate_key(50); $query = ' SELECT COUNT(*) FROM ' . USER_FEED_TABLE . ' WHERE id = \'' . $key . '\' ;'; list($count) = pwg_db_fetch_row(pwg_query($query)); if (0 == $count) { return $key; } } }
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 Register_PhpBB_InitPage() { global $conf, $user; include_once REGPHPBB_PATH . 'include/functions.inc.php'; if (isset($_POST['validate']) and !is_admin()) { if (!empty($_POST['use_new_pwd'])) { $query = ' SELECT ' . $conf['user_fields']['username'] . ' AS username FROM ' . USERS_TABLE . ' WHERE ' . $conf['user_fields']['id'] . ' = \'' . $user['id'] . '\' ;'; list($username) = pwg_db_fetch_row(pwg_query($query)); PhpBB_Updateuser($user['id'], stripslashes($username), md5($_POST['use_new_pwd']), $_POST['mail_address']); } } }
function find_available_check_key() { while (true) { $key = generate_key(16); $query = ' select count(*) from ' . USER_MAIL_NOTIFICATION_TABLE . ' where check_key = \'' . $key . '\';'; list($count) = pwg_db_fetch_row(pwg_query($query)); if ($count == 0) { return $key; } } }
/** * 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 pfemail_admin_menu($menu) { global $page; $query = ' SELECT COUNT(*) FROM ' . PFEMAIL_PENDINGS_TABLE . ' JOIN ' . IMAGES_TABLE . ' ON image_id = id WHERE state = \'moderation_pending\' ;'; $result = pwg_query($query); list($page['pfemail_nb_pendings']) = pwg_db_fetch_row($result); $name = 'Photo from Email'; if ($page['pfemail_nb_pendings'] > 0) { $style = 'background-color:#666;'; $style .= 'color:white;'; $style .= 'padding:1px 5px;'; $style .= 'border-radius:10px;'; $style .= 'margin-left:5px;'; $name .= '<span style="' . $style . '">' . $page['pfemail_nb_pendings'] . '</span>'; } array_push($menu, array('NAME' => $name, 'URL' => get_root_url() . 'admin.php?page=plugin-photo_from_email')); return $menu; }
/** * 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; 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; }
} mass_inserts(USER_GROUP_TABLE, array('user_id', 'group_id'), $usr_grp); $page['infos'][] = l10n('group "%s" added', $_POST['duplicate_' . $group . '']); } } // + // | toggle_default // + if ($action == "toggle_default") { foreach ($groups as $group) { $query = ' SELECT name, is_default FROM ' . GROUPS_TABLE . ' WHERE id = ' . $group . ' ;'; list($groupname, $is_default) = pwg_db_fetch_row(pwg_query($query)); // update of the group $query = ' UPDATE ' . GROUPS_TABLE . ' SET is_default = \'' . boolean_to_string(!get_boolean($is_default)) . '\' WHERE id = ' . $group . ' ;'; pwg_query($query); $page['infos'][] = l10n('group "%s" updated', $groupname); } } invalidate_user_cache(); } // +-----------------------------------------------------------------------+ // | template init | // +-----------------------------------------------------------------------+
if ($conf['activate_comments']) { $template->assign('CAT_COMMENTABLE', boolean_to_string($category['commentable'])); } // manage album elements link if ($category['has_images']) { $template->assign('U_MANAGE_ELEMENTS', $base_url . 'batch_manager&filter=album-' . $category['id']); $query = ' SELECT COUNT(image_id), MIN(DATE(date_available)), MAX(DATE(date_available)) FROM ' . IMAGES_TABLE . ' JOIN ' . IMAGE_CATEGORY_TABLE . ' ON image_id = id WHERE category_id = ' . $category['id'] . ' ;'; list($image_count, $min_date, $max_date) = pwg_db_fetch_row(pwg_query($query)); if ($min_date == $max_date) { $intro = l10n('This album contains %d photos, added on %s.', $image_count, format_date($min_date)); } else { $intro = l10n('This album contains %d photos, added between %s and %s.', $image_count, format_date($min_date), format_date($max_date)); } } else { $intro = l10n('This album contains no photo.'); } $intro .= '<br>' . l10n('Numeric identifier : %d', $category['id']); $template->assign(array('INTRO' => $intro, 'U_MANAGE_RANKS' => $base_url . 'element_set_ranks&cat_id=' . $category['id'], 'CACHE_KEYS' => get_admin_client_cache_keys(array('categories')))); if ($category['is_virtual']) { $template->assign(array('U_DELETE' => $self_url . '&delete=' . $category['id'] . '&pwg_token=' . get_pwg_token())); } else { $category['cat_full_dir'] = get_complete_dir($_GET['cat_id']); $template->assign(array('CAT_FULL_DIR' => preg_replace('/\\/$/', '', $category['cat_full_dir'])));
} else { $query .= 'id=' . $sync_options['cat_id']; } $cat_ids = array_from_query($query, 'id'); $query = "\n SELECT `id`, `file`, `path`\n FROM " . IMAGES_TABLE . " INNER JOIN " . IMAGE_CATEGORY_TABLE . " ON id=image_id\n WHERE " . SQL_VIDEOS . " " . $OVERWRITE . "\n AND category_id IN (" . implode(',', $cat_ids) . ")\n GROUP BY id"; } else { $query = "SELECT `id`, `file`, `path`\n FROM " . IMAGES_TABLE . "\n WHERE " . SQL_VIDEOS . " " . $OVERWRITE . ";"; } // Do the work, share with batch manager require_once dirname(__FILE__) . '/../include/function_sync2.php'; // Send sync result to template $template->assign('sync_errors', $errors); $template->assign('sync_warnings', $warnings); $template->assign('sync_infos', $infos); // Send result to templates $template->assign('update_result', array('NB_ELEMENTS_POSTER' => $posters, 'NB_ELEMENTS_THUMB' => $thumbs, 'NB_ELEMENTS_EXIF' => $metadata, 'NB_ELEMENTS_CANDIDATES' => $videos, 'NB_ERRORS' => count($errors), 'NB_WARNINGS' => count($warnings))); } /* Get statistics */ // All videos with supported extensions by VideoJS $query = "SELECT COUNT(*) FROM " . IMAGES_TABLE . " WHERE " . SQL_VIDEOS . ";"; list($nb_videos) = pwg_db_fetch_row(pwg_query($query)); // All videos with supported extensions by VideoJS and thumb $query = "SELECT COUNT(*) FROM " . IMAGES_TABLE . " WHERE `representative_ext` IS NOT NULL AND " . SQL_VIDEOS . ";"; list($nb_videos_thumb) = pwg_db_fetch_row(pwg_query($query)); // All videos with supported extensions by VideoJS and with GPS data $query = "SELECT COUNT(*) FROM " . IMAGES_TABLE . " WHERE `latitude` IS NOT NULL and `longitude` IS NOT NULL AND " . SQL_VIDEOS . ";"; list($nb_videos_geotagged) = pwg_db_fetch_row(pwg_query($query)); $query = 'SELECT id, CONCAT(name, IF(dir IS NULL, " (V)", "") ) AS name, uppercats, global_rank FROM ' . CATEGORIES_TABLE; display_select_cat_wrapper($query, array($sync_options['cat_id']), 'categories', false); // send value to template $template->assign(array('SUBCATS_INCLUDED_CHECKED' => $sync_options['subcats_included'] ? 'checked="checked"' : '', 'NB_VIDEOS' => $nb_videos, 'NB_VIDEOS_GEOTAGGED' => $nb_videos_geotagged, 'NB_VIDEOS_THUMB' => $nb_videos_thumb, 'VIDEOJS_PATH' => VIDEOJS_PATH));
$page = array(); $begin = $step = microtime(true); $timing = array(); foreach (explode(',', 'load,rotate,crop,scale,sharpen,watermark,save,send') as $k) { $timing[$k] = ''; } include_once PHPWG_ROOT_PATH . 'include/dblayer/functions_' . $conf['dblayer'] . '.inc.php'; include_once PHPWG_ROOT_PATH . '/include/derivative_params.inc.php'; include_once PHPWG_ROOT_PATH . '/include/derivative_std_params.inc.php'; try { pwg_db_connect($conf['db_host'], $conf['db_user'], $conf['db_password'], $conf['db_base']); } catch (Exception $e) { $logger->error($e->getMessage(), 'i.php'); } pwg_db_check_charset(); list($conf['derivatives']) = pwg_db_fetch_row(pwg_query('SELECT value FROM ' . $prefixeTable . 'config WHERE param=\'derivatives\'')); ImageStdParams::load_from_db(); parse_request(); //var_export($page); $params = $page['derivative_params']; $src_mtime = @filemtime($page['src_path']); if ($src_mtime === false) { ierror('Source not found', 404); } $need_generate = false; $derivative_mtime = @filemtime($page['derivative_path']); if ($derivative_mtime === false or $derivative_mtime < $src_mtime or $derivative_mtime < $params->last_mod_time) { $need_generate = true; } $expires = false; $now = time();
// | USA. | // +-----------------------------------------------------------------------+ /** * This file is included by the picture page to manage rates * */ if ($conf['rate']) { $rate_summary = array('count' => 0, 'score' => $picture['current']['rating_score'], 'average' => null); if (NULL != $rate_summary['score']) { $query = ' SELECT COUNT(rate) AS count , 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);
/** * returns the number of available comments for the connected user * * @return int */ function get_nb_available_comments() { global $user; if (!isset($user['nb_available_comments'])) { $where = array(); if (!is_admin()) { $where[] = 'validated=\'true\''; } $where[] = get_sql_condition_FandF(array('forbidden_categories' => 'category_id', 'forbidden_images' => 'ic.image_id'), '', true); $query = ' SELECT COUNT(DISTINCT(com.id)) FROM ' . IMAGE_CATEGORY_TABLE . ' AS ic INNER JOIN ' . COMMENTS_TABLE . ' AS com ON ic.image_id = com.image_id WHERE ' . implode(' AND ', $where); list($user['nb_available_comments']) = pwg_db_fetch_row(pwg_query($query)); single_update(USER_CACHE_TABLE, array('nb_available_comments' => $user['nb_available_comments']), array('user_id' => $user['id'])); } return $user['nb_available_comments']; }
die('Hacking attempt!'); } function delete_gthumb_cache($height) { $pattern = '#.*-cu_s9999x' . $height . '\\.[a-zA-Z0-9]{3,4}$#'; if ($contents = @opendir(PHPWG_ROOT_PATH . PWG_DERIVATIVE_DIR)) { while (($node = readdir($contents)) !== false) { if ($node != '.' and $node != '..' and is_dir(PHPWG_ROOT_PATH . PWG_DERIVATIVE_DIR . $node)) { clear_derivative_cache_rec(PHPWG_ROOT_PATH . PWG_DERIVATIVE_DIR . $node, $pattern); } } closedir($contents); } } if (isset($_GET['getMissingDerivative'])) { list($max_id, $image_count) = pwg_db_fetch_row(pwg_query('SELECT MAX(id)+1, COUNT(*) FROM ' . IMAGES_TABLE)); $start_id = intval($_POST['prev_page']); $max_urls = intval($_POST['max_urls']); if ($start_id <= 0) { $start_id = $max_id; } $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
function pwg_db_get_recent_period($period, $date = 'CURRENT_DATE') { $query = ' SELECT ' . pwg_db_get_recent_period_expression($period); list($d) = pwg_db_fetch_row(pwg_query($query)); return $d; }
FROM ' . USERS_TABLE . ' WHERE ' . $conf['user_fields']['id'] . ' = ' . $row['added_by'] . ' ;'; $result = pwg_query($query); while ($user_row = pwg_db_fetch_assoc($result)) { $row['added_by'] = $user_row['username']; } $intro_vars = array('file' => l10n('Original file : %s', $row['file']), 'add_date' => l10n('Posted %s on %s', time_since($row['date_available'], 'year'), format_date($row['date_available'], array('day', 'month', 'year'))), 'added_by' => l10n('Added by %s', $row['added_by']), 'size' => $row['width'] . '×' . $row['height'] . ' pixels, ' . sprintf('%.2f', $row['filesize'] / 1024) . 'MB', 'stats' => l10n('Visited %d times', $row['hit']), 'id' => l10n('Numeric identifier : %d', $row['id'])); if ($conf['rate'] and !empty($row['rating_score'])) { $query = ' SELECT COUNT(*) FROM ' . RATE_TABLE . ' WHERE element_id = ' . $_GET['image_id'] . ' ;'; list($row['nb_rates']) = pwg_db_fetch_row(pwg_query($query)); $intro_vars['stats'] .= ', ' . sprintf(l10n('Rated %d times, score : %.2f'), $row['nb_rates'], $row['rating_score']); } $query = ' SELECT * FROM ' . IMAGE_FORMAT_TABLE . ' WHERE image_id = ' . $row['id'] . ' ;'; $formats = query2array($query); if (!empty($formats)) { $format_strings = array(); foreach ($formats as $format) { $format_strings[] = sprintf('%s (%.2fMB)', $format['ext'], $format['filesize'] / 1024); } $intro_vars['formats'] = l10n('Formats: %s', implode(', ', $format_strings)); }
/** * 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; }
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; }
/** * API method * Sets representative image of a category * @param mixed[] $params * @option int category_id * @option int image_id */ function ws_categories_setRepresentative($params, &$service) { // does the category really exist? $query = ' SELECT COUNT(*) FROM ' . CATEGORIES_TABLE . ' WHERE id = ' . $params['category_id'] . ' ;'; list($count) = pwg_db_fetch_row(pwg_query($query)); if ($count == 0) { return new PwgError(404, 'category_id not found'); } // does the image really exist? $query = ' SELECT COUNT(*) FROM ' . IMAGES_TABLE . ' WHERE id = ' . $params['image_id'] . ' ;'; list($count) = pwg_db_fetch_row(pwg_query($query)); if ($count == 0) { return new PwgError(404, 'image_id not found'); } // apply change $query = ' UPDATE ' . CATEGORIES_TABLE . ' SET representative_picture_id = ' . $params['image_id'] . ' WHERE id = ' . $params['category_id'] . ' ;'; pwg_query($query); $query = ' UPDATE ' . USER_CACHE_CATEGORIES_TABLE . ' SET user_representative_picture_id = NULL WHERE cat_id = ' . $params['category_id'] . ' ;'; pwg_query($query); }
/** * Creates user informations based on default values. * * @param int|int[] $user_ids * @param array $override_values values used to override default user values */ function create_user_infos($user_ids, $override_values = null) { global $conf; if (!is_array($user_ids)) { $user_ids = array($user_ids); } if (!empty($user_ids)) { $inserts = array(); list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); $default_user = get_default_user_info(false); if ($default_user === false) { // Default on structure are used $default_user = array(); } if (!is_null($override_values)) { $default_user = array_merge($default_user, $override_values); } foreach ($user_ids as $user_id) { $level = isset($default_user['level']) ? $default_user['level'] : 0; if ($user_id == $conf['webmaster_id']) { $status = 'webmaster'; $level = max($conf['available_permission_levels']); } elseif ($user_id == $conf['guest_id'] or $user_id == $conf['default_user_id']) { $status = 'guest'; } else { $status = 'normal'; } $insert = array_merge($default_user, array('user_id' => $user_id, 'status' => $status, 'registration_date' => $dbnow, 'level' => $level)); $inserts[] = $insert; } mass_inserts(USER_INFOS_TABLE, array_keys($inserts[0]), $inserts); } }
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(); $query = 'SHOW TABLES LIKE "' . $prefixeTable . '%"'; $result = pwg_query($query); while ($row = pwg_db_fetch_row($result)) { array_push($all_tables, $row[0]); } $all_tables_definition = array(); foreach ($all_tables as $table) { $query = 'SHOW FULL COLUMNS FROM ' . $table; $result = pwg_query($query); $field_definitions = array(); while ($row = pwg_db_fetch_assoc($result)) { if (!isset($row['Collation']) or $row['Collation'] == 'NULL') { continue; } array_push($field_definitions, $row); } $all_tables_definition[$table] = $field_definitions; }
// themes class if (!defined('PWG_CHARSET')) { define('PWG_CHARSET', 'utf-8'); } activate_core_themes(); activate_core_plugins(); $insert = array('id' => 1, 'galleries_url' => PHPWG_ROOT_PATH . 'galleries/'); mass_inserts(SITES_TABLE, array_keys($insert), array($insert)); // webmaster admin user $inserts = array(array('id' => 1, 'username' => $admin_name, 'password' => md5($admin_pass1), 'mail_address' => $admin_mail), array('id' => 2, 'username' => 'guest')); mass_inserts(USERS_TABLE, array_keys($inserts[0]), $inserts); create_user_infos(array(1, 2), array('language' => $language)); // Available upgrades must be ignored after a fresh installation. To // make PWG avoid upgrading, we must tell it upgrades have already been // made. list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); define('CURRENT_DATE', $dbnow); $datas = array(); foreach (get_available_upgrade_ids() as $upgrade_id) { $datas[] = array('id' => $upgrade_id, 'applied' => CURRENT_DATE, 'description' => 'upgrade included in installation'); } mass_inserts(UPGRADE_TABLE, array_keys($datas[0]), $datas); if ($is_newsletter_subscribe) { fetchRemote(get_newsletter_subscribe_base_url($language) . $admin_mail, $result, array(), array('origin' => 'installation')); } } } //------------------------------------------------------ start template output foreach ($languages->fs_languages as $language_code => $fs_language) { if ($language == $language_code) { $template->assign('language_selection', $language_code);
function pfemail_validate($id) { global $conf, $page, $user; list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); single_update(PFEMAIL_PENDINGS_TABLE, array('state' => 'validated', 'validated_by' => $user['id']), array('image_id' => $id)); single_update(IMAGES_TABLE, array('date_available' => $dbnow, 'level' => 0), array('id' => $id)); array_push($page['infos'], l10n('photo validated')); invalidate_user_cache(); // notify users /* $query = ' SELECT from FROM '.PFEMAIL_PENDINGS_TABLE.' WHERE image_id = '.$id.' ;'; list($to) = pwg_db_fetch_row(pwg_query($query)); if (empty($to)) { return; } $headers = 'From: '.get_webmaster_mail_address()."\n"; $headers.= 'X-Mailer: Piwigo Mailer'."\n"; $headers.= "MIME-Version: 1.0\n"; $headers.= "Content-type: text/plain; charset=utf-8\n"; $headers.= "Content-Transfer-Encoding: quoted-printable\n"; set_make_full_url(); $message = 'Hi, Your photo was added to the Piwigo Showcase, see it on '.make_picture_url(array('image_id' => $id)).' Have a great day! -- Piwigo Team http://piwigo.org'; mail( $to, '[Piwigo Showcase] your gallery '.showcase_admin_get_simplified_url($url, true).' was successfully added', $message, $headers ); unset_make_full_url(); */ return true; }