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

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

Connect the plugin to the RBuilder component + fixe some small bugs

  • Property svn:executable set to *
File size: 9.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
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'));
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,
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            WHERE $where ";
216      if($category!=0)
217      {
218        $sql.=" AND pct.id = '$category' ";
219      }
220      else
221      {
222        $sql.=" AND pgcm.categoryId = 0 ";
223      }
224      $sql.=" AND pgcm.applySubCat='y'
225            ORDER BY priorityRank DESC, pgmm.displayType ASC, pgcm.categoryId ASC, pgcm.imgSort ASC;";
226      $result=pwg_query($sql);
227
228      if($result)
229      {
230        // for each found row, choose the highest only
231        $pcat='';
232        $displayType=array(
233         'IC' => true,
234         'IP' => true,
235         'MP' => true,
236        );
237        while($row=pwg_db_fetch_assoc($result))
238        {
239          if($row['displayType']!='MP')
240          {
241            $themeConf=$template->get_template_vars('themeconf');
242            $fileName=preg_replace('/^([i|c]\d+x\d+)(?:_\d+){0,1}(\..*)/i', '$1$2', $row['icon']);
243
244            if(file_exists(PHPWG_ROOT_PATH.$themeConf['icon_dir'].'/gmaps/'.$fileName))
245            {
246              $row['icon']=$themeConf['icon_dir'].'/gmaps/'.$fileName;
247              $row['iconStyle']=false;
248            }
249            else
250            {
251              $row['icon']='plugins/GMaps/img/'.$row['icon'];
252              $row['iconStyle']=true;
253            }
254          }
255
256          if($displayType[$row['displayType']])
257          {
258            if($row['displayType']=='MP')
259            {
260              if($displayType['MP'] and ($row['categoryId']==$pcat or $pcat=='')) $this->maps[]=$row;
261              if($displayType['MP'] and $row['categoryId']!=$pcat and $pcat!='') $displayType['MP']=false;
262              $pcat=$row['categoryId'];
263            }
264            else
265            {
266              $this->maps[]=$row;
267              $displayType[$row['displayType']]=false;
268            }
269          }
270        }
271      }
272    }
273
274
275
276  } //class
277
278
279
280class GMaps_functions
281  {
282    static private $tables = Array();
283    static private $config = Array();
284
285    /**
286     * initialise the class
287     *
288     * @param String $prefixeTable : the piwigo prefixe used on tables name
289     * @param String $pluginNameFile : the plugin name used for tables name
290     */
291    static public function init($prefixeTable)
292    {
293      GPCCore::loadConfig(GMaps_root::$pluginNameFile, self::$config);
294      $list=GMaps_root::$pluginTables;
295
296      for($i=0;$i<count($list);$i++)
297      {
298        self::$tables[$list[$i]]=$prefixeTable.GMaps_root::$pluginNameFile.'_'.$list[$i];
299      }
300    }
301
302
303    /**
304     *  return all HTML&JS code necessary to display a dialogbox to choose
305     *  geographic area
306     */
307    static public function dialogBoxGMaps()
308    {
309      global $template;
310
311      $template->set_filename('gmaps_choose',
312                    dirname(__FILE__).'/templates/gmaps_dialog_area_choose.tpl');
313
314      $datas=Array();
315
316      $template->assign('datas', $datas);
317
318      return($template->parse('gmaps_choose', true));
319    }
320
321    /**
322     * convert a decimal degree to D°M'S'
323     *
324     * @param Float $value : the value to convert
325     * @return String : value converted in DMS
326     */
327    static public function DDtoDMS($value)
328    {
329      $degrees=(int)$value;
330      $value=($value-$degrees)*60;
331      $minutes=(int)$value;
332      $seconds=($value-$minutes)*60;
333
334      return(sprintf('%d° %d\' %.2f"', $degrees, $minutes, $seconds));
335    }
336
337  } //GMaps_functions
338
339
340
341?>
Note: See TracBrowser for help on using the repository browser.