function ws_images_addFlickr($photo, &$service) { if (!is_admin()) { return new PwgError(403, 'Forbidden'); } global $conf; if (empty($conf['flickr2piwigo']['api_key']) or empty($conf['flickr2piwigo']['secret_key'])) { return new PwgError(null, l10n('Please fill your API keys on the configuration tab')); } include_once PHPWG_ROOT_PATH . 'admin/include/functions.php'; include_once PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php'; include_once FLICKR_PATH . 'include/functions.inc.php'; if (test_remote_download() === false) { return new PwgError(null, l10n('No download method available')); } // init flickr API include_once FLICKR_PATH . 'include/phpFlickr/phpFlickr.php'; $flickr = new phpFlickr($conf['flickr2piwigo']['api_key'], $conf['flickr2piwigo']['secret_key']); $flickr->enableCache('fs', FLICKR_FS_CACHE); // user $u = $flickr->test_login(); if ($u === false or empty($_SESSION['phpFlickr_auth_token'])) { return new PwgError(403, l10n('API not authenticated')); } // photos infos $photo_f = $flickr->photos_getInfo($photo['id']); $photo = array_merge($photo, $photo_f['photo']); $photo['url'] = $flickr->get_biggest_size($photo['id'], 'original'); $photo['path'] = FLICKR_FS_CACHE . 'flickr-' . $u['username'] . '-' . $photo['id'] . '.' . get_extension($photo['url']); // copy file if (download_remote_file($photo['url'], $photo['path']) == false) { return new PwgError(null, l10n('Can\'t download file')); } // category if (!preg_match('#^[0-9]+$#', $photo['category'])) { $categories_names = explode(',', $photo['category']); $photo['category'] = array(); foreach ($categories_names as $category_name) { $query = ' SELECT id FROM ' . CATEGORIES_TABLE . ' WHERE LOWER(name) = "' . strtolower($category_name) . '" ;'; $result = pwg_query($query); if (pwg_db_num_rows($result)) { list($cat_id) = pwg_db_fetch_row($result); $photo['category'][] = $cat_id; } else { $cat = create_virtual_category($category_name); $photo['category'][] = $cat['id']; } } } else { $photo['category'] = array($photo['category']); } // add photo $photo['image_id'] = add_uploaded_file($photo['path'], basename($photo['path']), $photo['category']); // do some updates if (!empty($photo['fills'])) { $photo['fills'] = rtrim($photo['fills'], ','); $photo['fills'] = explode(',', $photo['fills']); $updates = array(); if (in_array('fill_name', $photo['fills'])) { $updates['name'] = pwg_db_real_escape_string($photo['title']); } if (in_array('fill_posted', $photo['fills'])) { $updates['date_available'] = date('Y-m-d H:i:s', $photo['dates']['posted']); } if (in_array('fill_taken', $photo['fills'])) { $updates['date_creation'] = $photo['dates']['taken']; } if (in_array('fill_author', $photo['fills'])) { $updates['author'] = pwg_db_real_escape_string($photo['owner']['username']); } if (in_array('fill_description', $photo['fills'])) { $updates['comment'] = pwg_db_real_escape_string(@$photo['description']); } if (in_array('fill_geotag', $photo['fills']) and !empty($photo['location'])) { $updates['latitude'] = pwg_db_real_escape_string($photo['location']['latitude']); $updates['longitude'] = pwg_db_real_escape_string($photo['location']['longitude']); } if (in_array('level', $photo['fills']) && !$photo['visibility']['ispublic']) { $updates['level'] = 8; if ($photo['visibility']['isfamily']) { $updates['level'] = 4; } if ($photo['visibility']['isfriend']) { $updates['level'] = 2; } } if (count($updates)) { single_update(IMAGES_TABLE, $updates, array('id' => $photo['image_id'])); } if (!empty($photo['tags']['tag']) and in_array('fill_tags', $photo['fills'])) { $raw_tags = array_map(create_function('$t', 'return $t["_content"];'), $photo['tags']['tag']); $raw_tags = implode(',', $raw_tags); set_tags(get_tag_ids($raw_tags), $photo['image_id']); } } return l10n('Photo "%s" imported', $photo['title']); }
/** * Save picture form * @trigger loc_begin_picture */ function admintools_save_picture() { global $page, $conf, $MultiView, $user, $picture; if (!isset($_GET['delete']) and !isset($_POST['action']) and @$_POST['action'] != 'quick_edit') { return; } $query = 'SELECT added_by FROM ' . IMAGES_TABLE . ' WHERE id = ' . $page['image_id'] . ';'; list($added_by) = pwg_db_fetch_row(pwg_query($query)); if (!$MultiView->is_admin() and $user['id'] != $added_by) { return; } if (isset($_GET['delete']) and get_pwg_token() == @$_GET['pwg_token']) { include_once PHPWG_ROOT_PATH . 'admin/include/functions.php'; delete_elements(array($page['image_id']), true); invalidate_user_cache(); if (isset($page['rank_of'][$page['image_id']])) { redirect(duplicate_index_url(array('start' => floor($page['rank_of'][$page['image_id']] / $page['nb_image_page']) * $page['nb_image_page']))); } else { redirect(make_index_url()); } } if ($_POST['action'] == 'quick_edit') { include_once PHPWG_ROOT_PATH . 'admin/include/functions.php'; $data = array('name' => $_POST['name'], 'author' => $_POST['author']); if ($MultiView->is_admin()) { $data['level'] = $_POST['level']; } if ($conf['allow_html_descriptions']) { $data['comment'] = @$_POST['comment']; } else { $data['comment'] = strip_tags(@$_POST['comment']); } if (!empty($_POST['date_creation']) and strtotime($_POST['date_creation']) !== false) { $data['date_creation'] = $_POST['date_creation'] . ' ' . $_POST['date_creation_time']; } single_update(IMAGES_TABLE, $data, array('id' => $page['image_id'])); $tag_ids = array(); if (!empty($_POST['tags'])) { $tag_ids = get_tag_ids($_POST['tags']); } set_tags($tag_ids, $page['image_id']); } }
if ($conf['allow_html_descriptions']) { $data['comment'] = @$_POST['description']; } else { $data['comment'] = strip_tags(@$_POST['description']); } if (!empty($_POST['date_creation'])) { $data['date_creation'] = $_POST['date_creation']; } else { $data['date_creation'] = null; } $data = trigger_change('picture_modify_before_update', $data); single_update(IMAGES_TABLE, $data, array('id' => $data['id'])); // time to deal with tags $tag_ids = array(); if (!empty($_POST['tags'])) { $tag_ids = get_tag_ids($_POST['tags']); } set_tags($tag_ids, $_GET['image_id']); // association to albums if (!isset($_POST['associate'])) { $_POST['associate'] = array(); } check_input_parameter('associate', $_POST, true, PATTERN_ID); move_images_to_categories(array($_GET['image_id']), $_POST['associate']); invalidate_user_cache(); // thumbnail for albums if (!isset($_POST['represent'])) { $_POST['represent'] = array(); } check_input_parameter('represent', $_POST, true, PATTERN_ID); $no_longer_thumbnail_for = array_diff($represented_albums, $_POST['represent']);
if (isset($_POST['filter_duplicates_date'])) { $_SESSION['bulk_manager_filter']['duplicates_date'] = true; } if (isset($_POST['filter_duplicates_dimensions'])) { $_SESSION['bulk_manager_filter']['duplicates_dimensions'] = true; } } } if (isset($_POST['filter_category_use'])) { $_SESSION['bulk_manager_filter']['category'] = $_POST['filter_category']; if (isset($_POST['filter_category_recursive'])) { $_SESSION['bulk_manager_filter']['category_recursive'] = true; } } if (isset($_POST['filter_tags_use'])) { $_SESSION['bulk_manager_filter']['tags'] = get_tag_ids($_POST['filter_tags'], false); if (isset($_POST['tag_mode']) and in_array($_POST['tag_mode'], array('AND', 'OR'))) { $_SESSION['bulk_manager_filter']['tag_mode'] = $_POST['tag_mode']; } } if (isset($_POST['filter_level_use'])) { check_input_parameter('filter_level', $_POST, false, '/^\\d+$/'); if (in_array($_POST['filter_level'], $conf['available_permission_levels'])) { $_SESSION['bulk_manager_filter']['level'] = $_POST['filter_level']; if (isset($_POST['filter_level_include_lower'])) { $_SESSION['bulk_manager_filter']['level_include_lower'] = true; } } } if (isset($_POST['filter_dimension_use'])) { foreach (array('min_width', 'max_width', 'min_height', 'max_height') as $type) {
/** * Get the tag tds assigned to a lead. * * @param mixed Id (int) or ids (array) of the lead/s. * @param array [Optional] Items to filter the tags. * * @return array The list of the tag ids. */ function get_lead_tag_ids($lead_id = false, $tag_filter = array()) { $lead_filter = array(); if (!empty($lead_id)) { $lead_filter = array(LEADS_TABLE_LEAD_ID_COL => $lead_id); } return get_tag_ids(LEAD, $lead_filter, $tag_filter); }
function gallery($app, $lang) { if (!file_exists($app->view()->getTemplatesDirectory() . "/" . $lang . "/gallery.html")) { $app->notFound(); return; } $cs_id = $app->request()->params("cs_id"); if (!empty($cs_id) && !is_string($cs_id)) { $cs_id = null; } $api_types = $app->request()->params("api_types"); if (!is_array($api_types)) { $api_types = array_keys($GLOBALS["api_type_list"]); } $tag_names = $app->request()->params("tag_names"); if (!is_array($tag_names)) { $tag_names = array(); } $tag_ids = get_tag_ids($tag_names); $themes_count = find_themes($api_types, $cs_id, $tag_ids, null, null, true); $array = array(); for ($i = 0; $i < $themes_count; $i++) { $array[$i] = $i; } $page = $app->request()->params("page"); if (is_null($page)) { $page = 1; } $adapter = new ArrayAdapter($array); $pagerfanta = new Pagerfanta($adapter); $pagerfanta->setMaxPerPage(GALLERY_MAX_PER_PAGE); try { $pagerfanta->setCurrentPage($page); $current_page_results = $pagerfanta->getCurrentPageResults(); if (count($current_page_results) == 0) { $themes = array(); } else { $themes = find_themes($api_types, $cs_id, $tag_ids, count($current_page_results), $current_page_results[0]); } } catch (Exception $e) { $themes = array(); } $pagerfanta_view = new TwitterBootstrap3View(); $pager_html = $pagerfanta_view->render($pagerfanta, function ($page) use($app, $lang, $cs_id, $api_types, $tag_names) { $params = array("page" => $page); if ($cs_id != "") { $params["cs_id"] = $cs_id; } if (count($api_types) > 0) { $params["api_types"] = $api_types; } if (count($tag_names) > 0) { $params["tag_names"] = $tag_names; } return BASE_URL . get_lang_url_dir($lang) . "gallery?" . http_build_query($params); }); $app->render($lang . "/gallery.html", array("lang" => get_lang_url_dir($lang), "this_url" => "gallery/", "bootstrap_version" => BOOTSTRAP_VERSION, "active_pages" => array($lang, "gallery"), "body_class" => "gallery", "themes" => $themes, "pagerfanta" => $pagerfanta, "pager_html" => $pager_html, "cs_id" => $cs_id, "api_types" => $api_types, "tag_names" => $tag_names)); }
$data['level'] = $_POST['level-' . $row['id']]; if ($conf['allow_html_descriptions']) { $data['comment'] = @$_POST['description-' . $row['id']]; } else { $data['comment'] = strip_tags(@$_POST['description-' . $row['id']]); } if (!empty($_POST['date_creation-' . $row['id']])) { $data['date_creation'] = $_POST['date_creation-' . $row['id']]; } else { $data['date_creation'] = null; } $datas[] = $data; // tags management $tag_ids = array(); if (!empty($_POST['tags-' . $row['id']])) { $tag_ids = get_tag_ids($_POST['tags-' . $row['id']]); } set_tags($tag_ids, $row['id']); } mass_updates(IMAGES_TABLE, array('primary' => array('id'), 'update' => array('name', 'author', 'level', 'comment', 'date_creation')), $datas); $page['infos'][] = l10n('Photo informations updated'); invalidate_user_cache(); } // +-----------------------------------------------------------------------+ // | template init | // +-----------------------------------------------------------------------+ $template->set_filenames(array('batch_manager_unit' => 'batch_manager_unit.tpl')); $base_url = PHPWG_ROOT_PATH . 'admin.php'; $template->assign(array('U_ELEMENTS_PAGE' => $base_url . get_query_string_diff(array('display', 'start')), 'F_ACTION' => $base_url . get_query_string_diff(array()), 'level_options' => get_privacy_level_options())); // +-----------------------------------------------------------------------+ // | global mode thumbnails |
if ('remove_from_caddie' == $action) { $query = ' DELETE FROM ' . CADDIE_TABLE . ' WHERE element_id IN (' . implode(',', $collection) . ') AND user_id = ' . $user['id'] . ' ;'; pwg_query($query); // remove from caddie action available only in caddie so reload content $redirect = true; } else { if ('add_tags' == $action) { if (empty($_POST['add_tags'])) { $page['errors'][] = l10n('Select at least one tag'); } else { $tag_ids = get_tag_ids($_POST['add_tags']); add_tags($tag_ids, $collection); if ('no_tag' == $page['prefilter']) { $redirect = true; } } } else { if ('del_tags' == $action) { if (isset($_POST['del_tags']) and count($_POST['del_tags']) > 0) { $query = ' DELETE FROM ' . IMAGE_TAG_TABLE . ' WHERE image_id IN (' . implode(',', $collection) . ') AND tag_id IN (' . implode(',', $_POST['del_tags']) . ') ;'; pwg_query($query);