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

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

Fix bugs on install process ; add street view control management

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