FestiPlugin

The Woocart Popup Lite for WooCommerce FestiPlugin class.

Defined (1)

The class is defined in the following location(s).

/common/FestiPlugin.php  
  1. abstract class FestiPlugin implements IFestiEngine 
  2. protected $_wpUrl; 
  3. protected $_wpPluginsUrl; 
  4.  
  5. protected $_pluginDirName; 
  6. protected $_pluginMainFile; 
  7.  
  8. protected $_pluginPath; 
  9. protected $_pluginUrl; 
  10.  
  11. protected $_pluginCachePath; 
  12. protected $_pluginCacheUrl; 
  13.  
  14. protected $_pluginStaticPath; 
  15. protected $_pluginStaticUrl; 
  16.  
  17. protected $_pluginCssPath; 
  18. protected $_pluginCssUrl; 
  19.  
  20. protected $_pluginImagesPath; 
  21. protected $_pluginImagesUrl; 
  22.  
  23. protected $_pluginJsPath; 
  24. protected $_pluginJsUrl; 
  25.  
  26. protected $_pluginTemplatePath; 
  27. protected $_pluginTemplateUrl; 
  28.  
  29. protected $_pluginLanguagesPath; 
  30. protected $_pluginLanguagesUrl; 
  31.  
  32. protected $_languageDomain = ''; 
  33. protected $_optionsPrefix = ''; 
  34.  
  35. protected $_fileSystem = ''; 
  36.  
  37. public function __construct($pluginMainFile) 
  38. $this->_wpUrl = get_site_url(); 
  39. $this->_wpUrl = $this->makeUniversalLink($this->_wpUrl); 
  40.  
  41. $this->_wpPluginsUrl = plugins_url('/'); 
  42. $this->_wpPluginsUrl = $this->makeUniversalLink($this->_wpPluginsUrl); 
  43.  
  44. $this->_pluginDirName = plugin_basename(dirname($pluginMainFile)).'/'; 
  45.  
  46. $this->_pluginMainFile = $pluginMainFile; 
  47.  
  48. $this->_pluginPath = plugin_dir_path($pluginMainFile); 
  49. $this->_pluginUrl = plugins_url('/', $pluginMainFile); 
  50. $this->_pluginUrl = $this->makeUniversalLink($this->_pluginUrl); 
  51.  
  52. $this->_pluginCachePath = $this->_pluginPath.'cache/'; 
  53. $this->_pluginCacheUrl = $this->_pluginUrl.'cache/'; 
  54.  
  55. $this->_pluginStaticPath = $this->_pluginPath.'static/'; 
  56. $this->_pluginStaticUrl = $this->_pluginUrl.'static/'; 
  57.  
  58. $this->_pluginCssPath = $this->_pluginStaticPath.'styles/'; 
  59. $this->_pluginCssUrl = $this->_pluginStaticUrl.'styles/'; 
  60.  
  61. $this->_pluginImagesPath = $this->_pluginStaticPath.'images/'; 
  62. $this->_pluginImagesUrl = $this->_pluginStaticUrl.'images/'; 
  63.  
  64. $this->_pluginJsPath = $this->_pluginStaticPath.'js/'; 
  65. $this->_pluginJsUrl = $this->_pluginStaticUrl.'js/'; 
  66.  
  67. $this->_pluginTemplatePath = $this->_pluginPath.'templates/'; 
  68. $this->_pluginTemplateUrl = $this->_pluginUrl.'templates/'; 
  69.  
  70. $this->_pluginLanguagesPath = $this->_pluginDirName.'languages/'; 
  71.  
  72. $this->onInit(); 
  73. } // end __construct 
  74.  
  75. public function makeUniversalLink($url = '') 
  76. $protocols = array( 
  77. 'http:',  
  78. 'https:' 
  79. ); 
  80.  
  81. foreach ($protocols as $protocol) { 
  82. $url = str_replace($protocol, '', $url); 
  83.  
  84. return $url; 
  85. } // end makeUniversalLink 
  86.  
  87. protected function onInit() 
  88. {  
  89. register_activation_hook( 
  90. $this->_pluginMainFile,  
  91. array(&$this, 'onInstall') 
  92. ); 
  93.  
  94. register_deactivation_hook( 
  95. $this->_pluginMainFile,  
  96. array(&$this, 'onUninstall') 
  97. ); 
  98.  
  99. if (defined('WP_BLOG_ADMIN')) { 
  100. $this->onBackendInit(); 
  101. } else { 
  102. $this->onFrontendInit(); 
  103. } // end onInit 
  104.  
  105. protected function onBackendInit() 
  106. } // end onBackendInit 
  107.  
  108. protected function onFrontendInit() 
  109. } // end onFrontendInit 
  110.  
  111. public function onInstall() 
  112. } // end onInstall 
  113.  
  114. public function onUninstall() 
  115. } // end onUninstall 
  116.  
  117. public function getLanguageDomain() 
  118. return $this->_languageDomain; 
  119. } // end getLanguageDomain 
  120.  
  121. public function getPluginPath() 
  122. return $this->_pluginPath; 
  123. } // end getPluginPath 
  124.  
  125. public function getPluginCachePath($fileName) 
  126. return $this->_pluginCachePath.$fileName.'.php'; 
  127. } // end getPluginCachePath 
  128.  
  129. public function getPluginStaticPath($fileName) 
  130. return $this->_pluginStaticPath.$fileName; 
  131. } // end pluginStaticPath 
  132.  
  133. public function getPluginCssPath($fileName) 
  134. return $this->_pluginCssPath.$fileName; 
  135. } // end pluginCssPath 
  136.  
  137. public function getPluginImagesPath($fileName) 
  138. return $this->_pluginImagesPath.$fileName; 
  139. } // end pluginImagesPath 
  140.  
  141. public function getPluginJsPath($fileName) 
  142. return $this->_pluginJsPath.$fileName; 
  143. } // end pluginJsPath 
  144.  
  145. public function getPluginTemplatePath($fileName) 
  146. return $this->_pluginTemplatePath.$fileName; 
  147. } // end getPluginTemplatePath 
  148.  
  149. public function getPluginLanguagesPath() 
  150. return $this->_pluginLanguagesPath; 
  151. } // end getPluginLanguagesPath 
  152.  
  153. public function getPluginUrl() 
  154. return $this->_pluginUrl; 
  155. } // end getPluginUrl 
  156.  
  157. public function getPluginCacheUrl() 
  158. return $this->_pluginCacheUrl; 
  159. } // end getPluginCacheUrl 
  160.  
  161. public function getPluginStaticUrl() 
  162. return $this->_pluginStaticUrl; 
  163. } // end getPluginStaticUrl 
  164.  
  165. public function getPluginCssUrl($fileName)  
  166. return $this->_pluginCssUrl.$fileName; 
  167. } // end getPluginCssUrl 
  168.  
  169. public function getPluginImagesUrl($fileName) 
  170. return $this->_pluginImagesUrl.$fileName; 
  171. } // end getPluginImagesUrl 
  172.  
  173. public function getPluginJsUrl($fileName) 
  174. return $this->_pluginJsUrl.$fileName; 
  175. } // end getPluginJsUrl 
  176.  
  177. public function getPluginTemplateUrl($fileName) 
  178. return $this->_pluginTemplateUrl.$fileName; 
  179. } // end getPluginTemplateUrl 
  180.  
  181. public function isPluginActive($pluginMainFilePath) 
  182. if (is_multisite()) 
  183. $activPlugins = get_site_option('active_sitewide_plugins'); 
  184. $result = array_key_exists($pluginMainFilePath, $activPlugins); 
  185. if ($result) { 
  186. return true; 
  187.  
  188. $activPlugins = get_option('active_plugins');  
  189. return in_array($pluginMainFilePath, $activPlugins); 
  190. } // end isPluginActive 
  191.  
  192. public function addActionListener( 
  193. $hook, $method, $priority = 10, $acceptedArgs = 1 
  194. add_action($hook, array(&$this, $method), $priority, $acceptedArgs); 
  195. } // end addActionListener 
  196.  
  197. public function addFilterListener( 
  198. $hook, $method, $priority = 10, $acceptedArgs = 1 
  199. add_filter($hook, array(&$this, $method), $priority, $acceptedArgs); 
  200. } // end addFilterListener 
  201.  
  202. public function addShortcodeListener($tag, $method) 
  203. add_shortcode( 
  204. $tag,  
  205. array(&$this, $method) 
  206. ); 
  207. } // end addShortcodeListener 
  208.  
  209. public function getOptions($optionName) 
  210. $options = $this->getCache($optionName); 
  211.  
  212. if (!$options) { 
  213. $options = get_option($this->_optionsPrefix.$optionName);  
  214.  
  215. $options = json_decode($options, true); 
  216.  
  217. return $options; 
  218. } // end getOptions 
  219.  
  220. public function getCache($fileName) 
  221. $file = $this->getPluginCachePath($fileName); 
  222.  
  223. if (!file_exists($file)) { 
  224. return false; 
  225.  
  226. $content = include($file); 
  227.  
  228. return $content; 
  229. } //end getCache 
  230.  
  231. public function updateOptions($optionName, $values = array()) 
  232. $values = $this->_doChangeSingleQuotesToDouble($values); 
  233.  
  234. $value = json_encode($values); 
  235.  
  236. update_option($this->_optionsPrefix.$optionName, $value); 
  237.  
  238. $result = $this->updateCacheFile($optionName, $value); 
  239.  
  240. return $result; 
  241.  
  242. } // end updateOptions 
  243.  
  244. private function _doChangeSingleQuotesToDouble($options = array()) 
  245. foreach ($options as $key => $value) { 
  246. if (is_string($value)) { 
  247. $result = str_replace("'", '"', $value); 
  248. $options[$key] = stripslashes($result); 
  249. }  
  250.  
  251. return $options; 
  252. } // end _doChangeSingleQuotesToDouble 
  253.  
  254. public function updateCacheFile($fileName, $values) 
  255. if (!$this->_fileSystem) { 
  256. $this->_fileSystem = $this->getFileSystemInstance(); 
  257.  
  258. if (!$this->_fileSystem) { 
  259. return false; 
  260.  
  261. if (!$this->_fileSystem->is_writable($this->_pluginCachePath)) { 
  262. return false; 
  263.  
  264. $content = "<?php return '".$values."';"; 
  265.  
  266. $filePath = $this->getPluginCachePath($fileName); 
  267.  
  268. $this->_fileSystem->put_contents($filePath, $content, 0777); 
  269. } //end updateCacheFile 
  270.  
  271. public function &getFileSystemInstance($method = 'direct') 
  272. $wpFileSystem = false; 
  273.  
  274. if ($this->_hasWordpessFileSystemObjectInGlobals()) { 
  275. $wpFileSystem = $GLOBALS['wp_filesystem']; 
  276.  
  277. if (!$wpFileSystem) { 
  278. define('FS_METHOD', $method); 
  279. WP_Filesystem(); 
  280. $wpFileSystem = $GLOBALS['wp_filesystem']; 
  281.  
  282. return $wpFileSystem; 
  283. } // end doWriteCacheToFile 
  284.  
  285. private function _hasWordpessFileSystemObjectInGlobals() 
  286. return array_key_exists('wp_filesystem', $GLOBALS); 
  287. } // end _hasWordpessFileSystemObjectInGlobals 
  288.  
  289. public function onEnqueueJsFileAction($handle, $file = '', $deps = '') 
  290. $version = ''; 
  291. $inFooter = ''; 
  292.  
  293. $args = func_get_args(); 
  294.  
  295. if (isset($args[3])) { 
  296. $version = $args[3]; 
  297.  
  298. if (isset($args[4])) { 
  299. $inFooter = $args[4]; 
  300.  
  301. $src = ''; 
  302.  
  303. if ($file) { 
  304. $src = $this->getPluginJsUrl($file); 
  305.  
  306. if ($deps) { 
  307. $deps = array($deps); 
  308.  
  309. wp_enqueue_script($handle, $src, $deps, $version, $inFooter); 
  310. } // end onEnqueueJsFileAction 
  311.  
  312. public function onEnqueueCssFileAction( 
  313. $handle, $file = false, $deps = array() 
  314. $version = false; 
  315. $media = 'all'; 
  316.  
  317. $args = func_get_args(); 
  318.  
  319. if (isset($args[3])) { 
  320. $version = $args[3]; 
  321.  
  322. if (isset($args[4])) { 
  323. $media = $args[4]; 
  324.  
  325. $src = ''; 
  326.  
  327. if ($file) { 
  328. $src = $this->getPluginCssUrl($file); 
  329.  
  330. if ($deps) { 
  331. $deps = array($deps); 
  332.  
  333. wp_enqueue_style($handle, $src, $deps, $version, $media); 
  334. } // end onEnqueueCssFileAction 
  335.  
  336. public function fetch($template, $vars = array())  
  337. if ($vars) { 
  338. extract($vars); 
  339.  
  340. ob_start(); 
  341.  
  342. $templatePath = $this->getPluginTemplatePath($template);  
  343.  
  344. include $templatePath; 
  345.  
  346. $content = ob_get_clean();  
  347.  
  348. return $content;  
  349. } // end fetch 
  350.  
  351. public function getUrl() 
  352. $url = $_SERVER['REQUEST_URI']; 
  353.  
  354. $args = func_get_args(); 
  355. if (!$args) { 
  356. return $url; 
  357.  
  358. if (!is_array($args[0])) { 
  359. $url = $args[0]; 
  360. $args = array_slice($args, 1); 
  361.  
  362. if (isset($args[0]) && is_array($args[0])) { 
  363.  
  364. $data = parse_url($url); 
  365.  
  366. if (array_key_exists('query', $data)) { 
  367. $url = $data['path']; 
  368. parse_str($data['query'], $params); 
  369.  
  370. foreach ($args[0] as $key => $value) { 
  371. if ($value != '') { 
  372. continue; 
  373.  
  374. unset($args[0][$key]); 
  375.  
  376. if (array_key_exists($key, $params)) { 
  377. unset($params[$key]); 
  378.  
  379. $args[0] = array_merge($params, $args[0]); 
  380.  
  381. $seperator = preg_match("#\?#Umis", $url) ? '&' : '?'; 
  382. $url .= $seperator.http_build_query($args[0]); 
  383.  
  384. return $url; 
  385. } // end getUrl 
  386.  
  387. public function displayError($error) 
  388. $this->displayMessage($error, 'error'); 
  389. } // end displayError 
  390.  
  391. public function displayUpdate($text) 
  392. $this->displayMessage($text, 'updated'); 
  393. } // end displayUpdate 
  394.  
  395. public function displayMessage($text, $type) 
  396. $message = __( 
  397. $text,  
  398. $this->_languageDomain 
  399. ); 
  400.  
  401. $template = 'message.phtml'; 
  402.  
  403. $vars = array( 
  404. 'type' => $type,  
  405. 'message' => $message 
  406. ); 
  407.  
  408. echo $this->fetch($template, $vars); 
  409. }// end displayMessage