/** * @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; }
/** * @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')); } } }
/** * @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 string $docUrl * @return string */ protected function _getHelpSidebar($docUrl = '') { $sidebar = '<p><b>' . __('For more information:', 'ifw') . '</b></p>'; $sidebar .= sprintf('<p><a href="%s" target="_blank">' . __('Plugin homepage', 'ifw') . '</a></p>', $this->_pm->getEnv()->getHomepage()); if (!empty($this->_pm->getConfig()->plugin->docUrl)) { $sidebar .= sprintf('<p><a href="%s" target="_blank">' . __('Documentation', 'ifw') . '</a></p>', $this->_pm->getConfig()->plugin->docUrl . $docUrl); } return $sidebar; }
protected function _addHelpBlock() { $content = ''; if (!empty($this->_pm->getConfig()->plugin->docUrl)) { $content .= sprintf(__('Read the <a href="%s" target="_blank">plugin documentation</a>', 'ifw'), $this->_pm->getConfig()->plugin->docUrl) . '<br>'; } if (!empty($this->_pm->getConfig()->plugin->faqUrl)) { $content .= sprintf(__('Check the <a href="%s" target="_blank">FAQ</a>', 'ifw'), $this->_pm->getConfig()->plugin->faqUrl) . '<br>'; } $content = strtr($content, array('target="_blank"' => 'target="_blank" class="ifw-external-link"')); $this->addBlock('help', __('Need help?', 'ifw'), '<br>' . $content, 'help'); }
/** * @return IfwPsn_Wp_Http_Request */ protected function _getRequest() { if ($this->_request === null) { $this->_request = new IfwPsn_Wp_Http_Request(); $this->_request->setUrl($this->_pm->getConfig()->plugin->updateServer); $this->_request->addData('api-key', md5(IfwPsn_Wp_Proxy_Blog::getUrl())); $this->_request->addData('referrer', IfwPsn_Wp_Proxy_Blog::getUrl()); if (isset($_SERVER['HTTP_USER_AGENT'])) { $this->_request->addData('browser_user_agent', $_SERVER['HTTP_USER_AGENT']); } } return $this->_request; }
/** * Loads the modules after preBootstrap objects are initialized */ private function _moduleBootstrap() { require_once $this->_pm->getPathinfo()->getRootLib() . 'IfwPsn/Wp/Module/Manager.php'; $this->_moduleManager = new IfwPsn_Wp_Module_Manager($this->_pm); IfwPsn_Wp_Proxy_Action::doPlugin($this->_pm, 'before_modules_load', $this->_moduleManager); $pluginConfig = $this->_pm->getConfig()->plugin; if (!isset($pluginConfig->simulateLiteVersion) || empty($pluginConfig->simulateLiteVersion)) { $this->_moduleManager->load(); } $this->_notifyObservers(self::OBSERVER_POST_MODULES); // register module controller path before controller init IfwPsn_Wp_Proxy_Action::addPlugin($this->_pm, 'before_controller_init', array($this->_moduleManager, 'registerModules')); }
/** * @return IfwPsn_Wp_Http_Request */ protected function _getRequest($endpoint = 'am-software-api') { $result = null; if ($this->_isAllowedEndpoint($endpoint)) { $url = $this->_pm->getConfig()->plugin->updateServer; $url = add_query_arg('wc-api', $endpoint, $url); $url = esc_url_raw($url); $request = new IfwPsn_Wp_Http_Request(); $request->setSendMethod('get'); $request->setUrl($url); $request->addData('product_id', $this->_getProductId()); $result = $request; } return $result; }
/** * Fires at the end of the update message container in each row of the plugins list table. * * @param array $plugin_data An array of plugin data. * @param $meta_data */ public function onPluginUpdateMessage($plugin_data, $meta_data) { $plugin_slug = $this->_pm->getPathinfo()->getDirname(); $request = new IfwPsn_Wp_Plugin_Update_Request($this->_pm); $request->setAction('plugin_update_message')->addData('slug', $plugin_slug)->addData('version', $plugin_data['Version'])->addData('lang', IfwPsn_Wp_Proxy_Blog::getLanguage()); if ($this->_pm->isPremium()) { $license = $this->_pm->getOptionsManager()->getOption('license_code'); $request->addData('license', $license); } $response = $request->send(); if ($response->isSuccess()) { if ($this->_pm->isPremium() && empty($license)) { printf('<div style="padding: 5px 10px; border: 1px dashed red; margin-top: 10px;">%s</div>', sprintf(__('You have to enter your plugin <b>license code</b> in the <a href="%s">plugin options</a> to be able to download this update!', 'ifw'), $this->_pm->getConfig()->plugin->optionsPage)); } echo $response->getBody(); } }
/** * Assembles a URL path defined by this route * * @param array $data An array of variable and value pairs used as parameters * @param bool $reset * @param bool $encode * @return string Route path with user submitted parameters */ public function assemble($data = array(), $reset = false, $encode = false) { $frontController = IfwPsn_Vendor_Zend_Controller_Front::getInstance(); if (!array_key_exists('mod', $data) && !$reset && array_key_exists('mod', $this->_current) && $this->_current['mod'] != $frontController->getDefaultModule()) { $data = array_merge(array('mod' => $this->_current['mod']), $data); } if (!array_key_exists('controller', $data) && !$reset && array_key_exists('controller', $this->_current) && $this->_current['controller'] != $frontController->getDefaultControllerName()) { $data = array_merge(array('controller' => $this->_current['controller']), $data); } if (!array_key_exists('action', $data) && !$reset && array_key_exists('action', $this->_current) && $this->_current['action'] != $frontController->getDefaultAction()) { $data = array_merge(array('action' => $this->_current['action']), $data); } if (!empty($data)) { $querydata = array(); if (isset($data['page'])) { $url = IfwPsn_Wp_Proxy_Admin::getOptionsBaseUrl(); $querydata['page'] = $data['page']; unset($data['page']); } elseif (isset($data['adminpage'])) { $url = IfwPsn_Wp_Proxy_Admin::getAdminPageBaseUrl(); $querydata['page'] = $data['adminpage']; unset($data['adminpage']); } elseif (isset($data['editpage'])) { $url = 'edit.php'; if (isset($data['posttype'])) { $querydata['post_type'] = $data['posttype']; unset($data['posttype']); } $querydata['page'] = $data['editpage']; unset($data['editpage']); } if (isset($data['module'])) { $querydata['mod'] = $data['module']; unset($data['module']); } if (isset($data['action'])) { $querydata[$this->_pm->getConfig()->getActionKey()] = $data['action']; unset($data['action']); } $querydata = array_merge($querydata, $data); $url .= '?' . http_build_query($querydata, '', '&'); } return $url; }
/** * @param IfwPsn_Vendor_Zend_Controller_Request_Abstract $request * @param IfwPsn_Vendor_Zend_Controller_Response_Abstract $response * @throws Exception */ public function initController(IfwPsn_Wp_Plugin_Manager $pm, IfwPsn_Vendor_Zend_Controller_Request_Abstract $request = null, IfwPsn_Vendor_Zend_Controller_Response_Abstract $response = null) { if (!$this->getParam('noErrorHandler') && !$this->_plugins->hasPlugin('IfwPsn_Vendor_Zend_Controller_Plugin_ErrorHandler')) { // Register with stack index of 100 //require_once 'IfwZend/Controller/Plugin/ErrorHandler.php'; $this->_plugins->registerPlugin(new IfwPsn_Vendor_Zend_Controller_Plugin_ErrorHandler(), 100); } if (!$this->getParam('noViewRenderer') && !IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::hasHelper('viewRenderer')) { //require_once 'IfwZend/Controller/Action/Helper/ViewRenderer.php'; IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStack()->offsetSet(-80, new IfwPsn_Vendor_Zend_Controller_Action_Helper_ViewRenderer()); } /** * Instantiate default request object (HTTP version) if none provided */ if (null !== $request) { $this->setRequest($request); } elseif (null === $request && null === ($request = $this->getRequest())) { //require_once 'IfwZend/Controller/Request/Http.php'; $request = new IfwPsn_Vendor_Zend_Controller_Request_Http(); $this->setRequest($request); } $request->setActionKey($pm->getConfig()->getActionKey()); /** * Set base URL of request object, if available */ if (is_callable(array($this->_request, 'setBaseUrl'))) { if (null !== $this->_baseUrl) { $this->_request->setBaseUrl($this->_baseUrl); } } /** * Instantiate default response object (HTTP version) if none provided */ if (null !== $response) { $this->setResponse($response); } elseif (null === $this->_response && null === ($this->_response = $this->getResponse())) { //require_once 'IfwZend/Controller/Response/Http.php'; $response = new IfwPsn_Vendor_Zend_Controller_Response_Http(); $this->setResponse($response); } //IfwPsn_Wp_Proxy_Action::doPlugin($pm, 'before_controller_init', $this); /** * Register request and response objects with plugin broker */ $this->_plugins->setRequest($this->_request)->setResponse($this->_response); IfwPsn_Wp_Proxy_Action::doPlugin($pm, 'before_controller_init', $this); /** * Initialize router */ $router = $this->getRouter(); $router->setParams($this->getParams()); /** * Initialize dispatcher */ $dispatcher = $this->getDispatcher(); $dispatcher->setParams($this->getParams())->setResponse($this->_response); // Begin dispatch try { /** * Route request to controller/action, if a router is provided */ /** * Notify plugins of router startup */ $this->_plugins->routeStartup($this->_request); try { $router->route($this->_request); } catch (Exception $e) { throw $e; } /** * Needed for custom route RequestVars */ $this->_plugins->routeShutdown($this->_request); /** * skip plugins dispatchLoopStartup on initController */ //$this->_plugins->dispatchLoopStartup($this->_request); /** * Attempt to dispatch the controller/action. If the $this->_request * indicates that it needs to be dispatched, move to the next * action in the request. */ do { $this->_request->setDispatched(true); /** * skip plugins preDispatch on initController */ $this->_plugins->preDispatch($this->_request); /** * Skip requested action if preDispatch() has reset it */ //if (!$this->_request->isDispatched()) { // continue; //} /** * init controller */ try { // this will add custom WP action to the controller object $dispatcher->initController($this->_request, $this->_response); } catch (Exception $e) { throw $e; } /** * skip plugins postDispatch on initController */ //$this->_plugins->postDispatch($this->_request); } while (!$this->_request->isDispatched()); } catch (Exception $e) { throw $e; } }
/** * @param IfwPsn_Wp_Plugin_Manager $pm * @param $controller * @param string $action * @param null $page * @param array $extra * @return string */ public static function getAdminPageUrl(IfwPsn_Wp_Plugin_Manager $pm, $page, $controller, $action = 'index', $extra = array()) { $urlOptions = array_merge(array($pm->getConfig()->getControllerKey() => $controller, $pm->getConfig()->getActionKey() => $action, 'adminpage' => $page), $extra); $router = IfwPsn_Zend_Controller_Front::getInstance()->initRouter($pm)->getRouter(); return $router->assemble($urlOptions, 'requestVars'); }
/** * Gets the error message * @return mixed */ public function getErrorMessage() { return sprintf(__('Your WordPress version is not supported. Please upgrade to at least version %s', 'ifw'), $this->_pm->getConfig()->plugin->wpMinVersion); }
/** * @return string|null */ public function getAction() { $key = $this->_pm->getConfig()->application->action->key; return isset($_GET[$key]) ? $_GET[$key] : null; }
/** * Resets the error reporting to default in dev mode */ public function disableErrorReporting() { if ($this->_pm->getEnv()->getEnvironmet() == 'development' || $this->_pm->getConfig()->debug->show_errors == '1') { error_reporting($this->_errorReportingLevel); } }