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

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

Pb with last commit (3636)
Convert all file into UTF8 and Unix format
Add TODO in chinese language file

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