source: extensions/lmt/lmt_root.class.inc.php @ 6769

Last change on this file since 6769 was 5548, checked in by grum, 14 years ago

Update the plugin for compatibility with Piwigo 2.1

  • Property svn:executable set to *
File size: 9.6 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_root : common classe for admin and public classes
13
14  --------------------------------------------------------------------------- */
15  include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/CommonPlugin.class.inc.php');
16  include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCCss.class.inc.php');
17  include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCAjax.class.inc.php');
18
19  class LMT_root extends CommonPlugin
20  {
21    protected $css;   //the css object
22    protected $css_icn;   //the css object
23
24    protected $licences=array('BY', 'BY-ND', 'BY-NC', 'BY-NC-ND', 'BY-NC-SA', 'BY-SA', 'CRIGHT', 'CLEFT', 'DEFAULT');
25
26    public function __construct($prefixeTable, $filelocation)
27    {
28      $this->setPluginName('LMT');
29      $this->setPluginNameFiles("lmt");
30      parent::__construct($prefixeTable, $filelocation);
31      $this->section_name=$this->getPluginNameFiles();
32
33      $this->setTablesList(array('images', 'licence_author'));
34
35
36      $this->css = new GPCCss(dirname($this->getFileLocation()).'/'.$this->getPluginNameFiles().".css");
37      $this->css_icn = new GPCCss(dirname($this->getFileLocation()).'/'.$this->getPluginNameFiles()."_icn.css");
38    }
39
40    public function __destruct()
41    {
42      unset($this->css);
43      unset($this->css_icn);
44      unset($this->licences);
45      parent::__destruct();
46    }
47
48    public function initEvents()
49    {
50      add_event_handler('blockmanager_register_blocks', array(&$this, 'register_blocks') );
51    }
52
53    /*
54      menu block management
55    */
56    public function register_blocks()
57    {
58    }
59
60
61
62    /*
63      surchage of CommonPlugin->saveConfig function
64    */
65    public function saveConfig()
66    {
67      if(parent::saveConfig())
68      {
69        $this->css->makeCSS($this->generate_CSS());
70        $this->css_icn->makeCSS($this->generate_CSS2());
71        return(true);
72      }
73      return(false);
74    }
75
76    /*
77      surchage of CommonPlugin->saveConfig function
78    */
79    public function loadConfig()
80    {
81      parent::loadConfig();
82      if(!$this->css->fileExists())
83      {
84        $this->css->makeCSS($this->generate_CSS());
85      }
86      if(!$this->css_icn->fileExists())
87      {
88        $this->css_icn->makeCSS($this->generate_CSS2());
89      }
90    }
91
92    /*
93      intialize default values
94    */
95    public function initConfig()
96    {
97      //global $user;
98      $this->config=array(
99        'lmt_mouseovercolor' => '303030', /**/
100        'lmt_list_maxheight' => '650',
101        'lmt_list_maxitems' => '0',    /* limit number of item displayed ; 0 : no limit */
102        'lmt_licence_default' => 'BY',
103        'lmt_licence_default_author' => 0,
104        'lmt_licence_activated' => 'n',
105        'lmt_licence_visible' => 'n',  /* y:always visible, n:only if needed */
106        'lmt_licence_logo' => '80x15', /* 80x15, 88x31, text */
107        'lmt_warning_visible' => 'y',     /* y: display a text at the bottom of each page */
108        'lmt_warning_texts' => array(), /* text displayed - multi lang */
109        'lmt_redirect_activated' => 'y',     /* y: the text is an url to a warning page */
110        'lmt_redirect_open_target' => 'n',   /* y: url are openned in a new page/tab */
111        'lmt_redirect_url-by' => array(),
112        'lmt_redirect_url-by-nd' => array(),
113        'lmt_redirect_url-by-nc' => array(),
114        'lmt_redirect_url-by-nc-nd' => array(),
115        'lmt_redirect_url-by-nc-sa' => array(),
116        'lmt_redirect_url-by-sa' => array(),
117        'lmt_redirect_url-cright' => array(),
118        'lmt_redirect_url-cleft' => array(),
119      );
120
121      $languages=get_languages();
122      foreach($languages as $key => $val)
123      {
124        $lang=substr($key,0,2)."/";
125        if($lang=="en/") { $lang=""; }
126        $this->config['lmt_warning_texts'][$key]='';
127        $this->config['lmt_redirect_url-by'][$key]='http://creativecommons.org/licenses/by/2.0/'.$lang;
128        $this->config['lmt_redirect_url-by-nd'][$key]='http://creativecommons.org/licenses/by-nd/2.0/'.$lang;
129        $this->config['lmt_redirect_url-by-nc'][$key]='http://creativecommons.org/licenses/by-nc/2.0/'.$lang;
130        $this->config['lmt_redirect_url-by-nc-nd'][$key]='http://creativecommons.org/licenses/by-nc-nd/2.0/'.$lang;
131        $this->config['lmt_redirect_url-by-nc-sa'][$key]='http://creativecommons.org/licenses/by-nc-sa/2.0/'.$lang;
132        $this->config['lmt_redirect_url-by-sa'][$key]='http://creativecommons.org/licenses/by-sa/2.0/'.$lang;
133        $this->config['lmt_redirect_url-cright'][$key]='';
134        $this->config['lmt_redirect_url-cleft'][$key]='';
135      }
136
137    }
138
139    /*
140      generate the css code
141    */
142    protected function generate_CSS()
143    {
144      $text = "
145.TableRow:hover
146{
147  background-color:#".$this->config['lmt_mouseovercolor'].";
148}
149
150.formtable
151{
152  text-align:justify;
153  display:block;
154  margin-top:0px;
155  margin-bottom:0px;
156  width:100%;
157}
158
159.formtable tr {
160  vertical-align:top;
161}
162
163.littlefont { font-size:90%; }
164table.littlefont th { text-align:center; padding:3px;padding-left:9px;padding-right:9px; }
165table.littlefont td { text-align:left; padding:0px;padding-left:3px;padding-right:3px; }
166
167.lmt_page
168{
169  text-align:justify;
170  margin:8px;
171}
172
173.lmt  {
174  text-align:justify;
175}
176
177#list {
178  width:100%;
179  overflow-y:scroll;
180  min-height:250px;
181  max-height:650px;
182}
183
184#ullist li {
185  width:300px;
186  display:block;
187  float:left;
188  text-align:left;
189}
190
191#ullist label {
192  float:left;
193}
194
195#ullist li table {
196  margin:0px;
197  text-align:left;
198  width:300px;
199  font-size:80%;
200}
201
202#ullist li tr {
203  vertical-align:top;
204}
205
206.content ul.thumbnails span.extendwrap1 {
207  margin:0px;
208  cursor:pointer;
209}
210
211.is_on, .is_off {
212  z-index:20;
213  width:12px;
214  height:12px;
215  display:block;
216  cursor:pointer;
217}
218
219.is_on {
220  background:url(./img/cb_on.png);
221}
222.is_off {
223  background:url(./img/cb_off.png);
224}
225
226.icnhelp {
227  weight:bold;
228  text-decoration:none;
229  cursor:help;
230}
231
232.hinthlp {
233  position:absolute;
234  max-width:400px;
235  border:1px solid #000000;
236  background:#ffffa0;
237  color:#000000;
238  top:0px;
239  left:-450px;
240  padding:2px;
241  text-align:justify;
242}
243
244      ";
245      return($text);
246    }
247
248    /*
249      generate the css code
250    */
251    protected function generate_CSS2()
252    {
253      $text = "
254.logo80x15 {
255  position:relative;
256  top:4px;
257  margin-right:4px;
258  border:0px none;
259}
260
261.logo88x31 {
262  position:relative;
263  margin-right:4px;
264  border:0px none;
265}
266
267#theImage img.logo80x15, #theImage img.logo88x31 {
268  border:0px none;
269  padding:0px;
270}
271
272.licencetag {
273  display:block;
274  padding-top:10px;
275  font-size:80%;
276}
277      ";
278      return($text);
279    }
280
281
282
283
284    /* -------------------------------------------------------------------------
285     return the licence type for an image
286      $default = 'y' => if no licence for the picture, return de default licence
287                 'n' => if no licence for the picture, return empty values
288    ------------------------------------------------------------------------- */
289    public function get_image_licence($image_id)
290    {
291
292      $return=array(
293        "default" => "",
294        "licence" => "",
295        "aut_text1" => "",
296        "aut_text2" => ""
297      );
298      $sql="SELECT lmti.licence_type, lmta.text1, lmta.text2
299            FROM ".$this->tables['images']." lmti
300              LEFT OUTER JOIN ".$this->tables['licence_author']." lmta ON lmti.author_id = lmta.id
301            WHERE lmti.image_id = '".$image_id."'";
302      $result=pwg_query($sql);
303      if($result)
304      {
305        while($row=pwg_db_fetch_assoc($result))
306        {
307          $return=array(
308            "defaut" => "n",
309            "licence" => $row['licence_type'],
310            "aut_text1" => $row['text1'],
311            "aut_text2" => $row['text2']
312          );
313        }
314      }
315
316      if(($return["licence"]=="")&&($this->config["lmt_licence_visible"]=="y"))
317      {
318        $return=array(
319          "defaut" => "y",
320          "licence" => $this->config["lmt_licence_default"],
321          "aut_text1" => "",
322          "aut_text2" => ""
323        );
324
325        $sql="SELECT * FROM ".$this->tables['licence_author']."
326              WHERE id = '".$this->config["lmt_licence_default_author"]."'";
327        $result=pwg_query($sql);
328        if($result)
329        {
330          while($row=pwg_db_fetch_assoc($result))
331          {
332            $return["aut_text1"]=$row['text1'];
333            $return["aut_text2"]=$row['text2'];
334          }
335        }
336      }
337
338      return($return);
339    }
340
341
342    /* -------------------------------------------------------------------------
343     returns an array of image id with the licence type
344      if $licence = "" => return all picture with a specific licences
345    ------------------------------------------------------------------------- */
346    public function get_images_licences($licence)
347    {
348      $sql="".$this->tables['lmt'];
349
350      $result=pwg_query($sql.$sql_where.$sql_order);
351      if($result)
352      {
353        $returned=array();
354        while($row=pwg_db_fetch_assoc($result))
355        {
356          array_push($returned, $row);
357        }
358        return($returned);
359      }
360      return(false);
361    }
362
363  protected function displayResult($action_msg, $result)
364  {
365    global $page;
366
367    if($result)
368    {
369      array_push($page['infos'], $action_msg);
370    }
371    else
372    {
373      array_push($page['errors'], $action_msg);
374    }
375  }
376
377
378    /* ---------------------------------------------------------------------------
379      ajax functions
380    --------------------------------------------------------------------------- */
381
382
383  } //class
384
385?>
Note: See TracBrowser for help on using the repository browser.