1 | <?php |
---|
2 | /* ----------------------------------------------------------------------------- |
---|
3 | Plugin : Histogram |
---|
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 | --------------------------------------------------------------------------- */ |
---|
13 | |
---|
14 | |
---|
15 | define('PHPWG_ROOT_PATH',dirname(dirname(dirname(__FILE__))).'/'); |
---|
16 | |
---|
17 | /* |
---|
18 | * set ajax module in admin mode if request is used for admin interface |
---|
19 | */ |
---|
20 | if(!isset($_REQUEST['ajaxfct'])) $_REQUEST['ajaxfct']=''; |
---|
21 | if(preg_match('/^admin\./i', $_REQUEST['ajaxfct'])) |
---|
22 | { |
---|
23 | define('IN_ADMIN', true); |
---|
24 | } |
---|
25 | |
---|
26 | // the common.inc.php file loads all the main.inc.php plugins files |
---|
27 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
28 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCAjax.class.inc.php'); |
---|
29 | include_once('hgram_root.class.inc.php'); |
---|
30 | |
---|
31 | load_language('plugin.lang', HGRAM_PATH); |
---|
32 | |
---|
33 | |
---|
34 | class HGram_ajax extends HGram_root |
---|
35 | { |
---|
36 | |
---|
37 | |
---|
38 | /** |
---|
39 | * constructor |
---|
40 | */ |
---|
41 | public function __construct($prefixeTable, $filelocation) |
---|
42 | { |
---|
43 | parent::__construct($prefixeTable, $filelocation); |
---|
44 | $this->loadConfig(); |
---|
45 | $this->checkRequest(); |
---|
46 | $this->returnAjaxContent(); |
---|
47 | } |
---|
48 | |
---|
49 | /** |
---|
50 | * check the $_REQUEST values and set default values |
---|
51 | * |
---|
52 | */ |
---|
53 | protected function checkRequest() |
---|
54 | { |
---|
55 | global $user; |
---|
56 | |
---|
57 | if(!isset($_REQUEST['ajaxfct'])) $_REQUEST['ajaxfct']=''; |
---|
58 | |
---|
59 | // check if asked function is valid |
---|
60 | if(!( |
---|
61 | $_REQUEST['ajaxfct']=='public.histo.build' |
---|
62 | ) |
---|
63 | ) $_REQUEST['ajaxfct']=''; |
---|
64 | |
---|
65 | |
---|
66 | if(preg_match('/^admin\./i', $_REQUEST['ajaxfct']) and !is_admin()) $_REQUEST['ajaxfct']=''; |
---|
67 | |
---|
68 | // check token validity |
---|
69 | if(!isset($_REQUEST['token'])) $_REQUEST['token']=''; |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | if($_REQUEST['ajaxfct']!='') |
---|
74 | { |
---|
75 | /* |
---|
76 | * check public.histo.build |
---|
77 | */ |
---|
78 | if($_REQUEST['ajaxfct']=="public.histo.build") |
---|
79 | { |
---|
80 | if(!isset($_REQUEST['id'])) $_REQUEST['ajaxfct']=''; |
---|
81 | if($_REQUEST['token']!=self::getToken($_REQUEST['id'])) $_REQUEST['ajaxfct']=''; |
---|
82 | } |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | /** |
---|
88 | * return ajax content |
---|
89 | */ |
---|
90 | protected function returnAjaxContent() |
---|
91 | { |
---|
92 | $result="<p class='errors'>An error has occured</p>"; |
---|
93 | switch($_REQUEST['ajaxfct']) |
---|
94 | { |
---|
95 | case 'public.histo.build': |
---|
96 | $result=$this->ajax_hgram_public_histoBuild($_REQUEST['id']); |
---|
97 | break; |
---|
98 | } |
---|
99 | GPCAjax::returnResult($result); |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | /*------------------------------------------------------------------------* |
---|
104 | * |
---|
105 | * PUBLIC FUNCTIONS |
---|
106 | * |
---|
107 | *----------------------------------------------------------------------- */ |
---|
108 | private function ajax_hgram_public_histoBuild($imageId) |
---|
109 | { |
---|
110 | return(self::getHistogramGraph($imageId, true)); |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | /*------------------------------------------------------------------------* |
---|
116 | * |
---|
117 | * ADMIN FUNCTIONS |
---|
118 | * |
---|
119 | *----------------------------------------------------------------------- */ |
---|
120 | |
---|
121 | |
---|
122 | |
---|
123 | } //class |
---|
124 | |
---|
125 | |
---|
126 | $returned=new HGram_ajax($prefixeTable, __FILE__); |
---|
127 | ?> |
---|