source: extensions/lmt/lmt_pip.class.inc.php @ 30537

Last change on this file since 30537 was 17604, checked in by grum, 12 years ago

bug:2726

  • Property svn:executable set to *
File size: 7.1 KB
Line 
1<?php
2/* -----------------------------------------------------------------------------
3  Plugin     : LMT
4  Author     : Grum
5    email    : grum@piwigo.org
6    website  : http://photos.grum.fr
7
8    << May the Little SpaceFrog be with you ! >>
9  ------------------------------------------------------------------------------
10  See main.inc.php for release information
11
12  LMT_PIP : classe to manage plugin public pages
13
14  --------------------------------------------------------------------------- */
15
16include_once('lmt_root.class.inc.php');
17//include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCPublicIntegration.class.inc.php');
18
19global $user;
20
21
22class LMT_PIP extends LMT_root
23{
24  protected $section_page;
25
26  public function __construct($prefixeTable, $filelocation)
27  {
28    parent::__construct($prefixeTable, $filelocation);
29    $this->loadConfig();
30
31    $this->initEvents();
32  }
33
34  public function __destruct()
35  {
36    unset($section_page);
37    parent::__destruct();
38  }
39
40  /**
41   * initialize events call for the plugin
42   */
43  public function initEvents()
44  {
45    parent::initEvents();
46
47    if($this->config['lmt_licence_activated']=='y')
48    {
49      add_event_handler('user_init', array(&$this, 'loadLang'));
50      add_event_handler('loc_end_picture', array(&$this, 'manageLicenceElement'));
51
52      if($this->config['lmt_warning_visible']=='y')
53      {
54        add_event_handler('loc_end_page_tail', array(&$this, 'manageWarningText'));
55      }
56    }
57  }
58
59  public function loadCSS()
60  {
61    //parent::loadCSS();  -- don't call the ancestor!
62    GPCCore::addHeaderCSS('lmt_icn.css', 'plugins/'.$this->getDirectory().'/'.$this->getPluginNameFiles()."_icn.css");
63  }
64
65  public function loadLang()
66  {
67    load_language('plugin.lang', LMT_PATH);
68  }
69
70  /* -------------------------------------------------------------------------
71    FUNCTIONS TO MANAGE LMT DISPLAY
72  ------------------------------------------------------------------------- */
73  public function manageLicenceElement()
74  {
75    global $template, $page, $user, $lang;
76
77    $licence=$this->getImageLicence($page['image_id']);
78    if($licence['licence']=="")
79    {
80      return("");
81    }
82
83    if($this->config['lmt_redirect_activated']=='y')
84    {
85      $url=$this->config['lmt_redirect_url-'.strToLower($licence['licence'])][$user['language']];
86      if($url=='')
87      {
88        $url=$this->config['lmt_redirect_url-'.strToLower($licence['licence'])]['en_UK'];
89      }
90    }
91    else
92    {
93      $url="";
94    }
95
96    $alternateText=" alt='".htmlspecialchars($this->translateCopyright('lmt_lbl_cc_s-'.strToLower($licence['licence'])), ENT_QUOTES)."'
97      title='".htmlspecialchars(
98        $this->translateCopyright('lmt_lbl_under-'.strtolower($licence['licence'])).' '.
99        $this->translateCopyright('lmt_lbl_cc_s-'.strtolower($licence['licence'])).' : '.
100        $this->translateCopyright('lmt_lbl_cc-'.strtolower($licence['licence'])),ENT_QUOTES
101    )."' ";
102
103    $style="";
104    $text="";
105    $target=($this->config['lmt_redirect_open_target']=="y")?" onclick='window.open(this.href); return false;'":"";
106    switch($this->config['lmt_licence_logo'])
107    {
108      case '80x15':
109        if($url!="")
110        {
111          $text = "<br/><a href='".$url."'".$target."><img $alternateText class='logo80x15' src='". LMT_PATH."img/".strToLower($licence['licence'])."_80x15.png'></a>".$licence['aut_text1']." ".$licence['aut_text2'];
112        }
113        else
114        {
115          $text = "<br/><img $alternateText class='logo80x15' src='". LMT_PATH."img/".strToLower($licence['licence'])."_80x15.png'>".$licence['aut_text1']." ".$licence['aut_text2'];
116        }
117      break;
118      case '88x31';
119        $style=" style='text-align:left;'";
120        if($url!="")
121        {
122          $text = "<table style='margin:auto;'><tr><td><a href='".$url."'".$target."><img $alternateText class='logo88x31' src='". LMT_PATH."img/".strToLower($licence['licence'])."_88x31.png'></a></td><td>".$licence['aut_text1']."<br/>".$licence['aut_text2']."</td></tr></table>";
123        }
124        else
125        {
126          $text = "<table style='margin:auto;'><tr><td><img $alternateText class='logo88x31' src='". LMT_PATH."img/".strToLower($licence['licence'])."_88x31.png'></td><td>".$licence['aut_text1']."<br/>".$licence['aut_text2']."</td></tr></table>";
127        }
128        break;
129      case 'text';
130        if($url!="")
131        {
132          $text ="<br/>".$this->translateCopyright("lmt_lbl_under-".strToLower($licence['licence']))." <a href='".$url."'".$target.">".$this->translateCopyright("lmt_lbl_cc_s-".strToLower($licence['licence']))."</a> ".$licence['aut_text1']." ".$licence['aut_text2'];
133        }
134        else
135        {
136          $text ="<br/>".$this->translateCopyright("lmt_lbl_under-".strToLower($licence['licence']))." ".$this->translateCopyright("lmt_lbl_cc_s-".strToLower($licence['licence']))." ".$licence['aut_text1']." ".$licence['aut_text2'];
137        }
138        break;
139    }
140
141    $template->concat('COMMENT_IMG', '<span class="licencetag" '.$style.'>'.$text.'</span>');
142  }
143
144  public function manageWarningText()
145  {
146    global $template, $user, $lang;
147
148
149    if(isset($this->config['lmt_warning_texts'][$user['language']]))
150    {
151      $text=$this->config['lmt_warning_texts'][$user['language']];
152    }
153    else
154    {
155      $text=$this->config['lmt_warning_texts']['en_UK'];
156    }
157
158    $alternateText=" alt='".htmlspecialchars($this->translateCopyright('lmt_lbl_cc_s-'.strtolower($this->config['lmt_licence_default'])), ENT_QUOTES)."'
159      title='".htmlspecialchars(
160        $this->translateCopyright('lmt_lbl_under-'.strtolower($this->config['lmt_licence_default'])).' '.
161        $this->translateCopyright('lmt_lbl_cc_s-'.strtolower($this->config['lmt_licence_default'])).' : '.
162        $this->translateCopyright('lmt_lbl_cc-'.strtolower($this->config['lmt_licence_default'])),ENT_QUOTES
163    )."' ";
164
165    $patterns = array('/\[logo=80x15\]/i', '/\[logo=88x31\]/i', '/\[logo=text\]/i');
166    $replacements = array(
167      "<img $alternateText class='logo80x15' src='". LMT_PATH."img/".strtolower($this->config['lmt_licence_default'])."_80x15.png'>",
168      "<img $alternateText class='logo88x31' src='". LMT_PATH."img/".strtolower($this->config['lmt_licence_default'])."_88x31.png'>",
169      $this->translateCopyright("lmt_lbl_cc_s-".strtolower($this->config['lmt_licence_default']))
170    );
171
172    if($this->config['lmt_redirect_activated']=='y')
173    {
174      $url=$this->config['lmt_redirect_url-'.strToLower($this->config['lmt_licence_default'])][$user['language']];
175      if($url=='')
176      {
177        $url=$this->config['lmt_redirect_url-'.strToLower($this->config['lmt_licence_default'])]['en_UK'];
178      }
179      if($url!="")
180      {
181        $target=($this->config['lmt_redirect_open_target']=="y")?" onclick='window.open(this.href); return false;'":"";
182        $replacements[0]="<a href='".$url."'".$target.">".$replacements[0]."</a>";
183        $replacements[1]="<a href='".$url."'".$target.">".$replacements[1]."</a>";
184        $replacements[2]="<a href='".$url."'".$target.">".$replacements[2]."</a>";
185      }
186    }
187
188    $text = preg_replace($patterns, $replacements, $text);
189
190    $template->append("footer_elements", "<span>".htmlspecialchars_decode($text)."</span>");
191  }
192
193
194} //class
195
196?>
Note: See TracBrowser for help on using the repository browser.