コード例 #1
1
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']);
}
コード例 #2
0
ファイル: cat_list.php プロジェクト: lcorbasson/Piwigo
// +-----------------------------------------------------------------------+
// |                    virtual categories management                      |
// +-----------------------------------------------------------------------+
// request to delete a virtual category
if (isset($_GET['delete']) and is_numeric($_GET['delete'])) {
    delete_categories(array($_GET['delete']));
    $_SESSION['page_infos'] = array(l10n('Virtual album deleted'));
    update_global_rank();
    invalidate_user_cache();
    $redirect_url = get_root_url() . 'admin.php?page=cat_list';
    if (isset($_GET['parent_id'])) {
        $redirect_url .= '&parent_id=' . $_GET['parent_id'];
    }
    redirect($redirect_url);
} elseif (isset($_POST['submitAdd'])) {
    $output_create = create_virtual_category($_POST['virtual_name'], @$_GET['parent_id']);
    invalidate_user_cache();
    if (isset($output_create['error'])) {
        $page['errors'][] = $output_create['error'];
    } else {
        $page['infos'][] = $output_create['info'];
    }
} elseif (isset($_POST['submitManualOrder'])) {
    asort($_POST['catOrd'], SORT_NUMERIC);
    save_categories_order(array_keys($_POST['catOrd']));
    $page['infos'][] = l10n('Album manual order was saved');
} elseif (isset($_POST['submitAutoOrder'])) {
    if (!isset($sort_orders[$_POST['order_by']])) {
        die('Invalid sort order');
    }
    $query = '
コード例 #3
0
/**
 * API method
 * Adds a category
 * @param mixed[] $params
 *    @option string name
 *    @option int parent (optional)
 *    @option string comment (optional)
 *    @option bool visible
 *    @option string status (optional)
 *    @option bool commentable
 */
function ws_categories_add($params, &$service)
{
    include_once PHPWG_ROOT_PATH . 'admin/include/functions.php';
    $options = array();
    if (!empty($params['status']) and in_array($params['status'], array('private', 'public'))) {
        $options['status'] = $params['status'];
    }
    if (!empty($params['comment'])) {
        $options['comment'] = $params['comment'];
    }
    $creation_output = create_virtual_category($params['name'], $params['parent'], $options);
    if (isset($creation_output['error'])) {
        return new PwgError(500, $creation_output['error']);
    }
    invalidate_user_cache();
    return $creation_output;
}
コード例 #4
0
function osm_get_items($page)
{
    // Limit search by category, by tag, by smartalbum
    $LIMIT_SEARCH = "";
    $INNER_JOIN = "";
    if (isset($page['section'])) {
        if ($page['section'] === 'categories' and isset($page['category']) and isset($page['category']['id'])) {
            $LIMIT_SEARCH = "FIND_IN_SET(" . $page['category']['id'] . ", c.uppercats) AND ";
            $INNER_JOIN = "INNER JOIN " . CATEGORIES_TABLE . " AS c ON ic.category_id = c.id";
        }
        if ($page['section'] === 'tags' and isset($page['tags']) and isset($page['tags'][0]['id'])) {
            $items = get_image_ids_for_tags(array($page['tags'][0]['id']));
            if (!empty($items)) {
                $LIMIT_SEARCH = "ic.image_id IN (" . implode(',', $items) . ") AND ";
            }
        }
        if ($page['section'] === 'tags' and isset($page['category']) and isset($page['category']['id'])) {
            $LIMIT_SEARCH = "FIND_IN_SET(" . $page['category']['id'] . ", c.uppercats) AND ";
            $INNER_JOIN = "INNER JOIN " . CATEGORIES_TABLE . " AS c ON ic.category_id = c.id";
        }
    }
    $forbidden = get_sql_condition_FandF(array('forbidden_categories' => 'ic.category_id', 'visible_categories' => 'ic.category_id', 'visible_images' => 'i.id'), "\n AND");
    /* We have lat and lng coordonate for virtual album */
    if (isset($_GET['min_lat']) and isset($_GET['max_lat']) and isset($_GET['min_lng']) and isset($_GET['max_lng'])) {
        $LIMIT_SEARCH = "";
        $INNER_JOIN = "";
        /* Delete all previous album */
        $query = "SELECT `id` FROM " . CATEGORIES_TABLE . " WHERE `name` = 'Locations' AND `comment` LIKE '%OSM plugin%';";
        $ids = array_from_query($query, 'id');
        /* Unlink items for the previous album */
        delete_categories($ids, $photo_deletion_mode = 'no_delete');
        /* Create an album */
        $options = array('comment' => 'Generated by OSM plugin');
        $osm_album = create_virtual_category('Locations', NULL, $options);
        /* Create a sub album */
        $options = array('comment' => "OSM virtual album\nlat:" . $_GET['min_lat'] . " " . $_GET['max_lat'] . "\nlng:" . $_GET['min_lng'] . " " . $_GET['max_lng']);
        $osm_sub_album = create_virtual_category("OSM" . $_GET['min_lat'] . "", $osm_album['id'], $options);
        /* Get all items inside the lat and lng */
        $query = "SELECT  `id`, `latitude`, `longitude` \n    FROM " . IMAGES_TABLE . " AS i\n        INNER JOIN " . IMAGE_CATEGORY_TABLE . " AS ic ON id = ic.image_id\n    WHERE " . $LIMIT_SEARCH . " `latitude` IS NOT NULL AND `longitude` IS NOT NULL \n    AND `latitude` > " . $_GET['min_lat'] . " AND `latitude` < " . $_GET['max_lat'] . "\n    AND `longitude` > " . $_GET['min_lng'] . " AND `longitude` < " . $_GET['max_lng'] . "\n    " . $forbidden . ";";
        $items = hash_from_query($query, 'id');
        /* Add  items to the new sub album */
        foreach ($items as $item) {
            $query = "INSERT INTO " . IMAGE_CATEGORY_TABLE . " ( `image_id` ,`category_id` ,`rank` ) VALUES ( '" . $item['id'] . "', '" . $osm_sub_album['id'] . "', NULL );";
            pwg_query($query);
        }
        /* Redirect to the new album */
        header('Location: ' . get_absolute_root_url() . 'index.php?/category/' . $osm_sub_album['id']);
        exit;
    }
    // Fetch data with latitude and longitude
    //$query="SELECT `latitude`, `longitude`, `name`, `path` FROM ".IMAGES_TABLE." WHERE `latitude` IS NOT NULL AND `longitude` IS NOT NULL;";
    // SUBSTRING_INDEX(TRIM(LEADING '.' FROM `path`), '.', 1) full path without filename extension
    // SUBSTRING_INDEX(TRIM(LEADING '.' FROM `path`), '.', -1) full path with only filename extension
    if (isset($page['image_id'])) {
        $LIMIT_SEARCH .= 'i.id = ' . $page['image_id'] . ' AND ';
    }
    $query = "SELECT i.latitude, i.longitude,\n    IFNULL(i.name, '') AS `name`,\n    IF(i.representative_ext IS NULL,\n        CONCAT(SUBSTRING_INDEX(TRIM(LEADING '.' FROM i.path), '.', 1 ), '-sq.', SUBSTRING_INDEX(TRIM(LEADING '.' FROM i.path), '.', -1 )),\n        TRIM(LEADING '.' FROM\n            REPLACE(i.path, TRIM(TRAILING '.' FROM SUBSTRING_INDEX(i.path, '/', -1 )),\n                CONCAT('pwg_representative/',\n                    CONCAT(\n                        TRIM(TRAILING '.' FROM SUBSTRING_INDEX( SUBSTRING_INDEX(i.path, '/', -1 ) , '.', 1 )),\n                        CONCAT('-sq.', i.representative_ext)\n                    )\n                )\n            )\n        )\n    ) AS `pathurl`,\n    TRIM(TRAILING '/' FROM CONCAT( i.id, '/category/', IFNULL(i.storage_category_id, '') ) ) AS `imgurl`,\n    IFNULL(i.comment, '') AS `comment`,\n    IFNULL(i.author, '') AS `author`,\n    i.width\n        FROM " . IMAGES_TABLE . " AS i\n            INNER JOIN (" . IMAGE_CATEGORY_TABLE . " AS ic " . $INNER_JOIN . ") ON i.id = ic.image_id\n            WHERE " . $LIMIT_SEARCH . " i.latitude IS NOT NULL AND i.longitude IS NOT NULL " . $forbidden . " GROUP BY i.id;";
    //echo $query;
    $php_data = array_from_query($query);
    //print_r($php_data);
    $js_data = array();
    foreach ($php_data as $array) {
        // MySQL did all the job
        //print_r($array);
        $js_data[] = array((double) $array['latitude'], (double) $array['longitude'], $array['name'], get_absolute_root_url() . "i.php?" . $array['pathurl'], get_absolute_root_url() . "picture.php?/" . $array['imgurl'], $array['comment'], $array['author'], (int) $array['width']);
    }
    /* START Debug generate dummy data
       $js_data = array();
       $str = 'abcdef';
       $minLat = -90.00;
       $maxLat = 90.00;
       $minLon = -180.00;
       $maxLon = 180.00;
       for ($i = 1; $i <= 5000; $i++)
       {
           $js_data[] = array( (double)$minLat + (double)((float)rand()/(float)getrandmax() * (($maxLat - $minLat) + 1)),
                      (double)$minLon + (double)((float)rand()/(float)getrandmax() * (($maxLon - $minLon) + 1)),
                      str_shuffle($str),
                      "http://placehold.it/120x120",
                      "http://placehold.it/200x200",
                      "Comment",
                      "Author",
                      (int)120
                      );
       }
       END Debug generate dummy data */
    return $js_data;
}