function language_controler_flags() { global $user, $template, $conf, $page; $available_lang = get_languages(); if (isset($conf['no_flag_languages'])) { $available_lang = array_diff_key($available_lang, array_flip($conf['no_flag_languages'])); } $url_starting = get_query_string_diff(array('lang')); if (isset($page['section']) and $page['section'] == 'additional_page' and isset($page['additional_page'])) { $base_url = make_index_url(array('section' => 'page')) . '/' . (isset($page['additional_page']['permalink']) ? $page['additional_page']['permalink'] : $page['additional_page']['id']); } else { $base_url = duplicate_index_url(); } foreach ($available_lang as $code => $displayname) { $qlc = array('url' => add_url_params($base_url, array('lang' => $code)), 'alt' => ucwords($displayname), 'title' => substr($displayname, 0, -4), 'code' => $code); $lsw['flags'][$code] = $qlc; if ($code == $user['language']) { $lsw['Active'] = $qlc; } } $safe_themes = array('clear', 'dark', 'elegant', 'Sylvia', 'simple-grey', 'simple-black', 'simple-white', 'kardon', 'luciano', 'montblancxl'); // stripped (2.6) $template->assign(array('lang_switch' => $lsw, 'LANGUAGE_SWITCH_PATH' => LANGUAGE_SWITCH_PATH, 'LANGUAGE_SWITCH_LOAD_STYLE' => !in_array($user['theme'], $safe_themes))); $template->set_filename('language_flags', dirname(__FILE__) . '/flags.tpl'); $template->concat('PLUGIN_INDEX_ACTIONS', $template->parse('language_flags', true)); $template->clear_assign('lang_switch'); }
static function on_index_thumbnails($thumbs) { global $page, $template; $total = count($page['items']); if (count($thumbs) >= $total) { add_event_handler('loc_end_index', array('RVTS', 'on_end_index')); return $thumbs; } $url_model = str_replace('123456789', '%start%', duplicate_index_url(array('start' => 123456789))); $ajax_url_model = add_url_params($url_model, array('rvts' => '%per%')); $url_model = str_replace('&', '&', $url_model); $ajax_url_model = str_replace('&', '&', $ajax_url_model); $my_base_name = basename(dirname(__FILE__)); $ajax_loader_image = get_root_url() . "plugins/{$my_base_name}/ajax-loader.gif"; $template->func_combine_script(array('id' => 'jquery', 'load' => 'footer', 'path' => 'themes/default/js/jquery.min.js')); $template->func_combine_script(array('id' => $my_base_name, 'load' => 'async', 'path' => 'plugins/' . $my_base_name . '/rv_tscroller.min.js', 'require' => 'jquery', 'version' => RVTS_VERSION)); $start = (int) $page['start']; $per_page = $page['nb_image_page']; $moreMsg = 'See the remaining %d photos'; if ('en' != $GLOBALS['lang_info']['code']) { load_language('lang', dirname(__FILE__) . '/'); $moreMsg = l10n($moreMsg); } // the String.fromCharCode comes from google bot which somehow manage to get these urls $template->block_footer_script(null, "var RVTS = {\najaxUrlModel: String.fromCharCode(" . ord($ajax_url_model[0]) . ")+'" . substr($ajax_url_model, 1) . "',\nstart: {$start},\nperPage: {$per_page},\nnext: " . ($start + $per_page) . ",\ntotal: {$total},\nurlModel: String.fromCharCode(" . ord($url_model[0]) . ")+'" . substr($url_model, 1) . "',\nmoreMsg: '{$moreMsg}',\nprevMsg: '" . l10n("Previous") . "',\najaxLoaderImage: '{$ajax_loader_image}'\n};\njQuery('.navigationBar').hide();"); return $thumbs; }
/** * Returns the current url minus MultiView params * * @param bool $with_amp - adds ? or & at the end of the url * @return string */ public function get_clean_url($with_amp = false) { if (script_basename() == 'picture') { $url = duplicate_picture_url(array(), $this->data_url_params); } else { if (script_basename() == 'index') { $url = duplicate_index_url(array(), $this->data_url_params); } else { $url = get_query_string_diff($this->data_url_params); } } if ($with_amp) { $url .= strpos($url, '?') !== false ? '&' : '?'; } return $url; }
/** * Assigns the next/previous link to the template with regards to * the currently choosen date. */ protected function build_next_prev() { global $template, $page; $prev = $next = null; if (empty($page['chronology_date'])) { return; } $sub_queries = array(); $nb_elements = count($page['chronology_date']); for ($i = 0; $i < $nb_elements; $i++) { if ('any' === $page['chronology_date'][$i]) { $sub_queries[] = '\'any\''; } else { $sub_queries[] = pwg_db_cast_to_text($this->calendar_levels[$i]['sql']); } } $query = 'SELECT ' . pwg_db_concat_ws($sub_queries, '-') . ' AS period'; $query .= $this->inner_sql . ' AND ' . $this->date_field . ' IS NOT NULL GROUP BY period'; $current = implode('-', $page['chronology_date']); $upper_items = query2array($query, null, 'period'); usort($upper_items, 'version_compare'); $upper_items_rank = array_flip($upper_items); if (!isset($upper_items_rank[$current])) { $upper_items[] = $current; // just in case (external link) usort($upper_items, 'version_compare'); $upper_items_rank = array_flip($upper_items); } $current_rank = $upper_items_rank[$current]; $tpl_var = array(); if ($current_rank > 0) { // has previous $prev = $upper_items[$current_rank - 1]; $chronology_date = explode('-', $prev); $tpl_var['previous'] = array('LABEL' => $this->get_date_nice_name($prev), 'URL' => duplicate_index_url(array('chronology_date' => $chronology_date), array('start'))); } if ($current_rank < count($upper_items) - 1) { // has next $next = $upper_items[$current_rank + 1]; $chronology_date = explode('-', $next); $tpl_var['next'] = array('LABEL' => $this->get_date_nice_name($next), 'URL' => duplicate_index_url(array('chronology_date' => $chronology_date), array('start'))); } if (!empty($tpl_var)) { $existing = $template->smarty->getVariable('chronology_navigation_bars'); if (!$existing instanceof Undefined_Smarty_Variable) { $existing->value[sizeof($existing->value) - 1] = array_merge($existing->value[sizeof($existing->value) - 1], $tpl_var); } else { $template->append('chronology_navigation_bars', $tpl_var); } } }
/** * Save category form * @trigger loc_begin_index */ function admintools_save_category() { global $page, $conf, $MultiView; if (!$MultiView->is_admin()) { return; } if (@$_POST['action'] == 'quick_edit') { $data = array('name' => $_POST['name']); if ($conf['allow_html_descriptions']) { $data['comment'] = @$_POST['comment']; } else { $data['comment'] = strip_tags(@$_POST['comment']); } single_update(CATEGORIES_TABLE, $data, array('id' => $page['category']['id'])); redirect(duplicate_index_url()); } }
/** * 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'); }
$representative_infos = $infos_of_image[$category['representative_picture_id']]; $tpl_var = array_merge($category, array('ID' => $category['id'], 'representative' => $representative_infos, 'TN_ALT' => strip_tags($category['name']), 'URL' => make_index_url(array('category' => $category)), 'CAPTION_NB_IMAGES' => get_display_images_count($category['nb_images'], $category['count_images'], $category['count_categories'], true, '<br>'), 'DESCRIPTION' => trigger_change('render_category_literal_description', trigger_change('render_category_description', @$category['comment'], 'subcatify_category_description')), 'NAME' => $name)); if ($conf['index_new_icon']) { $tpl_var['icon_ts'] = get_icon($category['max_date_last'], $category['is_child_date_last']); } if ($conf['display_fromto']) { if (isset($dates_of_category[$category['id']])) { $from = $dates_of_category[$category['id']]['from']; $to = $dates_of_category[$category['id']]['to']; if (!empty($from)) { $tpl_var['INFO_DATES'] = format_fromto($from, $to); } } } $tpl_thumbnails_var[] = $tpl_var; } // pagination $page['total_categories'] = count($tpl_thumbnails_var); $tpl_thumbnails_var_selection = array_slice($tpl_thumbnails_var, $page['startcat'], $conf['nb_categories_page']); $derivative_params = trigger_change('get_index_album_derivative_params', ImageStdParams::get_by_type(IMG_THUMB)); $tpl_thumbnails_var_selection = trigger_change('loc_end_index_category_thumbnails', $tpl_thumbnails_var_selection); $template->assign(array('maxRequests' => $conf['max_requests'], 'category_thumbnails' => $tpl_thumbnails_var_selection, 'derivative_params' => $derivative_params)); $template->assign_var_from_handle('CATEGORIES', 'index_category_thumbnails'); // navigation bar $page['cats_navigation_bar'] = array(); if ($page['total_categories'] > $conf['nb_categories_page']) { $page['cats_navigation_bar'] = create_navigation_bar(duplicate_index_url(array(), array('startcat')), $page['total_categories'], $page['startcat'], $conf['nb_categories_page'], true, 'startcat'); } $template->assign('cats_navbar', $page['cats_navigation_bar']); } pwg_debug('end include/category_cats.inc.php');
$page['first_rank'] = 0; $page['last_rank'] = count($page['items']) - 1; $page['current_rank'] = $page['rank_of'][$page['image_id']]; // caching current item : readability purpose $page['current_item'] = $page['image_id']; if ($page['current_rank'] != $page['first_rank']) { // caching first & previous item : readability purpose $page['previous_item'] = $page['items'][$page['current_rank'] - 1]; $page['first_item'] = $page['items'][$page['first_rank']]; } if ($page['current_rank'] != $page['last_rank']) { // caching next & last item : readability purpose $page['next_item'] = $page['items'][$page['current_rank'] + 1]; $page['last_item'] = $page['items'][$page['last_rank']]; } $url_up = duplicate_index_url(array('start' => floor($page['current_rank'] / $page['nb_image_page']) * $page['nb_image_page']), array('start')); $url_self = duplicate_picture_url(); // +-----------------------------------------------------------------------+ // | actions | // +-----------------------------------------------------------------------+ /** * Actions are favorite adding, user comment deletion, setting the picture * as representative of the current category... * * Actions finish by a redirection */ if (isset($_GET['action'])) { switch ($_GET['action']) { case 'add_to_favorites': $query = ' INSERT INTO ' . FAVORITES_TABLE . '
/** * Build month calendar and assign the result in _$tpl_var_ * * @param array $tpl_var * @return bool */ protected function build_month_calendar(&$tpl_var) { global $page, $lang, $conf; $query = 'SELECT ' . pwg_db_get_dayofmonth($this->date_field) . ' as period, COUNT(DISTINCT id) as count'; $query .= $this->inner_sql; $query .= $this->get_date_where(); $query .= ' GROUP BY period ORDER BY period ASC'; $items = array(); $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { $d = (int) $row['period']; $items[$d] = array('nb_images' => $row['count']); } foreach ($items as $day => $data) { $page['chronology_date'][CDAY] = $day; $query = ' SELECT id, file,representative_ext,path,width,height,rotation, ' . pwg_db_get_dayofweek($this->date_field) . '-1 as dow'; $query .= $this->inner_sql; $query .= $this->get_date_where(); $query .= ' ORDER BY ' . DB_RANDOM_FUNCTION . '() LIMIT 1'; unset($page['chronology_date'][CDAY]); $row = pwg_db_fetch_assoc(pwg_query($query)); $derivative = new DerivativeImage(IMG_SQUARE, new SrcImage($row)); $items[$day]['derivative'] = $derivative; $items[$day]['file'] = $row['file']; $items[$day]['dow'] = $row['dow']; } if (!empty($items)) { list($known_day) = array_keys($items); $known_dow = $items[$known_day]['dow']; $first_day_dow = ($known_dow - ($known_day - 1)) % 7; if ($first_day_dow < 0) { $first_day_dow += 7; } //first_day_dow = week day corresponding to the first day of this month $wday_labels = $lang['day']; if ('monday' == $conf['week_starts_on']) { if ($first_day_dow == 0) { $first_day_dow = 6; } else { $first_day_dow -= 1; } $wday_labels[] = array_shift($wday_labels); } list($cell_width, $cell_height) = ImageStdParams::get_by_type(IMG_SQUARE)->sizing->ideal_size; $tpl_weeks = array(); $tpl_crt_week = array(); //fill the empty days in the week before first day of this month for ($i = 0; $i < $first_day_dow; $i++) { $tpl_crt_week[] = array(); } for ($day = 1; $day <= $this->get_all_days_in_month($page['chronology_date'][CYEAR], $page['chronology_date'][CMONTH]); $day++) { $dow = ($first_day_dow + $day - 1) % 7; if ($dow == 0 and $day != 1) { $tpl_weeks[] = $tpl_crt_week; // add finished week to week list $tpl_crt_week = array(); // start new week } if (!isset($items[$day])) { // empty day $tpl_crt_week[] = array('DAY' => $day); } else { $url = duplicate_index_url(array('chronology_date' => array($page['chronology_date'][CYEAR], $page['chronology_date'][CMONTH], $day))); $tpl_crt_week[] = array('DAY' => $day, 'DOW' => $dow, 'NB_ELEMENTS' => $items[$day]['nb_images'], 'IMAGE' => $items[$day]['derivative']->get_url(), 'U_IMG_LINK' => $url, 'IMAGE_ALT' => $items[$day]['file']); } } //fill the empty days in the week after the last day of this month while ($dow < 6) { $tpl_crt_week[] = array(); $dow++; } $tpl_weeks[] = $tpl_crt_week; $tpl_var['month_view'] = array('CELL_WIDTH' => $cell_width, 'CELL_HEIGHT' => $cell_height, 'wday_labels' => $wday_labels, 'weeks' => $tpl_weeks); } return true; }
$page['meta_robots']['noindex'] = 1; } elseif ('search' == $page['section']) { $page['meta_robots']['nofollow'] = 1; } if ($filter['enabled']) { $page['meta_robots']['noindex'] = 1; } // see if we need a redirect because of a permalink if ('categories' == $page['section'] and isset($page['category'])) { $need_redirect = false; if (empty($page['category']['permalink'])) { if ($conf['category_url_style'] == 'id-name' and @$page['hit_by']['cat_url_name'] !== str2url($page['category']['name'])) { $need_redirect = true; } } else { if ($page['category']['permalink'] !== @$page['hit_by']['cat_permalink']) { $need_redirect = true; } } if ($need_redirect) { $redirect_url = script_basename() == 'picture' ? duplicate_picture_url() : duplicate_index_url(); if (!headers_sent()) { // this is a permanent redirection set_status_header(301); redirect_http($redirect_url); } redirect($redirect_url); } unset($need_redirect, $page['hit_by']); } trigger_notify('loc_end_section_init');
} // category comment if ($page['start'] == 0 and !isset($page['chronology_field']) and !empty($page['comment'])) { $template->assign('CONTENT_DESCRIPTION', $page['comment']); } if (isset($page['category']['count_categories']) and $page['category']['count_categories'] == 0) { // count_categories might be computed by menubar - if the case unassign flat link if no sub albums $template->clear_assign('U_MODE_FLAT'); } //------------------------------------------------------ main part : thumbnails if (0 == $page['start'] and !isset($page['flat']) and !isset($page['chronology_field']) and ('recent_cats' == $page['section'] or 'categories' == $page['section']) and (!isset($page['category']['count_categories']) or $page['category']['count_categories'] > 0)) { include PHPWG_ROOT_PATH . 'include/category_cats.inc.php'; } if (!empty($page['items'])) { include PHPWG_ROOT_PATH . 'include/category_default.inc.php'; $url = add_url_params(duplicate_index_url(), array('display' => '')); $selected_type = $template->get_template_vars('derivative_params')->type; $template->clear_assign('derivative_params'); $type_map = ImageStdParams::get_defined_type_map(); unset($type_map[IMG_XXLARGE], $type_map[IMG_XLARGE]); foreach ($type_map as $params) { $template->append('image_derivatives', array('DISPLAY' => l10n($params->type), 'URL' => $url . $params->type, 'SELECTED' => $params->type == $selected_type ? true : false)); } } // slideshow // execute after init thumbs in order to have all picture informations if (!empty($page['cat_slideshow_url'])) { if (isset($_GET['slideshow'])) { redirect($page['cat_slideshow_url']); } elseif ($conf['index_slideshow_icon']) { $template->assign('U_SLIDESHOW', $page['cat_slideshow_url']);
function Fotorama_end_picture() { global $template, $conf, $user, $page; if (Fotorama_is_replace_picture()) { $url_up = duplicate_index_url(array('start' => floor($page['current_rank'] / $page['nb_image_page']) * $page['nb_image_page']), array('start')); //slideshow end $template->assign(array('U_SLIDESHOW_STOP' => $url_up)); $template->assign('replace_picture', true); } if (!$page['slideshow']) { return; } load_language('plugin.lang', FOTORAMA_PATH); $split_limit = 400; if ('mobile' == get_device()) { $split_limit /= 2; } $view_offset = null; if (count($page['items']) >= 1.2 * $split_limit) { $first = $split_limit * 0.2; $last = $split_limit - $first; $first = $page['current_rank'] - $first; if ($first < 0) { $first += count($page['items']); } $last = $page['current_rank'] + $last; if ($last >= count($page['items'])) { $last -= count($page['items']); } if ($first < $last) { $selection = array_slice($page['items'], $first, $last - $first); $view_borders = array(0, count($selection) - 1); $view_offset = array('from' => 0, 'offset' => $first); } else { $selection = array_slice($page['items'], 0, $last); $view_borders = array(count($selection), count($selection) - 1); $view_offset = array('from' => count($selection), 'offset' => $first - count($selection)); $selection = array_merge($selection, array_slice($page['items'], $first)); } } else { $selection = $page['items']; $view_borders = null; } $query = ' SELECT * FROM ' . IMAGES_TABLE . ' WHERE id IN (' . implode(',', $selection) . ') ORDER BY FIELD(id, ' . implode(',', $selection) . ') ;'; $result = pwg_query($query); $current = $template->get_template_vars('current'); if (isset($current['selected_derivative'])) { $type = $current['selected_derivative']->get_type(); } $defined = ImageStdParams::get_defined_type_map(); if (!isset($type) or !isset($defined[$type])) { $type = pwg_get_session_var('picture_deriv', $conf['derivative_default_size']); } $skip = -1; $big_type = $type; $next_type = $type; foreach (ImageStdParams::get_defined_type_map() as $def_type => $params) { if ($def_type == $type) { $skip = 2; } if ($skip >= 0) { $big_type = $def_type; } if ($skip >= 1 and $conf['Fotorama']['resize']) { $next_type = $def_type; } if ($skip == 0) { break; } $skip = $skip - 1; } $type = $next_type; // +1 size for inpage slideshow if ($conf['Fotorama']['only_fullscreen']) { $type = $big_type; } $type_params = ImageStdParams::get_by_type($type); $big_type_params = ImageStdParams::get_by_type($big_type); if ($conf['Fotorama']['nav'] == 'thumbs' or $conf['Fotorama']['fullscreen_nav'] == 'thumbs') { $has_thumbs = true; } else { $has_thumbs = false; } if ($has_thumbs) { if ($conf['Fotorama']['square_thumb']) { $thumb_params = ImageStdParams::get_custom($conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight'], 1, $conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight']); } else { $thumb_params = ImageStdParams::get_custom(9999, $conf['Fotorama']['thumbheight']); } } $picture = array(); while ($row = pwg_db_fetch_assoc($result)) { $row['src_image'] = new SrcImage($row); $row['derivative'] = new DerivativeImage($type_params, $row['src_image']); $row['derivative_big'] = new DerivativeImage($big_type_params, $row['src_image']); if ($has_thumbs) { $row['derivative_thumb'] = new DerivativeImage($thumb_params, $row['src_image']); } $row['url'] = duplicate_picture_url(array('image_id' => $row['id'], 'image_file' => $row['file']), array('start')); $row['TITLE'] = render_element_name($row); $picture[] = $row; } $picture = trigger_change('fotorama_items', $picture, $selection); $template->assign(array('TOTAL_ITEMS' => count($page['items']), 'view_borders' => $view_borders, 'view_offset' => $view_offset, 'current_rank' => array_search($page['image_id'], $selection))); $template->assign('item_height', ImageStdParams::get_by_type($type)->max_height()); $template->assign('items', $picture); $template->assign(array('Fotorama' => $conf['Fotorama'])); $template->assign('Fotorama_has_thumbs', $has_thumbs); if (is_file('./themes/' . $user['theme'] . '/template/fotorama.tpl')) { $template->set_filenames(array('slideshow' => realpath('./themes/' . $user['theme'] . '/template/fotorama.tpl'))); } else { $template->set_filenames(array('slideshow' => realpath(FOTORAMA_PATH . 'template/fotorama.tpl'))); } $template->assign('FOTORAMA_CONTENT_PATH', realpath(FOTORAMA_PATH . 'template/fotorama-content.tpl')); }
function pqv_end_section_init() { global $template, $page; if (!pqv_is_active()) { return; } if (empty($page['items'])) { return; } $query = ' SELECT id FROM ' . IMAGES_TABLE . ' WHERE id IN (' . implode(',', $page['items']) . ') AND pqv_validated = \'false\' ;'; $pqv_rejected = query2array($query, null, 'id'); if (isset($_GET['pqv_delete']) and count($pqv_rejected) > 0) { include_once PHPWG_ROOT_PATH . 'admin/include/functions.php'; $deleted_count = delete_elements($pqv_rejected, true); if ($deleted_count > 0) { invalidate_user_cache(); $_SESSION['page_infos'][] = l10n_dec('%d photo was deleted', '%d photos were deleted', $deleted_count); $redirect_url = duplicate_index_url(array(), array('pqv_delete')); redirect($redirect_url); } } if (count($pqv_rejected) > 0) { $delete_url = add_url_params(duplicate_index_url(), array('pqv_delete' => 1)); $template->assign('CONTENT_DESCRIPTION', '<a href="' . $delete_url . '" onclick="return confirm(\'' . l10n('Are you sure?') . '\');">delete the ' . count($pqv_rejected) . ' rejected photo(s)</a>'); } }
function pshare_section_init() { global $tokens, $page, $conf, $user, $template; if ($tokens[0] == 'pshare') { $page['section'] = 'pshare'; $page['title'] = l10n('Shared Picture'); if (!isset($tokens[1])) { die("missing key"); } if (!preg_match(PSHARE_KEY_PATTERN, $tokens[1])) { die("invalid key"); } $page['pshare_key'] = $tokens[1]; $query = ' SELECT *, NOW() AS dbnow FROM ' . PSHARE_KEYS_TABLE . ' WHERE uuid = \'' . $page['pshare_key'] . '\' ;'; $shares = query2array($query); if (count($shares) == 0) { die('unknown key'); } $share = $shares[0]; pshare_log($share['pshare_key_id'], 'visit'); // is the key still valid? if (strtotime($share['expire_on']) < strtotime($share['dbnow'])) { die('expired key'); } // if the user is permitted for this photo, let's redirect to // picture.php (with full details and actions) if (!is_a_guest() and pshare_is_photo_visible($share['image_id'])) { // find the first reachable category linked to the photo $query = ' SELECT category_id FROM ' . IMAGE_CATEGORY_TABLE . ' WHERE image_id = ' . $share['image_id'] . ' ;'; $authorizeds = array_diff(array_from_query($query, 'category_id'), explode(',', calculate_permissions($user['id'], $user['status']))); foreach ($authorizeds as $category_id) { $url = make_picture_url(array('image_id' => $share['image_id'], 'category' => get_cat_info($category_id))); if (function_exists('Fotorama_is_replace_picture') and Fotorama_is_replace_picture()) { $url .= '&slidestop'; } redirect($url); } redirect(make_picture_url(array('image_id' => $share['image_id']))); } $query = ' SELECT * FROM ' . IMAGES_TABLE . ' WHERE id = ' . $share['image_id'] . ' ;'; $rows = query2array($query); $image = $rows[0]; $src_image = new SrcImage($image); if (isset($tokens[2]) && 'download' == $tokens[2]) { $format_id = null; if (isset($tokens[3]) && preg_match('/^f(\\d+)$/', $tokens[3], $matches)) { $format_id = $matches[1]; $query = ' SELECT * FROM ' . IMAGE_FORMAT_TABLE . ' WHERE format_id = ' . $format_id . ' AND image_id = ' . $image['id'] . ' ;'; $formats = query2array($query); if (count($formats) == 0) { do_error(400, 'Invalid request - format'); } $format = $formats[0]; $file = original_to_format(get_element_path($image), $format['ext']); $image['file'] = get_filename_wo_extension($image['file']) . '.' . $format['ext']; } else { $file = $image['path']; } $gmt_mtime = gmdate('D, d M Y H:i:s', filemtime($file)) . ' GMT'; $http_headers = array('Content-Length: ' . @filesize($file), 'Last-Modified: ' . $gmt_mtime, 'Content-Type: ' . mime_content_type($file), 'Content-Disposition: attachment; filename="' . $image['file'] . '";', 'Content-Transfer-Encoding: binary'); foreach ($http_headers as $header) { header($header); } readfile($file); pshare_log($share['pshare_key_id'], 'download', $format_id); exit; } $template->set_filename('shared_picture', realpath(PSHARE_PATH . 'template/shared_picture.tpl')); $derivative = new DerivativeImage(ImageStdParams::get_by_type(IMG_MEDIUM), $src_image); $derivative_size = $derivative->get_size(); // a random string to avoid browser cache $rand = '&download=' . substr(md5(time()), 0, 6); $template->assign(array('SRC' => $derivative->get_url(), 'IMG_WIDTH' => $derivative_size[0], 'IMG_HEIGHT' => $derivative_size[1], 'DOWNLOAD_URL' => duplicate_index_url() . '/' . $page['pshare_key'] . '/download' . $rand)); // formats if (defined('IMAGE_FORMAT_TABLE')) { $query = ' SELECT * FROM ' . IMAGE_FORMAT_TABLE . ' WHERE image_id = ' . $share['image_id'] . ' ;'; $formats = query2array($query); if (!empty($formats)) { foreach ($formats as &$format) { $format['download_url'] = duplicate_index_url() . '/' . $page['pshare_key'] . '/download'; $format['download_url'] .= '/f' . $format['format_id'] . $rand; $format['filesize'] = sprintf('%.1fMB', $format['filesize'] / 1024); } } $template->assign('formats', $formats); } $template->parse('shared_picture'); $template->p(); exit; } }