source: extensions/piclens/piclens/include/Piclens.class.php @ 3636

Last change on this file since 3636 was 3636, checked in by tiico, 15 years ago

Correct name and description of pictures with extendedDescriotion plugin

File size: 18.5 KB
Line 
1<?php
2/*
3 * Plugin Name: CoolIris-Piclens
4 * Version: 0.3.4
5 * Description: Cooliris/Piclens activation
6 * Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=234
7 * Author: Tiico
8 * Author URI:
9 * */
10/********* Fichier piclens.class.php  *********/
11 
12
13class Piclens
14{
15    var $my_config, $root_site_piclens;
16       
17        function Piclens()
18        {
19                // HTTPS
20                set_make_full_url();
21                $this->root_site_piclens = get_root_url();
22                // If needed NO_https can easily be set in your config_local thru LocalFiles Editor
23                if (isset($conf['NO_https']) and $conf['NO_https'] and strncasecmp($this->root_site_piclens, 'https://', 8) == 0 ) 
24                        $this->root_site_piclens = 'http://' . substr($this->root_site_piclens, 8);
25                // HTTPS
26                unset_make_full_url();
27        }
28       
29       
30        // Add Piclens CSS & Javascript in HEAD section
31        function piclens_link()
32        {
33            global $template, $page, $user;
34
35               
36                $jscript = '<script type="text/javascript"> function roll_over_piclens(img_name, img_src){document[img_name].src = img_src;}</script>';
37                $template->append('head_elements',$jscript);                   
38         
39//foreach ($page  as $key => $value)
40//echo "page[".$key."]=".$value."\n";
41
42                // Vérification d'activation du plugin (page administration)
43                if ($this->my_config['piclens_active'])
44                {
45                        // Correction bug compteur "fou". Les pages d'affichage des images seules ne sont pas a prendre en compte.
46                        if (isset($page['section']) && !isset($page['image_id']))
47                        {
48
49                                // Page images recentes
50                                if (($page['section']) == 'recent_pics' && $this->my_config['piclens_recentpics_active'])
51                                {
52                                        $piclnkMaster='<link rel="alternate"'
53                                                                . ' href="'.$this->root_site_piclens.PICLENS_PATH.'piclens-rss.php?/recent_pics"'
54                                                                .' type="application/rss+xml" title="" id="recent_pics"'
55                                                                . ' >' . "\n";                 
56                                }
57                                // Page categories recentes
58                                elseif (($page['section']) == 'recent_cats' && $this->my_config['piclens_recentcats_active'])
59                                {
60                                        if ($this->my_config['piclens_recursive_mode'] != 'standard')
61                                        {
62                                                $query = 'SELECT c.id, c.permalink
63                                                  FROM '.CATEGORIES_TABLE.' c INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
64                                                  ON id = cat_id and user_id = '.$user['id'].'
65                                                  WHERE date_last >= SUBDATE(
66                                                        CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY
67                                                  )
68                                                '.get_sql_condition_FandF
69                                                  (
70                                                        array
71                                                          (
72                                                                'visible_categories' => 'id',
73                                                          ),
74                                                        'AND'
75                                                  ).'
76                                                ;';
77                                                $piclnkMaster='';
78                                                $result = pwg_query($query);
79                                                while ($row = mysql_fetch_assoc($result))
80                                                {
81                                                        // Gestion des permalinks
82                                                        $categoryId = $row['id'] ;
83                                                        if (!empty($row['permalink']))
84                                                                $categoryId = $row['permalink'];
85                                       
86                                                        $piclnkMaster.='<link rel="alternate"'
87                                                                                . ' href="'.$this->root_site_piclens.PICLENS_PATH.'piclens-rss.php?/category/'
88                                                                                . $categoryId .'&norecurs"'
89                                                                                .' type="application/rss+xml" title="" id="'.$row['id'].'"'
90                                                                                . ' >' . "\n";
91                                                       
92                                                }
93                                        }
94                                        else
95                                        {
96
97                                                $piclnkMaster='<link rel="alternate"'
98                                                                        . ' href="'.$this->root_site_piclens.PICLENS_PATH.'piclens-rss.php?/recent_cats"'
99                                                                        .' type="application/rss+xml" title="" id="recent_cats"'
100                                                                        . ' >' . "\n";                 
101
102                                        }
103                                }
104                                // Page plus vues
105                                elseif (($page['section']) == 'most_visited' && $this->my_config['piclens_mostvisited_active'])
106                                {
107                                        $piclnkMaster='<link rel="alternate"'
108                                                                . ' href="'.$this->root_site_piclens.PICLENS_PATH.'piclens-rss.php?/most_visited"'
109                                                                .' type="application/rss+xml" title="" id="most_visited"'
110                                                                . ' >' . "\n";                 
111                                }
112                                // mieux notees
113                                else if ($page['section'] == 'best_rated' && $this->my_config['piclens_bestrated_active'])
114                                {
115                                        $piclnkMaster='<link rel="alternate"'
116                                                                . ' href="'.$this->root_site_piclens.PICLENS_PATH.'piclens-rss.php?/best_rated"'
117                                                                .' type="application/rss+xml" title="" id="best_rated"'
118                                                                . ' >' . "\n";                 
119                                }
120                                // favories     
121                                else if ($page['section'] == 'favorites' && $this->my_config['piclens_favorites_active'])
122                                {
123                                        $piclnkMaster='<link rel="alternate"'
124                                                                . ' href="'.$this->root_site_piclens.PICLENS_PATH.'piclens-rss.php?/favorites"'
125                                                                .' type="application/rss+xml" title="" id="favorites"'
126                                                                . ' >' . "\n";                 
127                                }
128
129                                // Seulement sur une page type 'categorie'
130                                // Correction bug compteur "fou". Les pages d'affichage des images seules ne sont pas a prendre en compte.
131                                elseif (($page['section']) == 'categories' && !isset($page['image_id']))
132                                {
133                                       
134                                        // Page accueil et option gallerie activee
135                                    if( (empty($page['category'])) && $this->my_config['piclens_gallerie_active'] )
136                                    {
137                                                if ($this->my_config['piclens_recursive_mode'] != 'standard')
138                                                {
139                                                        $query = 'SELECT id,name,permalink FROM ' . CATEGORIES_TABLE
140                                                        .' WHERE id_uppercat is NULL';
141                                                       
142                                                        $piclnkMaster='';
143                                                        $result = pwg_query($query);
144
145                                                        while ($row = mysql_fetch_assoc($result))
146                                                        {
147                                                                if (!(in_array($row['id'], explode(',', $user['forbidden_categories']))))
148                                                                {
149                                                                        $piclnkMaster.='<link rel="alternate"'
150                                                                                                . ' href="'.$this->root_site_piclens.PICLENS_PATH.'piclens-rss.php?/category/'
151                                                                                                . $row['id'] .'"'
152                                                                                                .' type="application/rss+xml" title="" id="'.$row['id'].'"'
153                                                                                                . ' >' . "\n";                                                                         
154                                                                }
155                                                        }
156                                               
157                                                }
158                                                else
159                                                {
160                                                        $piclnkMaster='<link rel="alternate"'
161                                                                                . ' href="'.$this->root_site_piclens.PICLENS_PATH.'piclens-rss.php?/categories"'
162                                                                                .' type="application/rss+xml" title="" id="accueil"'
163                                                                                . ' >' . "\n";
164                                                }
165                                    }
166                                        // Add only if we are in category page
167                                    elseif (!empty($page['category']['id']))
168                                        {
169
170                                                if ($this->my_config['piclens_recursive_mode'] != 'standard')
171                                                {
172                                                        $categoryId = $page['category']['id'] ;
173                                                        if (!empty($page['category']['permalink']))
174                                                                $categoryId = $page['category']['permalink'];
175
176                                                        $piclnkMaster='<link rel="alternate"'
177                                                                                . ' href="'.$this->root_site_piclens.PICLENS_PATH.'piclens-rss.php?/category/'
178                                                                                . $categoryId .'&norecurs"'
179                                                                                .' type="application/rss+xml" title="" id="'.$page['category']['id'].'"'
180                                                                                . ' >' . "\n";
181
182                                                        $query = '
183                                                        SELECT DISTINCT(id)
184                                                        FROM '.CATEGORIES_TABLE.'
185                                                        WHERE id_uppercat='.$page['category']['id'].';';
186                                                        $result = pwg_query($query);
187
188                                                        while ($row = mysql_fetch_array($result))
189                                                        {
190                                                                $piclnkMaster.='<link rel="alternate"'
191                                                                                        . ' href="'.$this->root_site_piclens.PICLENS_PATH.'piclens-rss.php?/category/'
192                                                                                        . $row['id'] .'"'
193                                                                                        .' type="application/rss+xml" title="" id="'.$row['id'].'"'
194                                                                                        . ' >' . "\n";
195                                                        }
196/*                                                     
197                                                        $piclnkMaster.='<link rel="alternate"'
198                                                                                . ' href="'.get_root_url().PICLENS_PATH.'piclens-rss.php?/category/'
199                                                                                . $categoryId .'&norecurs"'
200                                                                                .' type="application/rss+xml" title="" id="'.$page['category']['id'].'"'
201                                                                                . ' >' . "\n";
202*/
203                                                }
204                                               
205                                                else
206                                                {
207                                                        // Gestion des permalinks
208                                                        $categoryId = $page['category']['id'] ;
209                                                        if (!empty($page['category']['permalink']))
210                                                                $categoryId = $page['category']['permalink'];
211                                       
212                                                        $piclnkMaster='<link rel="alternate"'
213                                                                                . ' href="'.$this->root_site_piclens.PICLENS_PATH.'piclens-rss.php?/category/'
214                                                                                . $categoryId .'"'
215                                                                                .' type="application/rss+xml" title="" id="'.$page['category']['id'].'"'
216                                                                                . ' >' . "\n";
217                                                }
218                                        }
219
220                                }
221                               
222                                if (isset($piclnkMaster))
223                                {
224                                        $piclnk=$piclnkMaster;
225                                        // We need absolute path
226                               
227                                         $template->append('head_elements',$piclnk.'<script type="text/javascript" src="http://lite.piclens.com/current/piclens.js"></script>');                       
228                                }
229                        }
230            }
231               
232        }
233
234
235        // Add piclens Flash slideshow to toolbar
236        // Thanks to P@t
237        function add_piclens_icon()
238        {
239                global $template, $page;
240                if ($this->my_config['piclens_lite_active'] && $this->my_config['piclens_active'])
241                {
242                        // Seulement sur une page type 'categorie'
243                        if (isset($page['section']))
244                        {
245                                // images recentes
246                               
247                                if (   (($page['section']) == 'recent_pics' && $this->my_config['piclens_recentpics_active'])
248                                        || (($page['section']) == 'recent_cats' && $this->my_config['piclens_recentcats_active'])
249                                        || (($page['section']) == 'most_visited' && $this->my_config['piclens_mostvisited_active'])
250                                        || (($page['section']) == 'best_rated' && $this->my_config['piclens_bestrated_active'])
251                                        || (($page['section']) == 'favorites' && $this->my_config['piclens_favorites_active'])
252                                        || (($page['section']) == 'categories')
253                                        )
254                                // categories recentes
255                                // plus vues
256                                // mieux notees
257                                // favories     
258                                {
259                                        if($page['section'] == 'categories')
260                                        {
261                                                if (empty($page['category']))   //      acceuil
262                                                        $rssfeed = $this->root_site_piclens.PICLENS_PATH.'piclens-rss.php?/categories';
263                                                else
264                                                {
265                                                        $rssfeed = $this->root_site_piclens.PICLENS_PATH.'piclens-rss.php?/category/';
266                                                        $rssfeed .= empty($page['category']['permalink']) ? $page['category']['id'] : $page['category']['permalink'];
267                                                }
268                                                if (isset($conf['NO_https']) and $conf['NO_https'] and strncasecmp($rssfeed, 'https://', 8) == 0 ) 
269                                                                $rssfeed = 'http://' . substr($rssfeed, 8);
270                               
271                                        }
272                                        $tpl_code = '<li><a href="javascript:PicLensLite.start('.(isset($rssfeed) ? ' {feedUrl:\''.$rssfeed.'\'}' : '').');" title="'.l10n('piclens_button').'" onmouseover="roll_over_piclens(\'but1\', \''.$this->root_site_piclens.PICLENS_IMG_PATH.'cooliris-icon-point.png\')" onmouseout="roll_over_piclens(\'but1\', \''.$this->root_site_piclens.PICLENS_IMG_PATH.'cooliris-icon.png\')">';
273                                        $tpl_code.='<img src="'.$this->root_site_piclens.PICLENS_IMG_PATH.'cooliris-icon.png" NAME="but1" class="button" alt="'.l10n('piclens_button').'" width="24" height="24"></a></li>';
274                                        if(($page['section'] == 'categories') && empty($page['category']) && !$this->my_config['piclens_gallerie_active'])      // Accueil et option piclens gallerie desactivee
275                                                $tpl_code='<img src="'.$this->root_site_piclens.PICLENS_IMG_PATH.'cooliris-icon-black.png" NAME="but1" class="button" alt="'.l10n('piclens_button').'" width="24" height="24"></a></li>';
276                                }
277                                if (isset($tpl_code))
278                                        $template->concat('PLUGIN_INDEX_ACTIONS', $tpl_code."\n");
279                        }
280                       
281                }
282        }
283
284
285        // Add piclens pics to start slideshow
286        // Another thanks to P@t
287        function set_make_full_url_piclens()
288        {
289                global $page;
290
291                set_make_full_url();
292                // HTTPS PATCH : If needed NO_https can easily be set in your config_local thru LocalFiles Editor
293                if (isset($conf['NO_https']) and $conf['NO_https'] and strncasecmp($page['root_path'], 'https://', 8) == 0 ) 
294                        $page['root_path'] = 'http://' . substr($page['root_path'], 8);
295               
296        }
297
298        /* Loading of the configuration on database */
299        function load_config()
300        {
301
302            $query = '
303              SELECT value
304              FROM '.CONFIG_TABLE.'
305              WHERE param = \''.PICLENS_CFG_DB.'\'
306            ;';
307
308            $result = pwg_query($query);
309
310            if($result) 
311                {
312                     $row = mysql_fetch_row($result);
313                     if(is_string($row[0])) 
314                         {
315                        $this->my_config = unserialize($row[0]);
316                     }
317            }
318                $this->load_default_config();
319                // Desactivation de piclenswall si PWG Stuff est installe
320                $this->my_config['piclens_wall'] = (get_db_plugins('active','PWG_Stuffs') ? false : $this->my_config['piclens_wall']);
321
322                // Si tri = defaut PIWIGO ==> l'ordre est egalement defaut PIWIGO
323                if ($this->my_config['piclens_order'] == 1)                     $this->my_config['piclens_sort'] = 1;
324                if ($this->my_config['piclens_order_cat'] == 1)         $this->my_config['piclens_sort_cat'] = 1;
325               
326        }
327
328        /* Loading of the configuration file - If not exist -> load default values */
329        function load_config_file()
330        {
331                // changement du nom du fichier de conf.
332                if (!file_exists(PICLENS_CFG_FILE))
333                {
334                        if (file_exists(PICLENS_CFG_FILE_OLD))
335                                @rename(PICLENS_CFG_FILE_OLD,PICLENS_CFG_FILE);
336                }
337               
338                $x = @file_get_contents( PICLENS_CFG_FILE );
339                if ($x!==false)
340                {
341                  $c = unserialize($x);
342                  $this->my_config = $c;
343                }
344                // Init default value for the config file
345                $this->load_default_config();
346               
347                // Desactivation de piclenswall si PWG Stuff est installe
348                $this->my_config['piclens_wall'] = (get_db_plugins('active','PWG_Stuffs') ? false : $this->my_config['piclens_wall']);
349
350                // Si tri = defaut PIWIGO ==> l'ordre est egalement defaut PIWIGO
351                if ($this->my_config['piclens_order'] == 1)                     $this->my_config['piclens_sort'] = 1;
352                if ($this->my_config['piclens_order_cat'] == 1)         $this->my_config['piclens_sort_cat'] = 1;
353        }
354
355        /* Saving of the configuration on DB*/
356        function save_config()
357        {
358            $query = '
359              REPLACE INTO '.CONFIG_TABLE.'
360              VALUES(
361                \''.PICLENS_CFG_DB.'\',
362                \''.serialize($this->my_config).'\',
363                \'Configuration de Piclens\')
364            ;';
365
366            $result = pwg_query($query);
367
368            if($result) 
369                        return true;
370            else 
371                        return false;
372
373        }
374
375        /* Saving of the configuration file with data */
376        function save_config_file()
377        {
378                $file = fopen( PICLENS_CFG_FILE, 'w' );
379                fwrite($file, serialize($this->my_config) );
380                fclose( $file );
381        }
382
383       
384        private function load_default_config()
385        {
386            include PICLENS_INC_PATH.'default_values.inc.php';
387            foreach ($piclens_default_values as $key => $value) 
388                {
389                    if (!isset($this->my_config[$key]))         $this->my_config[$key] = $value;
390                }
391        }
392       
393        function piclens_admin_menu($menu)
394        {
395            array_push($menu,
396               array(
397                    'NAME' => 'Cooliris-Piclens',
398                    'URL' => get_admin_plugin_menu_link(PICLENS_ADMIN_PATH.'piclens_admin.php')
399                ) 
400            );
401            return $menu;
402        }
403
404        function piclenswall()
405        {
406            global $page;
407                // piclens active+ activation du mur
408//              if ($this->my_config['piclens_active'] && $this->my_config['piclens_wall'])
409                if ($this->my_config['piclens_wall'])
410            if (isset($page['body_id']) and $page['section'] == 'categories')
411                        include_once(PICLENS_PATH.'piclenswall.php');   
412        }
413
414        function piclens_thumbnails()
415        {
416          global $template, $page;
417         
418                // piclens active
419                if (    isset($page['section'])
420                        and $this->my_config['piclens_active'])
421                {
422               
423                        // Pages speciales et configuration activee
424                        if ($this->my_config['piclens_wall_spec'])
425                        {
426                                // Page images recentes
427                                if (($page['section']) == 'recent_pics' && $this->my_config['piclens_wall_spec_recentpics'])
428                                        $rssfeed = $this->root_site_piclens.PICLENS_PATH.'piclens-rss.php?/recent_pics';
429
430                                // Page categories recentes
431                                elseif (($page['section']) == 'recent_cats' && $this->my_config['piclens_wall_spec_recentcats'])
432                                        $rssfeed = $this->root_site_piclens.PICLENS_PATH.'piclens-rss.php?/recent_cats';
433
434                                // Page plus vues
435                                elseif (($page['section']) == 'most_visited' && $this->my_config['piclens_wall_spec_mostvisited'])
436                                        $rssfeed = $this->root_site_piclens.PICLENS_PATH.'piclens-rss.php?/most_visited';
437
438                                        // mieux notees
439                                else if ($page['section'] == 'best_rated' && $this->my_config['piclens_wall_spec_bestrated'])
440                                        $rssfeed = $this->root_site_piclens.PICLENS_PATH.'piclens-rss.php?/best_rated';
441
442                                        // favories     
443                                else if ($page['section'] == 'favorites' && $this->my_config['piclens_wall_spec_favorites'])
444                                        $rssfeed = $this->root_site_piclens.PICLENS_PATH.'piclens-rss.php?/favorites';
445                        }
446                        // Remplacement de la navigation
447                        if ($this->my_config['piclens_wall_nav'])
448                        {
449                                // Page categories     
450                                if ($page['section'] == 'categories'
451                                        and !empty($page['category'])
452                                    and !empty($page['items']))
453                                {
454                                        // verification de presence de la categorie dans la liste parametree
455                                        if (in_array($page['category']['id'], $this->my_config['piclens_wall_cat_nav_replace']))
456                                        {
457                                                $rssfeed = $this->root_site_piclens.PICLENS_PATH.'piclens-rss.php?/category/';
458                                                $rssfeed .= empty($page['category']['permalink']) ? $page['category']['id'] : $page['category']['permalink'];
459                                        }
460                                }
461                        }                       
462                }
463
464                if (isset($rssfeed))
465                {
466                        if (isset($conf['NO_https']) and $conf['NO_https'] and strncasecmp($rssfeed, 'https://', 8) == 0 ) 
467                                        $rssfeed = 'http://' . substr($rssfeed, 8);
468               
469                        $color = $this->my_config['piclens_wall_color'];
470                        $height = $this->my_config['piclens_wall_height'];
471                        $showfullscreen =  ($this->my_config['piclens_wall_showfullscreen'] ? "true" : "false");
472                        $showembed = ($this->my_config['piclens_wall_showembed'] ? "true" : "false");
473                        $showsearch = ($this->my_config['piclens_wall_showsearch'] ? "true" : "false");
474                        $template->assign('THUMBNAILS', 
475                                '<object id="o" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
476                                        width="100%" height="'.$this->my_config['piclens_wall_height'].'" >
477                                                <param name="movie" value="'
478// Test si utilisation du fichier flash local.
479                                                .($this->my_config['piclens_wall_swflocal'] ? $this->root_site_piclens.PICLENS_PATH.'swf/cooliris.swf' : 'http://apps.cooliris.com/embed/cooliris.swf') 
480                                                .'?feed='.$rssfeed.'&amp;style='.$color.'&amp;showEmbed='.$showembed.'&amp;showFullScreen='.$showfullscreen.'&amp;showSearch='.$showsearch.'" />
481                                                <param name="allowFullScreen" value="'.$showfullscreen.'" />
482                                                <param name="showEmbed" value="'.$showembed.'" />
483                                                <param name="showSearch" value="'.$showsearch.'" />
484                                                <param name="allowScriptAccess" value="always" />'
485                                                .($this->my_config['piclens_wall_transparent'] 
486                                                        ?       '<param name="wmode" value="transparent" />
487                                                                <embed WMODE="transparent"' 
488                                                        :       '<embed ')
489                                                .'type="application/x-shockwave-flash" src="'
490// Test si utilisation du fichier flash local.
491                                                .($this->my_config['piclens_wall_swflocal'] ? $this->root_site_piclens.PICLENS_PATH.'swf/cooliris.swf' : 'http://apps.cooliris.com/embed/cooliris.swf') 
492                                                .'?feed='.$rssfeed.'&amp;style='.$color.'&amp;showEmbed='.$showembed.'&amp;showFullScreen='.$showfullscreen.'&amp;showSearch='.$showsearch.'" width="100%" height="'.$height.'" showEmbed="'.$showembed.'" showSearch="'.$showsearch.'" allowFullScreen="'.$showfullscreen.'" allowScriptAccess="always" />
493                                </object>'); 
494
495                // Suppression de la barre de navigation
496                        $template->clear_assign('NAV_BAR');
497                        // Suppression de la barre de navigation categories (cas de l'affichage des categories recentes)
498                        if (($page['section']) == 'recent_cats')
499                                $template->clear_assign('CATEGORIES');
500                }
501               
502        }
503       
504
505       
506}
507
508?>
Note: See TracBrowser for help on using the repository browser.