source: extensions/piwishack/include/class.inc.php @ 6771

Last change on this file since 6771 was 6771, checked in by Gotcha, 14 years ago

bug:1800
bug:1801
Typo & CSS

File size: 17.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PiwiShack - a Piwigo Plugin                                           |
4// | Copyright (C) 2009 MOREAU Julien - gotcha@piwigo.org                  |
5// +-----------------------------------------------------------------------+
6// | This program is free software; you can redistribute it and/or modify  |
7// | it under the terms of the GNU General Public License as published by  |
8// | the Free Software Foundation                                          |
9// |                                                                       |
10// | This program is distributed in the hope that it will be useful, but   |
11// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
12// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
13// | General Public License for more details.                              |
14// |                                                                       |
15// | You should have received a copy of the GNU General Public License     |
16// | along with this program; if not, write to the Free Software           |
17// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
18// | USA.                                                                  |
19// +-----------------------------------------------------------------------+
20
21class PiwiShack
22{
23  var $plugin_name, $plugin_path;
24  var $opened, $to_close;
25 
26  function PiwiShack($plugin_name, $plugin_path)
27  {
28    // Args
29    $this->plugin_name = $plugin_name;
30    $this->plugin_path = $plugin_path;
31    // handler
32    $this->initialize_event_handler();
33  }
34
35  function initialize_event_handler()
36  {
37    if (script_basename() != $this->plugin_name.'_controller')
38    {
39      add_event_handler('loc_end_page_header', array(&$this, 'loc_end_page_header'));
40      add_event_handler('loc_end_index', array(&$this, 'loc_end_index'));
41      add_event_handler('picture_pictures_data', array(&$this, 'picture_pictures_data'));
42    }
43
44    if (isset($_GET[$this->plugin_name]))
45    {
46      add_event_handler('loc_begin_page_header', array(&$this, 'loc_begin_page_header'));
47      pwg_set_session_var($this->plugin_name, ($_GET[$this->plugin_name] === 'open'));
48    }
49    $this->opened = pwg_get_session_var($this->plugin_name, false);
50    $this->to_close = (isset($_GET[$this->plugin_name]) and ($_GET[$this->plugin_name] === 'close'));
51  }
52 
53  function get_thumb_post_on_a_website()
54  {
55    global $page, $lang_info;
56
57    $list = array();
58 
59    $S = '';
60
61    switch (script_basename())
62    {
63      case 'index':
64      {
65        global $pictures;
66
67        if (isset($pictures))
68        {
69          $list = $pictures;
70        }
71        break;
72      }
73      case 'picture':
74      {
75        global $picture;
76
77        if (isset($picture['current']))
78        {
79          $list[] = $picture['current'];
80        }
81        break;
82      }
83    }
84
85    if (empty($list) and !empty($page['items']))
86    {
87      $query = '
88          SELECT *
89      FROM '.IMAGES_TABLE.'
90      WHERE id IN ('.implode(',', $page['items']).')
91          ;';
92
93      $result = pwg_query($query);
94
95      while ($row = mysql_fetch_assoc($result))
96      {
97        $row['rank'] = $page['rank_of'][ $row['id'] ];
98        array_push($list, $row);
99      }
100
101      usort($list, 'rank_compare');
102  }
103    if (!empty($list))
104    {
105
106      set_make_full_url();
107
108      foreach ($list as $row)
109      {
110           /*
111           Affichage de la miniature sur des sites. Cliquable.
112           EXEMPLE
113           <a href="{$ROOT_WAY}{$current.U_IMG}" target=_blank><img src="{$ROOT_WAY}{$current.THUMB_SRC|@replace:'./':''}" /></a>
114           */
115            $S .= '<a href=\"'.
116          duplicate_picture_url(
117            array(
118              'image_id' => $row['id'],
119              'image_file' => $row['file'],
120              )).'\" target=_blank><img src=\"'.
121                  str_replace('/./', '/', get_thumbnail_url($row)).'\" /></a>';
122            $S .= '\n\n';
123      }
124
125      unset_make_full_url();
126    }
127
128    return $S;
129  }
130 
131  function get_thumb_post_on_a_forum()
132  {
133    global $page, $lang_info;
134
135    $list = array();
136 
137    $S = '';
138
139    switch (script_basename())
140    {
141      case 'index':
142      {
143        global $pictures;
144
145        if (isset($pictures))
146        {
147          $list = $pictures;
148        }
149        break;
150      }
151      case 'picture':
152      {
153        global $picture;
154
155        if (isset($picture['current']))
156        {
157          $list[] = $picture['current'];
158        }
159        break;
160      }
161    }
162
163    if (empty($list) and !empty($page['items']))
164    {
165      $query = '
166          SELECT *
167      FROM '.IMAGES_TABLE.'
168      WHERE id IN ('.implode(',', $page['items']).')
169          ;';
170
171      $result = pwg_query($query);
172
173      while ($row = mysql_fetch_assoc($result))
174      {
175        $row['rank'] = $page['rank_of'][ $row['id'] ];
176        array_push($list, $row);
177      }
178
179      usort($list, 'rank_compare');
180  }
181    if (!empty($list))
182    {
183
184      set_make_full_url();
185
186      foreach ($list as $row)
187      {
188           /*
189           Affichage de la miniature sur des forums. Cliquable.
190           EXEMPLE
191           [url={$ROOT_WAY}{$current.U_IMG}][img]{$ROOT_WAY}{$current.THUMB_SRC|@replace:'./':''}[/img][/url]
192           */
193            $S .= '[url='.
194          duplicate_picture_url(
195            array(
196              'image_id' => $row['id'],
197              'image_file' => $row['file'],
198              )).'][img]'.
199                  str_replace('/./', '/', get_thumbnail_url($row)).'[/img][/url]';
200            $S .= '\n\n';
201      }
202
203      unset_make_full_url();
204    }
205
206    return $S;
207  }
208 
209  function get_view_post_on_a_website()
210  {
211    global $page, $lang_info;
212
213    $list = array();
214 
215    $S = '';
216
217    switch (script_basename())
218    {
219      case 'index':
220      {
221        global $pictures;
222
223        if (isset($pictures))
224        {
225          $list = $pictures;
226        }
227        break;
228      }
229      case 'picture':
230      {
231        global $picture;
232
233        if (isset($picture['current']))
234        {
235          $list[] = $picture['current'];
236        }
237        break;
238      }
239    }
240
241    if (empty($list) and !empty($page['items']))
242    {
243      $query = '
244          SELECT *
245      FROM '.IMAGES_TABLE.'
246      WHERE id IN ('.implode(',', $page['items']).')
247          ;';
248
249      $result = pwg_query($query);
250
251      while ($row = mysql_fetch_assoc($result))
252      {
253        $row['rank'] = $page['rank_of'][ $row['id'] ];
254        array_push($list, $row);
255      }
256
257      usort($list, 'rank_compare');
258  }
259    if (!empty($list))
260    {
261          include_once(PHPWG_ROOT_PATH.'/include/functions_picture.inc.php');
262      set_make_full_url();
263
264      foreach ($list as $row)
265      {
266           /*
267           Affichage de la vue normale sur des sites. Non cliquable.
268           EXEMPLE
269           <a href="{$ROOT_WAY}{$current.U_IMG}" target=_blank><img src="{$ROOT_WAY}{$SRC_IMG|@replace:'./':''}" /></a>
270           */
271            $S .= '<a href=\"'.
272          duplicate_picture_url(
273            array(
274              'image_id' => $row['id'],
275              'image_file' => $row['file'],
276              )).'\" target=_blank><img src=\"'.get_absolute_root_url().
277                  str_replace('./', '', get_image_url($row)).'\" /></a>';
278                $S .= '\n\n';
279      }
280
281      unset_make_full_url();
282    }
283
284    return $S;
285  }
286 
287  function get_view_post_on_a_forum()
288  {
289    global $page, $lang_info;
290
291    $list = array();
292 
293    $S = '';
294
295    switch (script_basename())
296    {
297      case 'index':
298      {
299        global $pictures;
300
301        if (isset($pictures))
302        {
303          $list = $pictures;
304        }
305        break;
306      }
307      case 'picture':
308      {
309        global $picture;
310
311        if (isset($picture['current']))
312        {
313          $list[] = $picture['current'];
314        }
315        break;
316      }
317    }
318
319    if (empty($list) and !empty($page['items']))
320    {
321      $query = '
322          SELECT *
323      FROM '.IMAGES_TABLE.'
324      WHERE id IN ('.implode(',', $page['items']).')
325          ;';
326
327      $result = pwg_query($query);
328
329      while ($row = mysql_fetch_assoc($result))
330      {
331        $row['rank'] = $page['rank_of'][ $row['id'] ];
332        array_push($list, $row);
333      }
334
335      usort($list, 'rank_compare');
336  }
337      if (!empty($list))
338    {
339          include_once(PHPWG_ROOT_PATH.'/include/functions_picture.inc.php');
340      set_make_full_url();
341
342      foreach ($list as $row)
343      {
344           /*
345           Affichage de la vue normale sur des forums.
346           EXEMPLE
347           [url={$ROOT_WAY}{$current.U_IMG}][img]{$ROOT_WAY}{$SRC_IMG|@replace:'./':''}[/img][/url]
348           */
349            $S .= '[url='.
350          duplicate_picture_url(
351            array(
352              'image_id' => $row['id'],
353              'image_file' => $row['file'],
354              )).'][img]'.
355                  str_replace('/./', '/', get_image_url($row)).'[/img][/url]';
356            $S .= '\n\n';
357      }
358
359      unset_make_full_url();
360    }
361
362    return $S;
363  }
364 
365  function get_view_direct_link()
366  {
367    global $page, $lang_info;
368
369    $list = array();
370 
371    $S = '';
372
373    switch (script_basename())
374    {
375      case 'index':
376      {
377        global $pictures;
378
379        if (isset($pictures))
380        {
381          $list = $pictures;
382        }
383        break;
384      }
385      case 'picture':
386      {
387        global $picture;
388
389        if (isset($picture['current']))
390        {
391          $list[] = $picture['current'];
392        }
393        break;
394      }
395    }
396
397    if (empty($list) and !empty($page['items']))
398    {
399      $query = '
400          SELECT *
401      FROM '.IMAGES_TABLE.'
402      WHERE id IN ('.implode(',', $page['items']).')
403          ;';
404
405      $result = pwg_query($query);
406
407      while ($row = mysql_fetch_assoc($result))
408      {
409        $row['rank'] = $page['rank_of'][ $row['id'] ];
410        array_push($list, $row);
411      }
412
413      usort($list, 'rank_compare');
414  }
415    if (!empty($list))
416    {
417          include_once(PHPWG_ROOT_PATH.'/include/functions_picture.inc.php');
418      set_make_full_url();
419         
420          $page_name = script_basename();
421          if ( $page_name == 'picture') 
422          {
423        foreach ($list as $row)
424        {
425             /*
426             Affichage du chemin en clair du lien vers la vue normale.
427             EXEMPLE
428             {$ROOT_WAY}{$SRC_IMG|@replace:'./':''}
429             */
430              $S .= get_absolute_root_url().
431                    str_replace('./', '', get_image_url($row));
432                  $S .= '\n\n';
433        }
434
435      unset_make_full_url();
436      }
437        else
438          {
439        foreach ($list as $row)
440        {
441             /*
442             Affichage du chemin en clair du lien vers la vue normale.
443             EXEMPLE
444             {$ROOT_WAY}{$SRC_IMG|@replace:'./':''}
445             */
446              $S .= get_image_url($row);
447                  $S .= '\n\n';
448        }
449          }
450
451      unset_make_full_url();
452        }
453
454
455    return $S;
456  }
457 
458  function get_p_perso_writer_01()
459  {
460    global $page, $lang_info;
461
462    $list = array();
463 
464    $S = '';
465
466    switch (script_basename())
467    {
468      case 'index':
469      {
470        global $pictures;
471
472        if (isset($pictures))
473        {
474          $list = $pictures;
475        }
476        break;
477      }
478      case 'picture':
479      {
480        global $picture;
481
482        if (isset($picture['current']))
483        {
484          $list[] = $picture['current'];
485        }
486        break;
487      }
488    }
489
490    if (empty($list) and !empty($page['items']))
491    {
492      $query = '
493          SELECT *
494      FROM '.IMAGES_TABLE.'
495      WHERE id IN ('.implode(',', $page['items']).')
496          ;';
497
498      $result = pwg_query($query);
499
500      while ($row = mysql_fetch_assoc($result))
501      {
502        $row['rank'] = $page['rank_of'][ $row['id'] ];
503        array_push($list, $row);
504      }
505
506      usort($list, 'rank_compare');
507  }
508    if (!empty($list))
509    {
510          include_once(PHPWG_ROOT_PATH.'/include/functions_picture.inc.php');
511      set_make_full_url();
512
513      foreach ($list as $row)
514      {
515           /*
516           Affichage Personnalisé, 01.
517           EXEMPLE
518           <h6 style="text-align: center;"><a href="{$ROOT_WAY}{$current.U_IMG}" target="_blank"><img class="aligncenter" style="width: 100%; height: 100%;" src="{$ROOT_WAY}{$SRC_IMG|@replace:'./':''}" alt="{$ALT_IMG}" /></a><em><a href="{$ROOT_WAY}{$U_UP}"; target="_blank">Galerie complète à visiter</a></em></h6>
519           */
520           
521                $S .= '<h6 style=\"text-align: center;\"><a href=\"'. // Arguments à transmettre
522          duplicate_picture_url( // Lien Piwigo vers la page de la vue normale
523            array(
524              'image_id' => $row['id'],
525              'image_file' => $row['file'],
526              )).
527                  '\" target=\"_blank\"><img class=\"aligncenter\" style=\"width: 100%; height: 100%;\" src=\"'. // Arguments à transmettre
528                  get_absolute_root_url().str_replace('./', '', get_image_url($row)). // Liens direct vers la vue normale
529                  '\" alt=\"'. // Arguments à transmettre
530                  $row['file']. // Noms du fichier
531                  '\" /></a><em><a href=\"'. // Arguments à transmettre
532                  duplicate_index_url(). // Catégorie parente
533                  '\"; target=\"_blank\"><br />Galerie complète à visiter</a></em></h6>'; // Arguments à transmettre
534            $S .= '\n\n';
535      }
536
537      unset_make_full_url();
538    }
539
540    return $S;
541  }
542 
543  function get_p_perso_writer_02()
544  {
545    global $page, $lang_info;
546
547    $list = array();
548 
549    $S = '';
550
551    switch (script_basename())
552    {
553      case 'index':
554      {
555        global $pictures;
556
557        if (isset($pictures))
558        {
559          $list = $pictures;
560        }
561        break;
562      }
563      case 'picture':
564      {
565        global $picture;
566
567        if (isset($picture['current']))
568        {
569          $list[] = $picture['current'];
570        }
571        break;
572      }
573    }
574
575    if (empty($list) and !empty($page['items']))
576    {
577      $query = '
578          SELECT *
579      FROM '.IMAGES_TABLE.'
580      WHERE id IN ('.implode(',', $page['items']).')
581          ;';
582
583      $result = pwg_query($query);
584
585      while ($row = mysql_fetch_assoc($result))
586      {
587        $row['rank'] = $page['rank_of'][ $row['id'] ];
588        array_push($list, $row);
589      }
590
591      usort($list, 'rank_compare');
592  }
593
594    if (!empty($list))
595    {
596          include_once(PHPWG_ROOT_PATH.'/include/functions_url.inc.php');
597      set_make_full_url();
598
599      foreach ($list as $row)
600      {
601       //'[(('.$picture['current']['thumbnail'].'))|'.$picture['current']['url'].'|'.$lang_info['code'].']';
602        $S  .= '*** '.(!empty($row['name']) ? $row['name'] : $row['file']).' ***\n';
603        $S  .= '[(('.
604          str_replace('/./', '/', get_thumbnail_url($row)).'))|'.
605          duplicate_picture_url(
606            array(
607              'image_id' => $row['id'],
608              'image_file' => $row['file'],
609              )).'|'.
610          $lang_info['code'].']';
611            $S .= '\n\n';
612      }
613
614      unset_make_full_url();
615
616    }
617
618    return $S;
619  }
620 
621  // Fin de la définition des champs
622
623  function loc_begin_page_header()
624  {
625    global $template;
626
627    $redirect_url = ( script_basename()=='picture'
628        ? duplicate_picture_url(array(), array($this->plugin_name))
629          : duplicate_index_url(array(), array($this->plugin_name))
630      );
631
632     $template->assign(
633        array(
634          'page_refresh' => array(
635                'TIME' => 1,
636                'U_REFRESH' => $redirect_url
637              )
638          ));
639  }
640
641  function loc_end_page_header()
642  {
643    global $template;
644
645    if ($this->opened or $this->to_close)
646    {
647      $plugin_root_url = get_root_url().'plugins/'.$this->plugin_name.'/';
648
649      $js = '
650  <script type="text/javascript">
651    var theController = window.open("", "'.$this->plugin_name.'_controller", "alwaysRaised=yes,dependent=yes,toolbar=no,height=807,width=1220,menubar=no,resizable=yes,scrollbars=yes,status=no");';
652
653    if ($this->to_close)
654    {
655      $js .= '
656    theController.close();';
657    }
658    else
659    {
660      $js .= '
661    if (theController.location.toString()=="about:blank" || !theController.location.toString().match(/^(https?.*\/)'.$this->plugin_name.'_controller\.php(\?.+)?$/))
662    {
663      theController.location = "'.$plugin_root_url.$this->plugin_name.'_controller.php";
664    }
665    else
666    {
667      theController.focus();
668    }
669    theController.document.getElementsByName("thumb_Post_on_a_website")[0].value = "'.$this->get_thumb_post_on_a_website().'";
670    theController.document.getElementsByName("thumb_Post_on_a_forum")[0].value = "'.$this->get_thumb_post_on_a_forum().'";
671        theController.document.getElementsByName("view_Post_on_a_website")[0].value = "'.$this->get_view_post_on_a_website().'";
672        theController.document.getElementsByName("view_Post_on_a_forum")[0].value = "'.$this->get_view_post_on_a_forum().'";
673        theController.document.getElementsByName("view_Direct_link")[0].value = "'.$this->get_view_direct_link().'";
674    theController.document.getElementsByName("p_Perso_writer_01")[0].value = "'.$this->get_p_perso_writer_01().'";
675    theController.document.getElementsByName("p_Perso_writer_02")[0].value = "'.$this->get_p_perso_writer_02().'";';
676    }
677      $js .= '
678  </script>';
679
680      $template->append('head_elements', $js);
681    }
682  }
683
684  function get_link_icon($main_link)
685  {
686    global $page;
687
688    if (empty($page['items']))
689    {
690        return;
691    }
692
693    $this->loading_lang();
694
695    if ($this->opened)
696    {
697      $suffix_url = 'close';
698      $link_title = l10n('close_window_piwishack');
699    }
700    else
701    {
702      $suffix_url = 'open';
703      $link_title = l10n('open_window_piwishack');
704    }
705
706    $link_url = add_url_params($main_link, array($this->plugin_name => $suffix_url));
707    if (!empty($link_url))
708    {
709      $link_url = 
710        '<a href="'.$link_url.'" title="'.$link_title.'" rel="nofollow"><img src="'.get_root_url().'plugins/'.$this->plugin_name.'/icon/controller_'.$suffix_url.'.png" class="button" alt="PiwiShack controller"></a>';
711    }
712
713    return $link_url;
714  }
715
716  function loc_end_index()
717  {
718    global $template;
719
720    $link_url = $this->get_link_icon(duplicate_index_url());
721    if (!empty($link_url))
722    {
723      $template->concat(
724        'PLUGIN_INDEX_ACTIONS',
725        '<li>'.$link_url.'</li>');
726    }
727  }
728
729  function picture_pictures_data($pictures)
730  {
731    global $template;
732
733    $link_url = $this->get_link_icon(duplicate_picture_url());
734    if (!empty($link_url))
735    {
736      $template->concat(
737        'PLUGIN_PICTURE_ACTIONS',
738        $link_url);
739    }
740
741    return $pictures;
742  }
743
744  function loading_lang()
745  {
746    load_language('plugin.lang', $this->plugin_path);
747  }
748}
749
750?>
Note: See TracBrowser for help on using the repository browser.