/**
  * Constructor
  *
  * @param	object	Database reference
  * @return	@e void
  */
 public function __construct(&$obj)
 {
     $reg = ipsRegistry::instance();
     $this->member = $reg->member();
     $this->DB = $reg->DB();
     $this->tbl = ips_DBRegistry::getPrefix();
 }
Example #2
0
 /**
  * Class entry point
  *
  * @param	object		Registry reference
  * @return	@e void		[Outputs to screen]
  */
 public function doExecute(ipsRegistry $registry)
 {
     $this->registry->class_localization->loadLanguageFile(array('public_reports'));
     $this->DB->loadCacheFile(IPSLib::getAppDir('core') . '/sql/' . ips_DBRegistry::getDriverType() . '_report_queries.php', 'report_sql_queries');
     $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('core') . '/sources/classes/reportLibrary.php', 'reportLibrary');
     $this->registry->setClass('reportLibrary', new $classToLoad($this->registry));
     /* What to do */
     switch ($this->request['do']) {
         case 'change_status':
             $this->output = $this->_changeStatus();
             break;
     }
 }
 /**
  * Search
  *
  * @param	int			Member ID who is searching
  * @param	string		Words to search (probably tainted at this point, so be careful!)
  * @param	int			Offset start
  * @param	int			Number of results to return
  * @param	array 		Array of folders to search (send nothing to search all)
  * @return 	boolean
  */
 public function execute($memberID, $words, $start = 0, $end = 50, $folders = array())
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $ids = array();
     $words = addslashes($words);
     $start = intval($start);
     $end = intval($end);
     $memberID = intval($memberID);
     $results = array();
     $dbpre = ips_DBRegistry::getPrefix();
     /* Do it... */
     if ($words) {
         $this->DB->allow_sub_select = 1;
         /* Type of search */
         if ($this->settings['use_fulltext'] and strtolower($this->settings['mysql_tbl_type']) == 'myisam') {
             $whereOne = "MATCH( t.mt_title ) AGAINST( '{$words}' IN BOOLEAN MODE )";
             $whereTwo = "MATCH( p.msg_post ) AGAINST( '{$words}' IN BOOLEAN MODE )";
         } else {
             $whereOne = "t.mt_title LIKE '%{$words}%'";
             $whereTwo = "p.msg_post LIKE '%{$words}%'";
         }
         $this->DB->query("SELECT SQL_CALC_FOUND_ROWS mt_id, mt_first_msg_id FROM ( ( SELECT t.mt_id, t.mt_first_msg_id\r\r\n\t\t\t\t\t\t\t\t\tFROM {$dbpre}message_topics t, {$dbpre}message_topic_user_map m\r\r\n\t\t\t\t\t\t\t\t\tWHERE (t.mt_id=m.map_topic_id AND m.map_user_id=" . $memberID . " AND m.map_user_banned=0 AND m.map_user_active=1 AND t.mt_is_deleted=0) AND {$whereOne}\r\r\n\t\t\t\t\t\t\t\t\tORDER BY t.mt_last_post_time DESC )\r\r\n\t\t\t\t\t\t\t\tUNION\r\r\n\t\t\t\t\t\t\t\t( SELECT p.msg_topic_id, p.msg_id\r\r\n\t\t\t\t\t\t\t\t\tFROM {$dbpre}message_posts p, {$dbpre}message_topic_user_map m\r\r\n\t\t\t\t\t\t\t\t\tWHERE (p.msg_topic_id=m.map_topic_id AND m.map_user_id=" . $memberID . " AND m.map_user_banned=0 AND m.map_user_active=1) AND {$whereTwo}\r\r\n\t\t\t\t\t\t\t\t\tORDER BY p.msg_date DESC ) ) as tbl\r\r\n\t\t\t\t\t\t\t\tGROUP BY mt_id\r\r\n\t\t\t\t\t\t\t\tLIMIT {$start}, {$end}");
         while ($row = $this->DB->fetch()) {
             $ids[] = $row['mt_id'];
         }
         $this->DB->query("SELECT FOUND_ROWS() as row_your_boat");
         $row = $this->DB->fetch();
         /* Set rows var */
         $this->_rows = intval($row['row_your_boat']);
         // comic genius
         $this->DB->allow_sub_select = 0;
         /* Now fetch some actual data! */
         if (count($ids)) {
             $this->DB->build(array('select' => 't.*', 'from' => array('message_topics' => 't'), 'where' => 'mt_id IN (' . implode(",", $ids) . ')', 'order' => 't.mt_last_post_time DESC', 'add_join' => array(array('select' => 'map.*', 'from' => array('message_topic_user_map' => 'map'), 'where' => 'map.map_topic_id=t.mt_id', 'type' => 'left'), array('select' => 'p.*', 'from' => array('message_posts' => 'p'), 'where' => 'p.msg_id=t.mt_first_msg_id', 'type' => 'left'))));
             $this->DB->execute();
             while ($row = $this->DB->fetch()) {
                 $results[$row['mt_id']] = $row;
             }
             $this->_results = $results;
         }
     }
 }
Example #4
0
 /**
  * Runs any additional sql files
  *
  * @return	@e void
  */
 public function sqlSteps()
 {
     /* INIT */
     $vars = $this->getVars();
     $output = array();
     $errors = array();
     $id = intval($this->request['id']);
     $id = $id < 1 ? 1 : $id;
     $sql_files = array();
     /* Any "extra" configs required for this driver? */
     if (is_file(IPS_ROOT_PATH . 'setup/sql/' . strtolower($this->settings['sql_driver']) . '_install.php')) {
         require_once IPS_ROOT_PATH . 'setup/sql/' . strtolower($this->settings['sql_driver']) . '_install.php';
         /*noLibHook*/
         $extra_install = new install_extra($this->registry);
     }
     /* Run any sql files we found */
     if (is_file($this->app_full_path . 'setup/versions/install/sql/' . $vars['app_directory'] . '_' . strtolower(ips_DBRegistry::getDriverType()) . '_sql_' . $id . '.php')) {
         /* INIT */
         $new_id = $id + 1;
         $count = 0;
         $SQL = array();
         /* Get the sql file */
         require_once $this->app_full_path . 'setup/versions/install/sql/' . $vars['app_directory'] . '_' . strtolower(ips_DBRegistry::getDriverType()) . '_sql_' . $id . '.php';
         /*noLibHook*/
         $this->DB->return_die = 1;
         /* Run the queries */
         foreach ($SQL as $query) {
             $this->DB->allow_sub_select = 1;
             $this->DB->error = '';
             $query = str_replace("<%time%>", time(), $query);
             if ($extra_install and method_exists($extra_install, 'process_query_insert')) {
                 $query = $extra_install->process_query_insert($query);
             }
             $this->DB->query($query);
             if ($this->DB->error) {
                 $errors[] = $query . "<br /><br />" . $this->DB->error;
             } else {
                 $count++;
             }
         }
         $output[] = sprintf($this->lang->words['redir__sql_run'], $count);
         /* Show redirect... */
         $this->showRedirectScreen($vars['app_directory'], $output, $errors, $this->getNextURL('sql_steps', $vars) . '&amp;id=' . $new_id);
     } else {
         $output[] = $this->lang->words['redir__nomore_sql'];
         /* Show redirect... */
         $this->showRedirectScreen($vars['app_directory'], $output, $errors, $this->getNextURL('next_check', $vars));
     }
 }
 /**
  * Rebuild the member cache array if it is outdated
  *
  * @return	integer		New 'total reports' count
  */
 public function rebuildMemberCacheArray()
 {
     $this->DB->loadCacheFile(IPSLib::getAppDir('core') . '/sql/' . ips_DBRegistry::getDriverType() . '_report_queries.php', 'report_sql_queries');
     $class_perm = $this->buildQueryPermissions();
     $total = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as reports', 'from' => array('rc_reports_index' => 'rep'), 'where' => $class_perm . " AND stat.is_active=1", 'add_join' => array(array('from' => array('rc_classes' => 'rcl'), 'where' => 'rcl.com_id=rep.rc_class'), array('from' => array('rc_status' => 'stat'), 'where' => 'stat.status=rep.status'))));
     $reports_by_plugin = array();
     $this->DB->build(array('select' => 'rep.id, rep.title, rep.num_reports, rep.exdat1, rep.exdat2, rep.exdat3', 'from' => array('rc_reports_index' => 'rep'), 'where' => $class_perm . " AND (stat.is_active=1 OR stat.is_new=1) AND rcl.onoff=1", 'order' => 'stat.is_new ASC', 'add_join' => array(array('select' => 'stat.is_active, stat.is_new', 'from' => array('rc_status' => 'stat'), 'where' => 'stat.status=rep.status'), array('select' => 'rcl.com_id, rcl.com_id, rcl.my_class, rcl.extra_data, rcl.app', 'from' => array('rc_classes' => 'rcl'), 'where' => 'rcl.com_id=rep.rc_class'))));
     $this->DB->execute();
     while ($row = $this->DB->fetch()) {
         if ($row['my_class'] != '') {
             $reports_by_plugin[$row['app']][$row['my_class']][] = $row;
         }
     }
     $build_member_cache_array['report_temp'] = array();
     foreach ($reports_by_plugin as $app => $plugins) {
         if (IPSLib::appIsInstalled($app)) {
             foreach ($plugins as $plugin_name => $reports_array) {
                 $this->loadPlugin($plugin_name, $app);
                 $this->plugins[$plugin_name]->updateReportsTimestamp($reports_array, $build_member_cache_array);
             }
         }
     }
     $build_member_cache_array['report_last_updated'] = time();
     $build_member_cache_array['report_num'] = $total['reports'];
     if (count($build_member_cache_array) > 0) {
         IPSMember::packMemberCache($this->memberData['member_id'], $build_member_cache_array);
     }
     return $total['reports'];
 }
 /**
  * Execute selected method
  *
  * @access	public
  * @param	object		Registry object
  * @return	void
  */
 public function doExecute(ipsRegistry $registry)
 {
     //-----------------------------------------
     // Load basic things
     //-----------------------------------------
     $this->registry->class_localization->loadLanguageFile(array('public_reports'));
     $this->DB->loadCacheFile(IPSLib::getAppDir('core') . '/sql/' . ips_DBRegistry::getDriverType() . '_report_queries.php', 'report_sql_queries');
     require_once IPSLib::getAppDir('core') . '/sources/classes/reportLibrary.php';
     $this->registry->setClass('reportLibrary', new reportLibrary($this->registry));
     //-----------------------------------------
     // Check permissions...
     //-----------------------------------------
     $showReportCenter = false;
     $this->member_group_ids = array($this->memberData['member_group_id']);
     $this->member_group_ids = array_diff(array_merge($this->member_group_ids, explode(',', $this->memberData['mgroup_others'])), array(''));
     $report_center = array_diff(explode(',', $this->settings['report_mod_group_access']), array(''));
     foreach ($report_center as $groupId) {
         if (in_array($groupId, $this->member_group_ids)) {
             $showReportCenter = true;
         }
     }
     if ($this->request['do'] and $this->request['do'] != 'report' and !$showReportCenter) {
         $this->registry->output->showError('no_reports_permission', 2018, true);
     }
     $this->registry->output->setTitle($this->lang->words['main_title']);
     //-----------------------------------------
     // Which road are we going to take?
     //-----------------------------------------
     switch ($this->request['do']) {
         default:
         case 'report':
             $this->_initReportForm();
             break;
         case 'showMessage':
             $this->_viewReportedMessage();
             break;
         case 'index':
             $this->_displayReportCenter();
             break;
         case 'process':
             $this->_processReports();
             break;
         case 'findfirst':
             $this->findFirstReport();
             break;
         case 'show_methods':
             $this->_showNotificationMethods();
             break;
         case 'save_methods':
             $this->_saveNotificationMethods();
             break;
         case 'show_report':
             $this->_displayReport();
             break;
         case 'save_comment':
             $this->_saveComment();
             break;
     }
     //-----------------------------------------
     // Output
     //-----------------------------------------
     $this->registry->getClass('output')->addContent($this->output);
     $this->registry->output->sendOutput();
 }
Example #7
0
 /**
  * Post save
  * Accepts an array of GENERIC data and allows manipulation after it's added to DB
  *
  * @param	string	Type of action (edit/add)
  * @param	array	Array of GENERIC data (comment_xxxx)
  * @param	int		Comment id (if available)
  * @param	int		Parent id
  * @return 	array	Array of GENERIC data
  */
 public function postSave($type, array $array, $commentId = 0, $parentId = 0)
 {
     $_cnt = $this->DB->buildAndFetch(array('select' => 'count(*) as total', 'from' => 'rc_comments', 'where' => 'rid=' . $parentId));
     $this->DB->update('rc_reports_index', array('num_comments' => intval($_cnt['total']), 'date_updated' => IPS_UNIX_TIME_NOW, 'updated_by' => $this->memberData['member_id']), "id=" . $parentId);
     $report = $this->fetchParent($parentId);
     //-----------------------------------------
     // Notify other moderators
     //-----------------------------------------
     if ($type == 'add') {
         $this->registry->class_localization->loadLanguageFile(array('public_reports'));
         $this->DB->loadCacheFile(IPSLib::getAppDir('core') . '/sql/' . ips_DBRegistry::getDriverType() . '_report_queries.php', 'report_sql_queries');
         $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('core') . '/sources/classes/reportLibrary.php', 'reportLibrary');
         $this->registry->setClass('reportLibrary', new $classToLoad($this->registry));
         $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('core') . '/sources/classes/reportNotifications.php', 'reportNotifications');
         $notify = new $classToLoad($this->registry);
         $this->registry->getClass('reportLibrary')->loadPlugin($report['my_class'], $report['app']);
         if (is_object($this->registry->getClass('reportLibrary')->plugins[$report['my_class']])) {
             if ($report['extra_data'] && $report['extra_data'] != 'N;') {
                 $this->registry->getClass('reportLibrary')->plugins[$report['my_class']]->_extra = unserialize($report['extra_data']);
             } else {
                 $this->registry->getClass('reportLibrary')->plugins[$report['my_class']]->_extra = array();
             }
             $report_data = $this->registry->getClass('reportLibrary')->plugins[$report['my_class']]->formatReportData($report);
             $notify->initNotify($this->registry->getClass('reportLibrary')->plugins[$report['my_class']]->getNotificationList(IPSText::cleanPermString($report['mod_group_perm']), $report_data), $report_data);
             $notify->sendReplyNotifications($array['comment_text']);
         }
     }
     //-----------------------------------------
     // Mark read
     //-----------------------------------------
     $this->registry->classItemMarking->markRead(array('forumID' => 0, 'itemID' => $report['id']), 'core');
     return $array;
 }
Example #8
0
 /**
  * Track
  * 
  * @param	string	HTTP Referrer
  * @param	string	Query string
  * @param	int		Member ID
  */
 public static function track($referrer, $queryString, $memberId)
 {
     foreach (self::$engines as $engine) {
         if (preg_match($engine['match'], $referrer)) {
             $obj = new self();
             $keywords = trim($obj->{$engine['parser']}($referrer));
             if (!empty($keywords)) {
                 ipsRegistry::DB()->allow_sub_select = 1;
                 ipsRegistry::DB()->loadCacheFile(IPSLib::getAppDir('core') . '/sql/' . ips_DBRegistry::getDriverType() . '_seo_queries.php', 'core_seo_queries');
                 ipsRegistry::DB()->buildFromCache('ipseo_increment_keyword_count', IPSText::parseCleanValue($keywords), 'core_seo_queries');
                 ipsRegistry::DB()->allow_sub_select = 1;
                 ipsRegistry::DB()->execute();
                 ipsRegistry::DB()->insert('search_visitors', array('date' => time(), 'member' => intval($memberId), 'engine' => $engine['name'], 'keywords' => $keywords, 'url' => $queryString));
             }
             break;
         }
     }
 }
Example #9
0
 /**
  * Main function executed automatically by the controller
  *
  * @param	object		$registry		Registry object
  * @return	@e void
  */
 public function doExecute(ipsRegistry $registry)
 {
     //-----------------------------------------
     // Load basic things
     //-----------------------------------------
     $this->registry->class_localization->loadLanguageFile(array('public_reports'));
     $this->DB->loadCacheFile(IPSLib::getAppDir('core') . '/sql/' . ips_DBRegistry::getDriverType() . '_report_queries.php', 'report_sql_queries');
     $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('core') . '/sources/classes/reportLibrary.php', 'reportLibrary');
     $this->registry->setClass('reportLibrary', new $classToLoad($this->registry));
     //-----------------------------------------
     // Check permissions...
     //-----------------------------------------
     if ($this->request['do'] and $this->request['do'] != 'report' and !IPSMember::isInGroup($this->memberData, explode(',', IPSText::cleanPermString($this->settings['report_mod_group_access'])))) {
         $this->registry->output->showError('no_reports_permission', 2018, true, null, 403);
     }
     $this->registry->output->setTitle($this->lang->words['main_title'] . ' - ' . ipsRegistry::$settings['board_name']);
     //-----------------------------------------
     // Which road are we going to take?
     //-----------------------------------------
     switch ($this->request['do']) {
         default:
         case 'report':
             $this->_initReportForm();
             break;
         case 'showMessage':
             $this->_viewReportedMessage();
             break;
         case 'index':
             $this->_displayReportCenter();
             break;
         case 'process':
             $this->_processReports();
             break;
         case 'findfirst':
             $this->findFirstReport();
             break;
         case 'show_report':
             $this->_displayReport();
             break;
     }
     if ($this->request['do'] and $this->request['do'] != 'report') {
         /* Init some data */
         $_tabs = array();
         $_activeNav = array('primary' => 'reported_content', 'secondary' => 'reports');
         $moderator = $this->registry->class_forums->getModerator();
         $this->registry->class_localization->loadLanguageFile(array('public_modcp'), 'core');
         /**
          * Loop through all apps and get plugins
          * 
          * @note	When updating this code below remember to update also the core in public_core_modcp_modcp
          */
         foreach (IPSLib::getEnabledApplications() as $appDir => $appData) {
             if (is_dir(IPSLib::getAppDir($appDir) . '/extensions/modcp')) {
                 try {
                     foreach (new DirectoryIterator(IPSLib::getAppDir($appDir) . '/extensions/modcp') as $file) {
                         if (!$file->isDot() && $file->isFile()) {
                             if (preg_match("/^plugin_(.+?)\\.php\$/", $file->getFileName(), $matches)) {
                                 //-----------------------------------------
                                 // We load each plugin so it can determine
                                 // if it should show based on permissions
                                 //-----------------------------------------
                                 $classToLoad = IPSLib::loadLibrary($file->getPathName(), 'plugin_' . $appDir . '_' . $matches[1], $appDir);
                                 $_plugins[$appDir][$matches[1]] = new $classToLoad($this->registry);
                                 if ($_plugins[$appDir][$matches[1]]->canView($moderator)) {
                                     //-----------------------------------------
                                     // Hacky solution - we want forum plugins to
                                     // come first as they're the most used
                                     //-----------------------------------------
                                     if ($appDir == 'forums' and !empty($_tabs[$_plugins[$appDir][$matches[1]]->getPrimaryTab()])) {
                                         array_unshift($_tabs[$_plugins[$appDir][$matches[1]]->getPrimaryTab()], array($_plugins[$appDir][$matches[1]]->getSecondaryTab(), $appDir, $matches[1]));
                                     } else {
                                         $_tabs[$_plugins[$appDir][$matches[1]]->getPrimaryTab()][] = array($_plugins[$appDir][$matches[1]]->getSecondaryTab(), $appDir, $matches[1]);
                                     }
                                 }
                             }
                         }
                     }
                 } catch (Exception $e) {
                 }
             }
         }
         // Move trash can to the bottom - if available
         if (isset($_tabs['deleted_content'])) {
             $trashCan = $_tabs['deleted_content'];
             unset($_tabs['deleted_content']);
             $_tabs['deleted_content'] = $trashCan;
         }
         $this->output = $this->registry->output->getTemplate('modcp')->portalPage($this->output, $_tabs, $_activeNav);
     }
     //-----------------------------------------
     // Output
     //-----------------------------------------
     $this->registry->getClass('output')->addContent($this->output);
     $this->registry->output->sendOutput();
 }
Example #10
0
 /**
  * getCloudData
  * 
  * Filters:
  * limit		Limit the number of tags returned
  * visible		The number of visible tags
  * noCache		Bypass any caching and always fetch fresh
  * 
  * @param	array	Filters (limit, visible)
  * @return	@e array
  */
 public function getCloudData($filters = array())
 {
     /* INIT */
     $where = array();
     $data = array();
     $raw = array();
     $nums = array('min' => 0, 'max' => 0, 'count' => 0);
     $final = array('tags' => array(), 'nums' => array());
     /* Clean up filters */
     $filters['limit'] = intval($filters['limit']);
     $filters['offset'] = intval($filters['offset']);
     $filters['visible'] = !isset($filters['visible']) ? 1 : intval($filters['visible']);
     if ($this->getApp() && $this->getArea() && $this->getRelId()) {
         $where[] = "t.tag_aai_lookup='" . $this->_getKey(array('meta_id' => $this->getRelId())) . "'";
     } else {
         if ($this->getApp() && $this->getArea() && $this->getParentId()) {
             $where[] = "t.tag_aap_lookup='" . $this->_getKey(array('meta_parent_id' => $this->getParentId())) . "'";
         }
     }
     if ($this->getApp()) {
         $where[] = "t.tag_meta_app='" . $this->DB->addSlashes($this->getApp()) . "'";
     }
     if ($this->getArea()) {
         $where[] = "t.tag_meta_area='" . $this->DB->addSlashes($this->getArea()) . "'";
     }
     /* Test against cache class */
     if (empty($filters['noCache'])) {
         $cacheKey = 'tagCloud-' . md5(implode('&', $where));
         $cached = $this->registry->getClass('cacheSimple')->get($cacheKey);
         if ($cached !== null && is_array($cached['data'])) {
             $cached['data']['cached'] = $cached['time'];
             return $cached['data'];
         }
     }
     /* Still here? Fetch from the database */
     $this->DB->allow_sub_select = true;
     $this->DB->loadCacheFile(IPSLib::getAppDir('core') . '/sql/' . ips_DBRegistry::getDriverType() . '_tag_queries.php', 'public_tag_sql_queries');
     $this->DB->buildFromCache('getCloudData', array('where' => $where, 'limit' => array($filters['offset'], $filters['limit'])), 'public_tag_sql_queries');
     $o = $this->DB->execute();
     while ($tag = $this->DB->fetch()) {
         $raw[$tag['times'] . '.' . md5($tag['tag_text'])] = $tag;
         if (empty($nums['min']) or $nums['min'] > $tag['times']) {
             $nums['min'] = $tag['times'];
         }
         if ($nums['max'] < $tag['times']) {
             $nums['max'] = $tag['times'];
         }
         $nums['count'] += $tag['times'];
     }
     /* Sort it */
     krsort($raw);
     require_once IPS_ROOT_PATH . 'sources/classes/tags/bootstrap.php';
     /*noLibHook*/
     /* Now give out some useful data */
     foreach ($raw as $key => $data) {
         /* Get plugin class to work out 'section' */
         if (!isset($this->plugins[$data['tag_meta_area']])) {
             $this->plugins[$data['tag_meta_area']] = classes_tags_bootstrap::run($data['tag_meta_app'], $data['tag_meta_area']);
         }
         /* Section */
         $section = $this->plugins[$data['tag_meta_area']]->getSearchSection();
         /* Work out a percentage */
         $percent = sprintf('%.2F', $data['times'] / $nums['max'] * 100);
         $final['tags'][] = array('tag' => $data['tag_text'], 'count' => $data['times'], 'app' => $data['tag_meta_app'], 'section' => $section, 'percent' => $percent, 'weight' => sprintf('%.2F', $percent / 100));
     }
     $final['nums'] = $nums;
     /* Cache */
     $this->registry->getClass('cacheSimple')->set($cacheKey, $final);
     return $final;
 }
 /**
  * Singleton init
  *
  * @access	public
  * @return	object
  */
 public static function instance()
 {
     if (!self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #12
0
 /**
  * Restore posts
  * @param array $where
  */
 public function restoreRecentPost($where)
 {
     $date = IPS_UNIX_TIME_NOW - 86400;
     $PRE = trim(ipsRegistry::dbFunctions()->getPrefix());
     $query = array();
     $remap = array('post_id' => 'pid', 'post_topic_id' => 'topic_id', 'post_author_id' => 'post_author_id');
     foreach (array('post_id', 'post_topic_id', 'post_forum_id', 'post_author_id') as $k) {
         if (!empty($where[$k])) {
             $query[] = is_array($where[$k]) ? $remap[$k] . ' IN (' . implode(',', $where[$k]) . ')' : $remap[$k] . '=' . intval($where[$k]);
         }
     }
     if (count($query)) {
         $this->DB->loadCacheFile(IPSLib::getAppDir('forums') . '/sql/' . ips_DBRegistry::getDriverType() . '_topics_queries.php', 'topics_sql_queries');
         $this->DB->buildFromCache('restoreRecentPost', array('query' => $query, 'date' => $date), 'topics_sql_queries');
         $this->DB->allow_sub_select = true;
         $this->DB->execute();
     }
 }
Example #13
0
 /**
  * Perform the search
  * @param array $tags
  * @param array $options
  */
 public function run(array $tags, array $options)
 {
     $where = array();
     $order = !empty($options['sortKey']) ? $options['sortKey'] : 'tg.tag_meta_id';
     $dir = !empty($options['sortOrder']) ? $options['sortOrder'] : 'desc';
     $return = array();
     /* Format query */
     if (isset($options['meta_parent_id']) && (is_numeric($options['meta_parent_id']) || count($options['meta_parent_id']))) {
         $where[] = is_array($options['meta_parent_id']) && count($options['meta_parent_id']) ? 'tg.tag_meta_parent_id IN (' . implode(',', IPSLib::cleanIntArray($options['meta_parent_id'])) . ')' : 'tg.tag_meta_parent_id=' . intval($options['meta_parent_id']);
     }
     if (isset($options['meta_id']) && (is_numeric($options['meta_id']) || count($options['meta_id']))) {
         $where[] = is_array($options['meta_id']) && count($options['meta_id']) ? 'tg.tag_meta_id IN (' . implode(',', IPSLib::cleanIntArray($options['meta_id'])) . ')' : 'tg.tag_meta_id=' . intval($options['meta_id']);
     }
     if (isset($options['meta_app'])) {
         $where[] = is_array($options['meta_app']) && count($options['meta_app']) ? 'tg.tag_meta_app IN (\'' . implode("','", $options['meta_app']) . '\')' : 'tg.tag_meta_app=\'' . $options['meta_app'] . '\'';
     }
     if (isset($options['meta_area'])) {
         $where[] = is_array($options['meta_area']) && count($options['meta_area']) ? 'tg.tag_meta_area IN (\'' . implode("','", $options['meta_area']) . '\')' : 'tg.tag_meta_area=\'' . $options['meta_area'] . '\'';
     }
     if (!empty($options['not_meta_id'])) {
         $where[] = is_array($options['not_meta_id']) && count($options['not_meta_id']) ? 'tg.tag_meta_id NOT IN (' . implode(",", $options['not_meta_id']) . ')' : 'tg.tag_meta_id !=' . intval($options['not_meta_id']);
     }
     if (isset($tags)) {
         if (isset($options['match']) and $options['match'] == 'loose') {
             $_tags = is_array($tags) ? $tags : array($tags);
             $_t = array();
             foreach ($_tags as $text) {
                 $_t[] = ' tg.tag_text LIKE \'%' . $this->DB->addSlashes($text) . '%\'';
             }
             if (count($_t)) {
                 $where[] = implode(" OR ", $_t);
             }
         } else {
             if (is_array($tags)) {
                 $_t = $tags;
                 $tags = array();
                 foreach ($_t as $t) {
                     $tags[] = $this->DB->addSlashes($t);
                 }
             }
             $where[] = is_array($tags) ? 'tg.tag_text IN (\'' . implode("','", $tags) . '\')' : 'tg.tag_text=\'' . $this->DB->addSlashes($tags) . '\'';
         }
     }
     $prefix = ips_DBRegistry::getPrefix();
     /* Did we add in perm check? */
     if (!empty($options['isViewable'])) {
         if ($options['joins']) {
             $select = array();
             $join = '';
             foreach ($options['joins'] as $j) {
                 foreach ($j['from'] as $name => $ref) {
                     $select[] = $j['select'];
                     $join .= ' LEFT JOIN ' . $prefix . $name . ' ' . $ref;
                     if ($j['where']) {
                         $join .= ' ON (' . $j['where'] . ')';
                     }
                 }
             }
         }
         if (count($select)) {
             $_select = ',' . implode(',', $select);
         }
         $options['limit'] = $options['limit'] > 0 && $options['limit'] < 5000 ? $options['limit'] : 250;
         /* we need to make an exception if filtering by date */
         if (class_exists('IPSSearchRegistry') && (IPSSearchRegistry::get('in.search_date_start') || IPSSearchRegistry::get('in.search_date_end'))) {
             $options['limit'] = 10000000000.0;
         }
         $this->DB->allow_sub_select = true;
         $this->DB->query('SELECT tg.* ' . $_select . ' FROM ' . $prefix . 'core_tags tg ' . $join . ' WHERE ' . implode(' AND ', $where) . ' AND tg.tag_aai_lookup IN (' . 'SELECT tag_perm_aai_lookup FROM  ' . $prefix . 'core_tags_perms WHERE ' . $this->DB->buildWherePermission($this->member->perm_id_array, 'tag_perm_text') . ' AND tag_perm_visible=1 ' . ') ORDER BY ' . $order . ' ' . $dir . ' LIMIT 0,' . $options['limit']);
         $this->DB->execute();
     } else {
         if (is_array($options['joins'])) {
             $db = array('select' => 'tg.*', 'from' => array('core_tags' => 'tg'), 'where' => implode(' AND ', $where), 'add_join' => array($options['joins']), 'order' => $order . ' ' . $dir);
         } else {
             $db = array('select' => 'tg.*', 'from' => 'core_tags tg', 'where' => implode(' AND ', $where), 'order' => $order . ' ' . $dir);
         }
         if (!empty($options['limit']) || !empty($options['offset'])) {
             $db['limit'] = array(intval($options['offset']), intval($options['limit']));
         }
         /* Fetch */
         $this->DB->build($db);
         $this->DB->execute();
     }
     /* Fetch data */
     while ($row = $this->DB->fetch()) {
         $return[$row['tag_id']] = $row;
     }
     return $return;
 }
 public function __construct(&$obj)
 {
     $this->DB = ipsRegistry::DB();
     $this->prefix = ips_DBRegistry::getPrefix();
 }