PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/themes/Avada/framework/plugins/revslider/inc_php/base_admin.class.php

https://bitbucket.org/rchlmrtn/chiari
PHP | 389 lines | 190 code | 91 blank | 108 comment | 20 complexity | ee67476e5c27dd5be0aa7583accac17b MD5 | raw file
  1. <?php
  2. class UniteBaseAdminClassRev extends UniteBaseClassRev{
  3. const ACTION_ADMIN_MENU = "admin_menu";
  4. const ACTION_ADMIN_INIT = "admin_init";
  5. const ACTION_ADD_SCRIPTS = "admin_enqueue_scripts";
  6. protected static $master_view;
  7. protected static $view;
  8. private static $arrSettings = array();
  9. private static $arrMenuPages = array();
  10. private static $tempVars = array();
  11. private static $startupError = "";
  12. /**
  13. *
  14. * main constructor
  15. */
  16. public function __construct($mainFile,$t,$defaultView){
  17. parent::__construct($mainFile,$t);
  18. //set view
  19. self::$view = self::getGetVar("view");
  20. if(empty(self::$view))
  21. self::$view = $defaultView;
  22. //add internal hook for adding a menu in arrMenus
  23. self::addAction(self::ACTION_ADMIN_MENU, "addAdminMenu");
  24. //if not inside plugin don't continue
  25. if($this->isInsidePlugin() == true){
  26. self::addAction(self::ACTION_ADD_SCRIPTS, "addCommonScripts");
  27. self::addAction(self::ACTION_ADD_SCRIPTS, "onAddScripts");
  28. }
  29. //a must event for any admin. call onActivate function.
  30. $this->addEvent_onActivate();
  31. self::addActionAjax("show_image", "onShowImage");
  32. }
  33. /**
  34. *
  35. * set startup error to be shown in master view
  36. */
  37. public static function setStartupError($errorMessage){
  38. self::$startupError = $errorMessage;
  39. }
  40. /**
  41. *
  42. * tells if the the current plugin opened is this plugin or not
  43. * in the admin side.
  44. */
  45. private function isInsidePlugin(){
  46. $page = self::getGetVar("page");
  47. if($page == self::$dir_plugin)
  48. return(true);
  49. return(false);
  50. }
  51. /**
  52. *
  53. * add common used scripts
  54. */
  55. public static function addCommonScripts(){
  56. //include jquery ui
  57. $version = get_bloginfo("version");
  58. $version = (double)$version;
  59. if($version >= 3.5){ //load new jquery ui library
  60. $urlJqueryUI = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js";
  61. self::addScriptAbsoluteUrl($urlJqueryUI,"jquery-ui");
  62. self::addStyle("jquery-ui-1.9.2.custom.min","jui-smoothness","css/jui/new");
  63. }else{ //load old jquery ui library
  64. $urlJqueryUI = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js";
  65. self::addScriptAbsoluteUrl($urlJqueryUI,"jquery-ui");
  66. self::addStyle("jquery-ui-1.8.18.custom","jui-smoothness","css/jui/old");
  67. }
  68. self::addScriptCommon("settings","unite_settings");
  69. self::addScriptCommon("admin","unite_admin");
  70. self::addScriptCommon("jquery.tipsy","tipsy");
  71. //--- add styles
  72. self::addStyleCommon("admin","unite_admin");
  73. //add tipsy
  74. self::addStyleCommon("tipsy","tipsy");
  75. //include farbtastic
  76. self::addScriptCommon("farbtastic","farbtastic","js/farbtastic");
  77. self::addStyleCommon("farbtastic","farbtastic","js/farbtastic");
  78. //include codemirror
  79. self::addScriptCommon("codemirror","codemirror_js","js/codemirror");
  80. self::addScriptCommon("css","codemirror_js_css","js/codemirror");
  81. self::addStyleCommon("codemirror","codemirror_css","js/codemirror");
  82. }
  83. /**
  84. *
  85. * admin pages parent, includes all the admin files by default
  86. */
  87. public static function adminPages(){
  88. self::validateAdminPermissions();
  89. }
  90. /**
  91. *
  92. * validate permission that the user is admin, and can manage options.
  93. */
  94. protected static function isAdminPermissions(){
  95. if( is_admin() && current_user_can("manage_options") )
  96. return(true);
  97. return(false);
  98. }
  99. /**
  100. *
  101. * validate admin permissions, if no pemissions - exit
  102. */
  103. protected static function validateAdminPermissions(){
  104. if(!self::isAdminPermissions()){
  105. echo "access denied";
  106. return(false);
  107. }
  108. }
  109. /**
  110. *
  111. * set view that will be the master
  112. */
  113. protected static function setMasterView($masterView){
  114. self::$master_view = $masterView;
  115. }
  116. /**
  117. *
  118. * inlcude some view file
  119. */
  120. protected static function requireView($view){
  121. try{
  122. //require master view file, and
  123. if(!empty(self::$master_view) && !isset(self::$tempVars["is_masterView"]) ){
  124. $masterViewFilepath = self::$path_views.self::$master_view.".php";
  125. UniteFunctionsRev::validateFilepath($masterViewFilepath,"Master View");
  126. self::$tempVars["is_masterView"] = true;
  127. require $masterViewFilepath;
  128. }
  129. else{ //simple require the view file.
  130. $viewFilepath = self::$path_views.$view.".php";
  131. UniteFunctionsRev::validateFilepath($viewFilepath,"View");
  132. require $viewFilepath;
  133. }
  134. }catch (Exception $e){
  135. echo "<br><br>View ($view) Error: <b>".$e->getMessage()."</b>";
  136. if(self::$debugMode == true)
  137. dmp($e->getTraceAsString());
  138. }
  139. }
  140. /**
  141. * require some template from "templates" folder
  142. */
  143. protected static function getPathTemplate($templateName){
  144. $pathTemplate = self::$path_templates.$templateName.".php";
  145. UniteFunctionsRev::validateFilepath($pathTemplate,"Template");
  146. return($pathTemplate);
  147. }
  148. /**
  149. *
  150. * require settings file, the filename without .php
  151. */
  152. protected static function requireSettings($settingsFile){
  153. try{
  154. require self::$path_plugin."settings/$settingsFile.php";
  155. }catch (Exception $e){
  156. echo "<br><br>Settings ($settingsFile) Error: <b>".$e->getMessage()."</b>";
  157. dmp($e->getTraceAsString());
  158. }
  159. }
  160. /**
  161. *
  162. * get path to settings file
  163. * @param $settingsFile
  164. */
  165. protected static function getSettingsFilePath($settingsFile){
  166. $filepath = self::$path_plugin."settings/$settingsFile.php";
  167. return($filepath);
  168. }
  169. /**
  170. *
  171. * add all js and css needed for media upload
  172. */
  173. protected static function addMediaUploadIncludes(){
  174. self::addWPScript("thickbox");
  175. self::addWPStyle("thickbox");
  176. self::addWPScript("media-upload");
  177. }
  178. /**
  179. * add admin menus from the list.
  180. */
  181. public static function addAdminMenu(){
  182. $role = "manage_options";
  183. switch(GlobalsRevSlider::SHOW_SLIDER_TO){
  184. case "author":
  185. $role = "edit_published_posts";
  186. break;
  187. case "editor":
  188. $role = "edit_pages";
  189. break;
  190. default:
  191. case "admin":
  192. $role = "manage_options";
  193. break;
  194. }
  195. foreach(self::$arrMenuPages as $menu){
  196. $title = $menu["title"];
  197. $pageFunctionName = $menu["pageFunction"];
  198. add_menu_page( $title, $title, $role, self::$dir_plugin, array(self::$t, $pageFunctionName) );
  199. }
  200. }
  201. /**
  202. *
  203. * add menu page
  204. */
  205. protected static function addMenuPage($title,$pageFunctionName){
  206. self::$arrMenuPages[] = array("title"=>$title,"pageFunction"=>$pageFunctionName);
  207. }
  208. /**
  209. *
  210. * get url to some view.
  211. */
  212. public static function getViewUrl($viewName,$urlParams=""){
  213. $params = "&view=".$viewName;
  214. if(!empty($urlParams))
  215. $params .= "&".$urlParams;
  216. $link = admin_url( "admin.php?page=".self::$dir_plugin.$params);
  217. return($link);
  218. }
  219. /**
  220. *
  221. * register the "onActivate" event
  222. */
  223. protected function addEvent_onActivate($eventFunc = "onActivate"){
  224. register_activation_hook( self::$mainFile, array(self::$t, $eventFunc) );
  225. }
  226. /**
  227. *
  228. * store settings in the object
  229. */
  230. protected static function storeSettings($key,$settings){
  231. self::$arrSettings[$key] = $settings;
  232. }
  233. /**
  234. *
  235. * get settings object
  236. */
  237. protected static function getSettings($key){
  238. if(!isset(self::$arrSettings[$key]))
  239. UniteFunctionsRev::throwError("Settings $key not found");
  240. $settings = self::$arrSettings[$key];
  241. return($settings);
  242. }
  243. /**
  244. *
  245. * add ajax back end callback, on some action to some function.
  246. */
  247. protected static function addActionAjax($ajaxAction,$eventFunction){
  248. self::addAction('wp_ajax_'.self::$dir_plugin."_".$ajaxAction, $eventFunction);
  249. self::addAction('wp_ajax_nopriv_'.self::$dir_plugin."_".$ajaxAction, $eventFunction);
  250. }
  251. /**
  252. *
  253. * echo json ajax response
  254. */
  255. private static function ajaxResponse($success,$message,$arrData = null){
  256. $response = array();
  257. $response["success"] = $success;
  258. $response["message"] = $message;
  259. if(!empty($arrData)){
  260. if(gettype($arrData) == "string")
  261. $arrData = array("data"=>$arrData);
  262. $response = array_merge($response,$arrData);
  263. }
  264. $json = json_encode($response);
  265. echo $json;
  266. exit();
  267. }
  268. /**
  269. *
  270. * echo json ajax response, without message, only data
  271. */
  272. protected static function ajaxResponseData($arrData){
  273. if(gettype($arrData) == "string")
  274. $arrData = array("data"=>$arrData);
  275. self::ajaxResponse(true,"",$arrData);
  276. }
  277. /**
  278. *
  279. * echo json ajax response
  280. */
  281. protected static function ajaxResponseError($message,$arrData = null){
  282. self::ajaxResponse(false,$message,$arrData,true);
  283. }
  284. /**
  285. * echo ajax success response
  286. */
  287. protected static function ajaxResponseSuccess($message,$arrData = null){
  288. self::ajaxResponse(true,$message,$arrData,true);
  289. }
  290. /**
  291. * echo ajax success response
  292. */
  293. protected static function ajaxResponseSuccessRedirect($message,$url){
  294. $arrData = array("is_redirect"=>true,"redirect_url"=>$url);
  295. self::ajaxResponse(true,$message,$arrData,true);
  296. }
  297. }
  298. ?>