source: extensions/GMaps/gmaps_root.class.inc.php @ 7479

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

implement feature:1950

  • Property svn:executable set to *
File size: 10.0 KB
Line 
1<?php
2/* -----------------------------------------------------------------------------
3  Plugin     : GMaps
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  GMaps_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
18  class GMaps_root extends CommonPlugin
19  {
20    const KML_DIRECTORY='/local/plugins/GMaps/kml/';
21    protected $css;
22    protected $maps=array();
23    protected $forceDisplay=0;
24
25    /**
26     * check the available AMD release
27     */
28    static public function checkAMDRelease()
29    {
30      if(!defined('AMD_VERSION')) return(false);
31
32      $currentAMDRelease = explode(".", GPC_VERSION);
33
34      $neededAMDRelease=explode('.', GMAPS_AMD_NEEDED);
35      $major=$neededAMDRelease[0];
36      $minor=$neededAMDRelease[1];
37      $minor2=$neededAMDRelease[2];
38
39      if(($currentAMDRelease[0]>$major) ||
40         ($currentAMDRelease[0]==$major)&&($currentAMDRelease[1]>$minor) ||
41         ($currentAMDRelease[0]==$major)&&($currentAMDRelease[1]==$minor)&&($currentAMDRelease[2]>=$minor2))
42      {
43        return(true);
44      }
45      return(false);
46    }
47
48    /**
49     * check if AMD plugin is activated and mode
50     *
51     * @return String : 'none' if plugin is not installed
52     *                  'inactive' if plugin is not active
53     *                  'basic' if plugin active in basic mode
54     *                  'advanced' if plugin active in advanced mode
55     */
56    static public function checkAMDActivated()
57    {
58      if(!self::checkAMDRelease()) return('none');
59
60      $sql="SELECT state FROM ".PLUGINS_TABLE." WHERE id='AMetaData';";
61      $result=pwg_query($sql);
62      if($result)
63      {
64        $row=pwg_db_fetch_assoc($result);
65        if(!(isset($row['state']) and $row['state']='active')) return('inactive');
66
67        $amdConfig=array();
68        GPCCore::loadConfig('amd', $amdConfig);
69
70        if($amdConfig['newInstall']=='n') return($amdConfig['amd_InterfaceMode']);
71      }
72
73      return('none');
74    }
75
76
77    public function __construct($prefixeTable, $filelocation)
78    {
79      $this->setPluginName('GMaps');
80      $this->setPluginNameFiles("gmaps");
81      parent::__construct($prefixeTable, $filelocation);
82      $this->section_name=$this->getPluginNameFiles();
83
84      $this->setTablesList(array('maps', 'category_maps', 'cache', 'kmlfiles'));
85      $this->css = new GPCCss(dirname($this->getFileLocation()).'/'.$this->getPluginNameFiles().".css");
86    }
87
88    public function __destruct()
89    {
90      parent::__destruct();
91    }
92
93    public function initEvents()
94    {
95    }
96
97
98    /*
99      surchage of CommonPlugin->saveConfig function
100    */
101    public function saveConfig()
102    {
103      if(parent::saveConfig())
104      {
105        return(true);
106      }
107      return(false);
108    }
109
110    /*
111      surchage of CommonPlugin->saveConfig function
112    */
113    public function loadConfig()
114    {
115      parent::loadConfig();
116    }
117
118    /*
119      intialize default values
120    */
121    public function initConfig()
122    {
123      //global $user;
124      $this->config=array(
125        'popupAutomaticSize' => 0.8
126      );
127    }
128
129
130    /**
131     *
132     */
133    protected function configForTemplate()
134    {
135      global $template;
136
137      $template->assign('gmapsConfig', $this->config);
138    }
139
140
141    public function getAdminLink($mode='')
142    {
143      if($mode=='ajax')
144      {
145        return('plugins/'.basename(dirname($this->getFileLocation())).'/gmaps_ajax.php');
146      }
147      else
148      {
149        return(parent::getAdminLink());
150      }
151    }
152
153    protected function displayResult($action_msg, $result)
154    {
155      global $page;
156
157      if($result)
158      {
159        array_push($page['infos'], $action_msg);
160      }
161      else
162      {
163        array_push($page['errors'], $action_msg);
164      }
165    }
166
167
168    /* ---------------------------------------------------------------------------
169
170    --------------------------------------------------------------------------- */
171
172    /**
173     * update the given bound with the given coords
174     *
175     * @param &Array $bounds : the bounds (N,S,E,W)
176     * @param Array $coords  : coords (0=>lat, 1=>lng)
177     */
178    protected function updateBounds(&$bounds, $coords)
179    {
180      if($bounds['E']<$coords['lng']) $bounds['E']=$coords['lng'];
181      if($bounds['N']<$coords['lat']) $bounds['N']=$coords['lat'];
182      if($bounds['W']>$coords['lng']) $bounds['W']=$coords['lng'];
183      if($bounds['S']>$coords['lat']) $bounds['S']=$coords['lat'];
184    }
185
186    /**
187     * build the list of maps (initialize the $this->maps var)
188     *
189     * used by GMaps_ajax & GMaps_pip classes
190     *
191     * @param Array $categories : array of categories id (cat + parent list)
192     * @param String $page : 'P' for picture page, 'C' for category page
193     */
194    protected function buildMapList($category, $page)
195    {
196      global $template ;
197
198      $this->maps=array();
199      $this->forceDisplay=0;
200
201      if($page=='C')
202      {
203        $where=" displayType='IC' ";
204      }
205      else
206      {
207        $where=" (displayType='IP' or displayType='MP') ";
208      }
209
210      /*
211       * sql request select all possible association, sorted from the highest to
212       * the lowest priority
213       */
214      $sql="SELECT DISTINCT pgcm.id, pgcm.categoryId,
215              pgcm.imgSort, pgcm.applySubCat, pgcm.kmlFileUrl, pgcm.kmlFileId, pgkf.file AS kmlFileUrlId,
216              pgcm.icon, pgcm.title, pgcm.marker,
217              pgmm.displayType, pgmm.sizeMode,
218              pgmm.width, pgmm.height, pgmm.zoomLevel,
219              pgmm.mapType, pgmm.mapTypeControl, pgmm.scaleControl, pgmm.streetViewControl,
220              pgmm.navigationControl, pgmm.style, pgmm.zoomLevelMaxActivated,
221              IF(pgcm.categoryId=0, 0, pct.global_rank) AS priorityRank,
222              pgcm.forceDisplay
223            FROM ((".$this->tables['category_maps']." pgcm
224                  LEFT JOIN ".$this->tables['maps']." pgmm ON pgcm.mapId = pgmm.id)
225                  LEFT JOIN ".CATEGORIES_TABLE." pct ON (FIND_IN_SET(pgcm.categoryId, pct.uppercats)!=0 OR pgcm.categoryId=0))
226                  LEFT JOIN ".$this->tables['kmlfiles']." pgkf ON  pgkf.id = pgcm.kmlFileId
227            WHERE $where ";
228      if($category!=0)
229      {
230        $sql.=" AND pct.id = '$category' ";
231      }
232      else
233      {
234        $sql.=" AND pgcm.categoryId = 0 ";
235      }
236      $sql.=" AND pgcm.applySubCat='y'
237            ORDER BY priorityRank DESC, pgmm.displayType ASC, pgcm.categoryId ASC, pgcm.imgSort ASC;";
238      $result=pwg_query($sql);
239
240      if($result)
241      {
242        // for each found row, choose the highest only
243        $pcat='';
244        $displayType=array(
245         'IC' => true,
246         'IP' => true,
247         'MP' => true,
248        );
249        while($row=pwg_db_fetch_assoc($result))
250        {
251          // if an kml file id is given, apply the url of the file (needs to give the complete URI for google)
252          if($row['kmlFileId']>0 and $row['kmlFileUrlId']!='') $row['kmlFileUrl']=dirname($_SERVER['SCRIPT_URI']).self::KML_DIRECTORY.$row['kmlFileUrlId'];
253
254          if($row['displayType']!='MP')
255          {
256            $themeConf=$template->get_template_vars('themeconf');
257            $fileName=preg_replace('/^([i|c]\d+x\d+)(?:_\d+){0,1}(\..*)/i', '$1$2', $row['icon']);
258
259            if(file_exists(PHPWG_ROOT_PATH.$themeConf['icon_dir'].'/gmaps/'.$fileName))
260            {
261              $row['icon']=$themeConf['icon_dir'].'/gmaps/'.$fileName;
262              $row['iconStyle']=false;
263            }
264            else
265            {
266              $row['icon']='plugins/GMaps/img/'.$row['icon'];
267              $row['iconStyle']=true;
268            }
269          }
270
271          if($displayType[$row['displayType']])
272          {
273            if($row['displayType']=='MP')
274            {
275              if($displayType['MP'] and ($row['categoryId']==$pcat or $pcat=='')) $this->maps[]=$row;
276              if($displayType['MP'] and $row['categoryId']!=$pcat and $pcat!='') $displayType['MP']=false;
277              $pcat=$row['categoryId'];
278            }
279            else
280            {
281              $this->maps[]=$row;
282              $displayType[$row['displayType']]=false;
283              if($row['forceDisplay']=='y' and ($row['kmlFileUrl']!='' or $row['kmlFileId']!=0)) $this->forceDisplay++;
284            }
285          }
286        }
287      }
288    }
289
290
291
292  } //class
293
294
295
296class GMaps_functions
297  {
298    static private $tables = Array();
299    static private $config = Array();
300
301    /**
302     * initialise the class
303     *
304     * @param String $prefixeTable : the piwigo prefixe used on tables name
305     * @param String $pluginNameFile : the plugin name used for tables name
306     */
307    static public function init($prefixeTable)
308    {
309      GPCCore::loadConfig(GMaps_root::$pluginNameFile, self::$config);
310      $list=GMaps_root::$pluginTables;
311
312      for($i=0;$i<count($list);$i++)
313      {
314        self::$tables[$list[$i]]=$prefixeTable.GMaps_root::$pluginNameFile.'_'.$list[$i];
315      }
316    }
317
318
319    /**
320     *  return all HTML&JS code necessary to display a dialogbox to choose
321     *  geographic area
322     */
323    static public function dialogBoxGMaps()
324    {
325      global $template;
326
327      $template->set_filename('gmaps_choose',
328                    dirname(__FILE__).'/templates/gmaps_dialog_area_choose.tpl');
329
330      $datas=Array();
331
332      $template->assign('datas', $datas);
333
334      return($template->parse('gmaps_choose', true));
335    }
336
337    /**
338     * convert a decimal degree to D°M'S'
339     *
340     * @param Float $value : the value to convert
341     * @return String : value converted in DMS
342     */
343    static public function DDtoDMS($value)
344    {
345      $degrees=(int)$value;
346      $value=($value-$degrees)*60;
347      $minutes=(int)$value;
348      $seconds=($value-$minutes)*60;
349
350      return(sprintf('%d° %d\' %.2f"', $degrees, $minutes, $seconds));
351    }
352
353  } //GMaps_functions
354
355
356
357?>
Note: See TracBrowser for help on using the repository browser.