/** (non-PHPdoc) * @see IfwPsn_Wp_Plugin_Admin_Menu_ListTable_Data_Interface::getTotalItems() */ public function getTotalItems() { $result = IfwPsn_Wp_ORM_Model::factory('Psn_Model_Rule')->count(); if (Psn_Model_Rule::hasMax()) { $result = Psn_Model_Rule::getMax(); } return $result; }
/** * Write a message to the log. * * @param array $event log data event * @return bool */ protected function _write($event) { $dataToInsert = array(); $r = new ReflectionProperty($this->_modelName, 'eventItems'); foreach ($r->getValue() as $item) { if (isset($event[$item])) { if (is_array($event[$item]) || is_object($event[$item])) { $dataToInsert[$item] = var_export($dataToInsert[$item], true); } else { //$dataToInsert[$item] = htmlentities(utf8_encode($event[$item]), ENT_COMPAT, IfwPsn_Wp_Proxy_Blog::getCharset()); //$dataToInsert[$item] = htmlentities($event[$item], ENT_COMPAT, IfwPsn_Wp_Proxy_Blog::getCharset()); $dataToInsert[$item] = $event[$item]; } } } return IfwPsn_Wp_ORM_Model::factory($this->_modelName)->create($dataToInsert)->save(); }
public static function reachedMax() { return IfwPsn_Wp_ORM_Model::factory('Psn_Model_Rule')->count() >= self::getMax(); }
/** * @param $statusAfter * @param $statusBefore * @param $post */ public function handlePostStatusTransition($statusAfter, $statusBefore, $post) { /** * Block * check for block setting */ if ($this->isBlockNotifications($post->ID)) { // skip if option to block notifications is set return; } /** * Postponed * check if post should be postponed */ if ($this->_postponedHandler instanceof Psn_Notification_Postponed && $this->_postponedHandler->applies()) { $this->_postponedHandler->add($statusAfter, $statusBefore, $post); return; } $this->_pm->getErrorHandler()->enableErrorReporting(); $this->_statusBefore = $statusBefore; $this->_statusAfter = $statusAfter; // get all active rules $activeRules = IfwPsn_Wp_ORM_Model::factory('Psn_Model_Rule')->filter('active')->find_many(); if (Psn_Model_Rule::hasMax()) { $activeRules = array_slice($activeRules, 0, Psn_Model_Rule::getMax()); } if ($this->isDeferredExecution()) { $deferredHandler = new Psn_Notification_Deferred_Handler(); } /** * @var $rule Psn_Model_Rule */ foreach ($activeRules as $rule) { if ($this->_pm->hasOption('psn_ignore_status_inherit')) { $rule->setIgnoreInherit(true); } // to skip a rulematch return false $doMatch = IfwPsn_Wp_Proxy_Filter::apply('psn_do_match', true, array('rule' => $rule, 'post' => $post, 'status_before' => $statusBefore, 'status_after' => $statusAfter)); if (!is_bool($doMatch)) { // for safety: $doMatch = true; } if ($doMatch && $rule->matches($post, $statusBefore, $statusAfter)) { // rule matches /** * Execute all registered notification services * * @var $service Psn_Notification_Service_Interface */ foreach ($this->getServices() as $service) { if ($this->isDeferredExecution()) { // prepare for deferred execution $deferredContainer = new Psn_Notification_Deferred_Container(); $deferredContainer->setService($service)->setRule($rule)->setPost($post); $deferredHandler->addCotainer($deferredContainer); } else { // execute directly // set the replacer $rule->setReplacer(Psn_Notification_Placeholders::getInstance($post)); $service->execute($rule, $post); } } } } $this->_pm->getErrorHandler()->disableErrorReporting(); }
/** * @param array $rules */ protected function _bulkActivate($rules) { foreach ($rules as $ruleId) { $rule = IfwPsn_Wp_ORM_Model::factory($this->getModelName())->find_one((int) $ruleId); $rule->active = 1; $rule->save(); } }
/** * Only supported by IfwPsn_Zend_Log_Writer_WpDb * @param array $options */ public function clear($options = array()) { foreach ($this->_writers as $writer) { if (get_class($writer) == 'IfwPsn_Zend_Log_Writer_WpDb') { $logs = IfwPsn_Wp_ORM_Model::factory($writer->getModelName()); if (isset($options['priority']) && !empty($options['priority'])) { $logs->where_equal('priority', (int) $options['priority']); } if (isset($options['type']) && !empty($options['type'])) { $logs->where_equal('type', (int) $options['type']); } $logs->delete_many(); } } }
/** * @param $modelName * @param $itemList * @param array $options */ public static function export($modelName, $itemList, $options = array()) { global $wp_filter, $merged_filters; $wp_filter = array(); $merged_filters = array(); if (!is_array($itemList)) { $itemList = array($itemList); } $itemList = array_map('intval', $itemList); $items = IfwPsn_Wp_ORM_Model::factory($modelName)->where_in('id', $itemList)->find_array(); if (isset($options['node_name_plural'])) { $itemNamePlural = $options['node_name_plural']; } elseif (isset($options['item_name_plural'])) { $itemNamePlural = $options['item_name_plural']; } else { $itemNamePlural = 'items'; } if (isset($options['node_name_singular'])) { $itemNameSingular = $options['node_name_singular']; } elseif (isset($options['item_name_singular'])) { $itemNameSingular = $options['item_name_singular']; } else { $itemNameSingular = 'item'; } if (count($items) > 1 && isset($options['filename_bundle'])) { $filename = $options['filename_bundle']; } elseif (count($items) == 1 && isset($options['filename'])) { $filename = $options['filename']; } else { $filename = 'Export_' . date('Y-m-d_H_i_s'); } // if (isset($options['filename'])) { // $filename = $options['filename']; // } else { // $filename = 'Export_'. date('Y-m-d_H_i_s'); // } $result = "<{$itemNamePlural}>\n"; foreach ($items as $item) { if (isset($options['item_callback']) && is_callable($options['item_callback'])) { $item = call_user_func($options['item_callback'], $item); } $result .= "\t<{$itemNameSingular}>\n"; foreach ($item as $field => $value) { if (isset($options['value_callback']) && is_callable($options['value_callback'])) { $value = call_user_func($options['value_callback'], $value); } else { $value = '<![CDATA[' . $value . ']]>'; } $result .= "\t\t" . '<column name="' . $field . '">' . $value . '</column>' . "\n"; } if (isset($options['item_result_callback']) && is_callable($options['item_result_callback'])) { $result .= call_user_func($options['item_result_callback'], $item); } $result .= "\t</{$itemNameSingular}>\n"; } $result .= "</{$itemNamePlural}>\n"; $xml = new SimpleXMLElement($result); $filename .= '.xml'; // so far export means to download an xml file, so this is directly integrated here. // refactoring could return the xml and pass it to an export handler header('Content-disposition: attachment; filename="' . $filename . '"'); header('Content-type: "text/xml"; charset="utf8"'); echo $xml->asXML(); exit; }
/** * Get the blog admins display_name (if there is a user matching the blog admin email) * @return WP_User|null */ public static function getAdminDisplayName() { $adminDisplayName = null; if (function_exists('get_user_by')) { $user = self::getByEmail(IfwPsn_Wp_Proxy_Blog::getAdminEmail()); if ($user instanceof WP_User) { $adminDisplayName = $user->display_name; } } else { $u = IfwPsn_Wp_ORM_Model::factory('IfwPsn_Wp_Model_User')->where_equal('user_email', IfwPsn_Wp_Proxy_Blog::getAdminEmail())->find_one(); if ($u instanceof IfwPsn_Wp_Model_User) { $adminDisplayName = $u->get('display_name'); } } return $adminDisplayName; }
/** * @param array $options */ public function handleCopy(array $options = array()) { $id = (int) $this->getRequest()->get('id'); if (!wp_verify_nonce($this->getRequest()->get('nonce'), IfwPsn_Zend_Controller_ModelBinding::getCopyNonceAction($this->getModelMapper()->getSingular(), $id))) { // verification failed $this->getAdminNotices()->persistError($this->getInvalidAccessMessage()); } else { // valid access $item = IfwPsn_Wp_ORM_Model::factory($this->getModelName())->find_one($id); if ($item instanceof IfwPsn_Wp_ORM_Model) { $itemName = $item->getName(); } else { $itemName = ''; } $options = array_merge(array('name_format' => '%s_%s%s'), $options); $result = IfwPsn_Wp_ORM_Model::duplicate($this->getModelName(), $id, $options); if (!empty($result)) { $this->getAdminNotices()->persistUpdated($this->getCopySuccessMessage($itemName)); } else { $this->getAdminNotices()->persistError($this->getCopyErrorMessage($itemName)); } } $this->gotoIndex(); }