function pick($src_image) { $ok = false; foreach ($this->candidates as $candidate) { $deriv = new DerivativeImage($candidate, $src_image); $size = $deriv->get_size(); if ($size[1] >= $row_height - 2) { $ok = true; break; } } if (!$ok) { $deriv = new DerivativeImage($this->default, $src_image); } return $deriv; }
function modus_index_category_thumbnails($items) { global $page, $template, $conf; if ('categories' != $page['section'] || !($wh = @$conf['modus_theme']['album_thumb_size'])) { return $items; } $template->assign('album_thumb_size', $wh); $def_params = ImageStdParams::get_custom($wh, $wh, 1, $wh, $wh); foreach (ImageStdParams::get_defined_type_map() as $params) { if ($params->max_height() == $wh) { $alt_params = $params; } } foreach ($items as &$item) { $src_image = $item['representative']['src_image']; $src_size = $src_image->get_size(); $deriv = null; if (isset($alt_params) && $src_size[0] >= $src_size[1]) { $dsize = $alt_params->compute_final_size($src_size); if ($dsize[0] >= $wh && $dsize[1] >= $wh) { $deriv = new DerivativeImage($alt_params, $src_image); $rect = new ImageRect($dsize); $rect->crop_h($dsize[0] - $wh, $item['representative']['coi']); $rect->crop_v($dsize[1] - $wh, $item['representative']['coi']); $l = -$rect->l; $t = -$rect->t; } } if (!isset($deriv)) { $deriv = new DerivativeImage($def_params, $src_image); $dsize = $deriv->get_size(); $l = intval($wh - $dsize[0]) / 2; $t = intval($wh - $dsize[1]) / 2; } $item['modus_deriv'] = $deriv; if (!empty($item['icon_ts'])) { $item['icon_ts']['TITLE'] = time_since($item['max_date_last'], 'month'); } $styles = array(); if ($l < -1 || $l > 1) { $styles[] = 'left:' . 100 * $l / $wh . '%'; } if ($t < -1 || $t > 1) { $styles[] = 'top:' . $t . 'px'; } if (count($styles)) { $styles = ' style=' . implode(';', $styles); } else { $styles = ''; } $item['MODUS_STYLE'] = $styles; } return $items; }
/** * API method * Returns a list of missing derivatives (not generated yet) * @param mixed[] $params * @option string types (optional) * @option int[] ids * @option int max_urls * @option int prev_page (optional) */ function ws_getMissingDerivatives($params, &$service) { global $conf; if (empty($params['types'])) { $types = array_keys(ImageStdParams::get_defined_type_map()); } else { $types = array_intersect(array_keys(ImageStdParams::get_defined_type_map()), $params['types']); if (count($types) == 0) { return new PwgError(WS_ERR_INVALID_PARAM, "Invalid types"); } } $max_urls = $params['max_urls']; $query = 'SELECT MAX(id)+1, COUNT(*) FROM ' . IMAGES_TABLE . ';'; list($max_id, $image_count) = pwg_db_fetch_row(pwg_query($query)); if (0 == $image_count) { return array(); } $start_id = $params['prev_page']; if ($start_id <= 0) { $start_id = $max_id; } $uid = '&b=' . time(); $conf['question_mark_in_urls'] = $conf['php_extension_in_urls'] = true; $conf['derivative_url_style'] = 2; //script $qlimit = min(5000, ceil(max($image_count / 500, $max_urls / count($types)))); $where_clauses = ws_std_image_sql_filter($params, ''); $where_clauses[] = 'id<start_id'; if (!empty($params['ids'])) { $where_clauses[] = 'id IN (' . implode(',', $params['ids']) . ')'; } $query_model = ' SELECT id, path, representative_ext, width, height, rotation FROM ' . IMAGES_TABLE . ' WHERE ' . implode(' AND ', $where_clauses) . ' ORDER BY id DESC LIMIT ' . $qlimit . ' ;'; $urls = array(); do { $result = pwg_query(str_replace('start_id', $start_id, $query_model)); $is_last = pwg_db_num_rows($result) < $qlimit; while ($row = pwg_db_fetch_assoc($result)) { $start_id = $row['id']; $src_image = new SrcImage($row); if ($src_image->is_mimetype()) { continue; } foreach ($types as $type) { $derivative = new DerivativeImage($type, $src_image); if ($type != $derivative->get_type()) { continue; } if (@filemtime($derivative->get_path()) === false) { $urls[] = $derivative->get_url() . $uid; } } if (count($urls) >= $max_urls and !$is_last) { break; } } if ($is_last) { $start_id = 0; } } while (count($urls) < $max_urls and $start_id); $ret = array(); if ($start_id) { $ret['next_page'] = $start_id; } $ret['urls'] = $urls; return $ret; }
/** * returns an array map of urls (thumb/element) for image_row - to be returned * in a standard way by different web service methods */ function ws_std_get_urls($image_row) { $ret = array(); $ret['page_url'] = make_picture_url(array('image_id' => $image_row['id'], 'image_file' => $image_row['file'])); $src_image = new SrcImage($image_row); if ($src_image->is_original()) { // we have a photo global $user; if ($user['enabled_high']) { $ret['element_url'] = $src_image->get_url(); } } else { $ret['element_url'] = get_element_url($image_row); } $derivatives = DerivativeImage::get_all($src_image); $derivatives_arr = array(); foreach ($derivatives as $type => $derivative) { $size = $derivative->get_size(); $size != null or $size = array(null, null); $derivatives_arr[$type] = array('url' => $derivative->get_url(), 'width' => $size[0], 'height' => $size[1]); } $ret['derivatives'] = $derivatives_arr; return $ret; }
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 → Z'), 'file DESC' => l10n('File name, Z → A'), 'name ASC' => l10n('Photo title, A → Z'), 'name DESC' => l10n('Photo title, Z → A'), 'date_creation DESC' => l10n('Date created, new → old'), 'date_creation ASC' => l10n('Date created, old → new'), 'date_available DESC' => l10n('Date posted, new → old'), 'date_available ASC' => l10n('Date posted, old → new'), 'rating_score DESC' => l10n('Rating score, high → low'), 'rating_score ASC' => l10n('Rating score, low → high'), 'hit DESC' => l10n('Visits, high → low'), 'hit ASC' => l10n('Visits, low → high'), 'id ASC' => l10n('Numeric identifier, 1 → 9'), 'id DESC' => l10n('Numeric identifier, 9 → 1'), 'rank ASC' => l10n('Manual sort order')); $template->assign('image_order_options', $sort_fields); $image_order = explode(',', $category['image_order']); for ($i = 0; $i < 3; $i++) {
WHERE id = ' . $_GET['image_id'] . ' ;'; $row = pwg_db_fetch_assoc(pwg_query($query)); $storage_category_id = null; if (!empty($row['storage_category_id'])) { $storage_category_id = $row['storage_category_id']; } $image_file = $row['file']; // +-----------------------------------------------------------------------+ // | template init | // +-----------------------------------------------------------------------+ $template->set_filenames(array('picture_modify' => 'picture_modify.tpl')); $admin_url_start = $admin_photo_base_url . '-properties'; $admin_url_start .= isset($_GET['cat_id']) ? '&cat_id=' . $_GET['cat_id'] : ''; $src_image = new SrcImage($row); $template->assign(array('tag_selection' => $tag_selection, 'U_SYNC' => $admin_url_start . '&sync_metadata=1', 'U_DELETE' => $admin_url_start . '&delete=1&pwg_token=' . get_pwg_token(), 'PATH' => $row['path'], 'TN_SRC' => DerivativeImage::url(IMG_THUMB, $src_image), 'FILE_SRC' => DerivativeImage::url(IMG_LARGE, $src_image), 'NAME' => isset($_POST['name']) ? stripslashes($_POST['name']) : @$row['name'], 'TITLE' => render_element_name($row), 'DIMENSIONS' => @$row['width'] . ' * ' . @$row['height'], 'FILESIZE' => @$row['filesize'] . ' KB', 'REGISTRATION_DATE' => format_date($row['date_available']), 'AUTHOR' => htmlspecialchars(isset($_POST['author']) ? stripslashes($_POST['author']) : @$row['author']), 'DATE_CREATION' => $row['date_creation'], 'DESCRIPTION' => htmlspecialchars(isset($_POST['description']) ? stripslashes($_POST['description']) : @$row['comment']), 'F_ACTION' => get_root_url() . 'admin.php' . get_query_string_diff(array('sync_metadata')))); $added_by = 'N/A'; $query = ' SELECT ' . $conf['user_fields']['username'] . ' AS username FROM ' . USERS_TABLE . ' WHERE ' . $conf['user_fields']['id'] . ' = ' . $row['added_by'] . ' ;'; $result = pwg_query($query); while ($user_row = pwg_db_fetch_assoc($result)) { $row['added_by'] = $user_row['username']; } $intro_vars = array('file' => l10n('Original file : %s', $row['file']), 'add_date' => l10n('Posted %s on %s', time_since($row['date_available'], 'year'), format_date($row['date_available'], array('day', 'month', 'year'))), 'added_by' => l10n('Added by %s', $row['added_by']), 'size' => $row['width'] . '×' . $row['height'] . ' pixels, ' . sprintf('%.2f', $row['filesize'] / 1024) . 'MB', 'stats' => l10n('Visited %d times', $row['hit']), 'id' => l10n('Numeric identifier : %d', $row['id'])); if ($conf['rate'] and !empty($row['rating_score'])) { $query = ' SELECT COUNT(*)
function ws_images_addRemote($params, &$service) { global $conf; if (!is_admin()) { return new PwgError(401, 'Access denied'); } load_language('plugin.lang', URLUPLOADER_PATH); $params = array_map('trim', $params); $allowed_extensions = array('jpg', 'jpeg', 'png', 'gif'); $allowed_mimes = array('image/jpeg', 'image/png', 'image/gif'); // check empty url if (empty($params['file_url'])) { return new PwgError(WS_ERR_INVALID_PARAM, l10n('File URL is empty')); } // check remote url if (!url_is_remote($params['file_url'])) { return new PwgError(WS_ERR_INVALID_PARAM, l10n('Invalid file URL')); } // check file extension if (!in_array(strtolower(get_extension($params['file_url'])), $allowed_extensions)) { return new PwgError(WS_ERR_INVALID_PARAM, l10n('Invalid file type')); } // download file include_once PHPWG_ROOT_PATH . 'admin/include/functions.php'; $temp_filename = $conf['data_location'] . basename($params['file_url']); $file = fopen($temp_filename, 'w+'); $result = fetchRemote($params['file_url'], $file); fclose($file); // download failed ? if (!$result) { @unlink($temp_filename); return new PwgError(WS_ERR_INVALID_PARAM, l10n('Unable to download file')); } // check mime-type if (!in_array(get_mime($temp_filename, $allowed_mimes[0]), $allowed_mimes)) { @unlink($temp_filename); return new PwgError(WS_ERR_INVALID_PARAM, l10n('Invalid file type')); } // add photo include_once PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php'; $image_id = add_uploaded_file($temp_filename, basename($temp_filename), array($params['category']), $params['level']); $updates = array(); if (!empty($params['name'])) { $updates['name'] = $params['name']; } if ($params['url_in_comment'] == 'true') { $url = parse_url($params['file_url']); $url = $url['scheme'] . '://' . $url['host']; $updates['comment'] = '<a href="' . $url . '">' . $url . '</a>'; } single_update(IMAGES_TABLE, $updates, array('id' => $image_id)); // return infos $query = ' SELECT id, name, permalink FROM ' . CATEGORIES_TABLE . ' WHERE id = ' . $params['category'] . ' ;'; $category = pwg_db_fetch_assoc(pwg_query($query)); $url_params = array('image_id' => $image_id, 'section' => 'categories', 'category' => $category); $query = ' SELECT id, path, name FROM ' . IMAGES_TABLE . ' WHERE id = ' . $image_id . ' ;'; $image_infos = pwg_db_fetch_assoc(pwg_query($query)); $query = ' SELECT COUNT(*) AS nb_photos FROM ' . IMAGE_CATEGORY_TABLE . ' WHERE category_id = ' . $params['category'] . ' ;'; $category_infos = pwg_db_fetch_assoc(pwg_query($query)); $category_name = get_cat_display_name_from_id($params['category'], null); return array('image_id' => $image_id, 'url' => make_picture_url($url_params), 'src' => DerivativeImage::thumb_url($image_infos), 'name' => $image_infos['name'], 'category' => array('id' => $params['category'], 'nb_photos' => $category_infos['nb_photos'], 'label' => $category_name)); }
/** * Add main toolbar to current page * @trigger loc_after_page_header */ function admintools_add_public_controller() { global $MultiView, $conf, $template, $page, $user, $picture; if (script_basename() == 'picture' and empty($picture['current'])) { return; } $url_root = get_root_url(); $tpl_vars = array(); if ($MultiView->is_admin()) { // full options for admin $tpl_vars['U_SITE_ADMIN'] = $url_root . 'admin.php?page='; $tpl_vars['MULTIVIEW'] = $MultiView->get_data(); $tpl_vars['USER'] = $MultiView->get_user(); $tpl_vars['CURRENT_USERNAME'] = $user['id'] == $conf['guest_id'] ? l10n('guest') : $user['username']; $tpl_vars['DELETE_CACHE'] = isset($conf['multiview_invalidate_cache']); if (($admin_lang = $MultiView->get_user_language()) !== false) { include_once PHPWG_ROOT_PATH . 'include/functions_mail.inc.php'; switch_lang_to($admin_lang); } } else { if ($conf['AdminTools']['public_quick_edit'] and script_basename() == 'picture' and $picture['current']['added_by'] == $user['id']) { // only "edit" button for photo owner } else { return; } } $tpl_vars['POSITION'] = $conf['AdminTools']['closed_position']; $tpl_vars['DEFAULT_OPEN'] = $conf['AdminTools']['default_open']; $tpl_vars['U_SELF'] = $MultiView->get_clean_url(true); // photo page if (script_basename() == 'picture') { $url_self = duplicate_picture_url(); $tpl_vars['IS_PICTURE'] = true; // admin can add to caddie and set representattive if ($MultiView->is_admin()) { $template->clear_assign(array('U_SET_AS_REPRESENTATIVE', 'U_PHOTO_ADMIN', 'U_CADDIE')); $template->set_prefilter('picture', 'admintools_remove_privacy'); $tpl_vars['U_CADDIE'] = add_url_params($url_self, array('action' => 'add_to_caddie')); $query = ' SELECT element_id FROM ' . CADDIE_TABLE . ' WHERE element_id = ' . $page['image_id'] . ' ;'; $tpl_vars['IS_IN_CADDIE'] = pwg_db_num_rows(pwg_query($query)) > 0; if (isset($page['category'])) { $tpl_vars['CATEGORY_ID'] = $page['category']['id']; $tpl_vars['U_SET_REPRESENTATIVE'] = add_url_params($url_self, array('action' => 'set_as_representative')); $tpl_vars['IS_REPRESENTATIVE'] = $page['category']['representative_picture_id'] == $page['image_id']; } $tpl_vars['U_ADMIN_EDIT'] = $url_root . 'admin.php?page=photo-' . $page['image_id'] . (isset($page['category']) ? '&cat_id=' . $page['category']['id'] : ''); } $tpl_vars['U_DELETE'] = add_url_params($url_self, array('delete' => '', 'pwg_token' => get_pwg_token())); // gets tags (full available list is loaded in ajax) include_once PHPWG_ROOT_PATH . 'admin/include/functions.php'; $query = ' SELECT id, name FROM ' . IMAGE_TAG_TABLE . ' AS it JOIN ' . TAGS_TABLE . ' AS t ON t.id = it.tag_id WHERE image_id = ' . $page['image_id'] . ' ;'; $tag_selection = get_taglist($query); $tpl_vars['QUICK_EDIT'] = array('img' => $picture['current']['derivatives']['square']->get_url(), 'name' => $picture['current']['name'], 'comment' => $picture['current']['comment'], 'author' => $picture['current']['author'], 'level' => $picture['current']['level'], 'date_creation' => substr($picture['current']['date_creation'], 0, 10), 'date_creation_time' => substr($picture['current']['date_creation'], 11, 5), 'tag_selection' => $tag_selection); } else { if ($MultiView->is_admin() and @$page['section'] == 'categories' and isset($page['category'])) { $url_self = duplicate_index_url(); $tpl_vars['IS_CATEGORY'] = true; $tpl_vars['CATEGORY_ID'] = $page['category']['id']; $template->clear_assign(array('U_EDIT', 'U_CADDIE')); $tpl_vars['U_ADMIN_EDIT'] = $url_root . 'admin.php?page=album-' . $page['category']['id']; if (!empty($page['items'])) { $tpl_vars['U_CADDIE'] = add_url_params($url_self, array('caddie' => 1)); } $tpl_vars['QUICK_EDIT'] = array('img' => null, 'name' => $page['category']['name'], 'comment' => $page['category']['comment']); if (!empty($page['category']['representative_picture_id'])) { $query = ' SELECT * FROM ' . IMAGES_TABLE . ' WHERE id = ' . $page['category']['representative_picture_id'] . ' ;'; $image_infos = pwg_db_fetch_assoc(pwg_query($query)); $tpl_vars['QUICK_EDIT']['img'] = DerivativeImage::get_one(IMG_SQUARE, $image_infos)->get_url(); } } } $template->assign(array('ADMINTOOLS_PATH' => './plugins/' . ADMINTOOLS_ID . '/', 'ato' => $tpl_vars)); $template->set_filename('ato_public_controller', realpath(ADMINTOOLS_PATH . 'template/public_controller.tpl')); $template->parse('ato_public_controller'); if ($MultiView->is_admin() && @$admin_lang !== false) { switch_lang_back(); } }
if (file_exists($file)) { array_push($videos, array('src' => embellish_url(get_gallery_home_url() . $parts['dirname'] . "/pwg_representative/" . $parts['filename'] . "." . $file_ext), 'ext' => vjs_get_mimetype_from_ext($file_ext))); } } //print_r($videos); /* Try to find WebVTT */ $file = $parts['dirname'] . "/pwg_representative/" . $parts['filename'] . ".vtt"; file_exists($file) ? $subtitle = embellish_url(get_gallery_home_url() . $file) : ($subtitle = null); /* Thumbnail videojs plugin */ $filematch = $parts['dirname'] . "/pwg_representative/" . $parts['filename'] . "-th_*"; $matches = glob($filematch); $thumbnails = array(); $sort = array(); // A list of sort columns and their data to pass to array_multisort if (is_array($matches) and !empty($matches)) { foreach ($matches as $filename) { $ext = explode("-th_", $filename); $second = explode(".", $ext[1]); // ./galleries/videos/pwg_representative/trailer_480p-th_0.jpg //echo "$filename second " . $second[0]. "\n"; $thumbnails[] = array('second' => $second[0], 'source' => embellish_url(get_gallery_home_url() . $filename)); $sort['second'][$second[0]] = $second[0]; } } //print_r($thumbnails); // Sort thumbnails by second !empty($sort['second']) and array_multisort($sort['second'], SORT_ASC, $thumbnails); $infos = array_merge(array('Poster' => $poster), array('Videos source' => count($videos)), array('videos' => $videos), array('Thumbnails' => count($thumbnails)), array('thumbnails' => $thumbnails), array('Subtitle' => $subtitle)); //print_r($infos); $template->assign(array('PWG_TOKEN' => get_pwg_token(), 'F_ACTION' => $self_url, 'SYNC_URL' => $sync_url, 'DELETE_URL' => $delete_url, 'TN_SRC' => DerivativeImage::thumb_url($picture) . '?' . time(), 'TITLE' => render_element_name($picture), 'EXIF' => $exif, 'INFOS' => $infos)); $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
SELECT id FROM ' . CATEGORIES_TABLE . ' INNER JOIN ' . IMAGE_CATEGORY_TABLE . ' ON category_id = id WHERE image_id = ' . $_GET['id'] . ' ' . get_sql_condition_FandF(array('forbidden_categories' => 'category_id', 'forbidden_images' => 'image_id'), ' AND') . ' LIMIT 1 ;'; if (pwg_db_num_rows(pwg_query($query)) < 1) { do_error(401, 'Access denied'); } include_once PHPWG_ROOT_PATH . 'include/functions_picture.inc.php'; $file = ''; switch ($_GET['part']) { case 'e': if (!$user['enabled_high']) { $deriv = new DerivativeImage(IMG_XXLARGE, new SrcImage($element_info)); if (!$deriv->same_as_source()) { do_error(401, 'Access denied e'); } } $file = get_element_path($element_info); break; case 'r': $file = original_to_representative(get_element_path($element_info), $element_info['representative_ext']); break; case 'f': $file = original_to_format(get_element_path($element_info), $format['ext']); $element_info['file'] = get_filename_wo_extension($element_info['file']) . '.' . $format['ext']; break; } if (empty($file)) {
$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 $template->assign_var_from_handle('ADMIN_CONTENT', 'batch_manager_global');
// +-----------------------------------------------------------------------+ // info by email to an access granted group of category informations if (isset($_POST['submitEmail']) and !empty($_POST['group'])) { set_make_full_url(); /* TODO: if $category['representative_picture_id'] is empty find child representative_picture_id */ if (!empty($category['representative_picture_id'])) { $query = ' SELECT id, file, path, representative_ext FROM ' . IMAGES_TABLE . ' WHERE id = ' . $category['representative_picture_id'] . ' ;'; $result = pwg_query($query); if (pwg_db_num_rows($result) > 0) { $element = pwg_db_fetch_assoc($result); $img_url = '<a href="' . make_picture_url(array('image_id' => $element['id'], 'image_file' => $element['file'], 'category' => $category)) . '" class="thumblnk"><img src="' . DerivativeImage::url(IMG_THUMB, $element) . '"></a>'; } } if (!isset($img_url)) { $img_url = ''; } pwg_mail_group($_POST['group'], array('subject' => l10n('[%s] Visit album %s', $conf['gallery_title'], trigger_change('render_category_name', $category['name'], 'admin_cat_list'))), array('filename' => 'cat_group_info', 'assign' => array('IMG_URL' => $img_url, 'CAT_NAME' => trigger_change('render_category_name', $category['name'], 'admin_cat_list'), 'LINK' => make_index_url(array('category' => array('id' => $category['id'], 'name' => trigger_change('render_category_name', $category['name'], 'admin_cat_list'), 'permalink' => $category['permalink']))), 'CPL_CONTENT' => empty($_POST['mail_content']) ? '' : stripslashes($_POST['mail_content'])))); unset_make_full_url(); $query = ' SELECT name FROM ' . GROUPS_TABLE . ' WHERE id = ' . $_POST['group'] . ' ;'; list($group_name) = pwg_db_fetch_row(pwg_query($query)); $page['infos'][] = l10n('An information email was sent to group "%s"', $group_name);
/** * API method * Adds a image (simple way) * @param mixed[] $params * @option int[] category * @option string name (optional) * @option string author (optional) * @option string comment (optional) * @option int level * @option string|string[] tags * @option int image_id (optional) */ function ws_images_upload($params, $service) { global $conf; if (get_pwg_token() != $params['pwg_token']) { return new PwgError(403, 'Invalid security token'); } // usleep(100000); // if (!isset($_FILES['image'])) // { // return new PwgError(405, 'The image (file) is missing'); // } // file_put_contents('/tmp/plupload.log', "[".date('c')."] ".__FUNCTION__."\n\n", FILE_APPEND); // file_put_contents('/tmp/plupload.log', '$_FILES = '.var_export($_FILES, true)."\n", FILE_APPEND); // file_put_contents('/tmp/plupload.log', '$_POST = '.var_export($_POST, true)."\n", FILE_APPEND); $upload_dir = $conf['upload_dir'] . '/buffer'; // create the upload directory tree if not exists if (!mkgetdir($upload_dir, MKGETDIR_DEFAULT & ~MKGETDIR_DIE_ON_ERROR)) { return new PwgError(500, 'error during buffer directory creation'); } // Get a file name if (isset($_REQUEST["name"])) { $fileName = $_REQUEST["name"]; } elseif (!empty($_FILES)) { $fileName = $_FILES["file"]["name"]; } else { $fileName = uniqid("file_"); } $filePath = $upload_dir . DIRECTORY_SEPARATOR . $fileName; // Chunking might be enabled $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0; $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0; // file_put_contents('/tmp/plupload.log', "[".date('c')."] ".__FUNCTION__.', '.$fileName.' '.($chunk+1).'/'.$chunks."\n", FILE_APPEND); // Open temp file if (!($out = @fopen("{$filePath}.part", $chunks ? "ab" : "wb"))) { die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); } if (!empty($_FILES)) { if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) { die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}'); } // Read binary input stream and append it to temp file if (!($in = @fopen($_FILES["file"]["tmp_name"], "rb"))) { die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); } } else { if (!($in = @fopen("php://input", "rb"))) { die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); } } while ($buff = fread($in, 4096)) { fwrite($out, $buff); } @fclose($out); @fclose($in); // Check if file has been uploaded if (!$chunks || $chunk == $chunks - 1) { // Strip the temp .part suffix off rename("{$filePath}.part", $filePath); include_once PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php'; $image_id = add_uploaded_file($filePath, stripslashes($params['name']), $params['category'], $params['level'], null); $query = ' SELECT id, name, representative_ext, path FROM ' . IMAGES_TABLE . ' WHERE id = ' . $image_id . ' ;'; $image_infos = pwg_db_fetch_assoc(pwg_query($query)); $query = ' SELECT COUNT(*) AS nb_photos FROM ' . IMAGE_CATEGORY_TABLE . ' WHERE category_id = ' . $params['category'][0] . ' ;'; $category_infos = pwg_db_fetch_assoc(pwg_query($query)); $category_name = get_cat_display_name_from_id($params['category'][0], null); return array('image_id' => $image_id, 'src' => DerivativeImage::thumb_url($image_infos), 'name' => $image_infos['name'], 'category' => array('id' => $params['category'][0], 'nb_photos' => $category_infos['nb_photos'], 'label' => $category_name)); } }
} $local_conf = array(); $local_conf['contextmenu'] = 'false'; $local_conf['control'] = true; $local_conf['img_popup'] = false; $local_conf['popup'] = 2; $local_conf['center_lat'] = $lat; $local_conf['center_lng'] = $lon; $local_conf['zoom'] = $zoom; $local_conf['editor'] = true; $pathurl = get_absolute_root_url() . "i.php?" . $picture['pathurl']; $js_data = array(array($lat, $lon, null, $pathurl, null, null, null, null)); $js = osm_get_js($conf, $local_conf, $js_data); // Fetch the template. global $prefixeTable; // Easy access define('osm_place_table', $prefixeTable . 'osm_places'); // Save location, eg Place $query = ' SELECT id, name, latitude, longitude FROM ' . osm_place_table . ' ;'; $result = pwg_query($query); // JS for the template while ($row = pwg_db_fetch_assoc($result)) { $list_of_places[$row['id']] = [$row['name'], $row['latitude'], $row['longitude']]; $available_places[$row['id']] = $row['name']; } $jsplaces = "\nvar arr_places = " . json_encode($list_of_places) . ";\n"; $template->assign(array('PWG_TOKEN' => get_pwg_token(), 'F_ACTION' => $self_url, 'TN_SRC' => DerivativeImage::thumb_url($picture) . '?' . time(), 'TITLE' => render_element_name($picture), 'OSM_PATH' => embellish_url(get_absolute_root_url() . OSM_PATH), 'OSM_JS' => $js, 'LAT' => $lat, 'LON' => $lon, 'AVAILABLE_PLACES' => $available_places, 'LIST_PLACES' => $jsplaces)); $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
function add_uploaded_file($source_filepath, $original_filename = null, $categories = null, $level = null, $image_id = null, $original_md5sum = null) { // 1) move uploaded file to upload/2010/01/22/20100122003814-449ada00.jpg // // 2) keep/resize original // // 3) register in database // TODO // * check md5sum (already exists?) global $conf, $user; if (isset($original_md5sum)) { $md5sum = $original_md5sum; } else { $md5sum = md5_file($source_filepath); } $file_path = null; $is_tiff = false; if (isset($image_id)) { // this photo already exists, we update it $query = ' SELECT path FROM ' . IMAGES_TABLE . ' WHERE id = ' . $image_id . ' ;'; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { $file_path = $row['path']; } if (!isset($file_path)) { die('[' . __FUNCTION__ . '] this photo does not exist in the database'); } // delete all physical files related to the photo (thumbnail, web site, HD) delete_element_files(array($image_id)); } else { // this photo is new // current date list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); list($year, $month, $day) = preg_split('/[^\\d]/', $dbnow, 4); // upload directory hierarchy $upload_dir = sprintf(PHPWG_ROOT_PATH . $conf['upload_dir'] . '/%s/%s/%s', $year, $month, $day); // compute file path $date_string = preg_replace('/[^\\d]/', '', $dbnow); $random_string = substr($md5sum, 0, 8); $filename_wo_ext = $date_string . '-' . $random_string; $file_path = $upload_dir . '/' . $filename_wo_ext . '.'; list($width, $height, $type) = getimagesize($source_filepath); if (IMAGETYPE_PNG == $type) { $file_path .= 'png'; } elseif (IMAGETYPE_GIF == $type) { $file_path .= 'gif'; } elseif (IMAGETYPE_TIFF_MM == $type or IMAGETYPE_TIFF_II == $type) { $is_tiff = true; $file_path .= 'tif'; } elseif (IMAGETYPE_JPEG == $type) { $file_path .= 'jpg'; } elseif (isset($conf['upload_form_all_types']) and $conf['upload_form_all_types']) { $original_extension = strtolower(get_extension($original_filename)); if (in_array($original_extension, $conf['file_ext'])) { $file_path .= $original_extension; } else { die('unexpected file type'); } } else { die('forbidden file type'); } prepare_directory($upload_dir); } if (is_uploaded_file($source_filepath)) { move_uploaded_file($source_filepath, $file_path); } else { rename($source_filepath, $file_path); } @chmod($file_path, 0644); if ($is_tiff and pwg_image::get_library() == 'ext_imagick') { // move the uploaded file to pwg_representative sub-directory $representative_file_path = dirname($file_path) . '/pwg_representative/'; $representative_file_path .= get_filename_wo_extension(basename($file_path)) . '.'; $representative_ext = $conf['tiff_representative_ext']; $representative_file_path .= $representative_ext; prepare_directory(dirname($representative_file_path)); $exec = $conf['ext_imagick_dir'] . 'convert'; if ('jpg' == $conf['tiff_representative_ext']) { $exec .= ' -quality 98'; } $exec .= ' "' . realpath($file_path) . '"'; $dest = pathinfo($representative_file_path); $exec .= ' "' . realpath($dest['dirname']) . '/' . $dest['basename'] . '"'; $exec .= ' 2>&1'; @exec($exec, $returnarray); // sometimes ImageMagick creates file-0.jpg (full size) + file-1.jpg // (thumbnail). I don't know how to avoid it. $representative_file_abspath = realpath($dest['dirname']) . '/' . $dest['basename']; if (!file_exists($representative_file_abspath)) { $first_file_abspath = preg_replace('/\\.' . $representative_ext . '$/', '-0.' . $representative_ext, $representative_file_abspath); if (file_exists($first_file_abspath)) { rename($first_file_abspath, $representative_file_abspath); } } } // // generate pwg_representative in case of video // $ffmpeg_video_exts = array('wmv', 'mov', 'mkv', 'mp4', 'mpg', 'flv', 'asf', 'xvid', 'divx', 'mpeg', 'avi', 'rm'); if (isset($original_extension) and in_array($original_extension, $ffmpeg_video_exts)) { $representative_file_path = dirname($file_path) . '/pwg_representative/'; $representative_file_path .= get_filename_wo_extension(basename($file_path)) . '.'; $representative_ext = 'jpg'; $representative_file_path .= $representative_ext; prepare_directory(dirname($representative_file_path)); $second = 1; $ffmpeg = $conf['ffmpeg_dir'] . 'ffmpeg'; $ffmpeg .= ' -i "' . $file_path . '"'; $ffmpeg .= ' -an -ss ' . $second; $ffmpeg .= ' -t 1 -r 1 -y -vcodec mjpeg -f mjpeg'; $ffmpeg .= ' "' . $representative_file_path . '"'; // file_put_contents('/tmp/ffmpeg.log', "\n==== ".date('c')."\n".__FUNCTION__.' : '.$ffmpeg."\n", FILE_APPEND); @exec($ffmpeg); if (!file_exists($representative_file_path)) { $representative_ext = null; } } if (isset($original_extension) and 'pdf' == $original_extension and pwg_image::get_library() == 'ext_imagick') { $representative_file_path = dirname($file_path) . '/pwg_representative/'; $representative_file_path .= get_filename_wo_extension(basename($file_path)) . '.'; $representative_ext = 'jpg'; $representative_file_path .= $representative_ext; prepare_directory(dirname($representative_file_path)); $exec = $conf['ext_imagick_dir'] . 'convert'; $exec .= ' -quality 98'; $exec .= ' "' . realpath($file_path) . '"[0]'; $dest = pathinfo($representative_file_path); $exec .= ' "' . realpath($dest['dirname']) . '/' . $dest['basename'] . '"'; $exec .= ' 2>&1'; @exec($exec, $returnarray); } if (pwg_image::get_library() != 'gd') { if ($conf['original_resize']) { $need_resize = need_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight']); if ($need_resize) { $img = new pwg_image($file_path); $img->pwg_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight'], $conf['original_resize_quality'], $conf['upload_form_automatic_rotation'], false); $img->destroy(); } } } // we need to save the rotation angle in the database to compute // width/height of "multisizes" $rotation_angle = pwg_image::get_rotation_angle($file_path); $rotation = pwg_image::get_rotation_code_from_angle($rotation_angle); $file_infos = pwg_image_infos($file_path); if (isset($image_id)) { $update = array('file' => pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path)), 'filesize' => $file_infos['filesize'], 'width' => $file_infos['width'], 'height' => $file_infos['height'], 'md5sum' => $md5sum, 'added_by' => $user['id'], 'rotation' => $rotation); if (isset($level)) { $update['level'] = $level; } single_update(IMAGES_TABLE, $update, array('id' => $image_id)); } else { // database registration $file = pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path)); $insert = array('file' => $file, 'name' => get_name_from_file($file), 'date_available' => $dbnow, 'path' => preg_replace('#^' . preg_quote(PHPWG_ROOT_PATH) . '#', '', $file_path), 'filesize' => $file_infos['filesize'], 'width' => $file_infos['width'], 'height' => $file_infos['height'], 'md5sum' => $md5sum, 'added_by' => $user['id'], 'rotation' => $rotation); if (isset($level)) { $insert['level'] = $level; } if (isset($representative_ext)) { $insert['representative_ext'] = $representative_ext; } single_insert(IMAGES_TABLE, $insert); $image_id = pwg_db_insert_id(IMAGES_TABLE); } if (isset($categories) and count($categories) > 0) { associate_images_to_categories(array($image_id), $categories); } // update metadata from the uploaded file (exif/iptc) if ($conf['use_exif'] and !function_exists('read_exif_data')) { $conf['use_exif'] = false; } sync_metadata(array($image_id)); invalidate_user_cache(); // cache thumbnail $query = ' SELECT id, path FROM ' . IMAGES_TABLE . ' WHERE id = ' . $image_id . ' ;'; $image_infos = pwg_db_fetch_assoc(pwg_query($query)); set_make_full_url(); // in case we are on uploadify.php, we have to replace the false path $thumb_url = preg_replace('#admin/include/i#', 'i', DerivativeImage::thumb_url($image_infos)); unset_make_full_url(); fetchRemote($thumb_url, $dest); return $image_id; }
/** * @param string $type * @param array $img * @return string */ function derivative_url($type, $img) { return DerivativeImage::url($type, $img); }
;'; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { if (isset($page['previous_item']) and $row['id'] == $page['previous_item']) { $i = 'previous'; } elseif (isset($page['next_item']) and $row['id'] == $page['next_item']) { $i = 'next'; } elseif (isset($page['first_item']) and $row['id'] == $page['first_item']) { $i = 'first'; } elseif (isset($page['last_item']) and $row['id'] == $page['last_item']) { $i = 'last'; } else { $i = 'current'; } $row['src_image'] = new SrcImage($row); $row['derivatives'] = DerivativeImage::get_all($row['src_image']); if ($i == 'current') { $row['element_path'] = get_element_path($row); if ($row['src_image']->is_original()) { // we have a photo if ($user['enabled_high'] == 'true') { $row['element_url'] = $row['src_image']->get_url(); $row['download_url'] = get_action_url($row['id'], 'e', true); } } else { // not a pic - need download link $row['download_url'] = $row['element_url'] = get_element_url($row); } } $row['url'] = duplicate_picture_url(array('image_id' => $row['id'], 'image_file' => $row['file']), array('start')); $picture[$i] = $row;
$query = 'SELECT * FROM ' . IMAGES_TABLE . ' WHERE id=' . $_GET['image_id']; $row = pwg_db_fetch_assoc(pwg_query($query)); if (isset($_POST['submit'])) { foreach (ImageStdParams::get_defined_type_map() as $params) { if ($params->sizing->max_crop != 0) { delete_element_derivatives($row, $params->type); } } delete_element_derivatives($row, IMG_CUSTOM); $uid = '&b=' . time(); $conf['question_mark_in_urls'] = $conf['php_extension_in_urls'] = true; if ($conf['derivative_url_style'] == 1) { $conf['derivative_url_style'] = 0; //auto } } else { $uid = ''; } $tpl_var = array('TITLE' => render_element_name($row), 'ALT' => $row['file'], 'U_IMG' => DerivativeImage::url(IMG_LARGE, $row)); if (!empty($row['coi'])) { $tpl_var['coi'] = array('l' => char_to_fraction($row['coi'][0]), 't' => char_to_fraction($row['coi'][1]), 'r' => char_to_fraction($row['coi'][2]), 'b' => char_to_fraction($row['coi'][3])); } foreach (ImageStdParams::get_defined_type_map() as $params) { if ($params->sizing->max_crop != 0) { $derivative = new DerivativeImage($params, new SrcImage($row)); $template->append('cropped_derivatives', array('U_IMG' => $derivative->get_url() . $uid, 'HTM_SIZE' => $derivative->get_size_htm())); } } $template->assign($tpl_var); $template->set_filename('picture_coi', 'picture_coi.tpl'); $template->assign_var_from_handle('ADMIN_CONTENT', 'picture_coi');
$rating['first_date'] = $row['date']; } $rating['rates'][$row['rate']][] = array('id' => $row['element_id'], 'date' => $row['date']); $image_ids[$row['element_id']] = 1; unset($rating); } // get image tn urls $image_urls = array(); if (count($image_ids) > 0) { $query = 'SELECT id, name, file, path, representative_ext, level FROM ' . IMAGES_TABLE . ' WHERE id IN (' . implode(',', array_keys($image_ids)) . ')'; $result = pwg_query($query); $params = ImageStdParams::get_by_type(IMG_SQUARE); while ($row = pwg_db_fetch_assoc($result)) { $image_urls[$row['id']] = array('tn' => DerivativeImage::url($params, $row), 'page' => make_picture_url(array('image_id' => $row['id'], 'image_file' => $row['file']))); } } //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
} $query .= ' ' . $conf['order_by'] . ' LIMIT ' . $page['nb_images'] . ' OFFSET ' . $page['start'] . ' ;'; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { $element_ids[] = $row['id']; $src_image = new SrcImage($row); $query = ' SELECT id, name FROM ' . IMAGE_TAG_TABLE . ' AS it JOIN ' . TAGS_TABLE . ' AS t ON t.id = it.tag_id WHERE image_id = ' . $row['id'] . ' ;'; $tag_selection = get_taglist($query); $legend = render_element_name($row); if ($legend != get_name_from_file($row['file'])) { $legend .= ' (' . $row['file'] . ')'; } $template->append('elements', array_merge($row, array('ID' => $row['id'], 'TN_SRC' => DerivativeImage::url(IMG_THUMB, $src_image), 'FILE_SRC' => DerivativeImage::url(IMG_LARGE, $src_image), 'LEGEND' => $legend, 'U_EDIT' => get_root_url() . 'admin.php?page=photo-' . $row['id'], 'NAME' => htmlspecialchars(@$row['name']), 'AUTHOR' => htmlspecialchars(@$row['author']), 'LEVEL' => !empty($row['level']) ? $row['level'] : '0', 'DESCRIPTION' => htmlspecialchars(@$row['comment']), 'DATE_CREATION' => $row['date_creation'], 'TAGS' => $tag_selection))); } $template->assign(array('ELEMENT_IDS' => implode(',', $element_ids), 'CACHE_KEYS' => get_admin_client_cache_keys(array('tags')))); } trigger_notify('loc_end_element_set_unit'); // +-----------------------------------------------------------------------+ // | sending html code | // +-----------------------------------------------------------------------+ $template->assign_var_from_handle('ADMIN_CONTENT', 'batch_manager_unit');
$template->assign('U_SYNC', $base_url . 'site_update&site=1&cat_id=' . $category['id']); } } // representant management if ($category['has_images'] or !empty($category['representative_picture_id'])) { $tpl_representant = array(); // picture to display : the identified representant or the generic random // representant ? if (!empty($category['representative_picture_id'])) { $query = ' SELECT id,representative_ext,path FROM ' . IMAGES_TABLE . ' WHERE id = ' . $category['representative_picture_id'] . ' ;'; $row = pwg_db_fetch_assoc(pwg_query($query)); $src = DerivativeImage::thumb_url($row); $url = get_root_url() . 'admin.php?page=photo-' . $category['representative_picture_id']; $tpl_representant['picture'] = array('SRC' => $src, 'URL' => $url); } // can the admin choose to set a new random representant ? $tpl_representant['ALLOW_SET_RANDOM'] = $category['has_images'] ? true : false; // can the admin delete the current representant ? if ($category['has_images'] and $conf['allow_random_representative'] or !$category['has_images'] and !empty($category['representative_picture_id'])) { $tpl_representant['ALLOW_DELETE'] = true; } $template->assign('representant', $tpl_representant); } if ($category['is_virtual']) { $template->assign('parent_category', empty($category['id_uppercat']) ? array() : array($category['id_uppercat'])); } trigger_notify('loc_end_cat_modify');
/** * Returns html description about recently published elements grouped by post date. * @todo clean up HTML output, currently messy and invalid ! * * @param array $date_detail returned value of get_recent_post_dates() * @return string */ function get_html_description_recent_post_date($date_detail, $auth_key = null) { global $conf; $add_url_params = array(); if (isset($auth_key)) { $add_url_params['auth'] = $auth_key; } $description = '<ul>'; $description .= '<li>' . l10n_dec('%d new photo', '%d new photos', $date_detail['nb_elements']) . ' (' . '<a href="' . add_url_params(make_index_url(array('section' => 'recent_pics')), $add_url_params) . '">' . l10n('Recent photos') . '</a>' . ')' . '</li><br>'; foreach ($date_detail['elements'] as $element) { $tn_src = DerivativeImage::thumb_url($element); $description .= '<a href="' . add_url_params(make_picture_url(array('image_id' => $element['id'], 'image_file' => $element['file'])), $add_url_params) . '"><img src="' . $tn_src . '"></a>'; } $description .= '...<br>'; $description .= '<li>' . l10n_dec('%d album updated', '%d albums updated', $date_detail['nb_cats']) . '</li>'; $description .= '<ul>'; foreach ($date_detail['categories'] as $cat) { $description .= '<li>' . get_cat_display_name_cache($cat['uppercats'], '', false, null, $auth_key) . ' (' . l10n_dec('%d new photo', '%d new photos', $cat['img_count']) . ')' . '</li>'; } $description .= '</ul>'; $description .= '</ul>'; return $description; }
function pfemail_check_accounts() { global $conf, $user; conf_update_param('pfemail_last_check', date('Y-m-d H:i:s')); require_once PFEMAIL_PATH . 'include/ImapMailbox.php'; $image_ids = array(); $query = ' SELECT * FROM ' . PFEMAIL_MAILBOXES_TABLE . ' ;'; $accounts = query2array($query); foreach ($accounts as $account) { $mailbox = new ImapMailbox($account['path'], $account['login'], $account['password'], $conf['upload_dir'] . '/buffer', 'utf-8'); $mails = array(); // Get some mail $mailsIds = $mailbox->searchMailBox('UNSEEN'); if (!$mailsIds) { continue; // check next email account } $mailId = reset($mailsIds); $mail = $mailbox->getMail($mailId); $attachments = $mail->getAttachments(); include_once PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php'; foreach ($attachments as $attachment) { $extension = strtolower(get_extension($attachment->{'name'})); if (!in_array($extension, $conf['picture_ext'])) { // the file has been downloaded, we have to remove it now unlink($attachment->{'filePath'}); continue; } $moderate = get_boolean($account['moderated']); $image_id = add_uploaded_file($attachment->{'filePath'}, stripslashes($attachment->{'name'}), array($account['category_id']), $moderate ? 16 : 0, null); // the photo is added by nobody (using the current user may make the // photo editable by her with Admin Tools...) single_update(IMAGES_TABLE, array('added_by' => null, 'name' => pfemail_clean_email_subject($mail->subject)), array('id' => $image_id)); $state = 'auto_validated'; if ($moderate) { $state = 'moderation_pending'; } list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); single_insert(PFEMAIL_PENDINGS_TABLE, array('image_id' => $image_id, 'state' => $state, 'added_on' => $dbnow, 'from_name' => $mail->fromName, 'from_address' => $mail->fromAddress, 'subject' => $mail->subject)); $image_ids[] = $image_id; } } if (count($image_ids) > 0) { include_once PHPWG_ROOT_PATH . 'admin/include/functions.php'; invalidate_user_cache(); // let's notify administrators $query = ' SELECT id FROM ' . GROUPS_TABLE . ' ;'; $group_ids = query2array($query, null, 'id'); if (count($group_ids) > 0) { include_once PHPWG_ROOT_PATH . 'include/functions_mail.inc.php'; $thumb_urls = array(); // force $conf['derivative_url_style'] to 2 (script) to make sure we // will use i.php?/upload and not _data/i/upload because you don't // know when the cache will be flushed $previous_derivative_url_style = $conf['derivative_url_style']; $conf['derivative_url_style'] = 2; $query = ' SELECT id, path FROM ' . IMAGES_TABLE . ' WHERE id IN (' . implode(',', $image_ids) . ') ;'; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { $thumb = DerivativeImage::thumb_url(array('id' => $row['id'], 'path' => $row['path'])); $thumb_urls[] = $thumb; } // restore configuration setting $conf['derivative_url_style'] = $previous_derivative_url_style; $thumbs_html_string = ''; foreach ($thumb_urls as $thumb_url) { if (!empty($thumbs_html_string)) { $thumbs_html_string .= ' '; } $thumbs_html_string .= '<img src="' . $thumb_url . '">'; } $content = $thumbs_html_string; // how many photos pending? $pendings = pfemail_get_pending_ids(); if (count($pendings) > 0) { $content .= '<br><br>'; $content .= '<a href="' . get_absolute_root_url() . 'admin.php?page=plugin-photo_from_email-pendings' . '">'; $content .= l10n('%d photos pending for validation', count($pendings)); $content .= '</a>'; } $real_user_id = $user['id']; $user['id'] = $conf['guest_id']; $subject = l10n('%d photos added by email', count($thumb_urls)); foreach ($group_ids as $group_id) { pwg_mail_group($group_id, array('subject' => '[' . $conf['gallery_title'] . '] ' . $subject, 'mail_title' => $conf['gallery_title'], 'mail_subtitle' => $subject, 'content' => $content, 'content_format' => 'text/html')); } } // restore current user $user['id'] = $real_user_id; } }
$image_title = '(' . $line['image_id'] . ')'; if (isset($image_infos[$line['image_id']]['label'])) { $image_title .= ' ' . trigger_change('render_element_description', $image_infos[$line['image_id']]['label']); } else { $image_title .= ' unknown filename'; } $image_string = ''; switch ($thumbnail_display) { case 'no_display_thumbnail': $image_string = '<a href="' . $picture_url . '">' . $image_title . '</a>'; break; case 'display_thumbnail_classic': $image_string = '<a class="thumbnail" href="' . $picture_url . '">' . '<span><img src="' . DerivativeImage::thumb_url($element) . '" alt="' . $image_title . '" title="' . $image_title . '">' . '</span></a>'; break; case 'display_thumbnail_hoverbox': $image_string = '<a class="over" href="' . $picture_url . '">' . '<span><img src="' . DerivativeImage::thumb_url($element) . '" alt="' . $image_title . '" title="' . $image_title . '">' . '</span>' . $image_title . '</a>'; break; } } $template->append('search_results', array('DATE' => $line['date'], 'TIME' => $line['time'], 'USER' => $user_string, 'IP' => $line['IP'], 'IMAGE' => $image_string, 'TYPE' => $line['image_type'], 'SECTION' => $line['section'], 'CATEGORY' => isset($line['category_id']) ? isset($name_of_category[$line['category_id']]) ? $name_of_category[$line['category_id']] : 'deleted ' . $line['category_id'] : '', 'TAGS' => $tags_string)); } $summary['nb_guests'] = 0; if (count(array_keys($summary['guests_IP'])) > 0) { $summary['nb_guests'] = count(array_keys($summary['guests_IP'])); // we delete the "guest" from the $username_of hash so that it is // avoided in next steps unset($username_of[$conf['guest_id']]); } $summary['nb_members'] = count($username_of); $member_strings = array(); foreach ($username_of as $user_id => $user_name) {
$query_model = 'SELECT * FROM ' . IMAGES_TABLE . ' WHERE id < start_id ORDER BY id DESC LIMIT ' . $qlimit; $urls = array(); do { $result = pwg_query(str_replace('start_id', $start_id, $query_model)); $is_last = pwg_db_num_rows($result) < $qlimit; while ($row = pwg_db_fetch_assoc($result)) { $start_id = $row['id']; $src_image = new SrcImage($row); if ($src_image->is_mimetype()) { continue; } $derivative = new DerivativeImage(ImageStdParams::get_custom(9999, $conf['GThumb']['height']), $src_image); if (@filemtime($derivative->get_path()) === false) { $urls[] = $derivative->get_url() . $uid; } if (count($urls) >= $max_urls && !$is_last) { break; } } if ($is_last) { $start_id = 0; } } while (count($urls) < $max_urls && $start_id); $ret = array(); if ($start_id) { $ret['next_page'] = $start_id; }
/** */ function get_category_representant_properties($image_id) { $query = ' SELECT id,representative_ext,path FROM ' . IMAGES_TABLE . ' WHERE id = ' . $image_id . ' ;'; $row = pwg_db_fetch_assoc(pwg_query($query)); $src = DerivativeImage::thumb_url($row); $url = get_root_url() . 'admin.php?page=photo-' . $image_id; return array('src' => $src, 'url' => $url); }
state, from_name, from_address, subject FROM ' . IMAGES_TABLE . ' JOIN ' . PFEMAIL_PENDINGS_TABLE . ' ON id = image_id WHERE image_id IN (' . implode(',', $pending_ids) . ') ORDER BY image_id DESC LIMIT ' . $page['start'] . ', ' . $page['nb_pendings_per_page'] . ' ;'; $result = pwg_query($query); $rows = array(); $image_ids = array(); while ($row = pwg_db_fetch_assoc($result)) { array_push($rows, $row); array_push($image_ids, $row['id']); } $template->assign(array('F_ACTION' => $admin_base_url)); foreach ($rows as $row) { $thumb = DerivativeImage::thumb_url(array('id' => $row['image_id'], 'path' => $row['path'])); $template->append('photos', array('U_EDIT' => get_root_url() . 'admin.php?page=plugin-showcase_admin-photo&image_id=' . $row['image_id'], 'ID' => $row['image_id'], 'TN_SRC' => $thumb, 'WEBSIZE_SRC' => $row['path'], 'ADDED_BY' => $row['author'], 'ADDED_ON' => format_date($row['date_available'], true), 'NAME' => $row['name'], 'FILE' => $row['file'], 'DATE_CREATION' => empty($row['date_creation']) ? l10n('N/A') : format_date($row['date_creation']), 'DESCRIPTION' => $row['comment'], 'FROM' => @$row['from_name'] . ' <' . $row['from_address'] . '>')); } // +-----------------------------------------------------------------------+ // | navigation bar | // +-----------------------------------------------------------------------+ $template->assign('navbar', create_navigation_bar(get_root_url() . 'admin.php' . get_query_string_diff(array('start', 'action', 'showcase_id')), count($pending_ids), $page['start'], $page['nb_pendings_per_page'])); // +-----------------------------------------------------------------------+ // | sending html code | // +-----------------------------------------------------------------------+ $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
// info by email to an access granted group of category informations if (isset($_POST['submitEmail'])) { set_make_full_url(); /* TODO: if $category['representative_picture_id'] is empty find child representative_picture_id */ if (!empty($category['representative_picture_id'])) { $img = array(); $query = ' SELECT id, file, path, representative_ext FROM ' . IMAGES_TABLE . ' WHERE id = ' . $category['representative_picture_id'] . ' ;'; $result = pwg_query($query); if (pwg_db_num_rows($result) > 0) { $element = pwg_db_fetch_assoc($result); $img = array('link' => make_picture_url(array('image_id' => $element['id'], 'image_file' => $element['file'], 'category' => $category)), 'src' => DerivativeImage::url(IMG_THUMB, $element)); } } $args = array('subject' => l10n('[%s] Visit album %s', $conf['gallery_title'], trigger_change('render_category_name', $category['name'], 'admin_cat_list'))); $tpl = array('filename' => 'cat_group_info', 'assign' => array('IMG' => $img, 'CAT_NAME' => trigger_change('render_category_name', $category['name'], 'admin_cat_list'), 'LINK' => make_index_url(array('category' => array('id' => $category['id'], 'name' => trigger_change('render_category_name', $category['name'], 'admin_cat_list'), 'permalink' => $category['permalink']))), 'CPL_CONTENT' => empty($_POST['mail_content']) ? '' : stripslashes($_POST['mail_content']))); if ('users' == $_POST['who'] and isset($_POST['users']) and count($_POST['users']) > 0) { check_input_parameter('users', $_POST, true, PATTERN_ID); // TODO code very similar to function pwg_mail_group. We'd better create // a function pwg_mail_users that could be called from here and from // pwg_mail_group // TODO to make checks even better, we should check that theses users // have access to this album. No real privacy issue here, even if we // send the email to a user without permission. $query = ' SELECT ui.user_id,
/** * API method * Returns a list of categories * @param mixed[] $params * @option int cat_id (optional) * @option bool recursive * @option bool public * @option bool tree_output * @option bool fullname */ function ws_categories_getList($params, &$service) { global $user, $conf; $where = array('1=1'); $join_type = 'INNER'; $join_user = $user['id']; if (!$params['recursive']) { if ($params['cat_id'] > 0) { $where[] = '( id_uppercat = ' . (int) $params['cat_id'] . ' OR id=' . (int) $params['cat_id'] . ' )'; } else { $where[] = 'id_uppercat IS NULL'; } } else { if ($params['cat_id'] > 0) { $where[] = 'uppercats ' . DB_REGEX_OPERATOR . ' \'(^|,)' . (int) $params['cat_id'] . '(,|$)\''; } } if ($params['public']) { $where[] = 'status = "public"'; $where[] = 'visible = "true"'; $join_user = $conf['guest_id']; } else { if (is_admin()) { // in this very specific case, we don't want to hide empty // categories. Function calculate_permissions will only return // categories that are either locked or private and not permitted // // calculate_permissions does not consider empty categories as forbidden $forbidden_categories = calculate_permissions($user['id'], $user['status']); $where[] = 'id NOT IN (' . $forbidden_categories . ')'; $join_type = 'LEFT'; } } $query = ' SELECT id, name, comment, permalink, uppercats, global_rank, id_uppercat, nb_images, count_images AS total_nb_images, representative_picture_id, user_representative_picture_id, count_images, count_categories, date_last, max_date_last, count_categories AS nb_categories FROM ' . CATEGORIES_TABLE . ' ' . $join_type . ' JOIN ' . USER_CACHE_CATEGORIES_TABLE . ' ON id=cat_id AND user_id=' . $join_user . ' WHERE ' . implode("\n AND ", $where) . ' ;'; $result = pwg_query($query); // management of the album thumbnail -- starts here $image_ids = array(); $categories = array(); $user_representative_updates_for = array(); // management of the album thumbnail -- stops here $cats = array(); while ($row = pwg_db_fetch_assoc($result)) { $row['url'] = make_index_url(array('category' => $row)); foreach (array('id', 'nb_images', 'total_nb_images', 'nb_categories') as $key) { $row[$key] = (int) $row[$key]; } if ($params['fullname']) { $row['name'] = strip_tags(get_cat_display_name_cache($row['uppercats'], null)); } else { $row['name'] = strip_tags(trigger_change('render_category_name', $row['name'], 'ws_categories_getList')); } $row['comment'] = strip_tags(trigger_change('render_category_description', $row['comment'], 'ws_categories_getList')); // management of the album thumbnail -- starts here // // on branch 2.3, the algorithm is duplicated from // include/category_cats, but we should use a common code for Piwigo 2.4 // // warning : if the API method is called with $params['public'], the // album thumbnail may be not accurate. The thumbnail can be viewed by // the connected user, but maybe not by the guest. Changing the // filtering method would be too complicated for now. We will simply // avoid to persist the user_representative_picture_id in the database // if $params['public'] if (!empty($row['user_representative_picture_id'])) { $image_id = $row['user_representative_picture_id']; } else { if (!empty($row['representative_picture_id'])) { // if a representative picture is set, it has priority $image_id = $row['representative_picture_id']; } else { if ($conf['allow_random_representative']) { // searching a random representant among elements in sub-categories $image_id = get_random_image_in_category($row); } else { // searching a random representant among representant of sub-categories if ($row['count_categories'] > 0 and $row['count_images'] > 0) { $query = ' SELECT representative_picture_id FROM ' . CATEGORIES_TABLE . ' INNER JOIN ' . USER_CACHE_CATEGORIES_TABLE . ' ON id=cat_id AND user_id=' . $user['id'] . ' WHERE uppercats LIKE \'' . $row['uppercats'] . ',%\' AND representative_picture_id IS NOT NULL ' . get_sql_condition_FandF(array('visible_categories' => 'id'), "\n AND") . ' ORDER BY ' . DB_RANDOM_FUNCTION . '() LIMIT 1 ;'; $subresult = pwg_query($query); if (pwg_db_num_rows($subresult) > 0) { list($image_id) = pwg_db_fetch_row($subresult); } } } } } if (isset($image_id)) { if ($conf['representative_cache_on_subcats'] and $row['user_representative_picture_id'] != $image_id) { $user_representative_updates_for[$row['id']] = $image_id; } $row['representative_picture_id'] = $image_id; $image_ids[] = $image_id; $categories[] = $row; } unset($image_id); // management of the album thumbnail -- stops here $cats[] = $row; } usort($cats, 'global_rank_compare'); // management of the album thumbnail -- starts here if (count($categories) > 0) { $thumbnail_src_of = array(); $new_image_ids = array(); $query = ' SELECT id, path, representative_ext, level FROM ' . IMAGES_TABLE . ' WHERE id IN (' . implode(',', $image_ids) . ') ;'; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { if ($row['level'] <= $user['level']) { $thumbnail_src_of[$row['id']] = DerivativeImage::thumb_url($row); } else { // problem: we must not display the thumbnail of a photo which has a // higher privacy level than user privacy level // // * what is the represented category? // * find a random photo matching user permissions // * register it at user_representative_picture_id // * set it as the representative_picture_id for the category foreach ($categories as &$category) { if ($row['id'] == $category['representative_picture_id']) { // searching a random representant among elements in sub-categories $image_id = get_random_image_in_category($category); if (isset($image_id) and !in_array($image_id, $image_ids)) { $new_image_ids[] = $image_id; } if ($conf['representative_cache_on_level']) { $user_representative_updates_for[$category['id']] = $image_id; } $category['representative_picture_id'] = $image_id; } } unset($category); } } if (count($new_image_ids) > 0) { $query = ' SELECT id, path, representative_ext FROM ' . IMAGES_TABLE . ' WHERE id IN (' . implode(',', $new_image_ids) . ') ;'; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { $thumbnail_src_of[$row['id']] = DerivativeImage::thumb_url($row); } } } // compared to code in include/category_cats, we only persist the new // user_representative if we have used $user['id'] and not the guest id, // or else the real guest may see thumbnail that he should not if (!$params['public'] and count($user_representative_updates_for)) { $updates = array(); foreach ($user_representative_updates_for as $cat_id => $image_id) { $updates[] = array('user_id' => $user['id'], 'cat_id' => $cat_id, 'user_representative_picture_id' => $image_id); } mass_updates(USER_CACHE_CATEGORIES_TABLE, array('primary' => array('user_id', 'cat_id'), 'update' => array('user_representative_picture_id')), $updates); } foreach ($cats as &$cat) { foreach ($categories as $category) { if ($category['id'] == $cat['id'] and isset($category['representative_picture_id'])) { $cat['tn_url'] = $thumbnail_src_of[$category['representative_picture_id']]; } } // we don't want them in the output unset($cat['user_representative_picture_id'], $cat['count_images'], $cat['count_categories']); } unset($cat); // management of the album thumbnail -- stops here if ($params['tree_output']) { return categories_flatlist_to_tree($cats); } return array('categories' => new PwgNamedArray($cats, 'category', ws_std_get_category_xml_attributes())); }
i.path, i.file, i.representative_ext, i.rating_score, r.element_id ORDER BY ' . $available_order_by[$order_by_index][1] . ' LIMIT ' . $elements_per_page . ' OFFSET ' . $start . ' ;'; $images = array(); $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { $images[] = $row; } $template->assign('images', array()); foreach ($images as $image) { $thumbnail_src = DerivativeImage::thumb_url($image); $image_url = get_root_url() . 'admin.php?page=photo-' . $image['id']; $query = 'SELECT * FROM ' . RATE_TABLE . ' AS r WHERE r.element_id=' . $image['id'] . ' ORDER BY date DESC;'; $result = pwg_query($query); $nb_rates = pwg_db_num_rows($result); $tpl_image = array('id' => $image['id'], 'U_THUMB' => $thumbnail_src, 'U_URL' => $image_url, 'SCORE_RATE' => $image['score'], 'AVG_RATE' => $image['avg_rates'], 'SUM_RATE' => $image['sum_rates'], 'NB_RATES' => (int) $image['nb_rates'], 'NB_RATES_TOTAL' => (int) $nb_rates, 'FILE' => $image['file'], 'rates' => array()); while ($row = pwg_db_fetch_assoc($result)) { if (isset($users[$row['user_id']])) { $user_rate = $users[$row['user_id']]; } else { $user_rate = '? ' . $row['user_id']; } if (strlen($row['anonymous_id']) > 0) {