/** * @return IfwPsn_Wp_Ajax_Response_Abstract */ public function getResponse() { $tpl = IfwPsn_Wp_Tpl::getInstance($this->_pm); if ($this->_iframeSrc !== null) { $iframeSrc = $this->_iframeSrc; } elseif (strpos($this->_pm->getConfig()->plugin->optionsPage, 'options-general.php') !== false) { $iframeSrc = IfwPsn_Wp_Proxy_Admin::getUrl() . IfwPsn_Wp_Proxy_Admin::getMenuUrl($this->_pm, 'selftest'); $iframeSrc = str_replace('wp-admin//', 'wp-admin/', $iframeSrc); } else { $iframeSrc = IfwPsn_Wp_Proxy_Admin::getAdminPageUrl($this->_pm, $this->_pm->getAbbrLower() . '_selftest', $this->_pm->getAbbrLower() . '_selftest'); } $context = array('ajax' => $this, 'iframe_src' => $iframeSrc, 'img_path' => $this->_pm->getEnv()->getUrlAdminImg()); $timestamp = $this->_pm->getBootstrap()->getSelftester()->getTimestamp(); if (!empty($timestamp)) { require_once $this->_pm->getPathinfo()->getRootLib() . 'IfwPsn/Wp/Date.php'; $timestamp = IfwPsn_Wp_Date::format($timestamp); } $context['timestamp'] = $timestamp; $status = $this->_pm->getBootstrap()->getSelftester()->getStatus(); if ($status === true || $status === 'true' || $status == '1') { $context['status'] = 'true'; } elseif ($status === false || $status === 'false' || $status == '0') { $context['status'] = 'false'; } else { $context['status'] = 'null'; } $html = $tpl->render('metabox_pluginstatus.html.twig', $context); $success = true; $response = new IfwPsn_Wp_Ajax_Response_Json($success); $response->addData('html', $html); return $response; }
/** * The task to be executed * @return mixed */ protected function _execute() { $updateApi = IfwPsn_Wp_Plugin_Update_Api_Factory::get($this->_pm); remove_action('in_plugin_update_message-' . $this->_pm->getPathinfo()->getFilenamePath(), array($updateApi, 'getUpdateInlineMessage')); remove_filter('pre_set_site_transient_update_plugins', array($updateApi, 'getUpdateData')); remove_filter('plugins_api', array($updateApi, 'getPluginInformation')); }
/** * @param IfwPsn_Wp_Plugin_Manager $pm * @param null $name * @throws IfwPsn_Wp_Plugin_Logger_Exception * @internal param \IfwPsn_Wp_Pathinfo_Plugin $pluginPathinfo * @internal param \IfwPsn_Wp_Plugin_Config $config * @return IfwPsn_Wp_Plugin_Logger */ public static function getInstance(IfwPsn_Wp_Plugin_Manager $pm, $name = null) { if ($name === null) { $name = self::$_defaultName; } if (!isset(self::$_instances[$pm->getAbbr()][$name])) { if ($pm->getConfig()->log->file != '') { // custom log file $logFile = $pm->getConfig()->log->file; } else { // default log file $logFile = $pm->getPathinfo()->getRoot() . 'log' . DIRECTORY_SEPARATOR . 'plugin.log'; } if (is_writable($logFile)) { // writable log file found require_once $pm->getPathinfo()->getRootLib() . '/IfwPsn/Wp/Plugin/Logger.php'; require_once $pm->getPathinfo()->getRootLib() . '/IfwPsn/Vendor/Zend/Log/Writer/Stream.php'; $writer = new IfwPsn_Vendor_Zend_Log_Writer_Stream($logFile); } else { // no log file found require_once $pm->getPathinfo()->getRootLib() . '/IfwPsn/Vendor/Zend/Log/Writer/Null.php'; $writer = new IfwPsn_Vendor_Zend_Log_Writer_Null(); } self::create($pm, $writer, $name); } return self::$_instances[$pm->getAbbr()][$name]; }
/** * */ protected function _initAutorun() { $interval = $this->_pm->getConfig()->plugin->selftestInterval; if (!empty($interval)) { require_once $this->_pm->getPathinfo()->getRootLib() . 'IfwPsn/Wp/Date.php'; if ($this->getTimestamp() == null || IfwPsn_Wp_Date::isOlderThanSeconds($this->getTimestamp(), $interval)) { // perform a selftest if no one was run before or the selftest interval is exceeded IfwPsn_Wp_Proxy_Action::addPluginsLoaded(array($this, 'performTests')); } } }
/** * Retrieves the application options * @return array */ protected function _getApplicationOptions() { $options = (include $this->_pm->getPathinfo()->getRootAdminMenu() . 'configs/application.php'); if ($this->_pm->getEnv()->getEnvironmet() == 'development') { $options['resources']['FrontController']['params']['displayExceptions'] = 1; $options['phpSettings']['error_reporting'] = 6143; // E_ALL & ~E_STRICT $options['phpSettings']['display_errors'] = 1; $options['phpSettings']['display_startup_errors'] = 1; } return $options; }
/** * @param IfwPsn_Wp_Plugin_Manager $pm * @return IfwPsn_Wp_Plugin_Update_Api_Envato|IfwPsn_Wp_Plugin_Update_Api_WooCommerce */ public static function get(IfwPsn_Wp_Plugin_Manager $pm) { $updateApiName = $pm->getConfig()->plugin->updateApi; switch ($updateApiName) { case 'woocommerce': require_once $pm->getPathinfo()->getRootLib() . 'IfwPsn/Wp/Plugin/Update/Api/WooCommerce.php'; $updateApi = new IfwPsn_Wp_Plugin_Update_Api_WooCommerce($pm, $pm->getConfig()->plugin->id); break; default: require_once $pm->getPathinfo()->getRootLib() . 'IfwPsn/Wp/Plugin/Update/Api/Envato.php'; $updateApi = new IfwPsn_Wp_Plugin_Update_Api_Envato($pm); } return $updateApi; }
/** * @param IfwPsn_Wp_Plugin_Manager $pm * @return IfwPsn_Wp_Plugin_Application */ public static function factory(IfwPsn_Wp_Plugin_Manager $pm) { // so far ZendFw is default // this should get refactored if other frameworks will be supported require_once $pm->getPathinfo()->getRootLib() . 'IfwPsn/Wp/Plugin/Application/Adapter/ZendFw.php'; return new self(new IfwPsn_Wp_Plugin_Application_Adapter_ZendFw($pm), $pm); }
/** * @param $module * @param $location * @param null $locationName * @return bool * @throws IfwPsn_Wp_Model_Exception * @throws IfwPsn_Wp_Module_Exception */ protected function _isValidModule($module, $location, $locationName = null) { // check for duplicate names if (!in_array($module, $this->_nameBuffer)) { array_push($this->_nameBuffer, $module); } else { $error = 'Module name already exists' . $module; if ($locationName == self::LOCATION_NAME_BUILTIN) { throw new IfwPsn_Wp_Model_Exception($error); } else { $this->_pm->getLogger()->err($error); } } // check for bootstrap class require_once $this->_pm->getPathinfo()->getRootLib() . '/IfwPsn/Wp/Module/Bootstrap/Abstract.php'; $path = $this->_getModuleBootstrapPath($module, $location); if (!file_exists($path)) { $this->_pm->getLogger()->err('Missing bootstrap class in module: ' . $module); return false; } require_once $path; if (!class_exists($this->_getModuleClassName($module))) { $error = 'Invalid module class found for module "' . $module . '". Expecting: ' . $this->_getModuleClassName($module); if ($locationName == self::LOCATION_NAME_BUILTIN) { throw new IfwPsn_Wp_Module_Exception($error); } else { $this->_pm->getLogger()->err($error); } } return true; }
/** * @param $updateData * @return mixed */ public function getUpdateData($updateData) { $plugin_slug = $this->_pm->getSlug(); if (!is_plugin_active($this->_pm->getSlugFilenamePath()) || !$this->_pm->isPremium() || !property_exists($updateData, 'checked') || empty($updateData->checked)) { return $updateData; } if (!empty($this->_pm->getConfig()->debug->update)) { $this->_pm->getLogger()->debug(' --- Update check data ' . $plugin_slug . ' --- '); $this->_pm->getLogger()->debug(var_export($updateData, true)); } // create request $request = $this->_getRequest(); $request->addData('action', 'plugin_update_check')->addData('slug', $plugin_slug)->addData('version', $updateData->checked[$this->_pm->getPathinfo()->getFilenamePath()])->addData('lang', IfwPsn_Wp_Proxy_Blog::getLanguage()); if ($this->_pm->isPremium()) { $license = $this->_getLicenseCode(); $request->addData('license', $license); } $response = $request->send(); if ($this->_pm->isPremium() && $response->isSuccess()) { $responseBody = $response->getBody(); $responseBody = unserialize($responseBody); if (!empty($this->_pm->getConfig()->debug->update)) { $this->_pm->getLogger()->debug('Update check response:'); $this->_pm->getLogger()->debug(var_export($responseBody, true)); } if (is_object($responseBody) && !empty($responseBody)) { // Feed the update data into WP updater $updateData->response[$this->_pm->getPathinfo()->getFilenamePath()] = $responseBody; } } return $updateData; }
/** * @return IfwPsn_Util_Version */ public function getPresentVersion() { if ($this->_presentVersion == null) { require_once $this->_pm->getPathinfo()->getRootLib() . 'IfwPsn/Util/Version.php'; $this->_presentVersion = new IfwPsn_Util_Version($this->_pm->getBootstrap()->getOptionsManager()->getOption('present_version')); } return $this->_presentVersion; }
/** * Redirects to controller/action * * @param string $controller * @param string|\unknown_type $action * @param string $page * @param array $extra * @return void */ protected function _gotoRoute($controller, $action = 'index', $page = null, $extra = array()) { if ($page == null) { $page = $this->_pm->getPathinfo()->getDirname(); } $urlOptions = array_merge(array($this->_pm->getConfig()->getControllerKey() => $controller, $this->_pm->getConfig()->getActionKey() => $action, 'page' => $page), $extra); $this->_redirector->gotoRoute($urlOptions, 'requestVars'); }
/** * Init custom router and plugins */ protected function _initPlugin() { if ($this->_pm->getAccess()->isPlugin()) { $this->bootstrap('FrontController'); $front = $this->getResource('FrontController'); // $front = IfwPsn_Zend_Controller_Front::getInstance(); // set custom router require_once $this->_pm->getPathinfo()->getRootLib() . 'IfwPsn/Zend/Controller/Router/WpRewrite.php'; $front->setRouter(new IfwPsn_Zend_Controller_Router_WpRewrite()); // launch the custom router to support request vars for controller / action $router = $front->getRouter(); require_once $this->_pm->getPathinfo()->getRootLib() . 'IfwPsn/Zend/Controller/Router/Route/RequestVars.php'; $router->addRoute('requestVars', new IfwPsn_Zend_Controller_Router_Route_RequestVars($this->_pm)); // launch the wp request dispatcher require_once $this->_pm->getPathinfo()->getRootLib() . 'IfwPsn/Zend/Controller/Plugin/WpRequestDispatcher.php'; $front->registerPlugin(new IfwPsn_Zend_Controller_Plugin_WpRequestDispatcher($this->_pm)); } }
/** * Checks if plugin translation files exist and inits the plugin textdomain * * @return bool */ protected function _initTranslation() { $result = false; if ($this->_pathinfo->hasRootLang()) { $langRelPath = $this->_pm->getPathinfo()->getDirname() . '/modules/' . $this->_pathinfo->getDirname() . '/lang'; $result = IfwPsn_Wp_Proxy::loadTextdomain($this->getTextDomain(), false, $langRelPath); } return $result; }
/** * @param IfwPsn_Wp_Plugin_Manager $pm * @param $controller * @param string $action * @param null $page * @param array $extra * @return string */ public static function getMenuUrl(IfwPsn_Wp_Plugin_Manager $pm, $controller, $action = 'index', $page = null, $extra = array()) { if ($page == null) { $page = $pm->getPathinfo()->getDirname(); } $urlOptions = array_merge(array($pm->getConfig()->getControllerKey() => $controller, $pm->getConfig()->getActionKey() => $action, 'page' => $page), $extra); $router = IfwPsn_Zend_Controller_Front::getInstance()->initRouter($pm)->getRouter(); return $router->assemble($urlOptions, 'requestVars'); }
/** * @param IfwPsn_Wp_Plugin_Manager|null $pm * @return mixed|void */ public static function execute($pm) { if (!$pm instanceof IfwPsn_Wp_Plugin_Manager) { return; } $logFilePath = $pm->getPathinfo()->getRoot() . 'log/plugin.log'; if (file_exists($logFilePath)) { unlink($logFilePath); } }
/** * Is access to a plugin admin page * * @return bool|null */ public function isPluginPage() { if ($this->_isPluginPage === null) { if (isset($_GET['page']) && (strpos($_GET['page'], $this->_pm->getPathinfo()->getDirname()) !== false || strpos($_GET['page'], $this->_pm->getAbbrLower()) !== false)) { $this->_isPluginPage = true; } else { $this->_isPluginPage = false; } } return $this->_isPluginPage; }
private function _applicationBootstrap() { if ($this->_pm->getAccess()->isPlugin() && $this->_pm->getPathinfo()->hasRootApplication() && !$this->_pm->getAccess()->isAjax()) { // it's an access to the plugin settings and no AJAX request // start the admin application ifw_raise_memory_limit(); require_once $this->_pm->getPathinfo()->getRootLib() . '/IfwPsn/Wp/Plugin/Application.php'; $this->_application = IfwPsn_Wp_Plugin_Application::factory($this->_pm); $this->_application->load(); } }
public function render() { require_once $this->_pm->getPathinfo()->getRootLib() . '/IfwPsn/Wp/Upload.php'; $uploader = new IfwPsn_Wp_Upload($this->_id); $uploader->setMimeTypes(array('zip' => 'application/zip', 'zip' => 'application/octet-stream')); echo '<div id="module_upload">'; if ($this->_extendingDocUrl != '') { echo '<div class="extending_doc_link"><a href="' . $this->_extendingDocUrl . '" target="_blank">' . sprintf(__('Learn how to extend %s', 'ifw'), $this->_pm->getAbbrUpper()) . '</a></div>'; } echo '<h3>' . __('Upload module', 'ifw') . '</h3>'; $uploader->displayForm($this->_optionsUrl); if ($uploader->isUploaded()) { if ($uploader->isSuccess()) { try { // handle the module archive $archive = new IfwPsn_Wp_Module_Archive($uploader->getFileInfo(), $this->_pm); if ($archive->isValid()) { $archive->extractTo($this->_pm->getBootstrap()->getModuleManager()->getCustomModulesLocation()); $archive->close(); } $this->_pm->getController()->getMessenger()->addMessage(__('Module installed.', 'ifw')); } catch (Exception $e) { $this->_pm->getController()->getMessenger()->addMessage($e->getMessage(), 'error'); } $uploader->remove(); } else { $this->_pm->getController()->getMessenger()->addMessage(__('Error', 'ifw') . ': ' . $uploader->getError(), 'error'); } $this->_pm->getController()->gotoRoute($this->getController(), $this->getAppaction(), $this->getPage()); } echo '</div>'; $tpl = IfwPsn_Wp_Tpl::getFilesytemInstance($this->_pm); $moduleManager = $this->_pm->getBootstrap()->getModuleManager(); $context = array('custom_modules' => $moduleManager->getCustomModules(), 'activate_url' => wp_nonce_url(admin_url($this->_optionsUrl), $this->_activateNonceName, $this->_activateActionName), 'deactivate_url' => wp_nonce_url(admin_url($this->_optionsUrl), $this->_deactivateNonceName, $this->_deactivateActionName), 'delete_url' => wp_nonce_url(admin_url($this->_optionsUrl), $this->_deleteNonceName, $this->_deleteActionName)); echo $tpl->render('module_frontend.html.twig', $context); }
/** * WP function * Handles default column handling if no custom method is provided * * @param array $item * @param string $column_name * @return string */ function column_default($item, $column_name) { require_once $this->_pm->getPathinfo()->getRootLib() . 'IfwPsn/Vendor/Zend/Filter/Word/UnderscoreToCamelCase.php'; $filter = new IfwPsn_Vendor_Zend_Filter_Word_UnderscoreToCamelCase(); $columnNameCamelCase = $filter->filter($column_name); $customColumnMethodName = 'getColumn' . $columnNameCamelCase; if (method_exists($this, $customColumnMethodName)) { // found a method for custom column handling, call it and pass the item return call_user_func(array($this, $customColumnMethodName), $item); } elseif (isset($item[$column_name])) { // print the value return $item[$column_name]; } else { return print_r($item, true); } }
/** * */ public function load() { // set tabbed options page renderer $this->_pm->getBootstrap()->getOptions()->setRenderer(new IfwPsn_Wp_Options_Renderer_Tabs($this->_pm)); require_once $this->_pm->getPathinfo()->getRootLib() . '/IfwPsn/Wp/Options/Section.php'; require_once $this->_pm->getPathinfo()->getRootLib() . '/IfwPsn/Wp/Options/Field/Checkbox.php'; require_once $this->_pm->getPathinfo()->getRootLib() . '/IfwPsn/Wp/Options/Field/Text.php'; require_once $this->_pm->getPathinfo()->getRootLib() . '/IfwPsn/Wp/Options/Field/Textarea.php'; require_once $this->_pm->getPathinfo()->getRootLib() . '/IfwPsn/Wp/Options/Field/Select.php'; $this->_addOptions(); }
/** * Retrieves the root UI theme directory (where all theme folders are) * * @param IfwPsn_Wp_Plugin_Manager $pm * @return string */ public static function getUiThemeRoot(IfwPsn_Wp_Plugin_Manager $pm) { return $pm->getPathinfo()->getRootCss() . 'jqueryui' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR; }
/** * @param IfwPsn_Wp_Plugin_Manager $pm * @param $function_to_add * @param int $priority * @return bool|void */ public static function addPluginActionLinks(IfwPsn_Wp_Plugin_Manager $pm, $function_to_add, $priority = 10) { return self::add('plugin_action_links_' . $pm->getPathinfo()->getFilenamePath(), $function_to_add, $priority, 2); }
public function init() { require_once $this->_pm->getPathinfo()->getRootLib() . '/IfwPsn/Wp/Proxy/Action.php'; IfwPsn_Wp_Proxy_Action::addAdminInit(array($this, 'register')); add_filter('pre_update_option_' . $this->_pageId, array($this, 'sanitizeFields'), 10, 2); }
/** * @param $navigation */ public function addRecipientsListsNav(IfwPsn_Vendor_Zend_Navigation $navigation) { $page = new IfwPsn_Zend_Navigation_Page_WpMvc(array('label' => __('Recipients lists', 'psn'), 'controller' => 'index', 'action' => 'adRecipientsLists', 'page' => $this->_pm->getPathinfo()->getDirname(), 'route' => 'requestVars')); $page->set('exactActiveMatch', true); $navigation->addPage($page); }
/** * Retrieves the direcotry where the plugin's widget class(es) reside * * @param IfwPsn_Wp_Plugin_Manager $pm * @return string */ public static function getWidgetDir(IfwPsn_Wp_Plugin_Manager $pm) { $widget_dir = $pm->getPathinfo()->getRootAdmin() . 'widget' . DIRECTORY_SEPARATOR; return $widget_dir; }
/** * load default services */ protected function _loadServices() { require_once $this->_pm->getPathinfo()->getRootLib() . 'Psn/Notification/Service/Email.php'; $this->addService(new Psn_Notification_Service_Email()); IfwPsn_Wp_Proxy_Action::doAction('psn_after_load_services', $this); }
/** * * @param IfwPsn_Wp_Plugin_Installer_UninstallInterface $uninstall */ public function addUninstall(IfwPsn_Wp_Plugin_Installer_UninstallInterface $uninstall) { array_push(self::$_uninstall[$this->_pm->getPathinfo()->getFilenamePath()], $uninstall); }