Ejemplo n.º 1
0
 /**
  * @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;
 }
Ejemplo n.º 2
0
 /**
  * Loads the application
  */
 public function load()
 {
     IfwPsn_Wp_Proxy_Action::doAction($this->_pm->getAbbrLower() . '_before_application_load', $this);
     $this->_pm->getLogger()->logPrefixed('Trying to load application...');
     $this->_adapter->load();
     IfwPsn_Wp_Proxy_Action::doAction($this->_pm->getAbbrLower() . '_after_application_load', $this);
 }
Ejemplo n.º 3
0
 protected function _init()
 {
     if (IfwPsn_Wp_Proxy_Screen::isLoadedCurrentScreen()) {
         $this->_pm->getLogger()->error('Screen option must be initialized before page load.');
     }
     $this->_type = $this->getType();
     IfwPsn_Wp_Proxy_Filter::addSetScreenOption(array($this, 'setScreenOptionCallback'), 10, 3);
     IfwPsn_Wp_Proxy_Action::addCurrentScreen(array($this, 'registerOption'));
 }
Ejemplo n.º 4
0
 /**
  * Inits admin navigation
  */
 public function initNavigation()
 {
     $this->_pm->getLogger()->logPrefixed('Init navigation.');
     require_once $this->_pm->getPathinfo()->getRootLib() . 'IfwPsn/Vendor/Zend/Navigation/Container.php';
     require_once $this->_pm->getPathinfo()->getRootLib() . 'IfwPsn/Vendor/Zend/Navigation.php';
     $this->_navigation = new IfwPsn_Vendor_Zend_Navigation();
     IfwPsn_Wp_Proxy_Action::doAction($this->_pm->getAbbrLower() . '_before_admin_navigation', $this->_navigation);
     $this->_loadNavigationPages();
     IfwPsn_Wp_Proxy_Action::doAction($this->_pm->getAbbrLower() . '_after_admin_navigation', $this->_navigation);
     $this->view->navigation = $this->_navigation;
 }
Ejemplo n.º 5
0
 /**
  *
  * @param IfwPsn_Vendor_Zend_Application $application
  */
 public function __construct($application)
 {
     $options = array('IfwPsn_Vendor_Zend_Application_Resource' => IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Application/Resource');
     $this->_pluginLoader = new IfwPsn_Vendor_Zend_Loader_PluginLoader($options);
     parent::__construct($application);
     $this->_pm = $this->getApplication()->getOption('pluginmanager');
     // init the custom front controller instance
     $this->_pm->getLogger()->logPrefixed('Initializing front controller.');
     $front = IfwPsn_Zend_Controller_Front::getInstance();
     IfwPsn_Vendor_Zend_Controller_Front::getInstance()->returnResponse(true);
     // set dispatcher
     require_once $this->_pm->getPathinfo()->getRootLib() . 'IfwPsn/Zend/Controller/Dispatcher/Wp.php';
     $dispatcher = new IfwPsn_Zend_Controller_Dispatcher_Wp($this->_pm);
     IfwPsn_Vendor_Zend_Controller_Front::getInstance()->setDispatcher($dispatcher);
 }
Ejemplo n.º 6
0
 /**
  * @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;
 }
Ejemplo n.º 7
0
 /**
  * @param $def
  * @param $action
  * @param $args
  * @return bool|mixed|WP_Error
  */
 public function getPluginInfo($def, $action, $args)
 {
     $result = '';
     $plugin_slug = $this->_pm->getPathinfo()->getDirname();
     if (!isset($args->slug) || $args->slug != $plugin_slug) {
         return false;
     }
     // Get the current version
     $plugin_info = get_site_transient('update_plugins');
     if (!empty($this->_pm->getConfig()->debug->update)) {
         $this->_pm->getLogger()->debug('Plugin info check:');
         $this->_pm->getLogger()->debug(var_export($plugin_info, true));
     }
     $current_version = $plugin_info->checked[$this->_pm->getPathinfo()->getFilenamePath()];
     require_once $this->_pm->getPathinfo()->getRootLib() . 'IfwPsn/Wp/Plugin/Update/Request.php';
     if (class_exists('IfwPsn_Wp_Plugin_Update_Request')) {
         $request = new IfwPsn_Wp_Plugin_Update_Request($this->_pm);
         $request->setAction($action)->addData('slug', $plugin_slug)->addData('version', $current_version)->addData('license', $this->_pm->getOptionsManager()->getOption('license_code'))->addData('lang', IfwPsn_Wp_Proxy_Blog::getLanguage());
         $response = $request->send();
         if ($response->isSuccess()) {
             $responseBody = $response->getBody();
             $result = unserialize($responseBody);
             if ($result === false) {
                 $result = new WP_Error('plugins_api_failed', __('An unknown error occurred'), $request['body']);
             }
         } else {
             $result = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.</p> <p><a href="javascript:void(0)" onclick="document.location.reload(); return false;">Try again</a>'), $response->getErrorMessage());
         }
         if (!empty($this->_pm->getConfig()->debug->update)) {
             $this->_pm->getLogger()->debug(' --- Plugin info check response --- ');
             $this->_pm->getLogger()->debug(var_export($response, true));
         }
     }
     return $result;
 }
Ejemplo n.º 8
0
 /**
  * 
  */
 protected function _debugPathinfo()
 {
     // check for pathinfo logging
     if ($this->_config->debug->pathinfo) {
         $this->_pluginPathinfo->setLogger($this->_pm->getLogger());
         $this->_pluginPathinfo->__toString();
     }
 }
Ejemplo n.º 9
0
 public function errorAction()
 {
     $this->view->pm = $this->_pm;
     $errors = $this->_getParam('error_handler');
     if (!$errors || !$errors instanceof ArrayObject) {
         $this->view->message = __('You have reached the error page', 'ifw');
         return;
     }
     switch ($errors->type) {
         case IfwPsn_Vendor_Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
         case IfwPsn_Vendor_Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
         case IfwPsn_Vendor_Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
             // 404 error -- controller or action not found
             // $this->getResponse()->setHttpResponseCode(404);
             $priority = IfwPsn_Vendor_Zend_Log::NOTICE;
             $this->view->message = __('Page not found', 'ifw');
             break;
         default:
             // application error
             // $this->getResponse()->setHttpResponseCode(500);
             $priority = IfwPsn_Vendor_Zend_Log::CRIT;
             $this->view->message = __('Application error', 'ifw');
             break;
     }
     // Log exception
     $this->_pm->getLogger()->error($this->view->message);
     $this->_pm->getLogger()->error($errors->exception->getMessage());
     if ($this->getInvokeArg('displayExceptions') == true) {
         $this->view->exception = $errors->exception;
     }
     $this->view->request = $errors->request;
     $this->view->exception = $errors->exception;
     // conditionally display exceptions in dev env
     $this->view->displayExceptions = $this->getInvokeArg('displayExceptions');
     $this->view->langHeadline = __('An error occurred', 'ifw');
 }
Ejemplo n.º 10
0
 /**
  * @param Exception $e
  */
 protected function _handleException(Exception $e)
 {
     $this->_pm->getLogger()->error($e->getMessage());
     $request = IfwPsn_Zend_Controller_Front::getInstance()->getRequest();
     // Repoint the request to the default error handler
     //        $request->setModuleName('default');
     //        $request->setControllerName('Psn-ewrror');
     //        $request->setActionName('error');
     // Set up the error handler
     $error = new IfwPsn_Vendor_Zend_Controller_Plugin_ErrorHandler(array('controller' => $this->_pm->getAbbrLower() . '-error'));
     $error->type = IfwPsn_Vendor_Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER;
     if (is_object($request)) {
         $error->request = clone $request;
     }
     $error->exception = $e;
     $request->setParam('error_handler', $error);
 }
Ejemplo n.º 11
0
 /**
  * @param $updateData
  * @return mixed
  */
 public function getUpdateData($updateData)
 {
     // slug
     $pluginSlug = $this->_pm->getSlugFilenamePath();
     if (!is_plugin_active($pluginSlug) || !$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 ' . $pluginSlug . ' --- ');
         $this->_pm->getLogger()->debug(var_export($updateData, true));
     }
     if ((!property_exists($updateData, 'checked') || empty($updateData->checked)) && (int) $this->_pm->getConfig()->plugin->updateTest == 0) {
         return $updateData;
     }
     if (apply_filters('ifw_woocommerce_is_slug_activated-' . $pluginSlug, false)) {
         $activationData = apply_filters('ifw_woocommerce_get_activation_data-' . $pluginSlug, array());
         $localVersion = $updateData->checked[$pluginSlug];
         $request = $this->_getRequest('upgrade-api');
         if ($request instanceof IfwPsn_Wp_Http_Request) {
             $request->addData('request', 'pluginupdatecheck')->addData('plugin_name', $pluginSlug)->addData('version', $localVersion)->addData('software_version', $localVersion)->addData('activation_email', $activationData['email'])->addData('api_key', $activationData['license'])->addData('domain', $this->_getPlatform())->addData('instance', $this->_getInstance($activationData['license'], $activationData['email']));
         }
         $response = $request->send();
         if ($response->isSuccess()) {
             $responseBody = $response->getBody();
             $remoteData = unserialize($responseBody);
             if (!empty($this->_pm->getConfig()->debug->update)) {
                 $this->_pm->getLogger()->debug('Update check response:');
                 $this->_pm->getLogger()->debug(var_export($remoteData, true));
             }
             if (is_object($remoteData) && !empty($remoteData) && isset($remoteData->new_version) && !empty($remoteData->new_version)) {
                 $remoteVersion = new IfwPsn_Util_Version((string) $remoteData->new_version);
                 if ($remoteVersion->isGreaterThan($localVersion)) {
                     // Feed the update data into WP updater
                     $updateData->response[$pluginSlug] = $remoteData;
                 }
             }
         }
     }
     return $updateData;
 }
Ejemplo n.º 12
0
 /**
  * Dispatch to a controller/action
  *
  * By default, if a controller is not dispatchable, dispatch() will throw
  * an exception. If you wish to use the default controller instead, set the
  * param 'useDefaultControllerAlways' via {@link setParam()}.
  *
  * @param IfwPsn_Vendor_Zend_Controller_Request_Abstract $request
  * @param IfwPsn_Vendor_Zend_Controller_Response_Abstract $response
  * @throws IfwPsn_Vendor_Zend_Controller_Dispatcher_Exception
  * @throws Exception
  * @return void
  */
 public function dispatch(IfwPsn_Vendor_Zend_Controller_Request_Abstract $request, IfwPsn_Vendor_Zend_Controller_Response_Abstract $response)
 {
     $this->setResponse($response);
     if (!$this->_controller instanceof IfwPsn_Vendor_Zend_Controller_Action_Interface or !strpos(strtolower($request->getControllerName()), strtolower($request->get('controller')))) {
         // if controller is not initialized by initController already or on error/excption
         /**
          * Get controller class
          */
         if (!$this->isDispatchable($request)) {
             $controller = $request->getControllerName();
             if (!$this->getParam('useDefaultControllerAlways') && !empty($controller)) {
                 //require_once 'IfwZend/Controller/Dispatcher/Exception.php';
                 throw new IfwPsn_Vendor_Zend_Controller_Dispatcher_Exception('Invalid controller specified (' . $request->getControllerName() . ')');
             }
             $className = $this->getDefaultControllerClass($request);
         } else {
             $className = $this->getControllerClass($request);
             if (!$className) {
                 $className = $this->getDefaultControllerClass($request);
             }
         }
         /**
          * Load the controller class file
          */
         $className = $this->loadClass($className);
         /**
          * Instantiate controller with request, response, and invocation
          * arguments; throw exception if it's not an action controller
          */
         $this->_controller = new $className($request, $this->getResponse(), $this->getParams());
         if (!$this->_controller instanceof IfwPsn_Vendor_Zend_Controller_Action_Interface && !$this->_controller instanceof IfwPsn_Vendor_Zend_Controller_Action) {
             //require_once 'IfwZend/Controller/Dispatcher/Exception.php';
             throw new IfwPsn_Vendor_Zend_Controller_Dispatcher_Exception('Controller "' . $className . '" is not an instance of IfwPsn_Vendor_Zend_Controller_Action_Interface');
         }
     }
     /**
      * Retrieve the action name
      */
     $action = $this->getActionMethod($request);
     /**
      * Dispatch the method call
      */
     $request->setDispatched(true);
     // by default, buffer output
     $disableOb = $this->getParam('disableOutputBuffering');
     $obLevel = ob_get_level();
     if (empty($disableOb)) {
         ob_start();
     }
     try {
         $this->_pm->getLogger()->logPrefixed(sprintf('Dispatching action %s on controller %s', $action, get_class($this->_controller)));
         $this->_controller->dispatch($action);
     } catch (Exception $e) {
         // Clean output buffer on error
         $curObLevel = ob_get_level();
         if ($curObLevel > $obLevel) {
             do {
                 ob_get_clean();
                 $curObLevel = ob_get_level();
             } while ($curObLevel > $obLevel);
         }
         throw $e;
     }
     if (empty($disableOb)) {
         $content = ob_get_clean();
         $response->appendBody($content);
     }
     // Destroy the page controller instance and reflection objects
     $this->_controller = null;
 }