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