Пример #1
0
 /**
  * buildQuery
  *
  * @param   bool  $overrideLimits  Param
  *
  * @return	F0FQuery
  */
 public function buildQuery($overrideLimits = false)
 {
     $db = $this->getDbo();
     $query = F0FQueryAbstract::getNew($db)->select('*')->from($db->quoteName('#__autotweet_posts'));
     $fltPostdate = $this->getState('postdate', null, 'date');
     if ($fltPostdate) {
         $fltPostdate = $fltPostdate . '%';
         $query->where($db->qn('postdate') . ' LIKE ' . $db->q($fltPostdate));
     }
     $fltAfterDate = $this->getState('after_date', null, 'date');
     if ($fltAfterDate) {
         $query->where($db->qn('postdate') . ' >= ' . $db->q($fltAfterDate));
     }
     $fltChannel = $this->getState('channel', null, 'int');
     if ($fltChannel) {
         $query->where($db->qn('channel_id') . ' = ' . $db->q($fltChannel));
     }
     $fltPlugin = $this->getState('plugin', null, 'string');
     if ($fltPlugin) {
         $query->where($db->qn('plugin') . ' = ' . $db->q($fltPlugin));
     }
     $fltRefId = $this->getState('ref_id', null, 'string');
     if ($fltRefId) {
         $query->where($db->qn('ref_id') . ' = ' . $db->q($fltRefId));
     }
     $fltNotId = $this->getState('not_id', null, 'string');
     if ($fltNotId) {
         $query->where($db->qn('id') . ' <> ' . $db->q($fltNotId));
     }
     $fltMessage = $this->getState('message', null, 'string');
     if ($fltMessage) {
         $query->where($db->qn('message') . ' = ' . $db->q($fltMessage));
     }
     $fltPubstate = $this->getState('pubstate', null);
     if (is_array($fltPubstate)) {
         if (count($fltPubstate) > 0) {
             $list = array();
             foreach ($fltPubstate as $pubstate) {
                 $list[] = $db->q($pubstate);
             }
             $fltPubstate = implode(',', $list);
             $query->where($db->qn('pubstate') . ' IN (' . $fltPubstate . ')');
         }
     } else {
         if ($fltPubstate != '') {
             $query->where($db->qn('pubstate') . ' = ' . $db->q($fltPubstate));
         }
     }
     $fltPubstates = $this->getState('pubstates', null, 'string');
     if ($fltPubstates != '') {
         $fltPubstates = TextUtil::listToArray($fltPubstates);
         $list = array();
         foreach ($fltPubstates as $p) {
             $list[] = $db->q($p);
         }
         $fltPubstates = implode(',', $list);
         $query->where($db->qn('pubstate') . ' IN (' . $fltPubstates . ')');
     }
     $search = $this->getState('search', null);
     if ($search) {
         $search = '%' . $search . '%';
         $query->where('(' . $db->qn('id') . ' LIKE ' . $db->quote($search) . ' OR ' . $db->qn('ref_id') . ' LIKE ' . $db->quote($search) . ' OR ' . $db->qn('resultmsg') . ' LIKE ' . $db->quote($search) . ' OR ' . $db->qn('message') . ' LIKE ' . $db->quote($search) . ' OR ' . $db->qn('title') . ' LIKE ' . $db->quote($search) . ' OR ' . $db->qn('url') . ' LIKE ' . $db->quote($search) . ')');
     }
     AclPermsHelper::whereOwnership($query);
     $order = $this->getState('filter_order', 'postdate', 'cmd');
     if (!in_array($order, array_keys($this->getTable()->getData()))) {
         $order = 'postdate';
     }
     $dir = $this->getState('filter_order_Dir', 'DESC', 'cmd');
     $query->order($order . ' ' . $dir);
     return $query;
 }
Пример #2
0
 /**
  * _getTagsToStrip
  *
  * @return	array
  */
 private function _getTagsToStrip()
 {
     $s = self::$_params->get('strip_list');
     $w = '';
     if (strpos($s, '+') === 0) {
         $s = FeedTextHelper::str_replace_first('+', '', $s);
         $w = '+';
     }
     $ts = TextUtil::listToArray($s);
     $ht = array();
     foreach ($ts as $k => $t) {
         if (JString::strpos($t, '=')) {
             $ht[] = $t;
             unset($ts[$k]);
         }
     }
     list($tags, $hook_tag) = array($w . implode(',', $ts), $w . implode(',', $ht));
     if ($tags) {
         if (strpos($tags, '+') !== false) {
             $tags = str_replace('+', '', $tags);
         } else {
             $tags = str_replace(' ', '', $tags);
             $tags = '*-' . str_replace(',', ' -', $tags);
         }
     }
     self::$_tags = $tags;
     self::$_hook_tag = $hook_tag;
     return array($tags, $hook_tag);
 }
Пример #3
0
 /**
  * loadINI
  *
  * @return	bool
  */
 protected static function loadINI()
 {
     if (self::$_compinfo && self::$_pluginfo) {
         return true;
     }
     self::$_compinfo = array();
     self::$_pluginfo = array();
     self::$_thirdparty = array();
     // Get component parameter
     $version_check = EParameter::getComponentParam(CAUTOTWEETNG, 'version_check', 1);
     $remoteFile = self::SERVER_INI_PATH . self::SERVER_INI_FILE;
     $localFile = JPATH_AUTOTWEET_HELPERS . '/' . self::SERVER_INI_FILE;
     $file = $localFile;
     if ($version_check) {
         try {
             $ch = curl_init($remoteFile);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::CXN_TIMEOUT);
             curl_setopt($ch, CURLOPT_TIMEOUT, self::EXEC_TIMEOUT);
             $data = curl_exec($ch);
             curl_close($ch);
             file_put_contents($localFile, $data);
         } catch (Exception $e) {
             $msg = $e->getMessage();
             $logger->log(JLog::ERROR, 'AutoTweetNG - ' . $msg);
         }
     }
     jimport('joomla.error.error');
     jimport('joomla.registry.registry');
     $registry = new JRegistry();
     if (!$registry->loadFile($file, 'INI', array('processSections' => 'true'))) {
         $logger->log(JLog::ERROR, 'AutoTweetNG - error reading INI file ' . $file);
         return false;
     }
     // Init logging
     $logger = AutotweetLogger::getInstance();
     $db = JFactory::getDBO();
     // Get component info and remove from array
     $data = JApplicationHelper::parseXMLInstallFile(JPATH_COMPONENT_ADMINISTRATOR . DIRECTORY_SEPARATOR . self::COMP_INSTALL_FILE);
     self::$_compinfo = array('id' => $registry->get('component.id'), 'name' => $registry->get('component.name'), 'server_version' => $registry->get('component.version'), 'client_version' => $data['version'], 'home' => $registry->get('component.home'), 'faq' => $registry->get('component.faq'), 'download' => $registry->get('component.download'), 'support' => $registry->get('component.support'), 'products' => $registry->get('component.products'), 'twitter' => $registry->get('component.twitter'), 'jed' => $registry->get('component.jed'), 'message' => $registry->get('component.message'), 'news' => $registry->get('component.news'));
     $extensions = TextUtil::listToArray($registry->get('component.extensions'));
     foreach ($extensions as $extension) {
         $state = self::EXT_NOTINSTALLED;
         $config = '';
         $client_version = '';
         $type = $registry->get($extension . '.type');
         $id = $registry->get($extension . '.id');
         $source = $registry->get($extension . '.source');
         if ('module' == $type) {
             $mod_filename = 'mod_' . $id;
             // Get the module id and set url for config
             $pluginsModel = F0FModel::getTmpInstance('Extensions', 'ExtlyModel');
             $pluginsModel->savestate(false)->setState('element', $mod_filename);
             $rows = $pluginsModel->getItemList();
             if (!empty($rows)) {
                 $row = $rows[0];
                 if ($row->client_id) {
                     $path = JPATH_ADMINISTRATOR . '/modules/' . $mod_filename . DIRECTORY_SEPARATOR . $mod_filename . '.xml';
                 } else {
                     $path = JPATH_ROOT . '/modules/' . $mod_filename . DIRECTORY_SEPARATOR . $mod_filename . '.xml';
                 }
                 $data = JApplicationHelper::parseXMLInstallFile($path);
                 $client_version = $data['version'];
                 if (self::_isEnabled($mod_filename)) {
                     $state = self::EXT_ENABLED;
                 } else {
                     $state = self::EXT_DISABLED;
                 }
                 // $config = 'index.php?option=com_modules&task=module.edit&id=' . $row->extension_id;
             }
         } else {
             // Get the plugin id and set url for config
             $pluginsModel = F0FModel::getTmpInstance('Plugins', 'AutoTweetModel');
             $pluginsModel->savestate(false)->set('element_id', $id);
             $rows = $pluginsModel->getItemList();
             if (!empty($rows)) {
                 $row = $rows[0];
                 $path = JPATH_PLUGINS . DIRECTORY_SEPARATOR . $row->folder . DIRECTORY_SEPARATOR . $row->element . DIRECTORY_SEPARATOR . $row->element . '.xml';
                 $data = JApplicationHelper::parseXMLInstallFile($path);
                 $client_version = $data['version'];
                 if (JPluginHelper::isEnabled($row->folder, $row->element)) {
                     $state = self::EXT_ENABLED;
                 } else {
                     $state = self::EXT_DISABLED;
                 }
                 $config = 'index.php?option=com_plugins&task=plugin.edit&extension_id=' . $row->id;
             }
         }
         // Append plugin state to result arrays
         if (self::FM_EXT_SOURCE == $source) {
             self::$_pluginfo[] = array('id' => $id, 'name' => $registry->get($extension . '.name'), 'state' => $state, 'client_version' => $client_version, 'server_version' => $registry->get($extension . '.version'), 'message' => $registry->get($extension . '.message'), 'config' => $config);
         } else {
             self::$_thirdparty[] = array('id' => $id, 'name' => $registry->get($extension . '.name'), 'state' => $state, 'client_version' => $client_version, 'message' => $registry->get($extension . '.message'), 'config' => $config, 'source' => $source, 'download' => $registry->get($extension . '.download'));
         }
     }
     // Add installed plugins without entry in ini file to 3rd party list
     $pluginsModel = F0FModel::getTmpInstance('Plugins', 'AutoTweetModel');
     $pluginsModel->savestate(false);
     $plugins = $pluginsModel->getItemList();
     foreach ($plugins as $plugin) {
         $id = $plugin->element;
         $type = $plugin->folder;
         if (!self::in_array_recursive($id, self::$_pluginfo) && !self::in_array_recursive($id, self::$_thirdparty)) {
             $path = JPATH_PLUGINS . DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR . $id . DIRECTORY_SEPARATOR . $id . '.xml';
             $data = JApplicationHelper::parseXMLInstallFile($path);
             $client_version = $data['version'];
             if (JPluginHelper::isEnabled($type, $id)) {
                 $state = self::EXT_ENABLED;
             } else {
                 $state = self::EXT_DISABLED;
             }
             $config = 'index.php?option=com_plugins&task=plugin.edit&extension_id=' . $plugin->id;
             if (!empty($data['authorUrl'])) {
                 $source = $data['authorUrl'];
                 $download = $data['authorUrl'];
             } else {
                 $source = self::EXT_UNKNOWN;
                 $download = '';
             }
             self::$_thirdparty[] = array('id' => $id, 'name' => $plugin->name, 'state' => $state, 'client_version' => $client_version, 'message' => 'unknown extension plugin', 'config' => $config, 'source' => $source, 'download' => $download);
         }
     }
     return true;
 }
Пример #4
0
 /**
  * buildQuery
  *
  * @param   bool  $overrideLimits  Param
  *
  * @return	F0FQuery
  */
 public function buildQuery($overrideLimits = false)
 {
     $db = $this->getDbo();
     $query = F0FQueryAbstract::getNew($db)->select('*')->from($db->quoteName('#__autotweet_requests'));
     $fltPublishup = $this->getState('publish_up', null, 'date');
     if ($fltPublishup) {
         $fltPublishup = $fltPublishup . '%';
         $query->where($db->qn('publish_up') . ' LIKE ' . $db->q($fltPublishup));
     }
     $fltUntilDate = $this->getState('until_date', null, 'date');
     if ($fltUntilDate) {
         $query->where($db->qn('publish_up') . ' <= ' . $db->q($fltUntilDate));
     }
     $input = new F0FInput();
     $start = $input->get('xtstart');
     if ($start) {
         $date = new JDate($start);
         $query->where($db->qn('publish_up') . ' >= ' . $db->q($date->toSql()));
     }
     $end = $input->get('xtend');
     if ($end) {
         $date = new JDate($end);
         $query->where($db->qn('publish_up') . ' <= ' . $db->q($date->toSql()));
     }
     $fltPlugin = $this->getState('plugin', null, 'string');
     if ($fltPlugin) {
         $query->where($db->qn('plugin') . ' = ' . $db->q($fltPlugin));
     }
     $fltRefId = $this->getState('ref_id', null, 'string');
     if ($fltRefId) {
         $query->where($db->qn('ref_id') . ' = ' . $db->q($fltRefId));
     }
     $fltRids = $this->getState('rids', null);
     if ($fltRids != '') {
         if (is_string($fltRids)) {
             $fltRids = TextUtil::listToArray($fltRids);
         }
         $list = array();
         foreach ($fltRids as $p) {
             $list[] = $db->q($p);
         }
         $fltRids = implode(',', $list);
         $query->where($db->qn('id') . ' IN (' . $fltRids . ')');
     }
     $fltTypeinfo = $this->getState('typeinfo', null, 'string');
     if ($fltTypeinfo) {
         $query->where($db->qn('typeinfo') . ' = ' . $db->q($fltTypeinfo));
     }
     $fltPublished = $this->getState('published', 0, 'int');
     $query->where($db->qn('published') . ' = ' . $db->q($fltPublished));
     $search = $this->getState('search', null);
     if ($search) {
         $search = '%' . $search . '%';
         $query->where('(' . $db->qn('id') . ' LIKE ' . $db->quote($search) . ' OR ' . $db->qn('ref_id') . ' LIKE ' . $db->quote($search) . ' OR ' . $db->qn('description') . ' LIKE ' . $db->quote($search) . ' OR ' . $db->qn('url') . ' LIKE ' . $db->quote($search) . ')');
     }
     AclPermsHelper::whereOwnership($query);
     $order = $this->getState('filter_order', 'publish_up', 'cmd');
     if (!in_array($order, array_keys($this->getTable()->getData()))) {
         $order = 'publish_up';
     }
     $dir = $this->getState('filter_order_Dir', 'ASC', 'cmd');
     $query->order($order . ' ' . $dir);
     return $query;
 }
Пример #5
0
 /**
  * _setCheck
  *
  * @param   mixed  $catIds      Param.
  * @param   array  $categories  Param.
  * @param   bool   $default     Param.
  *
  * @return	bool
  */
 private function _setCheck($catIds, $categories, $default)
 {
     // $categories as array
     if ($categories && !is_array($categories)) {
         $categories = TextUtil::listToArray($categories);
     }
     // Nothing to check
     if (empty($categories)) {
         return $default;
     }
     // Cleaning 0 from categories - Just in case
     if (array_search(0, $categories) !== false) {
         foreach (array_keys($categories, 0) as $key) {
             unset($categories[$key]);
         }
         // Nothing to check
         if (empty($categories)) {
             return $default;
         }
     }
     // $catIds as array
     if (!is_array($catIds)) {
         $catIds = (int) $catIds;
         $catIds = array($catIds);
     }
     // Nothing to check
     if (empty($catIds)) {
         return $default;
     }
     // Check
     $result = array_intersect($catIds, $categories);
     $result = !empty($result);
     return $result;
 }
Пример #6
0
 /**
  * getAllowedChannels.
  *
  * @param   object  &$post  Params
  *
  * @return	array
  */
 protected function getAllowedChannels(&$post)
 {
     $logger = AutotweetLogger::getInstance();
     $logger->log(JLog::INFO, 'getAllowedChannels', $post);
     $categories_to_check = $post->xtform->get('catids');
     $text_to_check = $post->message;
     if (isset($post->title)) {
         $text_to_check .= ' ' . $post->title;
     }
     if (isset($post->fulltext)) {
         $text_to_check .= ' ' . $post->fulltext;
     }
     $author_to_check = $post->xtform->get('author');
     $language_to_check = $post->xtform->get('language');
     $access_to_check = $post->xtform->get('access');
     $featured_to_check = $post->xtform->get('featured');
     $has_media = !empty($post->image_url);
     $allowed_channels = array();
     $catch_all_channels = array();
     $author = $post->xtform->get('author');
     $this->fillUniversalRules($this->rules, $author);
     $logger->log(JLog::INFO, 'getAllowedChannels rules n=' . count($this->rules));
     foreach ($this->rules as $rule) {
         if (!isset($rule->xtform)) {
             $rule->xtform = Eform::paramsToRegistry($rule);
         }
         if (self::REG_EXPR == $rule->ruletype_id) {
             $condition = $rule->cond;
         } else {
             $condition = TextUtil::listToArray(trim($rule->cond));
         }
         $channel = ChannelFactory::getInstance()->getChannel($rule->channel_id);
         $created_by = $channel->getField('created_by');
         $scope = $channel->getField('scope');
         $user = JFactory::getUser($created_by);
         $authorisedGroups = $user->getAuthorisedGroups();
         if ($rule->xtform->get('only_featured') && !$featured_to_check) {
             continue;
         }
         $hasMatched = false;
         switch ($rule->ruletype_id) {
             case self::CATEGORY_IN:
                 $matched = array_intersect($condition, $categories_to_check);
                 if (!empty($matched) && !array_key_exists($rule->channel_id, $allowed_channels)) {
                     $hasMatched = true;
                 }
                 break;
             case self::CATEGORY_NOTIN:
                 $matched = array_intersect($condition, $categories_to_check);
                 if (empty($matched) && !array_key_exists($rule->channel_id, $allowed_channels)) {
                     $hasMatched = true;
                 }
                 break;
             case self::TERM_OR:
                 $matched = '';
                 foreach ($condition as $term) {
                     $matched = JString::stristr($text_to_check, $term);
                     if (!empty($matched)) {
                         break;
                     }
                 }
                 if (!empty($matched) && !array_key_exists($rule->channel_id, $allowed_channels)) {
                     $hasMatched = true;
                 }
                 break;
             case self::TERM_AND:
                 $matched = '';
                 foreach ($condition as $term) {
                     $matched = JString::stristr($text_to_check, $term);
                     if (empty($matched)) {
                         break;
                     }
                 }
                 if (!empty($matched) && !array_key_exists($rule->channel_id, $allowed_channels)) {
                     $hasMatched = true;
                 }
                 break;
             case self::TERM_NOTIN:
                 $matched = '';
                 foreach ($condition as $term) {
                     $matched = JString::stristr($text_to_check, $term);
                     if (!empty($matched)) {
                         break;
                     }
                 }
                 if (empty($matched) && !array_key_exists($rule->channel_id, $allowed_channels)) {
                     $hasMatched = true;
                 }
                 break;
             case self::WORDTERM_OR:
                 $matched = '';
                 $token = strtok($text_to_check, self::TOKEN_DELIMITER);
                 while (false != $token) {
                     $matched = in_array(trim($token), $condition);
                     if (!empty($matched)) {
                         break;
                     }
                     $token = strtok(self::TOKEN_DELIMITER);
                 }
                 if (!empty($matched) && !array_key_exists($rule->channel_id, $allowed_channels)) {
                     $hasMatched = true;
                 }
                 break;
             case self::WORDTERM_AND:
                 $matched = '';
                 $text = array();
                 $token = strtok($text_to_check, self::TOKEN_DELIMITER);
                 while (false != $token) {
                     $text[] = trim($token);
                     $token = strtok(self::TOKEN_DELIMITER);
                 }
                 foreach ($condition as $term) {
                     $matched = in_array($term, $text);
                     if (empty($matched)) {
                         break;
                     }
                 }
                 if (!empty($matched) && !array_key_exists($rule->channel_id, $allowed_channels)) {
                     $hasMatched = true;
                 }
                 break;
             case self::WORDTERM_NOTIN:
                 $matched = '';
                 $text = array();
                 $token = strtok($text_to_check, self::TOKEN_DELIMITER);
                 while (false != $token) {
                     $text[] = trim($token);
                     $token = strtok(self::TOKEN_DELIMITER);
                 }
                 foreach ($condition as $term) {
                     $matched = in_array($term, $text);
                     if (!empty($matched)) {
                         break;
                     }
                 }
                 if (empty($matched) && !array_key_exists($rule->channel_id, $allowed_channels)) {
                     $hasMatched = true;
                 }
                 break;
             case self::AUTHOR_IN:
                 $matched = '';
                 foreach ($condition as $term) {
                     // Take care: strcmp returns 0 if strings are matching!
                     $matched = strcmp(trim($author_to_check), trim($term));
                     if (0 == $matched) {
                         break;
                     }
                 }
                 if (0 == $matched && !array_key_exists($rule->channel_id, $allowed_channels)) {
                     $hasMatched = true;
                 }
                 break;
             case self::AUTHOR_NOTIN:
                 $matched = '';
                 foreach ($condition as $term) {
                     // Take care: strcmp returns 0 if strings are matching!
                     $matched = strcmp(trim($author_to_check), trim($term));
                     if (0 == $matched) {
                         break;
                     }
                 }
                 if (0 != $matched && !array_key_exists($rule->channel_id, $allowed_channels)) {
                     $hasMatched = true;
                 }
                 break;
             case self::AUTHORGROUP_IN:
                 $user_id = JUserHelper::getUserId($author);
                 $user = JFactory::getUser($user_id);
                 $matched = array_intersect($user->groups, $condition);
                 $matched = !empty($matched);
                 if ($matched && !array_key_exists($rule->channel_id, $allowed_channels)) {
                     $hasMatched = true;
                 }
                 break;
             case self::AUTHORGROUP_NOTIN:
                 $user_id = JUserHelper::getUserId($author);
                 $user = JFactory::getUser($user_id);
                 $matched = array_intersect($user->groups, $condition);
                 $matched = !empty($matched);
                 if (!$matched && !array_key_exists($rule->channel_id, $allowed_channels)) {
                     $hasMatched = true;
                 }
                 break;
             case self::LANGUAGE_IN:
                 $matched = '';
                 foreach ($condition as $term) {
                     // Take care: strcmp returns 0 if strings are matching!
                     $matched = strcmp(trim($language_to_check), trim($term));
                     if (0 == $matched) {
                         break;
                     }
                 }
                 if (0 == $matched && !array_key_exists($rule->channel_id, $allowed_channels)) {
                     $hasMatched = true;
                 }
                 break;
             case self::LANGUAGE_NOTIN:
                 $matched = '';
                 foreach ($condition as $term) {
                     // Take care: strcmp returns 0 if strings are matching!
                     $matched = strcmp(trim($language_to_check), trim($term));
                     if (0 == $matched) {
                         break;
                     }
                 }
                 if (0 != $matched && !array_key_exists($rule->channel_id, $allowed_channels)) {
                     $hasMatched = true;
                 }
                 break;
             case self::ACCESS_IN:
                 $matched = '';
                 foreach ($condition as $term) {
                     // Take care: strcmp returns 0 if strings are matching!
                     $matched = strcmp(trim($access_to_check), trim($term));
                     if (0 == $matched) {
                         break;
                     }
                 }
                 if (0 == $matched && !array_key_exists($rule->channel_id, $allowed_channels)) {
                     $hasMatched = true;
                 }
                 break;
             case self::ACCESS_NOTIN:
                 $matched = '';
                 foreach ($condition as $term) {
                     // Take care: strcmp returns 0 if strings are matching!
                     $matched = strcmp(trim($access_to_check), trim($term));
                     if (0 == $matched) {
                         break;
                     }
                 }
                 if (0 != $matched && !array_key_exists($rule->channel_id, $allowed_channels)) {
                     $hasMatched = true;
                 }
                 break;
             case self::REG_EXPR:
                 $matched = preg_match($condition, $text_to_check);
                 if (!empty($matched) && !array_key_exists($rule->channel_id, $allowed_channels)) {
                     $hasMatched = true;
                 }
                 break;
             case self::FEATURED_IS:
                 $hasMatched = $featured_to_check;
                 break;
             case self::FEATURED_ISNOT:
                 $hasMatched = !$featured_to_check;
                 break;
             case self::MEDIA_HAS:
                 $hasMatched = $has_media;
                 break;
             case self::MEDIA_HASNOT:
                 $hasMatched = !$has_media;
                 break;
                 // Joocial types
             // Joocial types
             case self::CHANNEL_SCOPESCOPE_ISUSER:
                 $hasMatched = $scope == 'U';
                 break;
             case self::CHANNEL_SCOPE_ISSITE:
                 $hasMatched = $scope == 'S';
                 break;
             case self::CHANNEL_OWNERGROUP_IN:
                 $hasMatched = array_intersect($condition, $authorisedGroups);
                 $hasMatched = !empty($hasMatched);
                 break;
             case self::CHANNEL_OWNERGROUP_NOTIN:
                 $hasMatched = array_intersect($condition, $authorisedGroups);
                 $hasMatched = empty($hasMatched);
                 break;
             case self::CATCH_ALL:
                 if (!array_key_exists($rule->channel_id, $allowed_channels)) {
                     $hasMatched = true;
                 }
                 break;
             case self::CATCH_ALL_NOTFITS:
                 if (!array_key_exists($rule->channel_id, $catch_all_channels)) {
                     $catch_all_channels[$rule->channel_id] = $rule;
                 }
                 break;
         }
         if ($hasMatched) {
             $allowed_channels[$rule->channel_id] = $rule;
         }
     }
     if (empty($allowed_channels)) {
         $allowed_channels = $catch_all_channels;
     }
     return $allowed_channels;
 }
Пример #7
0
 /**
  * getHookTagList
  *
  * @return	void
  */
 public static function getHookTagList()
 {
     static $regex = '/([\\S]+)\\s*?([^=]*)?=?([\\S]*)?/';
     $hook_tag = FeedProcessorHelper::getHookTag();
     $whitemode = strpos($hook_tag, '+') === 0 ? 1 : 0;
     if ($whitemode) {
         $hook_tag = self::str_replace_first('+', '', $hook_tag);
     }
     $parts = TextUtil::listToArray($hook_tag);
     $tags_attrs = array();
     foreach ($parts as $part) {
         preg_match($regex, $part, $matches);
         if (count($matches) == 4) {
             $element = trim($matches[1]);
             $attr = trim($matches[2]);
             $value = trim($matches[3]);
             $tags_attrs[$element . '-' . $attr] = $value;
         }
     }
     self::$hasHookTags = !empty($tags_attrs);
     self::$whitemode = $whitemode;
     self::$tags_attrs = $tags_attrs;
 }
 /**
  * Returns hashtags from comma seperated string
  *
  * @param   string  $tags   Param
  * @param   int     $count  Param
  *
  * @return	string
  */
 public static function getHashtags($tags, $count = 1)
 {
     $h = array();
     if (!empty($tags)) {
         $i = 0;
         $words = TextUtil::listToArray($tags);
         foreach ($words as $word) {
             $h[] = self::getAsHashtag($word);
             $i++;
             if ($i >= $count) {
                 break;
             }
         }
     }
     $h = implode(' ', $h);
     return $h;
 }
Пример #9
0
 /**
  * generateKeywords
  *
  * @param   string  $oldKeys         Params
  * @param   string  $text            Params
  * @param   string  $article         Params
  * @param   string  $processGlobals  Params
  * @param   string  $author          Params
  * @param   string  $cat_enabled     Params
  *
  * @return	void
  */
 private function generateKeywords($oldKeys, $text, $article, $processGlobals, $author = true, $cat_enabled = true)
 {
     // Keywords to preserve
     if ($this->_addkeyParams->preserveKeys == 1) {
         $oldKeys = html_entity_decode($oldKeys, ENT_QUOTES, 'UTF-8');
         if (preg_match('#{([\\s\\S]*)}#u', $oldKeys, $matches)) {
             $savedKeys = $matches[1];
         }
     } else {
         $savedKeys = null;
     }
     $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
     // Get rid of &nbsp; - deprecated but kept for pre-PHP5.2 support
     if ($this->_addkeyParams->oldphp) {
         $replace = array("&nbsp;','&bdquo;','&rdquo;','&rsquo;','&Idquo;','&Isquo;','&ndash;','&quot;");
         $text = JString::str_ireplace($replace, ' ', $text);
     }
     // Start cleaning up the article text
     // Cleans up plugin calls
     $text = preg_replace('#{[^}]*?}(?(?=[^{]*?{\\/[^}]*?})[^{]*?{\\/[^}]*?})#u', '', $text);
     // Cleans any numbers or punctuation/newlines etc which were causing blanks/dashes etc in the final output
     if ($this->_addkeyParams->oldphp) {
         $text = preg_replace('#[\\d\\W]#u', ' ', $text);
     } else {
         // New syntax more forgiving for hyphenated words but may still break them and does not work with PHP <5.2
         // Non-English character safe!
         $text = preg_replace("#\\P{L}#u', ' ", $text);
     }
     // More efficient to change entire string to lower case here than via array_map
     $text = preg_replace('#[\\s]{2,}#u', ' ', $text);
     $text = JString::strtolower($text);
     // Get rid of undefined variables errors
     $whiteToAdd = '';
     $whiteToAddArray = array();
     $multiWordWhiteToAddArray = array();
     $keywords = '';
     if (isset($this->_addkeyParams->multiWordWhiteList)) {
         JString::strtolower($this->_addkeyParams->multiWordWhiteList);
         $multiWordWhiteArray = TextUtil::listToArray($this->_addkeyParams->multiWordWhiteList);
         foreach ($multiWordWhiteArray as $multiWordWhiteWord) {
             $multiWordWhiteWord = JString::trim($multiWordWhiteWord);
             if ($multiWordWhiteWord) {
                 if ($multiWordCount = substr_count($text, $multiWordWhiteWord)) {
                     $multiWordCount *= $this->_addkeyParams->multiWordWeighting;
                     $multiWordWhiteToAddArray[$multiWordWhiteWord] = $multiWordCount;
                     if ($this->_addkeyParams->unsetMultiWord) {
                         JString::str_ireplace($multiWordWhiteWord, '', $text);
                     }
                 }
             }
         }
     }
     if (isset($this->_addkeyParams->whiteList)) {
         JString::strtolower($this->_addkeyParams->whiteList);
         $whiteArray = TextUtil::listToArray($this->_addkeyParams->whiteList);
         foreach ($whiteArray as $whiteWord) {
             $whiteWord = JString::trim($whiteWord);
             if ($whiteWord) {
                 if ($whiteWordCount = substr_count($text, $whiteWord)) {
                     $whiteWordCount *= $this->_addkeyParams->whiteWordWeighting;
                     $whiteToAddArray[$whiteWord] = $whiteWordCount;
                     JString::str_ireplace($whiteWord, '', $text);
                 }
             }
         }
     }
     if ($this->_addkeyParams->whiteListOnly) {
         $textArray = array();
     } else {
         $textArray = explode(' ', $text);
         $textArray = array_count_values($textArray);
         // Remove blacklisted words
         JString::strtolower($this->_addkeyParams->blackList);
         $blackArray = TextUtil::listToArray($this->_addkeyParams->blackList);
         foreach ($blackArray as $blackWord) {
             if (isset($textArray[JString::trim($blackWord)])) {
                 unset($textArray[JString::trim($blackWord)]);
             }
         }
     }
     $textArray = array_merge($textArray, $whiteToAddArray, $multiWordWhiteToAddArray);
     // Sort by frequency
     arsort($textArray);
     $i = 1;
     foreach ($textArray as $word => $instances) {
         if ($i > $this->_addkeyParams->keyCount) {
             break;
         }
         if (strlen(JString::trim($word)) >= $this->_addkeyParams->minLength) {
             if (!isset($keywordsIn)) {
                 $keywordsIn = array();
             }
             $keywordsIn[] = JString::trim($word);
             $i++;
         }
     }
     // Make the vars whiteToAdd and keywords, add in the whitelist words
     if (isset($keywordsIn)) {
         $keywords = implode(',', $keywordsIn);
     }
     // Add in the preserved meta keywords
     if (isset($savedKeys)) {
         $keywords .= ', ' . $savedKeys;
     }
     // Add the author or author alias as a keyword if desired
     if ($author) {
         if ($this->_addkeyParams->addAuthor == 1) {
             $keywords = self::addAuthor($article, $keywords);
         }
     }
     // Add section/category if set
     if ($cat_enabled) {
         if ($this->_addkeyParams->addSectCat) {
             $keywords = self::addCategory($article, $keywords, $this->_addkeyParams->addSectCat);
         }
     }
     if ($processGlobals) {
         $this->_akProcessKeys = 1;
     }
     // Do we need to revert encoding for non-English characters?
     return JString::trim(JString::strtolower($keywords));
 }