/** returns a category id that corresponds to the given permalink (or null) * @param string permalink */ function get_cat_id_from_permalink($permalink) { $query = ' SELECT id FROM ' . CATEGORIES_TABLE . ' WHERE permalink=\'' . $permalink . '\''; $ids = array_from_query($query, 'id'); if (!empty($ids)) { return $ids[0]; } return null; }
function flickr_perform_batch_manager_prefilters($filter_sets, $prefilter) { if ($prefilter == 'flickr') { $query = ' SELECT id FROM ' . IMAGES_TABLE . ' WHERE file LIKE "flickr-%" ;'; $filter_sets[] = array_from_query($query, 'id'); } return $filter_sets; }
function vjs_perform_batch_manager_prefilters($filter_sets, $prefilter) { if ($prefilter === "videojs0") { $filter = ""; } else { if ($prefilter === "videojs1") { $filter = "AND `representative_ext` IS NOT NULL"; } else { if ($prefilter === "videojs2") { $filter = "AND `representative_ext` IS NULL"; } } } if (isset($filter)) { $query = "SELECT id FROM " . IMAGES_TABLE . " WHERE " . SQL_VIDEOS . " " . $filter; $filter_sets[] = array_from_query($query, 'id'); } return $filter_sets; }
function osm_perform_batch_manager_prefilters($filter_sets, $prefilter) { if ($prefilter === "osm0") { $filter = "`latitude` IS NOT NULL and `longitude` IS NOT NULL"; } else { if ($prefilter === "osm1") { $filter = "`latitude` IS NULL OR `longitude` IS NULL"; } else { if ($prefilter === "osm2") { $filter = "`path` LIKE '%gpx%'"; } } } if (isset($filter)) { $query = "SELECT id FROM " . IMAGES_TABLE . " WHERE " . $filter; $filter_sets[] = array_from_query($query, 'id'); } return $filter_sets; }
SELECT id AS group_id FROM ' . GROUPS_TABLE . ' ;'; $all_group_ids = array_from_query($query, 'group_id'); if (count($all_group_ids) == 0) { $template->assign('no_group_in_gallery', true); } else { if ('private' == $category['status']) { $query = ' SELECT group_id FROM ' . GROUP_ACCESS_TABLE . ' WHERE cat_id = ' . $category['id'] . ' ;'; $group_ids = array_from_query($query, 'group_id'); if (count($group_ids) == 0) { $template->assign('permission_url', $admin_album_base_url . '-permissions'); } } else { $group_ids = $all_group_ids; } if (count($group_ids) > 0) { $query = ' SELECT id, name FROM ' . GROUPS_TABLE . ' WHERE id IN (' . implode(',', $group_ids) . ') ORDER BY name ASC ;';
} else { if (!in_array('rotation', $columns_of[PREFIX_TABLE . 'images'])) { $current_release = '2.3.0'; } else { if (!in_array('website_url', $columns_of[PREFIX_TABLE . 'comments'])) { $current_release = '2.4.0'; } else { if (!in_array('nb_available_tags', $columns_of[PREFIX_TABLE . 'user_cache'])) { $current_release = '2.5.0'; } else { // retrieve already applied upgrades $query = ' SELECT id FROM ' . PREFIX_TABLE . 'upgrade ;'; $applied_upgrades = array_from_query($query, 'id'); if (!in_array(144, $applied_upgrades)) { $current_release = '2.6.0'; } else { // confirm that the database is in the same version as source code files conf_update_param('piwigo_db_version', get_branch_from_version(PHPWG_VERSION)); header('Content-Type: text/html; charset=' . get_pwg_charset()); echo 'No upgrade required, the database structure is up to date'; echo '<br><a href="index.php">← back to gallery</a>'; exit; } } } } } }
/** * Returns the list of items corresponding to the advanced search array. * * @param array $search * @param string $images_where optional additional restriction on images table * @return array */ function get_regular_search_results($search, $images_where = '') { global $conf; $forbidden = get_sql_condition_FandF(array('forbidden_categories' => 'category_id', 'visible_categories' => 'category_id', 'visible_images' => 'id'), "\n AND"); $items = array(); $tag_items = array(); if (isset($search['fields']['tags'])) { $tag_items = get_image_ids_for_tags($search['fields']['tags']['words'], $search['fields']['tags']['mode']); } $search_clause = get_sql_search_clause($search); if (!empty($search_clause)) { $query = ' SELECT DISTINCT(id) FROM ' . IMAGES_TABLE . ' i INNER JOIN ' . IMAGE_CATEGORY_TABLE . ' AS ic ON id = ic.image_id WHERE ' . $search_clause; if (!empty($images_where)) { $query .= "\n AND " . $images_where; } $query .= $forbidden . ' ' . $conf['order_by']; $items = array_from_query($query, 'id'); } if (!empty($tag_items)) { switch ($search['mode']) { case 'AND': if (empty($search_clause)) { $items = $tag_items; } else { $items = array_values(array_intersect($items, $tag_items)); } break; case 'OR': $before_count = count($items); $items = array_unique(array_merge($items, $tag_items)); break; } } return $items; }
/** * returns true if there are available upgrade files */ function check_upgrade_feed() { // retrieve already applied upgrades $query = ' SELECT id FROM ' . UPGRADE_TABLE . ' ;'; $applied = array_from_query($query, 'id'); // retrieve existing upgrades $existing = get_available_upgrade_ids(); // which upgrades need to be applied? return count(array_diff($existing, $applied)) > 0; }
/** * Perform history search. * * @param array $data - used in trigger_change * @param array $search * @param string[] $types * @param array */ function get_history($data, $search, $types) { if (isset($search['fields']['filename'])) { $query = ' SELECT id FROM ' . IMAGES_TABLE . ' WHERE file LIKE \'' . $search['fields']['filename'] . '\' ;'; $search['image_ids'] = array_from_query($query, 'id'); } // echo '<pre>'; print_r($search); echo '</pre>'; $clauses = array(); if (isset($search['fields']['date-after'])) { $clauses[] = "date >= '" . $search['fields']['date-after'] . "'"; } if (isset($search['fields']['date-before'])) { $clauses[] = "date <= '" . $search['fields']['date-before'] . "'"; } if (isset($search['fields']['types'])) { $local_clauses = array(); foreach ($types as $type) { if (in_array($type, $search['fields']['types'])) { $clause = 'image_type '; if ($type == 'none') { $clause .= 'IS NULL'; } else { $clause .= "= '" . $type . "'"; } $local_clauses[] = $clause; } } if (count($local_clauses) > 0) { $clauses[] = implode(' OR ', $local_clauses); } } if (isset($search['fields']['user']) and $search['fields']['user'] != -1) { $clauses[] = 'user_id = ' . $search['fields']['user']; } if (isset($search['fields']['image_id'])) { $clauses[] = 'image_id = ' . $search['fields']['image_id']; } if (isset($search['fields']['filename'])) { if (count($search['image_ids']) == 0) { // a clause that is always false $clauses[] = '1 = 2 '; } else { $clauses[] = 'image_id IN (' . implode(', ', $search['image_ids']) . ')'; } } if (isset($search['fields']['ip'])) { $clauses[] = 'IP LIKE "' . $search['fields']['ip'] . '"'; } $clauses = prepend_append_array_items($clauses, '(', ')'); $where_separator = implode("\n AND ", $clauses); $query = ' SELECT date, time, user_id, IP, section, category_id, tag_ids, image_id, image_type FROM ' . HISTORY_TABLE . ' WHERE ' . $where_separator . ' ;'; // LIMIT '.$conf['nb_logs_page'].' OFFSET '.$page['start'].' $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { $data[] = $row; } return $data; }
SET polaroid_active = \'true\' WHERE id IN (' . implode(',', $_POST['albums']) . ') ;'; pwg_query($query); } $page['infos'][] = l10n('Your configuration settings are saved'); } // +-----------------------------------------------------------------------+ // | template init | // +-----------------------------------------------------------------------+ $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/admin_config.tpl'); // +-----------------------------------------------------------------------+ // | form options | // +-----------------------------------------------------------------------+ // associate to albums $query = ' SELECT id FROM ' . CATEGORIES_TABLE . ' WHERE polaroid_active = \'true\' ;'; $polaroid_albums = array_from_query($query, 'id'); $query = ' SELECT id,name,uppercats,global_rank FROM ' . CATEGORIES_TABLE . ' ;'; display_select_cat_wrapper($query, $polaroid_albums, 'album_options'); $template->assign('apply_to_albums', $conf['polaroid']['apply_to_albums']); // +-----------------------------------------------------------------------+ // | sending html code | // +-----------------------------------------------------------------------+ $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
define('PHPWG_ROOT_PATH', './'); include_once PHPWG_ROOT_PATH . 'include/common.inc.php'; // +-----------------------------------------------------------------------+ // | Check Access and exit when user status is not ok | // +-----------------------------------------------------------------------+ check_status(ACCESS_GUEST); if (empty($_GET['q'])) { redirect(make_index_url()); } $search = array(); $search['q'] = $_GET['q']; $query = ' SElECT id FROM ' . SEARCH_TABLE . ' WHERE rules = \'' . addslashes(serialize($search)) . '\' ;'; $search_id = array_from_query($query, 'id'); if (!empty($search_id)) { $search_id = $search_id[0]; $query = ' UPDATE ' . SEARCH_TABLE . ' SET last_seen=NOW() WHERE id=' . $search_id; pwg_query($query); } else { $query = ' INSERT INTO ' . SEARCH_TABLE . ' (rules, last_seen) VALUES (\'' . addslashes(serialize($search)) . '\', NOW() ) ;'; pwg_query($query);
/** * 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); }
// photo in the selection $groups = $_POST['group_selection']; if (count($groups) == 0) { $page['errors'][] = l10n('Select at least one group'); } $action = $_POST['selectAction']; // + // |rename a group // + if ($action == "rename") { // is the group not already existing ? $query = ' SELECT name FROM ' . GROUPS_TABLE . ' ;'; $group_names = array_from_query($query, 'name'); foreach ($groups as $group) { if (in_array($_POST['rename_' . $group . ''], $group_names)) { $page['errors'][] = $_POST['rename_' . $group . ''] . ' | ' . l10n('This name is already used by another group.'); } elseif (!empty($_POST['rename_' . $group . ''])) { $query = ' UPDATE ' . GROUPS_TABLE . ' SET name = \'' . pwg_db_real_escape_string($_POST['rename_' . $group . '']) . '\' WHERE id = ' . $group . ' ;'; pwg_query($query); } } } // + // |delete a group
/** * Initialize _$page_ and _$template_ vars for calendar view. */ function initialize_calendar() { global $page, $conf, $user, $template, $persistent_cache, $filter; //------------------ initialize the condition on items to take into account --- $inner_sql = ' FROM ' . IMAGES_TABLE; if ($page['section'] == 'categories') { // we will regenerate the items by including subcats elements $page['items'] = array(); $inner_sql .= ' INNER JOIN ' . IMAGE_CATEGORY_TABLE . ' ON id = image_id'; if (isset($page['category'])) { $sub_ids = array_diff(get_subcat_ids(array($page['category']['id'])), explode(',', $user['forbidden_categories'])); if (empty($sub_ids)) { return; // nothing to do } $inner_sql .= ' WHERE category_id IN (' . implode(',', $sub_ids) . ')'; $inner_sql .= ' ' . get_sql_condition_FandF(array('visible_images' => 'id'), 'AND', false); } else { $inner_sql .= ' ' . get_sql_condition_FandF(array('forbidden_categories' => 'category_id', 'visible_categories' => 'category_id', 'visible_images' => 'id'), 'WHERE', true); } } else { if (empty($page['items'])) { return; // nothing to do } $inner_sql .= ' WHERE id IN (' . implode(',', $page['items']) . ')'; } //-------------------------------------- initialize the calendar parameters --- pwg_debug('start initialize_calendar'); $fields = array('created' => array('label' => l10n('Creation date')), 'posted' => array('label' => l10n('Post date'))); $styles = array('monthly' => array('include' => 'calendar_monthly.class.php', 'view_calendar' => true, 'classname' => 'CalendarMonthly'), 'weekly' => array('include' => 'calendar_weekly.class.php', 'view_calendar' => false, 'classname' => 'CalendarWeekly')); $views = array(CAL_VIEW_LIST, CAL_VIEW_CALENDAR); // Retrieve calendar field isset($fields[$page['chronology_field']]) or fatal_error('bad chronology field'); // Retrieve style if (!isset($styles[$page['chronology_style']])) { $page['chronology_style'] = 'monthly'; } $cal_style = $page['chronology_style']; $classname = $styles[$cal_style]['classname']; include PHPWG_ROOT_PATH . 'include/' . $styles[$cal_style]['include']; $calendar = new $classname(); // Retrieve view if (!isset($page['chronology_view']) or !in_array($page['chronology_view'], $views)) { $page['chronology_view'] = CAL_VIEW_LIST; } if (CAL_VIEW_CALENDAR == $page['chronology_view'] and !$styles[$cal_style]['view_calendar']) { $page['chronology_view'] = CAL_VIEW_LIST; } // perform a sanity check on $requested if (!isset($page['chronology_date'])) { $page['chronology_date'] = array(); } while (count($page['chronology_date']) > 3) { array_pop($page['chronology_date']); } $any_count = 0; for ($i = 0; $i < count($page['chronology_date']); $i++) { if ($page['chronology_date'][$i] == 'any') { if ($page['chronology_view'] == CAL_VIEW_CALENDAR) { // we dont allow any in calendar view while ($i < count($page['chronology_date'])) { array_pop($page['chronology_date']); } break; } $any_count++; } elseif ($page['chronology_date'][$i] == '') { while ($i < count($page['chronology_date'])) { array_pop($page['chronology_date']); } } else { $page['chronology_date'][$i] = (int) $page['chronology_date'][$i]; } } if ($any_count == 3) { array_pop($page['chronology_date']); } $calendar->initialize($inner_sql); //echo ('<pre>'. var_export($calendar, true) . '</pre>'); $must_show_list = true; // true until calendar generates its own display if (script_basename() != 'picture') { if ($calendar->generate_category_content()) { $page['items'] = array(); $must_show_list = false; } $page['comment'] = ''; $template->assign('FILE_CHRONOLOGY_VIEW', 'month_calendar.tpl'); foreach ($styles as $style => $style_data) { foreach ($views as $view) { if ($style_data['view_calendar'] or $view != CAL_VIEW_CALENDAR) { $selected = false; if ($style != $cal_style) { $chronology_date = array(); if (isset($page['chronology_date'][0])) { $chronology_date[] = $page['chronology_date'][0]; } } else { $chronology_date = $page['chronology_date']; } $url = duplicate_index_url(array('chronology_style' => $style, 'chronology_view' => $view, 'chronology_date' => $chronology_date)); if ($style == $cal_style and $view == $page['chronology_view']) { $selected = true; } $template->append('chronology_views', array('VALUE' => $url, 'CONTENT' => l10n('chronology_' . $style . '_' . $view), 'SELECTED' => $selected)); } } } $url = duplicate_index_url(array(), array('start', 'chronology_date')); $calendar_title = '<a href="' . $url . '">' . $fields[$page['chronology_field']]['label'] . '</a>'; $calendar_title .= $calendar->get_display_name(); $template->assign('chronology', array('TITLE' => $calendar_title)); } // end category calling if ($must_show_list) { if (isset($page['super_order_by'])) { $order_by = $conf['order_by']; } else { if (count($page['chronology_date']) == 0 or in_array('any', $page['chronology_date'])) { // selected period is very big so we show newest first $order = ' DESC, '; } else { // selected period is small (month,week) so we show oldest first $order = ' ASC, '; } $order_by = str_replace('ORDER BY ', 'ORDER BY ' . $calendar->date_field . $order, $conf['order_by']); } if ('categories' == $page['section'] && !isset($page['category']) && (count($page['chronology_date']) == 0 or $page['chronology_date'][0] == 'any' && count($page['chronology_date']) == 1)) { $cache_key = $persistent_cache->make_key($user['id'] . $user['cache_update_time'] . $calendar->date_field . $order_by); } if (!isset($cache_key) || !$persistent_cache->get($cache_key, $page['items'])) { $query = 'SELECT DISTINCT id ' . $calendar->inner_sql . ' ' . $calendar->get_date_where() . ' ' . $order_by; $page['items'] = array_from_query($query, 'id'); if (isset($cache_key)) { $persistent_cache->set($cache_key, $page['items']); } } } pwg_debug('end initialize_calendar'); }
pwg_query($query); // // replace gallery_description by page_banner // $query = ' SELECT value FROM ' . PREFIX_TABLE . 'config WHERE param=\'gallery_title\' ;'; list($t) = array_from_query($query, 'value'); $query = ' SELECT value FROM ' . PREFIX_TABLE . 'config WHERE param=\'gallery_description\' ;'; list($d) = array_from_query($query, 'value'); $page_banner = '<h1>' . $t . '</h1><p>' . $d . '</p>'; $page_banner = addslashes($page_banner); $query = ' INSERT INTO ' . PREFIX_TABLE . 'config (param,value,comment) VALUES ( \'page_banner\', \'' . $page_banner . '\', \'html displayed on the top each page of your gallery\' ) ;'; pwg_query($query); $query = ' DELETE FROM ' . PREFIX_TABLE . 'config
// | | // | You should have received a copy of the GNU General Public License | // | along with this program; if not, write to the Free Software | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | // | USA. | // +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+ // | define and include | // +-----------------------------------------------------------------------+ define('PHPWG_ROOT_PATH', './'); include_once PHPWG_ROOT_PATH . 'include/common.inc.php'; // +-----------------------------------------------------------------------+ // | Check Access and exit when user status is not ok | // +-----------------------------------------------------------------------+ check_status(ACCESS_GUEST); // +-----------------------------------------------------------------------+ // | generate random element list | // +-----------------------------------------------------------------------+ $query = ' SELECT id FROM ' . IMAGES_TABLE . ' INNER JOIN ' . IMAGE_CATEGORY_TABLE . ' AS ic ON id = ic.image_id ' . get_sql_condition_FandF(array('forbidden_categories' => 'category_id', 'visible_categories' => 'category_id', 'visible_images' => 'id'), 'WHERE') . ' ORDER BY ' . DB_RANDOM_FUNCTION . '() LIMIT ' . min(50, $conf['top_number'], $user['nb_image_page']) . ' ;'; // +-----------------------------------------------------------------------+ // | redirect | // +-----------------------------------------------------------------------+ redirect(make_index_url(array('list' => array_from_query($query, 'id'))));
UPDATE ' . IMAGES_TABLE . ' SET hit = hit+1, lastmodified = lastmodified WHERE id = ' . $page['image_id'] . ' ;'; pwg_query($query); } //---------------------------------------------------------- related categories $query = ' SELECT id,uppercats,commentable,visible,status,global_rank FROM ' . IMAGE_CATEGORY_TABLE . ' INNER JOIN ' . CATEGORIES_TABLE . ' ON category_id = id WHERE image_id = ' . $page['image_id'] . ' ' . get_sql_condition_FandF(array('forbidden_categories' => 'id', 'visible_categories' => 'id'), 'AND') . ' ;'; $related_categories = array_from_query($query); usort($related_categories, 'global_rank_compare'); //-------------------------first, prev, current, next & last picture management $picture = array(); $ids = array($page['image_id']); if (isset($page['previous_item'])) { $ids[] = $page['previous_item']; $ids[] = $page['first_item']; } if (isset($page['next_item'])) { $ids[] = $page['next_item']; $ids[] = $page['last_item']; } $query = ' SELECT * FROM ' . IMAGES_TABLE . '
/** * Send an email to a group. * @see pwg_mail() * * @param int $group_id * @param array $args - as in pwg_mail() * o language_selected: filters users of the group by language [default value empty] * @param array $tpl - as in pwg_mail() * @return boolean */ function pwg_mail_group($group_id, $args = array(), $tpl = array()) { if (empty($group_id) or empty($args['content']) and empty($tpl)) { return false; } global $conf; $return = true; // get distinct languages of targeted users $query = ' SELECT DISTINCT language FROM ' . USER_GROUP_TABLE . ' AS ug INNER JOIN ' . USERS_TABLE . ' AS u ON ' . $conf['user_fields']['id'] . ' = ug.user_id INNER JOIN ' . USER_INFOS_TABLE . ' AS ui ON ui.user_id = ug.user_id WHERE group_id = ' . $group_id . ' AND ' . $conf['user_fields']['email'] . ' <> ""'; if (!empty($args['language_selected'])) { $query .= ' AND language = \'' . $args['language_selected'] . '\''; } $query .= ' ;'; $languages = array_from_query($query, 'language'); if (empty($languages)) { return $return; } foreach ($languages as $language) { // get subset of users in this group for a specific language $query = ' SELECT ui.user_id, ui.status, u.' . $conf['user_fields']['username'] . ' AS name, u.' . $conf['user_fields']['email'] . ' AS email FROM ' . USER_GROUP_TABLE . ' AS ug INNER JOIN ' . USERS_TABLE . ' AS u ON ' . $conf['user_fields']['id'] . ' = ug.user_id INNER JOIN ' . USER_INFOS_TABLE . ' AS ui ON ui.user_id = ug.user_id WHERE group_id = ' . $group_id . ' AND ' . $conf['user_fields']['email'] . ' <> "" AND language = \'' . $language . '\' ;'; $users = array_from_query($query); if (empty($users)) { continue; } switch_lang_to($language); foreach ($users as $u) { $authkey = create_user_auth_key($u['user_id'], $u['status']); $user_tpl = $tpl; if ($authkey !== false) { $user_tpl['assign']['LINK'] = add_url_params($tpl['assign']['LINK'], array('auth' => $authkey['auth_key'])); if (isset($user_tpl['assign']['IMG']['link'])) { $user_tpl['assign']['IMG']['link'] = add_url_params($user_tpl['assign']['IMG']['link'], array('auth' => $authkey['auth_key'])); } } $user_args = $args; if ($authkey !== false) { $user_args['auth_key'] = $authkey['auth_key']; } $return &= pwg_mail($u['email'], $user_args, $user_tpl); } switch_lang_back(); } return $return; }
// Filter on existing poster $OVERWRITE = ""; if (!$sync_options['posteroverwrite']) { $OVERWRITE = " AND `representative_ext` IS NULL "; } // Filter on selected ablum if ($sync_options['cat_id'] != 0) { $query = ' SELECT id FROM ' . CATEGORIES_TABLE . ' WHERE '; if ($sync_options['subcats_included']) { $query .= 'uppercats REGEXP \'(^|,)' . $sync_options['cat_id'] . '(,|$)\''; } 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
$template->assign('groups_selected', $group_granted_ids); // users... $users = array(); $query = ' SELECT ' . $conf['user_fields']['id'] . ' AS id, ' . $conf['user_fields']['username'] . ' AS username FROM ' . USERS_TABLE . ' ;'; $users = simple_hash_from_query($query, 'id', 'username'); $template->assign('users', $users); $query = ' SELECT user_id FROM ' . USER_ACCESS_TABLE . ' WHERE cat_id = ' . $page['cat'] . ' ;'; $user_granted_direct_ids = array_from_query($query, 'user_id'); $template->assign('users_selected', $user_granted_direct_ids); $user_granted_indirect_ids = array(); if (count($group_granted_ids) > 0) { $granted_groups = array(); $query = ' SELECT user_id, group_id FROM ' . USER_GROUP_TABLE . ' WHERE group_id IN (' . implode(',', $group_granted_ids) . ') '; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { if (!isset($granted_groups[$row['group_id']])) { $granted_groups[$row['group_id']] = array(); } $granted_groups[$row['group_id']][] = $row['user_id'];
} //all image averages $query = 'SELECT element_id, AVG(rate) AS avg FROM ' . RATE_TABLE . ' GROUP BY element_id'; $all_img_sum = array(); $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { $all_img_sum[(int) $row['element_id']] = array('avg' => (double) $row['avg']); } $query = 'SELECT id FROM ' . IMAGES_TABLE . ' ORDER by rating_score DESC LIMIT ' . $consensus_top_number; $best_rated = array_flip(array_from_query($query, 'id')); // by user stats foreach ($by_user_ratings as $id => &$rating) { $c = 0; $s = 0; $ss = 0; $consensus_dev = 0; $consensus_dev_top = 0; $consensus_dev_top_count = 0; foreach ($rating['rates'] as $rate => $rates) { $ct = count($rates); $c += $ct; $s += $ct * $rate; $ss += $ct * $rate * $rate; foreach ($rates as $id_date) { $dev = abs($rate - $all_img_sum[$id_date['id']]['avg']);
function set_default_theme($theme_id) { global $conf; // first we need to know which users are using the current default theme $default_theme = get_default_theme(); $query = ' SELECT user_id FROM ' . USER_INFOS_TABLE . ' WHERE theme = \'' . $default_theme . '\' ;'; $user_ids = array_unique(array_merge(array_from_query($query, 'user_id'), array($conf['guest_id'], $conf['default_user_id']))); // $user_ids can't be empty, at least the default user has the default // theme $query = ' UPDATE ' . USER_INFOS_TABLE . ' SET theme = \'' . $theme_id . '\' WHERE user_id IN (' . implode(',', $user_ids) . ') ;'; pwg_query($query); }
if (!defined('PHPWG_ROOT_PATH')) { die('This page cannot be loaded directly, load upgrade.php'); } else { if (!defined('PHPWG_IN_UPGRADE') or !PHPWG_IN_UPGRADE) { die('Hacking attempt!'); } } // +-----------------------------------------------------------------------+ // | Fill upgrade table without applying upgrade | // +-----------------------------------------------------------------------+ // retrieve already applied upgrades $query = ' SELECT id FROM ' . PREFIX_TABLE . 'upgrade ;'; $applied = array_from_query($query, 'id'); // retrieve existing upgrades $existing = get_available_upgrade_ids(); // which upgrades need to be applied? $to_apply = array_diff($existing, $applied); $inserts = array(); foreach ($to_apply as $upgrade_id) { if ($upgrade_id >= 112) { break; } array_push($inserts, array('id' => $upgrade_id, 'applied' => CURRENT_DATE, 'description' => '[migration from 2.3.0 to ' . PHPWG_VERSION . '] not applied')); } if (!empty($inserts)) { mass_inserts('`' . UPGRADE_TABLE . '`', array_keys($inserts[0]), $inserts); } // +-----------------------------------------------------------------------+
/** * Send an email to a group. * @see pwg_mail() * * @param int $group_id * @param array $args - as in pwg_mail() * o language_selected: filters users of the group by language [default value empty] * @param array $tpl - as in pwg_mail() * @return boolean */ function pwg_mail_group($group_id, $args = array(), $tpl = array()) { if (empty($group_id) or empty($args['content']) and empty($tpl)) { return false; } global $conf; $return = true; // get distinct languages of targeted users $query = ' SELECT DISTINCT language FROM ' . USER_GROUP_TABLE . ' AS ug INNER JOIN ' . USERS_TABLE . ' AS u ON ' . $conf['user_fields']['id'] . ' = ug.user_id INNER JOIN ' . USER_INFOS_TABLE . ' AS ui ON ui.user_id = ug.user_id WHERE group_id = ' . $group_id . ' AND ' . $conf['user_fields']['email'] . ' <> ""'; if (!empty($args['language_selected'])) { $query .= ' AND language = \'' . $args['language_selected'] . '\''; } $query .= ' ;'; $languages = array_from_query($query, 'language'); if (empty($languages)) { return $return; } foreach ($languages as $language) { // get subset of users in this group for a specific language $query = ' SELECT u.' . $conf['user_fields']['username'] . ' AS name, u.' . $conf['user_fields']['email'] . ' AS email FROM ' . USER_GROUP_TABLE . ' AS ug INNER JOIN ' . USERS_TABLE . ' AS u ON ' . $conf['user_fields']['id'] . ' = ug.user_id INNER JOIN ' . USER_INFOS_TABLE . ' AS ui ON ui.user_id = ug.user_id WHERE group_id = ' . $group_id . ' AND ' . $conf['user_fields']['email'] . ' <> "" AND language = \'' . $language . '\' ;'; $users = array_from_query($query); if (empty($users)) { continue; } switch_lang_to($language); $return &= pwg_mail(null, array_merge($args, array('Bcc' => $users)), $tpl); switch_lang_back(); } return $return; }
/** * API method * Deletes a category * @param mixed[] $params * @option string|int[] category_id * @option string photo_deletion_mode * @option string pwg_token */ function ws_categories_delete($params, &$service) { if (get_pwg_token() != $params['pwg_token']) { return new PwgError(403, 'Invalid security token'); } $modes = array('no_delete', 'delete_orphans', 'force_delete'); if (!in_array($params['photo_deletion_mode'], $modes)) { return new PwgError(500, '[ws_categories_delete]' . ' invalid parameter photo_deletion_mode "' . $params['photo_deletion_mode'] . '"' . ', possible values are {' . implode(', ', $modes) . '}.'); } if (!is_array($params['category_id'])) { $params['category_id'] = preg_split('/[\\s,;\\|]/', $params['category_id'], -1, PREG_SPLIT_NO_EMPTY); } $params['category_id'] = array_map('intval', $params['category_id']); $category_ids = array(); foreach ($params['category_id'] as $category_id) { if ($category_id > 0) { $category_ids[] = $category_id; } } if (count($category_ids) == 0) { return; } $query = ' SELECT id FROM ' . CATEGORIES_TABLE . ' WHERE id IN (' . implode(',', $category_ids) . ') ;'; $category_ids = array_from_query($query, 'id'); if (count($category_ids) == 0) { return; } include_once PHPWG_ROOT_PATH . 'admin/include/functions.php'; delete_categories($category_ids, $params['photo_deletion_mode']); update_global_rank(); }
$template->append('related_categories', $name); } } // jump to link // // 1. find all linked categories that are reachable for the current user. // 2. if a category is available in the URL, use it if reachable // 3. if URL category not available or reachable, use the first reachable // linked category // 4. if no category reachable, no jumpto link $query = ' SELECT category_id FROM ' . IMAGE_CATEGORY_TABLE . ' WHERE image_id = ' . $_GET['image_id'] . ' ;'; $authorizeds = array_diff(array_from_query($query, 'category_id'), explode(',', calculate_permissions($user['id'], $user['status']))); if (isset($_GET['cat_id']) and in_array($_GET['cat_id'], $authorizeds)) { $url_img = make_picture_url(array('image_id' => $_GET['image_id'], 'image_file' => $image_file, 'category' => $cache['cat_names'][$_GET['cat_id']])); } else { foreach ($authorizeds as $category) { $url_img = make_picture_url(array('image_id' => $_GET['image_id'], 'image_file' => $image_file, 'category' => $cache['cat_names'][$category])); break; } } if (isset($url_img)) { $template->assign('U_JUMPTO', $url_img); } // associate to albums $query = ' SELECT id FROM ' . CATEGORIES_TABLE . '
if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } include_once PHPWG_ROOT_PATH . 'admin/include/functions.php'; check_status(ACCESS_ADMINISTRATOR); $tpl_extension = isset($conf['extents_for_templates']) ? unserialize($conf['extents_for_templates']) : array(); $new_extensions = get_extents(); /* Selective URLs keyword */ $relevant_parameters = array('----------', 'category', 'favorites', 'most_visited', 'best_rated', 'recent_pics', 'recent_cats', 'created-monthly-calendar', 'posted-monthly-calendar', 'search', 'flat', 'list', 'tags'); $query = ' SELECT permalink FROM ' . CATEGORIES_TABLE . ' WHERE permalink IS NOT NULL '; /* Add active permalinks */ $permalinks = array_from_query($query, 'permalink'); $relevant_parameters = array_merge($relevant_parameters, $permalinks); /* Link all supported templates to their respective handle */ $eligible_templates = array('----------' => 'N/A', 'about.tpl' => 'about', 'comments.tpl' => 'comments', 'comment_list.tpl' => 'comment_list', 'footer.tpl' => 'tail', 'header.tpl' => 'header', 'identification.tpl' => 'identification', 'index.tpl' => 'index', 'mainpage_categories.tpl' => 'index_category_thumbnails', 'menubar.tpl' => 'menubar', 'menubar_categories.tpl' => 'mbCategories', 'menubar_identification.tpl' => 'mbIdentification', 'menubar_links.tpl' => 'mbLinks', 'menubar_menu.tpl' => 'mbMenu', 'menubar_specials.tpl' => 'mbSpecials', 'menubar_tags.tpl' => 'mbTags', 'month_calendar.tpl' => 'month_calendar', 'navigation_bar.tpl' => 'navbar', 'nbm.tpl' => 'nbm', 'notification.tpl' => 'notification', 'password.tpl' => 'password', 'picture.tpl' => 'picture', 'picture_content.tpl' => 'default_content', 'picture_nav_buttons.tpl' => 'picture_nav_buttons', 'popuphelp.tpl' => 'popuphelp', 'profile.tpl' => 'profile', 'profile_content.tpl' => 'profile_content', 'redirect.tpl' => 'redirect', 'register.tpl' => 'register', 'search.tpl' => 'search', 'search_rules.tpl' => 'search_rules', 'slideshow.tpl' => 'slideshow', 'tags.tpl' => 'tags', 'thumbnails.tpl' => 'index_thumbnails'); $flip_templates = array_flip($eligible_templates); $available_templates = array_merge(array('N/A' => '----------'), get_dirs(PHPWG_ROOT_PATH . 'themes')); // +-----------------------------------------------------------------------+ // | selected templates | // +-----------------------------------------------------------------------+ if (isset($_POST['submit'])) { $replacements = array(); $i = 0; while (isset($_POST['reptpl'][$i])) { $newtpl = $_POST['reptpl'][$i]; $original = $_POST['original'][$i]; $handle = $eligible_templates[$original];
/** * API method * Add permissions * @param mixed[] $params * @option int[] cat_id * @option int[] group_id (optional) * @option int[] user_id (optional) * @option bool recursive */ function ws_permissions_add($params, &$service) { if (get_pwg_token() != $params['pwg_token']) { return new PwgError(403, 'Invalid security token'); } include_once PHPWG_ROOT_PATH . 'admin/include/functions.php'; if (!empty($params['group_id'])) { $cat_ids = get_uppercat_ids($params['cat_id']); if ($params['recursive']) { $cat_ids = array_merge($cat_ids, get_subcat_ids($params['cat_id'])); } $query = ' SELECT id FROM ' . CATEGORIES_TABLE . ' WHERE id IN (' . implode(',', $cat_ids) . ') AND status = \'private\' ;'; $private_cats = array_from_query($query, 'id'); $inserts = array(); foreach ($private_cats as $cat_id) { foreach ($params['group_id'] as $group_id) { $inserts[] = array('group_id' => $group_id, 'cat_id' => $cat_id); } } mass_inserts(GROUP_ACCESS_TABLE, array('group_id', 'cat_id'), $inserts, array('ignore' => true)); } if (!empty($params['user_id'])) { if ($params['recursive']) { $_POST['apply_on_sub'] = true; } add_permission_on_category($params['cat_id'], $params['user_id']); } return $service->invoke('pwg.permissions.getList', array('cat_id' => $params['cat_id'])); }
$page['infos'][] = $output_create['info']; } } elseif (isset($_POST['submitManualOrder'])) { asort($_POST['catOrd'], SORT_NUMERIC); save_categories_order(array_keys($_POST['catOrd'])); $page['infos'][] = l10n('Album manual order was saved'); } elseif (isset($_POST['submitAutoOrder'])) { if (!isset($sort_orders[$_POST['order_by']])) { die('Invalid sort order'); } $query = ' SELECT id FROM ' . CATEGORIES_TABLE . ' WHERE id_uppercat ' . (!isset($_GET['parent_id']) ? 'IS NULL' : '= ' . $_GET['parent_id']) . ' ;'; $category_ids = array_from_query($query, 'id'); if (isset($_POST['recursive'])) { $category_ids = get_subcat_ids($category_ids); } $categories = array(); $sort = array(); list($order_by_field, $order_by_asc) = explode(' ', $_POST['order_by']); $order_by_date = false; if (strpos($order_by_field, 'date_') === 0) { $order_by_date = true; $ref_dates = get_categories_ref_date($category_ids, $order_by_field, 'ASC' == $order_by_asc ? 'min' : 'max'); } $query = ' SELECT id, name, id_uppercat FROM ' . CATEGORIES_TABLE . ' WHERE id IN (' . implode(',', $category_ids) . ')
if (empty($filter['visible_categories'])) { // Must be not empty $filter['visible_categories'] = -1; } $query = ' SELECT distinct image_id FROM ' . IMAGE_CATEGORY_TABLE . ' INNER JOIN ' . IMAGES_TABLE . ' ON image_id = id WHERE '; if (!empty($filter['visible_categories'])) { $query .= ' category_id IN (' . $filter['visible_categories'] . ') and'; } $query .= ' date_available >= ' . pwg_db_get_recent_period_expression($filter['recent_period']); $filter['visible_images'] = implode(',', array_from_query($query, 'image_id')); if (empty($filter['visible_images'])) { // Must be not empty $filter['visible_images'] = -1; } // Save filter data on session pwg_set_session_var('filter_enabled', $filter['enabled']); pwg_set_session_var('filter_check_key', $filter_key); pwg_set_session_var('filter_categories', serialize($filter['categories'])); pwg_set_session_var('filter_visible_categories', $filter['visible_categories']); pwg_set_session_var('filter_visible_images', $filter['visible_images']); } else { // Read only data $filter['categories'] = unserialize(pwg_get_session_var('filter_categories', serialize(array()))); $filter['visible_categories'] = pwg_get_session_var('filter_visible_categories', ''); $filter['visible_images'] = pwg_get_session_var('filter_visible_images', '');