Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [MOD] - KPicasa gallery plugin for sNews?  (Read 8396 times)

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
[MOD] - KPicasa gallery plugin for sNews?
« on: July 15, 2008, 02:17:51 am »

This is my first working version of KPicasa port for sNews.

What is not done:
 - Pagination for the main list of photo albums
 - Control Panel (had no time, sorry. Is very little to do, anyway) and language variables

What is done:
 - Pagination inside albums. Default, there are 30 photos per page but you can change variable value to suit your needs
 - Integration as MOD. Also is SEO compliant (with a hacked title() function).
 - Code is XHTML valid (I have a XHTML 1.0 Strict theme, not tried on other versions - Because of this forum I became a "maniac" about validation ;D ).  

Requirements:
 - A hacked version of title() function (which will became a more hacked... :) )
 - Icons for categories ADD ON - there you will find also a little addition at the end of first post... you need that too. But with little modifications, you can drop the requirements for icons...
 - lightbox from Moshe's add on (you can put your version if you know what to do) - I'm using highslide and only this checked for validation :P


Let's start.
Backup first, as always.

Second, you need three functions included in sNews or in a separate file. Those functions represent the original code adapted for sNews (no more as classes but simple functions). I put here everything you need(imcluding caticons), just unpack in your root site.
Here is the package.


Locate in that tweaked title() function line:
if (!empty($articleTitle)) {$title = $articleTitle;}
and before it put this code:
Code: [Select]
<?php
if ($categorySEF == 'picasa'){
  
$myurl explode('/'clean(cleanXSS($_GET['category'])));
  if (
$myurl[1]) {
    
$article $myurl[1]; 
    
//$article = get_id('article');
    
if($myurl[2]){
      
$pageitem $myurl[2];
      
$page '';
      
$page ltrim($pageitem'p_');
      if((
$page != '') and intval($page)) {
        
$title 'Alternative - Picasa '.$article.' Photo Album, page nr.'.$page;
        
$dmeta 'Picasa '.$article.' Photo Album, page nr.'.$page;
        
$kmeta 'photo album';
      }
      else {
        
$title 'Alternative - Picasa '.$article.' Photo Album, page nr.1';
        
$dmeta 'Picasa '.$article.' Photo Album, page nr.1';
        
$kmeta 'photo album';
      }
    }
    else {
      
$title 'Alternative - Picasa '.$article.' Photo Album, page nr.1';
      
$dmeta 'Picasa '.$article.' Photo Album, page nr.1';
      
$kmeta 'photo album';
    }
  }
}


Locate in function center() line (the second one because here are two):
switch ($action) {
and after it, put this code:
Code: [Select]
<?php
//KPicasa MOD( -- in center() function
case 'picasa'
  
$myurl explode('/'clean(cleanXSS($_GET['category'])));
  if (
$myurl[1]) { // if a second parameter exist (album name) then show the gallery
$article $myurl[1]; 
if($myurl[2]){
  $pageitem $myurl[2];
  $page ''
          
$page ltrim($pageitem'p_');
          if((
$page != '') and intval($page)) displayPictures($article, (int) $page);
          else 
displayPictures($article1);
      }
      else 
displayPictures($article1);
   }
   else{ 
// else show all public albums
      
$icon_name file_exists('caticons/picasa32.png') ? db('website').'caticons/picasa32.png' db('website').'caticons/default32.png';  
      echo 
'<p class="note"><img class="leftalign" style="border:0;padding:none" src="'.$icon_name.'" alt="picasa 32 pixels icon" /><br /> You are currently browsing photo albums from <strong>Picasa</strong> photo gallery.</p>';
      echo 
'<div class="clear"></div>';
      
displayAlbums();
}
break;

//)

Add in your index php these lines:
Quote
<link href="http://yourdomain.com/kpicasa_gallery.css" rel="stylesheet" type="text/css" />
<link href="http://yourdomain.com/highslide/highslide.css" rel="stylesheet" type="text/css" />
Or, if you use lightbox:
Quote
<link href="http://yourdomain.com/css/slimbox.css" rel="stylesheet" type="text/css" />

After this, create a category Picasa (be sure that the seftitle is picasa.
Here we have a convention, to avoid duplicate meta... when you have an article which refer to an album, the link must be
http;//yourdomain.com/picasa/album_name/p_1/  even if you have only a single page for your album.
.
Avoid having links like this http;//yourdomain.com/picasa/album_name/ on your site (is working but you will have a duplicate meta).

P.S. I tried also with lightbox and code is not valid. Only with highslide.  :P
Here is the second sNews site which use KPicasa gallery:
« Last Edit: August 15, 2008, 08:09:25 am by funlw65 »
Logged

mosh

  • Hero Member
  • *****
  • Karma: 77
  • Posts: 510
  • Awesome day :)
    • cms-zen
Re: KPicasa gallery plugin for sNews?
« Reply #1 on: July 15, 2008, 11:47:13 pm »

 :P :P :P looking very good vasi,
and i loved the pigeons.

is it a mod, or an addon ?

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: KPicasa gallery plugin for sNews?
« Reply #2 on: July 16, 2008, 01:10:25 am »

Thank you Moshe, I am only a translator.  What you saw, is a function extracted from kpicasa class, which can be used with insert function mod, but don't have pagination yet. I will try to integrate it in sNews as hard coded page, with pagination. It will be a mod. For Wordpress, is a plug-in and for sNews will be as a modification. I hope... Right now, as it is, can be used for small galleries, with a small amount of images, to be easily loaded. I don't know yet if I will extract function members or I will try to adapt entire class object.

I have all my photos on Picasa, storing on a domain can be only a short time solution.
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: KPicasa gallery plugin for sNews?
« Reply #3 on: July 16, 2008, 01:55:22 pm »

This is what I have now. Is only a function and can be used inserting it in an article with "insert function" . Is working with public albums. You must download the original package because you have there lightbox and highslide scripts.
This function works only with PHP5 but I know the author have a version also for PHP4

Code: [Select]
<?php
//KPicasa MOD(  --  very WIP

function fetch$url )
{
$fopen_failed false;
$curl_failed  false;

// todo: add timeouts?

if ( ini_get('allow_url_fopen') == '1' )
{
$data file_get_contents($url);
if ($data !== false)
{
return $data;
}
$fopen_failed true;
}
if ( function_exists('curl_init') )
{
$ch curl_init($url);
curl_setopt($chCURLOPT_RETURNTRANSFER1);
$data curl_exec($ch);
curl_close($ch);
if ($data !== false)
{
return $data;
}
$curl_failed true;
}

if ($fopen_failed && $curl_failed)
{
echo ("<strong>Error:</strong> your PHP configuration reports that it allows kPicasa Gallery to connect to Picasa Web Albums, but in fact it seems your web host is blocking outgoing requests. Please ask your administrator to allow outgoing requests via file_get_contents() or cURL.") ;

}
elseif ($fopen_failed)
{
echo ("<strong>Error:</strong> kPicasa Gallery tried to connect to Picasa Web Albums using file_get_contents() and failed. Your web host is probably blocking outgoing requests.") ;
}
elseif ($curl_failed)
{
echo ("<strong>Error:</strong> kPicasa Gallery tried to connect to Picasa Web Albums using cURL and failed. Your web host is probably blocking outgoing requests.") ;
}
else
{
echo ("<strong>Error:</strong> your PHP configuration does not allow kPicasa Gallery to connect to Picasa Web Albums. Please ask your administrator to enable allow_url_fopen or cURL.") ;
}
}


function displayPictures( $album$direct true)
{
$username     'funlw65' ;
$picEngine    'highslide' ;
$albumPerPage 12 ;
$albumPerRow  ;
$photoPerPage 12 ;
$photoPerRow  ;

//----------------------------------------
// Get the XML
//----------------------------------------
$url "http://picasaweb.google.com/data/feed/api/user/".urlencode($username)."/album/".urlencode($album)."?kind=photo";
//$myxml = new SimpleXMLElement($url, NULL, TRUE);
$data fetch($url);
/*if ( is_wp_error($data) )
{
return $data;
}*/
$data str_replace('gphoto:''gphoto_'$data);
$data str_replace('media:''media_'$data);
//wp_cache_set('kPicasaGallery_'.$album, $data, 'kPicasaGallery', $this->cacheTimeout);
$xml simplexml_load_string($data);
if ( $xml === false )
{
echo ("<strong>Error:</strong> the communication with Picasa Web Albums didn't go as expected. Here's what Picasa Web Albums said:<br /><br /> ".$data) ;
}

//----------------------------------------
// Display "back" link
//----------------------------------------
if ( !$direct )
{
//$backURL = remove_query_arg('album');
//$backURL = remove_query_arg('kpap', $backURL);
$backURL '#';
echo "<div id='kpg-backLink'><a href='$backURL'>&laquo; Back to album list</a></div>";
}

//----------------------------------------
// Display album information
//----------------------------------------
$albumTitle    = (string) $xml->title ;
$albumSummary  = (string) $xml->subtitle ;
$albumLocation = (string) $xml->gphoto_location ;
$albumNbPhotos = (string) $xml->gphoto_numphotos;

echo "<h2>$albumTitle Photo Gallery</h2>";
if ( strlen($albumSummary) )
{
echo "<p><strong>Album description:</strong> $albumSummary</p>";
}
if ( strlen($albumLocation) )
{
echo "<p><strong>Album location:</strong> $albumLocation</p>";
}
echo "<p class='kpg-nbPhotos'><strong>$albumNbPhotos</strong> photo".($albumNbPhotos 's' '').'</p>';


if ( $picEngine == 'lightbox' )
{
echo '<script type="text/javascript" src="http://www.morisca.net/lightbox.js"></script>';
}
//----------------------------------------
// Prepare Highslide if needed
//----------------------------------------
if ( $picEngine == 'highslide' )
{
echo '<script type="text/javascript" src="http://www.morisca.net/highslide/highslide.js"></script>';
echo 
'
<script type="text/javascript">

// remove the registerOverlay call to disable the controlbar
hs.registerOverlay({
thumbnailId: null,
overlayId: "controlbar",
position: "top right",
hideOnMouseOut: true
});

hs.graphicsDir = "highslide/graphics/";
hs.outlineType = "rounded-white";

hs.captionEval = "this.thumb.title";


</script>
'
;

echo '<div id="controlbar" class="highslide-overlay controlbar">';
echo '<a href="#" class="previous" onclick="return hs.previous(this)" title="Previous (left arrow key)"></a>';
echo '<a href="#" class="next" onclick="return hs.next(this)" title="Next (right arrow key)"></a>';
echo '<a href="#" class="highslide-move" onclick="return false" title="Click and drag to move"></a>';
echo '<a href="#" class="close" onclick="return hs.close(this)" title="Close"></a>';
echo '</div>';

}

//----------------------------------------
// Prepare some variables
//----------------------------------------
$page 1// kpap = kPicasa Album Page

if ($photoPerPage 0)
{
$start = ($page 1) * $photoPerPage;
$stop  $start $photoPerPage 1;
}
else
{
$start 0;
$stop count$xml->entry ) - 1;
}

//----------------------------------------
// Loop through the pictures
//----------------------------------------
echo '<table class="kpg-pictures" id="kpg-pictures">';
$i 0$j 0;
foreach( $xml->entry as $photo )
{
if ($i >= $start && $i <= $stop)
{
if ($j $photoPerRow == 0)
{
$remainingWidth 100;
if ($j 0)
{
echo '</tr>';
}
echo '<tr>';
}

// if last cell, simply put remaining width
$width = ( ($j+1) % $photoPerRow == ) ? $remainingWidth round100 $photoPerRow );
$remainingWidth -= $width;
echo '<td>';

$summary  = (string) $photo->summary ;
$thumbURL = (string) $photo->media_group->media_thumbnail[1]['url'];
$thumbH   = (string) $photo->media_group->media_thumbnail[1]['height'];
$thumbW   = (string) $photo->media_group->media_thumbnail[1]['width'];
$fullURL  str_replace('s144''s800'$thumbURL);

if ( $picEngine == 'lightbox' )
{
if ( strlen($summary) )
{
//echo '<a href="'.$fullURL.'" rel="lightbox['.$album.']" title="'.str_replace("'", "&#38;#39;", $summary).'"><img src="'.$thumbURL.'" height="'.$thumbH.'" width="'.$thumbW.'" alt="'.str_replace("'", "&#38;#39;", $summary).'" class="kpg-thumb" /></a>';
echo '<a href="'.$fullURL.'" rel="lightbox" title="'.str_replace("'""&#38;#39;"$summary).'"><img src="'.$thumbURL.'" height="'.$thumbH.'" width="'.$thumbW.'" alt="'.str_replace("'""&#38;#39;"$summary).'" class="kpg-thumb" /></a>';
echo "<span class='kpg-summary'>$summary</span>";
}
else
{
//echo '<a href="'.$fullURL.'" rel="lightbox['.$album.']"><img src="'.$thumbURL.'" height="'.$thumbH.'" width="'.$thumbW.'" alt="" class="kpg-thumb" /></a>';
echo '<a href="'.$fullURL.'" rel="lightbox"><img src="'.$thumbURL.'" height="'.$thumbH.'" width="'.$thumbW.'" alt="" class="kpg-thumb" /></a>';
}
}
elseif ( $picEngine == 'highslide' )
{
if ( strlen($summary) )
{
echo "<a href='$fullURL' rel='highslide' class='highslide'><img src='$thumbURL' height='$thumbH' width='$thumbW' title='".str_replace("'""&#38;#39;"$summary)."' alt='".str_replace("'""&#38;#39;"$summary)."' class='kpg-thumb' /></a>";
echo "<span class='kpg-summary'>$summary</span>";
echo "<span class='highslide-caption'>$summary</span>";
}
else
{
echo "<a href='$fullURL' rel='highslide' class='highslide'><img src='$thumbURL' height='$thumbH' width='$thumbW' alt='' class='kpg-thumb' /></a>";
}
}
else
{
if ( strlen($summary) )
{
echo "<a href='$fullURL' title='".str_replace("'""&#38;#39;"$summary)."'><img src='$thumbURL' height='$thumbH' width='$thumbW' alt='".str_replace("'""&#38;#39;"$summary)."' class='kpg-thumb' /></a>";
echo "<span class='kpg-summary'>$summary</span>";
}
else
{
echo "<a href='$fullURL'><img src='$thumbURL' height='$thumbH' width='$thumbW' alt='' class='kpg-thumb' /></a>";
}
}
echo '</td>';
$j++;
}
$i++;
}

// never leave the last row with insuficient cells
if ($photoPerRow 0)
{
while ($j $photoPerRow 0)
{
echo '<td>&nbsp;</td>';
$j++;
}
}

echo '</tr>';
echo '</table>';
echo '<div style="clear:both;">&nbsp;</div>';
/*
//----------------------------------------
// Paginator
//----------------------------------------
$extraArgs = array('album' => $album);
if (isset($_GET['kpgp']) && intval($_GET['kpgp']) > 1)
{
$extraArgs['kpgp'] = intval($_GET['kpgp']);
}
$this->paginator( $page, 'kpap', $this->nbPhotosPerPage, count($xml->entry), $extraArgs );*/
//return true;
}
//)

« Last Edit: July 19, 2008, 01:20:12 pm by funlw65 »
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: KPicasa gallery plugin for sNews?
« Reply #4 on: July 16, 2008, 07:17:58 pm »

Code does not validate because I'm getting a plus <\div> tag... and I don't know yet why and where... must check the code...
Without the function, everything is ok.... with function inserted, I have that </div> tag... :P  :-\
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: KPicasa gallery plugin for sNews?
« Reply #5 on: July 19, 2008, 02:52:19 am »

But does validate now. Code updated. Ready to go further. :P
Logged

mosh

  • Hero Member
  • *****
  • Karma: 77
  • Posts: 510
  • Awesome day :)
    • cms-zen
Re: KPicasa gallery plugin for sNews?
« Reply #6 on: July 19, 2008, 09:22:25 am »

 8) good work Vasile

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: [MOD] - KPicasa gallery plugin for sNews?
« Reply #7 on: August 14, 2008, 05:13:43 am »

First post updated.
Have a good Summer!
Vasi
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: [MOD] - KPicasa gallery plugin for sNews?
« Reply #8 on: September 19, 2008, 07:28:02 pm »

If someone want to take this at a next level, here is a good resource http://www.ibm.com/developerworks/web/library/x-picasalbum/
Logged

kmadsen

  • Newbie
  • *
  • Karma: 1
  • Posts: 40
    • Santa Cruz al Salvador
Re: [MOD] - KPicasa gallery plugin for sNews?
« Reply #9 on: February 10, 2009, 08:37:13 am »

Vasile,

This looks very promising.  I'm attempting to add kpicasa_gallery to an sNews 1.7 site.  The album lookup is working, but I get "Requested contents could not be found. Please go back or use the search feature." (error 404) when I click on the album to view the photos.  Any ideas?  The URL in the browser task bar looks right when I hover over the album, but I get the error.

Kent
Logged
“Every exit is an entrance somewhere else” — Tom Stoppard, British playwright

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: [MOD] - KPicasa gallery plugin for sNews?
« Reply #10 on: February 10, 2009, 08:22:16 pm »

Hi kmadsen,

I'm not using sNews 1.7, I'm waiting 2.0. . I have better SEO with Rui's fork, Revolutions.

I will try to implement KPicasa in sNews 1.7 (from official download link - I hope it have all patches) on local host. But no promises...  not enough time..
Logged

kmadsen

  • Newbie
  • *
  • Karma: 1
  • Posts: 40
    • Santa Cruz al Salvador
Re: [MOD] - KPicasa gallery plugin for sNews?
« Reply #11 on: February 10, 2009, 10:12:50 pm »

Thanks -- I understand about the time, just thought something might spring to mind.  Do I need to create articles for each of my albums?  It just happens that I'm investigating 1.7 at the same time I came across the KPicasa work you've done, so that's where I'm trying it first.

Kent
Logged
“Every exit is an entrance somewhere else” — Tom Stoppard, British playwright

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: [MOD] - KPicasa gallery plugin for sNews?
« Reply #12 on: February 11, 2009, 03:43:43 am »

Do I need to create articles for each of my albums? 

No, is like a separate photo gallery... It have a hardcoded category, picasa, where are all albums displayed. Then you can click on an album and then, you will see all photos from that album, but with pagination if your number of photos is greater than the one set for maximum photos per page (you can set that inside code - I wanted to make a control panel for those settings: the user id for picasa album, number of albums per columns, number of album photos per column, and maximum photos per page)
« Last Edit: February 11, 2009, 03:49:06 am by funlw65 »
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: [MOD] - KPicasa gallery plugin for sNews?
« Reply #13 on: February 11, 2009, 03:56:56 am »

Vasile,

This looks very promising.  I'm attempting to add kpicasa_gallery to an sNews 1.7 site.  The album lookup is working, but I get "Requested contents could not be found. Please go back or use the search feature." (error 404) when I click on the album to view the photos.  Any ideas?  The URL in the browser task bar looks right when I hover over the album, but I get the error.

Kent

I remember I had problems in sNews 1.6 because the link for an picasa album contain some letters in upper case. And get_id (from memory, maybe I'm wrong) do not accept upper case... I had to avoid using that ... Of course in sNews 1.7 get_id was vanished,,, I don't know 1.7 version yet...
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: [MOD] - KPicasa gallery plugin for sNews?
« Reply #14 on: February 12, 2009, 05:49:41 pm »

At first sight, some checking must be avoided (in "function" startup) if category is "picasa" so you can take care of url inside function center, at 'picasa' case.


Nope, is working nice without need to modify startup function. Few more tests and I will post it as 1.7 mod
« Last Edit: February 12, 2009, 06:12:10 pm by funlw65 »
Logged