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

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

KML files manager implemented + fixe some small bugs + forgotten file for the search page

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