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

Last change on this file since 3666 was 3396, checked in by grum, 15 years ago

Add plugin LMT

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