Announcement

#1 2016-07-15 02:15:31

victorhugops
Member
2016-07-15
5

random rss feed

Hello Masters,

Do you know if the piwigo 2.8.2 have any option to make a rss feed with a random image ??

I had this function in my old gallery3
http://fotos.vhsantos.net/rss/feed/rss_ … m/portrait
and here the original code
http://codex.galleryproject.org/Gallery … rss_extra.

I used this to put a random photos on distinct social networks with a https://dlvr.it

any suggestions ?

thanks and attentive.

Offline

 

#2 2016-09-17 01:37:58

victorhugops
Member
2016-07-15
5

Re: random rss feed

Hello,

I was "working" in this request and attached is the patch.

Sorry, for the code...Im not a developer, I just copy and paste code from one place to other, but I think that is OK.. maybe a good developer can look and improve it.

to access the random feed:
http://site/feed.php?random

thanks and attentive.

Last edited by victorhugops (2016-09-17 01:38:44)

Offline

 

#3 2016-09-17 01:39:32

victorhugops
Member
2016-07-15
5

Re: random rss feed

the site not allow attachament ???



$ cat feed_random-patch.txt
diff -Naurp /tmp/piwigo-2.8.2/feed.php /tmp/piwigo-2.8.2-patch/feed.php
--- /tmp/piwigo-2.8.2/feed.php    2016-09-16 20:06:15.844348272 -0300
+++ /tmp/piwigo-2.8.2-patch/feed.php    2016-09-16 20:07:32.537900668 -0300
@@ -65,8 +65,21 @@ check_input_parameter('feed', $_GET, fal

$feed_id= isset($_GET['feed']) ? $_GET['feed'] : '';
$image_only=isset($_GET['image_only']);
+$image_random=isset($_GET['random']);

-// echo '<pre>'.generate_key(50).'</pre>';
+if(isset($_GET['image_random']))
+{
+ $image_random=true;
+}
+
+$add_url_params = array();
+if (isset($auth_key))
+{
+  $add_url_params['auth'] = $auth_key;
+}
+
+
+//echo '<pre>'.generate_key(50).'</pre>';
if ( !empty($feed_id) )
{
   $query = '
@@ -114,6 +127,68 @@ $rss->link = get_gallery_home_url();
// |                            Feed creation                              |
// +-----------------------------------------------------------------------+

+if ($image_random)
+{
+
+// Get the number of random images using the "top_image_random" variable.
+//
+$query_random = '
+SELECT *
+  FROM '.IMAGES_TABLE.'
+    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
+      '.get_sql_condition_FandF(
+        array(
+          'forbidden_categories' => 'category_id',
+          'visible_categories' => 'category_id',
+          'visible_images' => 'id'
+        ),
+        'WHERE'
+      ).'
+    ORDER BY '.DB_RANDOM_FUNCTION.'()
+    LIMIT '.$conf['top_image_random'].'
+    ;';
+
+$images_random = query2array($query_random);
+
+
+// Create a feed item for each random image selected
+//
+foreach($images_random as $date_detail)
+{
+//var_dump($images_random);
+
+  // Get the URL images
+  $link_url = add_url_params(
+        make_picture_url(
+          array(
+            'image_id' => $date_detail['id'],
+            'image_file' => $date_detail['file'],
+            )
+          ),
+        $add_url_params
+        );
+
+  // Get the thumb
+  $tn_src = DerivativeImage::thumb_url($date_detail);
+
+  $item = new FeedItem();
+  $item->date = ts_to_iso8601(datetime_to_ts($dbnow));
+  $item->title = $date_detail['name'];
+  $item->link =  $link_url;
+  $item->description = '<a href="'.$link_url.'"><img src="'.$tn_src.'"></a>';
+  $item->description .= '<br>';

+  $item->descriptionHtmlSyndicated = true;
+  $item->author = $conf['rss_feed_author'];
+
+  $rss->addItem($item);
+}
+
+
+}
+
+else
+{
$news = array();
if (!$image_only)
{
@@ -192,10 +267,11 @@ foreach($dates as $date_detail)

   $rss->addItem($item);
}
+}

$fileName= PHPWG_ROOT_PATH.$conf['data_location'].'tmp';
mkgetdir($fileName); // just in case
$fileName.='/feed.xml';
// send XML feed
echo $rss->saveFeed('RSS2.0', $fileName, true);
-?>
\ No newline at end of file
+?>
diff -Naurp /tmp/piwigo-2.8.2/include/config_default.inc.php /tmp/piwigo-2.8.2-patch/include/config_default.inc.php
--- /tmp/piwigo-2.8.2/include/config_default.inc.php    2016-09-16 20:06:15.880349001 -0300
+++ /tmp/piwigo-2.8.2-patch/include/config_default.inc.php    2016-09-16 20:16:32.000828357 -0300
@@ -846,4 +846,7 @@ $conf['proxy_server'] = 'proxy.domain.or
// If the http-proxy requires authentication, set username and password here
// e.g. username:password
$conf['proxy_auth'] = '';
+
+// top_image_random : number of random images to display on RSS feed
+$conf['top_image_random'] = 3;
?>
diff -Naurp /tmp/piwigo-2.8.2/language/en_UK/common.lang.php /tmp/piwigo-2.8.2-patch/language/en_UK/common.lang.php
--- /tmp/piwigo-2.8.2/language/en_UK/common.lang.php    2016-09-16 20:06:15.788347139 -0300
+++ /tmp/piwigo-2.8.2-patch/language/en_UK/common.lang.php    2016-09-16 20:07:48.142216693 -0300
@@ -274,6 +274,7 @@ $lang['Photo title, A &rarr; Z'] = 'Phot
$lang['Photo title, Z &rarr; A'] = 'Photo title, Z &rarr; A';
$lang['photo'] = "photo";
$lang['Photos only RSS feed'] = "Photos only RSS feed";
+$lang['Random Photos RSS feed'] = "Random Photos RSS feed";
$lang['photos posted during the last %d days'] = "photos posted during the last %d days";
$lang['Photos posted within the last %d day.'] = "Photos posted within the last %d day only.";
$lang['Photos posted within the last %d days.'] = "Photos posted within the last %d days only.";
@@ -426,4 +427,4 @@ $lang['Album name, A &rarr; Z'] = 'Album
$lang['Album name, Z &rarr; A'] = 'Album name, Z &rarr; A';
$lang['Link: %s'] = 'Link: %s';
$lang['Your authentication key is no longer valid.'] = 'Your authentication key is no longer valid.';
-?>
\ No newline at end of file
+?>
diff -Naurp /tmp/piwigo-2.8.2/notification.php /tmp/piwigo-2.8.2-patch/notification.php
--- /tmp/piwigo-2.8.2/notification.php    2016-09-16 20:06:15.972350863 -0300
+++ /tmp/piwigo-2.8.2-patch/notification.php    2016-09-16 20:07:53.690328777 -0300
@@ -76,13 +76,16 @@ pwg_query($query);
$feed_url=PHPWG_ROOT_PATH.'feed.php';
if (is_a_guest())
{
-  $feed_image_only_url=$feed_url;
+  //$feed_image_only_url=$feed_url;
   $feed_url .= '?feed='.$page['feed'];
+  $feed_image_only_url=$feed_url.'&amp;image_only';
+  $feed_image_only_random_url=$feed_url.'&amp;random';
}
else
{
   $feed_url .= '?feed='.$page['feed'];
   $feed_image_only_url=$feed_url.'&amp;image_only';
+  $feed_image_only_random_url=$feed_url.'&amp;random';
}

// +-----------------------------------------------------------------------+
@@ -100,6 +103,7 @@ $template->assign(
   array(
     'U_FEED' => $feed_url,
     'U_FEED_IMAGE_ONLY' => $feed_image_only_url,
+    'U_FEED_IMAGE_ONLY_RANDOM' => $feed_image_only_random_url,
     )
   );
   
@@ -119,4 +123,4 @@ flush_page_messages();
$template->pparse('notification');
include(PHPWG_ROOT_PATH.'include/page_tail.php');

-?>
\ No newline at end of file
+?>
diff -Naurp /tmp/piwigo-2.8.2/themes/default/template/notification.tpl /tmp/piwigo-2.8.2-patch/themes/default/template/notification.tpl
--- /tmp/piwigo-2.8.2/themes/default/template/notification.tpl    2016-09-16 20:06:15.972350863 -0300
+++ /tmp/piwigo-2.8.2-patch/themes/default/template/notification.tpl    2016-09-16 20:07:58.834433004 -0300
@@ -1,6 +1,7 @@
{html_head}
<link rel="alternate" type="application/rss+xml" title="{'Photos only RSS feed'|@translate}" href="{$U_FEED_IMAGE_ONLY}">
<link rel="alternate" type="application/rss+xml" title="{'Complete RSS feed (photos, comments)'|@translate}" href="{$U_FEED}">
+<link rel="alternate" type="application/rss+xml" title="{'Random Photos RSS feed'|@translate}" href="{$U_FEED_IMAGE_ONLY_RANDOM}">
{/html_head}

{if isset($MENUBAR)}{$MENUBAR}{/if}
@@ -22,7 +23,10 @@
       <a href="{$U_FEED_IMAGE_ONLY}">{'Photos only RSS feed'|@translate}</a><br><br>
     </dt>
     <dt>
-      <a href="{$U_FEED}">{'Complete RSS feed (photos, comments)'|@translate}</a>
+      <a href="{$U_FEED}">{'Complete RSS feed (photos, comments)'|@translate}</a><br><br>
+    </dt>
+    <dt>
+      <a href="{$U_FEED_IMAGE_ONLY_RANDOM}">{'Random Photos RSS feed'|@translate}</a>
     </dt>
   </dl>
   </div>

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact