Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fixes and additional functions #1

Merged
merged 4 commits into from
Jun 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 40 additions & 20 deletions flickrfeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
*
* Place the file `flickrfeed.php` into your `/plugins` folder, enable it and set the plugin options.
*
* Add `flickrFeed::printFreed(4);` to your theme where you want to display the latest images.
* Add `flickrFeed::printFeed(4);` to your theme where you want to display the latest images.
*
* Note the plugin does just print an unordered list with linked thumbs and does not provide any default CSS styling.
*
* @author Malte Müller (acrylian)
* @author Malte Müller (acrylian), with additions by kuzzzma (since v1.2)
* @licence GPL v3 or later
*/
$plugin_description = gettext('A simple plugin to display the latest public images from a Flickr account');
$plugin_author = 'Malte Müller (acrylian)';
$plugin_version = '1.1';
$plugin_version = '1.2';
$plugin_category = gettext('Media');
$option_interface = 'flickrFeedOptions';

Expand All @@ -36,7 +36,8 @@ function getOptionsSupported() {
'key' => 'flickrfeed_userid',
'type' => OPTION_TYPE_TEXTBOX,
'order' => 1,
'desc' => gettext('The user id of your Flickr account to fetch')),
'desc' => gettext('The user ID of your Flickr account to fetch. NOTE: Not an username! Flickr ID has a format of "XXXXXXXX@N00".<br>
To find yours - login into Flickr and check <a href="https://www.flickr.com/services/api/explore/flickr.people.getPublicPhotos">API page</a> - on the right there is a section "Useful Values", at the top your user ID is listed.')),
gettext('Cache time') => array(
'key' => 'flickrfeed_cachetime',
'type' => OPTION_TYPE_TEXTBOX,
Expand Down Expand Up @@ -75,7 +76,7 @@ static function getFeed() {
require_once(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/zenphoto_news/rsslib.php');
$userid = trim(getOption('flickrfeed_userid'));
if ($userid) {
$feedurl = 'https://api.flickr.com/services/feeds/photos_public.gne?id=' . sanitize($userid) . '&format=rss2';
$feedurl = 'https://www.flickr.com/services/feeds/photos_public.gne?id=' . sanitize($userid) . '&format=rss2';
$cache = flickrFeed::getCache();
$lastmod = flickrFeed::getLastMod();
$cachetime = getOption('flickrfeed_cachetime');
Expand All @@ -92,11 +93,11 @@ static function getFeed() {
}

/**
* Prints a list of images from a users flickrFeed
* Prints a list of images from a users Flickr public photos RSS feed
*
* Notes:
* The feed is always fetched compeltely as Flickr provides no limit here. The $number parameter is used internally only.
* Also flickr provides the images thumbnail size, there is no sizing available other than fake resizing using CSS.
* Also Flickr provides the images thumbnail size, there is no sizing available other than fake resizing using CSS.
*
* @param int $number The number of images to display
* @param string $class default "flickrfeed" to use the default styling
Expand All @@ -110,7 +111,7 @@ static function printFeed($number = 4, $class="flickrfeed") {
<?php
foreach ($content as $item) {
//echo "<pre>"; print_r($item); echo "</pre>";
$thumb = flickrfeed::getItemLinkAndThumb($item);
$thumb = flickrFeed::getItemLinkAndThumb($item);
if ($thumb) {
$count++;
echo '<li>' .$thumb . '</li>';
Expand All @@ -124,38 +125,57 @@ static function printFeed($number = 4, $class="flickrfeed") {
<?php
}
}

/**
* Return <a><img></a> HTML of the image posted
* Returns <a><img></a> HTML of the Image posted with medium thumbnail (max 240x240px)
*
* @param array $item The item array
* @param array $item The item array
*/
static function getItemLinkAndThumb($item) {
$expl = explode('<p>', $item['description']);
if (array_key_exists(2, $expl)) {
return $expl[2];
return str_replace('</p>','',$expl[2]);
}
}

/**
* Returns the image description wrapped in a paragraph.
* @param array $item The item array
* Returns the Image Description wrapped in a paragraph.
*
* @param array $item The item array
*/
static function getItemDescription($item) {
$expl = explode('<p>', $item['description']);
$expl = explode("<p>", $item['description']);
if (array_key_exists(3, $expl)) {
return $expl[3];
}
}

/**
* Returns the image description wrapped in a paragraph.
* @param array $item The item array
* Returns the URL of the Image.
*
* @param array $item The item array
*/
static function getItemURL($item) {
return $item['link'];
}

/**
* Returns the Title of the Image.
*
* @param array $item The item array
*/
static function getItemTitle($item) {
return $item['title'];
}

/**
* Returns the Image Date Published wrapped in a paragraph.
* @param array $item The item array
*/
static function getItemDate($item) {
return zpFormattedDate(DATE_FORMAT, strtotime($item['pubDate']));
}

/**
* Gets the content from cache if available
* @return array
Expand All @@ -175,7 +195,7 @@ static function getCache() {
*/
static function saveCache($content) {
global $_zp_db;
$hascache = flickrfeed::getCache();
$hascache = flickrFeed::getCache();
$cache = serialize($content);
if ($hascache) {
$sql = 'UPDATE ' . $_zp_db->prefix('plugin_storage') . ' SET `data`=' . $_zp_db->quote($cache) . ' WHERE `type`="flickrfeed" AND `aux` = "flickrfeed_cache"';
Expand Down Expand Up @@ -205,7 +225,7 @@ static function getLastMod() {
*/
static function saveLastmod() {
global $_zp_db;
$haslastmod = flickrfeed::getLastMod();
$haslastmod = flickrFeed::getLastMod();
$lastmod = time();
if($haslastmod) {
$sql = 'UPDATE ' . $_zp_db->prefix('plugin_storage') . ' SET `data` = ' . $lastmod . ' WHERE `type`="flickrfeed" AND `aux` = "flickrfeed_lastmod"';
Expand Down