Пример #1
0
function parse_request()
{
    global $conf, $page;
    if ($conf['question_mark_in_urls'] == false and isset($_SERVER["PATH_INFO"]) and !empty($_SERVER["PATH_INFO"])) {
        $req = $_SERVER["PATH_INFO"];
        $req = str_replace('//', '/', $req);
        $path_count = count(explode('/', $req));
        $page['root_path'] = PHPWG_ROOT_PATH . str_repeat('../', $path_count - 1);
    } else {
        $req = $_SERVER["QUERY_STRING"];
        if ($pos = strpos($req, '&')) {
            $req = substr($req, 0, $pos);
        }
        $req = rawurldecode($req);
        /*foreach (array_keys($_GET) as $keynum => $key)
          {
            $req = $key;
            break;
          }*/
        $page['root_path'] = PHPWG_ROOT_PATH;
    }
    $req = ltrim($req, '/');
    foreach (preg_split('#/+#', $req) as $token) {
        preg_match($conf['sync_chars_regex'], $token) or ierror('Invalid chars in request', 400);
    }
    $page['derivative_path'] = PHPWG_ROOT_PATH . PWG_DERIVATIVE_DIR . $req;
    $pos = strrpos($req, '.');
    $pos !== false || ierror('Missing .', 400);
    $ext = substr($req, $pos);
    $page['derivative_ext'] = $ext;
    $req = substr($req, 0, $pos);
    $pos = strrpos($req, '-');
    $pos !== false || ierror('Missing -', 400);
    $deriv = substr($req, $pos + 1);
    $req = substr($req, 0, $pos);
    $deriv = explode('_', $deriv);
    foreach (ImageStdParams::get_defined_type_map() as $type => $params) {
        if (derivative_to_url($type) == $deriv[0]) {
            $page['derivative_type'] = $type;
            $page['derivative_params'] = $params;
            break;
        }
    }
    if (!isset($page['derivative_type'])) {
        if (derivative_to_url(IMG_CUSTOM) == $deriv[0]) {
            $page['derivative_type'] = IMG_CUSTOM;
        } else {
            ierror('Unknown parsing type', 400);
        }
    }
    array_shift($deriv);
    if ($page['derivative_type'] == IMG_CUSTOM) {
        $params = $page['derivative_params'] = parse_custom_params($deriv);
        ImageStdParams::apply_global($params);
        if ($params->sizing->ideal_size[0] < 20 or $params->sizing->ideal_size[1] < 20) {
            ierror('Invalid size', 400);
        }
        if ($params->sizing->max_crop < 0 or $params->sizing->max_crop > 1) {
            ierror('Invalid crop', 400);
        }
        $greatest = ImageStdParams::get_by_type(IMG_XXLARGE);
        $key = array();
        $params->add_url_tokens($key);
        $key = implode('_', $key);
        if (!isset(ImageStdParams::$custom[$key])) {
            ierror('Size not allowed', 403);
        }
    }
    if (is_file(PHPWG_ROOT_PATH . $req . $ext)) {
        $req = './' . $req;
        // will be used to match #iamges.path
    } elseif (is_file(PHPWG_ROOT_PATH . '../' . $req . $ext)) {
        $req = '../' . $req;
    }
    $page['src_location'] = $req . $ext;
    $page['src_path'] = PHPWG_ROOT_PATH . $page['src_location'];
    $page['src_url'] = $page['root_path'] . $page['src_location'];
}
Пример #2
0
 /**
  * @todo : documentation of DerivativeImage::build
  */
 private static function build($src, &$params, &$rel_path, &$rel_url, &$is_cached = null)
 {
     if ($src->has_size() && $params->is_identity($src->get_size())) {
         // the source image is smaller than what we should do - we do not upsample
         if (!$params->will_watermark($src->get_size()) && !$src->rotation) {
             // no watermark, no rotation required -> we will use the source image
             $params = null;
             $rel_path = $rel_url = $src->rel_path;
             return;
         }
         $defined_types = array_keys(ImageStdParams::get_defined_type_map());
         for ($i = 0; $i < count($defined_types); $i++) {
             if ($defined_types[$i] == $params->type) {
                 for ($i--; $i >= 0; $i--) {
                     $smaller = ImageStdParams::get_by_type($defined_types[$i]);
                     if ($smaller->sizing->max_crop == $params->sizing->max_crop && $smaller->is_identity($src->get_size())) {
                         $params = $smaller;
                         self::build($src, $params, $rel_path, $rel_url, $is_cached);
                         return;
                     }
                 }
                 break;
             }
         }
     }
     $tokens = array();
     $tokens[] = substr($params->type, 0, 2);
     if ($params->type == IMG_CUSTOM) {
         $params->add_url_tokens($tokens);
     }
     $loc = $src->rel_path;
     if (substr_compare($loc, './', 0, 2) == 0) {
         $loc = substr($loc, 2);
     } elseif (substr_compare($loc, '../', 0, 3) == 0) {
         $loc = substr($loc, 3);
     }
     $loc = substr_replace($loc, '-' . implode('_', $tokens), strrpos($loc, '.'), 0);
     $rel_path = PWG_DERIVATIVE_DIR . $loc;
     global $conf;
     $url_style = $conf['derivative_url_style'];
     if (!$url_style) {
         $mtime = @filemtime(PHPWG_ROOT_PATH . $rel_path);
         if ($mtime === false or $mtime < $params->last_mod_time) {
             $is_cached = false;
             $url_style = 2;
         } else {
             $url_style = 1;
         }
     }
     if ($url_style == 2) {
         $rel_url = 'i';
         if ($conf['php_extension_in_urls']) {
             $rel_url .= '.php';
         }
         if ($conf['question_mark_in_urls']) {
             $rel_url .= '?';
         }
         $rel_url .= '/' . $loc;
     } else {
         $rel_url = $rel_path;
     }
 }
Пример #3
0
    file,
    path,
    representative_ext,
    width, height, rotation,
    name,
    rank
  FROM ' . IMAGES_TABLE . '
    JOIN ' . IMAGE_CATEGORY_TABLE . ' ON image_id = id
  WHERE category_id = ' . $page['category_id'] . '
  ORDER BY rank
;';
$result = pwg_query($query);
if (pwg_db_num_rows($result) > 0) {
    // template thumbnail initialization
    $current_rank = 1;
    $derivativeParams = ImageStdParams::get_by_type(IMG_SQUARE);
    while ($row = pwg_db_fetch_assoc($result)) {
        $derivative = new DerivativeImage($derivativeParams, new SrcImage($row));
        if (!empty($row['name'])) {
            $thumbnail_name = $row['name'];
        } else {
            $file_wo_ext = get_filename_wo_extension($row['file']);
            $thumbnail_name = str_replace('_', ' ', $file_wo_ext);
        }
        $current_rank++;
        $template->append('thumbnails', array('ID' => $row['id'], 'NAME' => $thumbnail_name, 'TN_SRC' => $derivative->get_url(), 'RANK' => $current_rank * 10, 'SIZE' => $derivative->get_size()));
    }
}
// image order management
$sort_fields = array('' => '', 'file ASC' => l10n('File name, A &rarr; Z'), 'file DESC' => l10n('File name, Z &rarr; A'), 'name ASC' => l10n('Photo title, A &rarr; Z'), 'name DESC' => l10n('Photo title, Z &rarr; A'), 'date_creation DESC' => l10n('Date created, new &rarr; old'), 'date_creation ASC' => l10n('Date created, old &rarr; new'), 'date_available DESC' => l10n('Date posted, new &rarr; old'), 'date_available ASC' => l10n('Date posted, old &rarr; new'), 'rating_score DESC' => l10n('Rating score, high &rarr; low'), 'rating_score ASC' => l10n('Rating score, low &rarr; high'), 'hit DESC' => l10n('Visits, high &rarr; low'), 'hit ASC' => l10n('Visits, low &rarr; high'), 'id ASC' => l10n('Numeric identifier, 1 &rarr; 9'), 'id DESC' => l10n('Numeric identifier, 9 &rarr; 1'), 'rank ASC' => l10n('Manual sort order'));
$template->assign('image_order_options', $sort_fields);
Пример #4
0
        $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');
Пример #5
0
    return $d == 0 ? 0 : ($d < 0 ? -1 : 1);
}
function cv_compare($a, $b)
{
    $d = $b['cv'] - $a['cv'];
    //desc
    return $d == 0 ? 0 : ($d < 0 ? -1 : 1);
}
function consensus_dev_compare($a, $b)
{
    $d = $b['cd'] - $a['cd'];
    //desc
    return $d == 0 ? 0 : ($d < 0 ? -1 : 1);
}
function last_rate_compare($a, $b)
{
    return -strcmp($a['last_date'], $b['last_date']);
}
$order_by_index = 4;
if (isset($_GET['order_by']) and is_numeric($_GET['order_by'])) {
    $order_by_index = $_GET['order_by'];
}
$available_order_by = array(array(l10n('Average rate'), 'avg_compare'), array(l10n('Number of rates'), 'count_compare'), array(l10n('Variation'), 'cv_compare'), array(l10n('Consensus deviation'), 'consensus_dev_compare'), array(l10n('Last'), 'last_rate_compare'));
for ($i = 0; $i < count($available_order_by); $i++) {
    $template->append('order_by_options', $available_order_by[$i][0]);
}
$template->assign('order_by_options_selected', array($order_by_index));
$x = uasort($by_user_ratings, $available_order_by[$order_by_index][1]);
$template->assign(array('F_ACTION' => get_root_url() . 'admin.php', 'F_MIN_RATES' => $filter_min_rates, 'CONSENSUS_TOP_NUMBER' => $consensus_top_number, 'available_rates' => $conf['rate_items'], 'ratings' => $by_user_ratings, 'image_urls' => $image_urls, 'TN_WIDTH' => ImageStdParams::get_by_type(IMG_SQUARE)->sizing->ideal_size[0]));
$template->set_filename('rating', 'rating_user.tpl');
$template->assign_var_from_handle('ADMIN_CONTENT', 'rating');
{
    global $tpl_thumbnails_var;
    return $tpl_thumbnails_var;
}
// Get better derive parameters for screen size
$type = IMG_LARGE;
if (!empty($_COOKIE['screen_size'])) {
    $screen_size = explode('x', $_COOKIE['screen_size']);
    foreach (ImageStdParams::get_all_type_map() as $type => $map) {
        if (max($map->sizing->ideal_size) >= max($screen_size) and min($map->sizing->ideal_size) >= min($screen_size)) {
            break;
        }
    }
}
$this->assign('picture_derivative_params', ImageStdParams::get_by_type($type));
$this->assign('thumbnail_derivative_params', ImageStdParams::get_by_type(IMG_SQUARE));
//------------------------------------------------------------- mobile version & theme config
add_event_handler('init', 'mobile_link');
function mobile_link()
{
    global $template, $conf;
    $config = unserialize($conf['smartpocket']);
    $template->assign('smartpocket', $config);
    if (!empty($conf['mobile_theme']) && (get_device() != 'desktop' || mobile_theme())) {
        $template->assign(array('TOGGLE_MOBILE_THEME_URL' => add_url_params(htmlspecialchars($_SERVER['REQUEST_URI']), array('mobile' => mobile_theme() ? 'false' : 'true'))));
    }
}
if (!function_exists('add_menu_on_public_pages')) {
    if (defined('IN_ADMIN') and IN_ADMIN) {
        return false;
    }
Пример #7
0
 /**
  * The "define_derivative" function allows to define derivative from tpl file.
  * It assigns a DerivativeParams object to _name_ template variable.
  *
  * @param array $params
  *    - name (required)
  *    - type (optional)
  *    - width (required if type is empty)
  *    - height (required if type is empty)
  *    - crop (optional, used if type is empty)
  *    - min_height (optional, used with crop)
  *    - min_height (optional, used with crop)
  * @param Smarty $smarty
  */
 function func_define_derivative($params, $smarty)
 {
     !empty($params['name']) or fatal_error('define_derivative missing name');
     if (isset($params['type'])) {
         $derivative = ImageStdParams::get_by_type($params['type']);
         $smarty->assign($params['name'], $derivative);
         return;
     }
     !empty($params['width']) or fatal_error('define_derivative missing width');
     !empty($params['height']) or fatal_error('define_derivative missing height');
     $w = intval($params['width']);
     $h = intval($params['height']);
     $crop = 0;
     $minw = null;
     $minh = null;
     if (isset($params['crop'])) {
         if (is_bool($params['crop'])) {
             $crop = $params['crop'] ? 1 : 0;
         } else {
             $crop = round($params['crop'] / 100, 2);
         }
         if ($crop) {
             $minw = empty($params['min_width']) ? $w : intval($params['min_width']);
             $minw <= $w or fatal_error('define_derivative invalid min_width');
             $minh = empty($params['min_height']) ? $h : intval($params['min_height']);
             $minh <= $h or fatal_error('define_derivative invalid min_height');
         }
     }
     $smarty->assign($params['name'], ImageStdParams::get_custom($w, $h, $crop, $minw, $minh));
 }
Пример #8
0
        $row['NB_COMMENTS'] = $row['nb_comments'] = (int) @$nb_comments_of[$row['id']];
    }
    $name = render_element_name($row);
    $desc = render_element_description($row, 'main_page_element_description');
    $tpl_var = array_merge($row, array('TN_ALT' => htmlspecialchars(strip_tags($name)), 'TN_TITLE' => get_thumbnail_title($row, $name, $desc), 'URL' => $url, 'DESCRIPTION' => $desc, 'src_image' => new SrcImage($row)));
    if ($conf['index_new_icon']) {
        $tpl_var['icon_ts'] = get_icon($row['date_available']);
    }
    if ($user['show_nb_hits']) {
        $tpl_var['NB_HITS'] = $row['hit'];
    }
    switch ($page['section']) {
        case 'best_rated':
            $name = '(' . $row['rating_score'] . ') ' . $name;
            break;
        case 'most_visited':
            if (!$user['show_nb_hits']) {
                $name = '(' . $row['hit'] . ') ' . $name;
            }
            break;
    }
    $tpl_var['NAME'] = $name;
    $tpl_thumbnails_var[] = $tpl_var;
}
$template->assign(array('derivative_params' => trigger_change('get_index_derivative_params', ImageStdParams::get_by_type(pwg_get_session_var('index_deriv', IMG_THUMB))), 'maxRequests' => $conf['max_requests'], 'SHOW_THUMBNAIL_CAPTION' => $conf['show_thumbnail_caption']));
$tpl_thumbnails_var = trigger_change('loc_end_index_thumbnails', $tpl_thumbnails_var, $pictures);
$template->assign('thumbnails', $tpl_thumbnails_var);
$template->assign_var_from_handle('THUMBNAILS', 'index_thumbnails');
unset($pictures, $selection, $tpl_thumbnails_var);
$template->clear_assign('thumbnails');
pwg_debug('end include/category_default.inc.php');
Пример #9
0
   /**
    * 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;
   }
Пример #10
0
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'));
}
Пример #11
0
        }
        $query .= '
    JOIN ' . IMAGE_CATEGORY_TABLE . ' ON id = image_id';
    }
    $query .= '
  WHERE id IN (' . implode(',', $page['cat_elements_id']) . ')';
    if ($is_category) {
        $query .= '
    AND category_id = ' . $_SESSION['bulk_manager_filter']['category'];
    }
    $query .= '
  ' . $conf['order_by'] . '
  LIMIT ' . $page['nb_images'] . ' OFFSET ' . $page['start'] . '
;';
    $result = pwg_query($query);
    $thumb_params = ImageStdParams::get_by_type(IMG_THUMB);
    // template thumbnail initialization
    while ($row = pwg_db_fetch_assoc($result)) {
        $nb_thumbs_page++;
        $src_image = new SrcImage($row);
        $ttitle = render_element_name($row);
        if ($ttitle != get_name_from_file($row['file'])) {
            $ttitle .= ' (' . $row['file'] . ')';
        }
        $template->append('thumbnails', array_merge($row, array('thumb' => new DerivativeImage($thumb_params, $src_image), 'TITLE' => $ttitle, 'FILE_SRC' => DerivativeImage::url(IMG_LARGE, $src_image), 'U_EDIT' => get_root_url() . 'admin.php?page=photo-' . $row['id'])));
    }
    $template->assign('thumb_params', $thumb_params);
}
$template->assign(array('nb_thumbs_page' => $nb_thumbs_page, 'nb_thumbs_set' => count($page['cat_elements_id']), 'CACHE_KEYS' => get_admin_client_cache_keys(array('tags', 'categories'))));
trigger_notify('loc_end_element_set_global');
//----------------------------------------------------------- sending html code
Пример #12
0
                $key = get_ephemeral_key(2, $comment['image_id']);
                $tpl_comment['KEY'] = $key;
                $tpl_comment['IMAGE_ID'] = $comment['image_id'];
                $tpl_comment['CONTENT'] = $comment['content'];
                $tpl_comment['PWG_TOKEN'] = get_pwg_token();
                $tpl_comment['U_CANCEL'] = $url_self;
            }
        }
        if (can_manage_comment('validate', $comment['author_id'])) {
            if ('true' != $comment['validated']) {
                $tpl_comment['U_VALIDATE'] = add_url_params($url_self, array('validate' => $comment['comment_id'], 'pwg_token' => get_pwg_token()));
            }
        }
        $template->append('comments', $tpl_comment);
    }
}
$derivative_params = trigger_change('get_comments_derivative_params', ImageStdParams::get_by_type(IMG_THUMB));
$template->assign('derivative_params', $derivative_params);
// include menubar
$themeconf = $template->get_template_vars('themeconf');
if (!isset($themeconf['hide_menu_on']) or !in_array('theCommentsPage', $themeconf['hide_menu_on'])) {
    include PHPWG_ROOT_PATH . 'include/menubar.inc.php';
}
// +-----------------------------------------------------------------------+
// |                           html code display                           |
// +-----------------------------------------------------------------------+
include PHPWG_ROOT_PATH . 'include/page_header.php';
trigger_notify('loc_end_comments');
flush_page_messages();
$template->pparse('comments');
include PHPWG_ROOT_PATH . 'include/page_tail.php';
Пример #13
0
function modus_get_index_photo_derivative_params($default)
{
    global $conf;
    if (isset($conf['modus_theme']) && pwg_get_session_var('index_deriv') === null) {
        $type = $conf['modus_theme']['index_photo_deriv'];
        if ($caps = pwg_get_session_var('caps')) {
            if ($caps[0] >= 2 && $caps[1] >= 768 || $caps[0] >= 3) {
                $type = $conf['modus_theme']['index_photo_deriv_hdpi'];
            }
        }
        $new = @ImageStdParams::get_by_type($type);
        if ($new) {
            return $new;
        }
    }
    return $default;
}
Пример #14
0
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 = '&amp;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;
    }
}