Esempio n. 1
0
 /**
  * Retrieves singleton IfwPsn_Wp_Proxy object
  * @param IfwPsn_Wp_Plugin_Manager $pm
  * @return IfwPsn_Wp_Proxy
  */
 public static function getInstance(IfwPsn_Wp_Plugin_Manager $pm)
 {
     if (!isset(self::$_instances[$pm->getAbbr()])) {
         self::$_instances[$pm->getAbbr()] = new self($pm);
     }
     return self::$_instances[$pm->getAbbr()];
 }
Esempio n. 2
0
 /**
  * @param IfwPsn_Wp_Plugin_Manager $pm
  */
 protected static function _loadCliCommand($command, IfwPsn_Wp_Plugin_Manager $pm)
 {
     $headline = '### %s %s CLI ###' . PHP_EOL . PHP_EOL;
     printf($headline, $pm->getEnv()->getName(), $pm->getEnv()->getVersion());
     $args = $_SERVER['argv'];
     $args = array_slice($args, 2);
     $executable = 'script';
     if ($pm->getEnv()->isWindows()) {
         $executable .= '.bat';
     } else {
         $executable .= '.sh';
     }
     try {
         // try to execute a command
         $cliCommand = IfwPsn_Wp_Plugin_Cli_Factory::getCommand($command, $args, $pm);
         $cliCommand->setExecutable($executable);
         // load the cli command after WP is completely loaded
         add_action('wp_loaded', array($cliCommand, 'execute'));
     } catch (IfwPsn_Wp_Plugin_Cli_Factory_Exception $e) {
         echo 'Initialization error: ' . $e->getMessage();
     } catch (IfwPsn_Wp_Plugin_Cli_Command_Exception_MissingOperand $e) {
         // fetch MissingOperand exception
         echo $executable . ' ' . $command . ': missing operand';
         echo PHP_EOL;
         echo $e->getMessage();
     } catch (IfwPsn_Wp_Plugin_Cli_Exception $e) {
         // fetch generell cli exception
         echo $e->getMessage();
     }
 }
Esempio n. 3
0
 /**
  * Handles options presetting on first install / activation
  * @param IfwPsn_Wp_Plugin_Manager $pm
  */
 protected function _presetOptions(IfwPsn_Wp_Plugin_Manager $pm)
 {
     if (!$pm->hasOption('selftest_timestamp')) {
         // on first install (no selftest timestam could be found)
         $pm->getOptions()->updateOption('psn_ignore_status_inherit', true);
     }
 }
Esempio n. 4
0
 /**
  * @param IfwPsn_Wp_Plugin_Manager $pm
  */
 public static function load(IfwPsn_Wp_Plugin_Manager $pm)
 {
     if (!$pm->getEnv()->isCli()) {
         // die if not command line accessed
         die('Invalid access');
     }
     $args = $_SERVER['argv'];
     $command = $args[1];
     $args = array_slice($args, 2);
     $executable = 'script';
     if ($pm->getEnv()->isWindows()) {
         $executable .= '.bat';
     } else {
         $executable .= '.sh';
     }
     try {
         // try to execute a command
         $cliCommand = IfwPsn_Wp_Plugin_Cli_Factory::getCommand($command, $args, $pm);
         $cliCommand->setExecutable($executable);
         $cliCommand->execute();
     } catch (IfwPsn_Wp_Plugin_Cli_Factory_Exception $e) {
         echo 'Initialization error: ' . $e->getMessage();
     } catch (IfwPsn_Wp_Plugin_Cli_Command_Exception_MissingOperand $e) {
         // fetch MissingOperand exception
         echo $executable . ' ' . $command . ': missing operand';
         echo PHP_EOL;
         echo $e->getMessage();
     } catch (IfwPsn_Wp_Plugin_Cli_Exception $e) {
         // fetch generell cli exception
         echo $e->getMessage();
     }
 }
Esempio n. 5
0
 /**
  * @return bool
  */
 public function isPatchesAvailable()
 {
     if ($this->_presentVersion->isLessThan($this->_pm->getEnv()->getVersion()) && $this->hasPatches()) {
         return true;
     }
     return false;
 }
Esempio n. 6
0
 /**
  * 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'));
 }
Esempio n. 7
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);
 }
Esempio n. 8
0
 /**
  * @param IfwPsn_Wp_Plugin_Manager $pm
  */
 public function __construct(IfwPsn_Wp_Plugin_Manager $pm)
 {
     $this->_pm = $pm;
     if (method_exists($this, '_init')) {
         $this->_init();
     }
     do_action($this->_pm->getAbbrLower() . '_add_feature', $this);
 }
Esempio n. 9
0
 /**
  * @param IfwPsn_Wp_Plugin_Manager $pm
  */
 protected static function _dropTable($pm)
 {
     global $wpdb;
     if ($pm->isPremium() || !$pm->isPremium() && !IfwPsn_Wp_Proxy_Blog::isPluginActive('post-status-notifier/post-status-notifier.php')) {
         // only delete rules table if it's the Premium version
         // or it's the Lite version and the Premium version is not activated
         $wpdb->query('DROP TABLE IF EXISTS `' . $wpdb->prefix . 'psn_rules`');
     }
 }
Esempio n. 10
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'));
 }
Esempio n. 11
0
 /**
  * Loads the menu
  */
 public function _load()
 {
     IfwPsn_Wp_Proxy_Action::doPlugin($this->_pm, 'before_load_options_page', $this);
     $this->_pageHook = add_options_page($this->getPageTitle(), $this->getMenuTitle(), $this->getCapability(), $this->getSlug(), array($this, 'handle'));
     IfwPsn_Wp_Proxy_Action::doPlugin($this->_pm, 'after_load_options_page', $this);
     if ($this->_pm->getAccess()->getPage() == $this->getSlug()) {
         $this->onLoad();
     }
 }
Esempio n. 12
0
 /**
  * (non-PHPdoc)
  * @see WP_Widget::widget()
  */
 public function widget($args, $instance)
 {
     echo $args['before_widget'];
     try {
         $this->_displayWidget($args, $instance);
     } catch (Exception $e) {
         $this->_pm->handleException($e);
     }
     echo $args['after_widget'];
 }
Esempio n. 13
0
 /**
  * @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);
     }
 }
Esempio n. 14
0
 /**
  * @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;
 }
Esempio n. 15
0
 /**
  * @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;
 }
Esempio n. 16
0
 /**
  * Loads the menu
  */
 public function _load()
 {
     if ($this->isIsMultisite()) {
         IfwPsn_Wp_Proxy_Action::doPlugin($this->_pm, 'before_load_multisite_menu_page', $this);
     } else {
         IfwPsn_Wp_Proxy_Action::doPlugin($this->_pm, 'before_load_menu_page', $this);
     }
     $this->_pageHook = add_menu_page($this->getPageTitle(), $this->getMenuTitle(), $this->getCapability(), $this->getSlug(), array($this, 'handle'), $this->getIconUrl(), $this->getPosition());
     /**
      * @var IfwPsn_Wp_Plugin_Menu_Page_Sub $subPage
      */
     foreach ($this->getSubPagesSorted() as $subPage) {
         $this->_triggerAction('before_load_submenu_page');
         if ($subPage->isHidden()) {
             global $_registered_pages;
             $hookname = get_plugin_page_hookname(plugin_basename($subPage->getSlug()), $subPage->getSlug());
             add_action($hookname, array($subPage, 'handle'));
             $subPage->setPageHook($hookname);
             $_registered_pages[$hookname] = true;
         } else {
             $subPageHook = add_submenu_page($this->getSlug(), $subPage->getPageTitle(), $subPage->getMenuTitle(), $subPage->getCapability(), $subPage->getSlug(), array($subPage, 'handle'));
             $subPage->setPageHook($subPageHook);
         }
         $this->_triggerAction('after_load_submenu_page');
         if ($this->_pm->getAccess()->getPage() == $subPage->getSlug()) {
             $subPage->onLoad();
         }
     }
     $this->_triggerAction('after_load_menu_page');
     if ($this->_pm->getAccess()->getPage() == $this->getSlug()) {
         $this->onLoad();
     }
 }
Esempio n. 17
0
 /**
  * Loads js/css on admin_enqueue_scripts
  */
 protected function _enqueueScripts()
 {
     if ($this->_pm->getAccess()->isModule(strtolower($this->getName()))) {
         $this->_loadAdminCss();
         $this->_loadAdminJs();
     }
 }
Esempio n. 18
0
 /**
  * @return bool
  */
 protected function _skipAutorun()
 {
     if ($this->_pm->getBootstrap()->getUpdateManager()->getPatcher()->isPatchesAvailable()) {
         return true;
     }
     return false;
 }
Esempio n. 19
0
 /**
  * @param $id
  * @return mixed|null
  */
 public function getOption($id)
 {
     if ($this->hasOption($id)) {
         $options = IfwPsn_Wp_Proxy::getOption($this->_pm->getOptions()->getPageId());
         return $options[$this->_pm->getOptions()->getOptionRealId($id)];
     }
     return null;
 }
Esempio n. 20
0
 /**
  * 
  */
 protected function _debugPathinfo()
 {
     // check for pathinfo logging
     if ($this->_config->debug->pathinfo) {
         $this->_pluginPathinfo->setLogger($this->_pm->getLogger());
         $this->_pluginPathinfo->__toString();
     }
 }
Esempio n. 21
0
 /**
  * @param IfwPsn_Wp_Plugin_Manager|null $pm
  * @return mixed|void
  */
 public static function execute($pm)
 {
     if (!$pm instanceof IfwPsn_Wp_Plugin_Manager) {
         return;
     }
     if (IfwPsn_Wp_Proxy_Blog::isMultisite()) {
         // multisite installation
         $currentBlogId = IfwPsn_Wp_Proxy_Blog::getBlogId();
         foreach (IfwPsn_Wp_Proxy_Blog::getMultisiteBlogIds() as $blogId) {
             IfwPsn_Wp_Proxy_Blog::switchToBlog($blogId);
             $pm->getOptions()->reset();
         }
         IfwPsn_Wp_Proxy_Blog::switchToBlog($currentBlogId);
     } else {
         // single blog installation
         $pm->getOptions()->reset();
     }
 }
Esempio n. 22
0
 /**
  * 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));
     }
 }
Esempio n. 23
0
 /**
  * @param $body
  * @param Psn_Notification_Service_Email $email
  * @return string
  */
 public function filterEmailBody($body, Psn_Notification_Service_Email $email)
 {
     $body = $this->_handleSpecialChars($body);
     if (!$this->_pm->isPremium()) {
         // please respect my work and buy the premium version if you want this plugin to stay alive!
         $body .= PHP_EOL . PHP_EOL . sprintf(__('This email was sent by WordPress plugin "%s". Visit the plugin homepage: %s'), $this->_pm->getEnv()->getName(), $this->_pm->getEnv()->getHomepage());
     }
     return $body;
 }
Esempio n. 24
0
 /**
  * Fetch a post on save / update and store it for later processing
  *
  * @param $post_ID
  * @param $post
  * @param $update
  */
 public function fetchPostOnInsert($post_ID, $post, $update = null)
 {
     // fetch post
     $this->_post = $post;
     if (IfwPsn_Wp_Plugin_Manager::getInstance('Psn')->hasOption('psn_late_execution')) {
         // register container execution for shutdown action
         IfwPsn_Wp_Proxy_Action::add('shutdown', array($this, 'execute'));
     } else {
         $this->execute();
     }
 }
Esempio n. 25
0
 /**
  * @return IfwPsn_Wp_Ajax_Response_Abstract
  */
 public function getResponse()
 {
     $listTable = new Psn_Admin_ListTable_Rules(IfwPsn_Wp_Plugin_Manager::getInstance('Psn'), array('metabox_embedded' => true, 'ajax' => true));
     if (isset($_POST['refresh_rows'])) {
         $html = $listTable->ajax_response();
     } else {
         $html = '<p><a href="' . IfwPsn_Wp_Proxy_Admin::getUrl() . IfwPsn_Wp_Proxy_Admin::getMenuUrl(IfwPsn_Wp_Plugin_Manager::getInstance('Psn'), 'rules', 'create') . '" class="ifw-wp-icon-plus" id="link_create_rule">' . __('Create new rule', 'psn') . '</a></p>';
         $html .= $listTable->fetch();
     }
     return new IfwPsn_Wp_Ajax_Response_Json(true, array('html' => $html));
 }
Esempio n. 26
0
 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');
 }
Esempio n. 27
0
 /**
  * @return bool
  * @throws IfwPsn_Wp_Module_Exception
  */
 public function isValid()
 {
     if (!$this->hasBootstrap()) {
         throw new IfwPsn_Wp_Module_Exception('Bootstrap file not found.');
     }
     $expectedClassname = $this->getDirname() . '_Bootstrap';
     $bootstrap = $this->getBootstrap();
     if (!in_array($expectedClassname, $this->_getClasses($bootstrap))) {
         throw new IfwPsn_Wp_Module_Exception('Bootstrap class is not valid. Expected: ' . $expectedClassname);
     }
     if (strstr(get_class($this), 'IfwPsn_') === false) {
         $classHeaderFormat = 'class %s extends Ifw' . $this->_pm->getAbbr() . '_Wp_Module_Bootstrap_Abstract';
     } else {
         $classHeaderFormat = 'class %s extends IfwPsn_Wp_Module_Bootstrap_Abstract';
     }
     $expectedClassHeader = sprintf($classHeaderFormat, $expectedClassname);
     if (strstr($bootstrap, $expectedClassHeader) === false) {
         throw new IfwPsn_Wp_Module_Exception('Bootstrap class header is not valid. Expected: "' . $expectedClassHeader . '"');
     }
     return true;
 }
Esempio n. 28
0
 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);
 }
Esempio n. 29
0
 /**
  * @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;
 }
Esempio n. 30
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');
 }