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

Last change on this file since 15382 was 11342, checked in by grum, 13 years ago

fix feature:2333 - add CC0 and PD licenses

  • Property svn:executable set to *
File size: 9.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_root : common classe for admin and public classes
13
14  --------------------------------------------------------------------------- */
15include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/CommonPlugin.class.inc.php');
16include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCCss.class.inc.php');
17include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCAjax.class.inc.php');
18
19class LMT_root extends CommonPlugin
20{
21  protected $css;   //the css object
22  protected $css_icn;   //the css object
23
24  static public $licences=array('BY', 'BY-ND', 'BY-NC', 'BY-NC-ND', 'BY-NC-SA', 'BY-SA', 'CRIGHT', 'CLEFT', 'CC0', 'PD', 'DEFAULT');
25
26  /**
27   * constructor
28   */
29  public function __construct($prefixeTable, $filelocation)
30  {
31    $this->setPluginName('LMT');
32    $this->setPluginNameFiles("lmt");
33    parent::__construct($prefixeTable, $filelocation);
34    $this->section_name=$this->getPluginNameFiles();
35
36    $this->setTablesList(array('images', 'licence_author'));
37
38    $this->css = new GPCCss(dirname($this->getFileLocation()).'/'.$this->getPluginNameFiles().".css");
39    $this->css_icn = new GPCCss(dirname($this->getFileLocation()).'/'.$this->getPluginNameFiles()."_icn.css");
40  }
41
42  /**
43   * destructor
44   */
45  public function __destruct()
46  {
47    unset($this->css);
48    unset($this->css_icn);
49    parent::__destruct();
50  }
51
52  public function initEvents()
53  {
54    add_event_handler('blockmanager_register_blocks', array(&$this, 'register_blocks') );
55  }
56
57  /**
58   * menu block management
59   */
60  public function register_blocks()
61  {
62  }
63
64
65  /**
66   * initialize default values for config var
67   */
68  public function initConfig()
69  {
70    //global $user;
71    $this->config=array(
72      'lmt_list_maxheight' => '650',
73      'lmt_list_maxitems' => '0',    /* limit number of item displayed ; 0 : no limit */
74      'lmt_licence_default' => 'BY',
75      'lmt_licence_default_author' => 0,
76      'lmt_licence_activated' => 'n',
77      'lmt_licence_visible' => 'n',  /* y:always visible, n:only if needed */
78      'lmt_licence_logo' => '80x15', /* 80x15, 88x31, text */
79      'lmt_warning_visible' => 'y',     /* y: display a text at the bottom of each page */
80      'lmt_warning_texts' => array(), /* text displayed - multi lang */
81      'lmt_redirect_activated' => 'y',     /* y: the text is an url to a warning page */
82      'lmt_redirect_open_target' => 'n',   /* y: url are openned in a new page/tab */
83      'lmt_redirect_url-by' => array(),
84      'lmt_redirect_url-by-nd' => array(),
85      'lmt_redirect_url-by-nc' => array(),
86      'lmt_redirect_url-by-nc-nd' => array(),
87      'lmt_redirect_url-by-nc-sa' => array(),
88      'lmt_redirect_url-by-sa' => array(),
89      'lmt_redirect_url-cright' => array(),
90      'lmt_redirect_url-cleft' => array(),
91    );
92
93    $languages=get_languages();
94    foreach($languages as $key => $val)
95    {
96      $lang=substr($key,0,2)."/";
97      if($lang=="en/") { $lang=""; }
98      $this->config['lmt_warning_texts'][$key]='';
99      $this->config['lmt_redirect_url-by'][$key]='http://creativecommons.org/licenses/by/2.0/'.$lang;
100      $this->config['lmt_redirect_url-by-nd'][$key]='http://creativecommons.org/licenses/by-nd/2.0/'.$lang;
101      $this->config['lmt_redirect_url-by-nc'][$key]='http://creativecommons.org/licenses/by-nc/2.0/'.$lang;
102      $this->config['lmt_redirect_url-by-nc-nd'][$key]='http://creativecommons.org/licenses/by-nc-nd/2.0/'.$lang;
103      $this->config['lmt_redirect_url-by-nc-sa'][$key]='http://creativecommons.org/licenses/by-nc-sa/2.0/'.$lang;
104      $this->config['lmt_redirect_url-by-sa'][$key]='http://creativecommons.org/licenses/by-sa/2.0/'.$lang;
105      $this->config['lmt_redirect_url-cright'][$key]='';
106      $this->config['lmt_redirect_url-cleft'][$key]='';
107      $this->config['lmt_redirect_url-cc0'][$key]='http://creativecommons.org/about/cc0';
108      $this->config['lmt_redirect_url-pd'][$key]='http://en.wikipedia.org/wiki/Public_domain';
109    }
110  }
111
112  /**
113   * returns the admin page link
114   */
115  public function getAdminLink($mode='')
116  {
117    if($mode=='ajax')
118    {
119      return('plugins/'.basename(dirname($this->getFileLocation())).'/lmt_ajax.php');
120    }
121    else
122    {
123      return(parent::getAdminLink());
124    }
125  }
126
127
128  /**
129   * return the licence type for an image
130   *
131   * returned array
132   *  'default'   => 'y' => if no licence for the picture, return de default
133   *                        licence
134   *                 'n' => if no licence for the picture, return empty values
135   *  'licence'   => the licence type
136   *  'aut_text1' => author, text 1
137   *  'aut_text2' => author, text 2
138   *
139   * @param Integer $image_id : the image id
140   * @return Array
141   */
142  public function getImageLicence($image_id)
143  {
144
145    $return=array(
146      "default" => "",
147      "licence" => "",
148      "aut_text1" => "",
149      "aut_text2" => ""
150    );
151    $sql="SELECT lmti.licence_type, lmta.text1, lmta.text2
152          FROM ".$this->tables['images']." lmti
153            LEFT OUTER JOIN ".$this->tables['licence_author']." lmta ON lmti.author_id = lmta.id
154          WHERE lmti.image_id = '".$image_id."'";
155    $result=pwg_query($sql);
156    if($result)
157    {
158      while($row=pwg_db_fetch_assoc($result))
159      {
160        $return=array(
161          "defaut" => "n",
162          "licence" => $row['licence_type'],
163          "aut_text1" => $row['text1'],
164          "aut_text2" => $row['text2']
165        );
166      }
167    }
168
169    if(($return["licence"]=="")&&($this->config["lmt_licence_visible"]=="y"))
170    {
171      $return=array(
172        "defaut" => "y",
173        "licence" => $this->config["lmt_licence_default"],
174        "aut_text1" => "",
175        "aut_text2" => ""
176      );
177
178      $sql="SELECT * FROM ".$this->tables['licence_author']."
179            WHERE id = '".$this->config["lmt_licence_default_author"]."'";
180      $result=pwg_query($sql);
181      if($result)
182      {
183        while($row=pwg_db_fetch_assoc($result))
184        {
185          $return["aut_text1"]=$row['text1'];
186          $return["aut_text2"]=$row['text2'];
187        }
188      }
189    }
190
191    return($return);
192  }
193
194
195  /**
196   * returns an array of image id with the asked licence type
197   * if $licence = "" => return all picture with a specific licences
198   *
199   * @param String $licence : licence to be filtered
200   * @return Array
201   */
202  public function getImagesLicences($licence)
203  {
204    $sql="".$this->tables['lmt'];
205
206    $result=pwg_query($sql.$sql_where.$sql_order);
207    if($result)
208    {
209      $returned=array();
210      while($row=pwg_db_fetch_assoc($result))
211      {
212        array_push($returned, $row);
213      }
214      return($returned);
215    }
216    return(false);
217  }
218
219  protected function displayResult($action_msg, $result)
220  {
221    global $page;
222
223    if($result)
224    {
225      array_push($page['infos'], $action_msg);
226    }
227    else
228    {
229      array_push($page['errors'], $action_msg);
230    }
231  }
232
233
234  /**
235   * build image url (for a given category)
236   *
237   *
238   */
239  protected function makeImageDatas($tmp, $imageId)
240  {
241    $tmp2=array();
242    foreach($tmp['id'] as $key=>$val)
243    {
244      $tmp2[]=array(
245        'id' => $tmp['id'][$key],
246        'name' => $tmp['name'][$key],
247        'type' => $tmp['type'][$key],
248        'plinks' => $tmp['plinks'][$key],
249        'link'=> make_picture_url(
250                  array(
251                    'image_id' => $imageId,
252                    'category' => array
253                      (
254                        'id' => $tmp['id'][$key],
255                        'name' => $tmp['name'][$key],
256                        'permalink' => $tmp['plinks'][$key]
257                      )
258                  )
259                )
260      );
261    }
262    return($tmp2);
263  }
264
265} //class
266
267
268
269
270class LMT_functions
271{
272  static private $tables = Array();
273  static private $config = Array();
274
275  /**
276   * initialise the class
277   *
278   * @param String $prefixeTable : the piwigo prefixe used on tables name
279   * @param String $pluginNameFile : the plugin name used for tables name
280   */
281  static public function init($prefixeTable)
282  {
283    GPCCore::loadConfig(LMT_root::$pluginNameFile, self::$config);
284    $list=LMT_root::$pluginTables;
285
286    for($i=0;$i<count($list);$i++)
287    {
288      self::$tables[$list[$i]]=$prefixeTable.LMT_root::$pluginNameFile.'_'.$list[$i];
289    }
290  }
291
292
293  /**
294   *  return all HTML&JS code necessary to display a dialogbox to choose
295   *  geographic area
296   */
297  static public function dialogBoxLMT()
298  {
299    global $template;
300
301    $template->set_filename('lmt_choose',
302                  dirname(__FILE__).'/templates/lmt_dialog_licence_choose.tpl');
303
304    $datas=Array(
305      'licencesList' => array()
306    );
307
308    foreach(LMT_root::$licences as $licence)
309    {
310      if($licence!='DEFAULT')
311      {
312        $datas['licencesList'][]=array(
313          'value' => $licence,
314          'name' => l10n('lmt_lbl_cc_s-'.strtolower($licence))
315        );
316      }
317    }
318
319    $template->assign('datas', $datas);
320
321    return($template->parse('lmt_choose', true));
322  }
323} //GMaps_functions
324
325
326
327?>
Note: See TracBrowser for help on using the repository browser.