/** * Perform the search * Populates $this->_count and $this->_results * * @access public * @return nothin' */ public function viewUserContent($member) { $app = IPSSearchRegistry::get('in.search_app'); IPSSearchRegistry::set('in.search_sort_by', 'date'); IPSSearchRegistry::set('in.search_sort_order', 'desc'); IPSSearchRegistry::set('opt.searchTitleOnly', IPSSearchRegistry::get('in.view_by_title')); IPSSearchRegistry::set('opt.noPostPreview', IPSSearchRegistry::get('in.view_by_title')); /* Set the member_id */ $this->setCondition('member_id', '=', $member['member_id']); /* Cut by date for efficiency? */ if ($this->settings['search_ucontent_days']) { $begin = ($member['last_post'] ? $member['last_post'] : time()) - 86400 * intval($this->settings['search_ucontent_days']); $this->setDateRange($begin, time()); } return $this->search(); }
/** * Returns an array used in the searchplugin's setCondition method * * @param array $data Array of forums to view * @return array Array with column, operator, and value keys, for use in the setCondition call */ public function buildFilterSQL($data) { /* INIT */ $return = array(); /* Set up some defaults */ IPSSearchRegistry::set('opt.noPostPreview', true); //IPSSearchRegistry::set( 'opt.searchType', 'both' ); /* Make default search type topics */ if (isset($data) && is_array($data) && count($data)) { foreach ($data as $field => $_data) { /* CONTENT ONLY */ if ($field == 'noPreview' and $_data == 0) { IPSSearchRegistry::set('opt.noPostPreview', false); } /* POST COUNT */ if ($field == 'pCount' and intval($_data) > 0) { $return[] = array('column' => 't.posts', 'operator' => '>=', 'value' => intval($_data)); } /* TOPIC VIEWS */ if ($field == 'pViews' and intval($_data) > 0) { $return[] = array('column' => 't.views', 'operator' => '>=', 'value' => intval($_data)); } } return $return; } else { return ''; } }
/** * Returns an array used in the searchplugin's setCondition method * * @param array $data Array of filters to apply * @return array Array with column, operator, and value keys, for use in the setCondition call */ public function buildFilterSQL($data) { /* INIT */ $return = array(); /* Set up some defaults */ IPSSearchRegistry::set('opt.noPostPreview', true); if (!IPSSearchRegistry::get('opt.searchType')) { IPSSearchRegistry::set('opt.searchType', 'both'); } if (isset($data) && is_array($data) && count($data)) { foreach ($data as $field => $_data) { /* CONTENT ONLY */ if ($field == 'noPreview' and $_data == 0) { IPSSearchRegistry::set('opt.noPostPreview', false); } /* POST COUNT */ if ($field == 'pCount' and intval($_data) > 0) { IPSSearchRegistry::set('opt.pCount', intval($_data)); } /* TOPIC VIEWS */ if ($field == 'pViews' and intval($_data) > 0) { IPSSearchRegistry::set('opt.pViews', intval($_data)); } } return $return; } else { return array(); } }
/** * View new posts since your last visit * * @return @e void */ public function viewNewContent() { IPSSearchRegistry::set('in.search_app', $this->request['search_app']); /* Fetch member cache to see if we have a value set */ $vncPrefs = IPSMember::getFromMemberCache($this->memberData, 'vncPrefs'); /* Guests */ if (!$this->memberData['member_id'] and (!$this->request['period'] or $this->request['period'] == 'unread')) { $this->request['period'] = 'today'; } /* In period */ if ($vncPrefs === null or !isset($vncPrefs[IPSSearchRegistry::get('in.search_app')]['view']) or !empty($this->request['period']) and isset($this->request['change'])) { $vncPrefs[IPSSearchRegistry::get('in.search_app')]['view'] = !empty($this->request['period']) ? $this->request['period'] : $this->settings['default_vnc_method']; } /* Follow filter enabled */ if ($vncPrefs === null or !isset($vncPrefs[IPSSearchRegistry::get('in.search_app')]['view']) or isset($this->request['followedItemsOnly'])) { $vncPrefs[IPSSearchRegistry::get('in.search_app')]['vncFollowFilter'] = !empty($this->request['followedItemsOnly']) ? 1 : 0; } /* User mode */ if ($vncPrefs === null or !isset($vncPrefs[IPSSearchRegistry::get('in.search_app')]['view']) or isset($this->request['userMode'])) { $vncPrefs[IPSSearchRegistry::get('in.search_app')]['userMode'] = !empty($this->request['userMode']) ? $this->request['userMode'] : ''; } /* Set filters up */ IPSSearchRegistry::set('forums.vncForumFilters', $vncPrefs['forums']['vnc_forum_filter']); IPSSearchRegistry::set('in.period', $vncPrefs[IPSSearchRegistry::get('in.search_app')]['view']); IPSSearchRegistry::set('in.vncFollowFilterOn', $vncPrefs[IPSSearchRegistry::get('in.search_app')]['vncFollowFilter']); IPSSearchRegistry::set('in.userMode', $vncPrefs[IPSSearchRegistry::get('in.search_app')]['userMode']); /* Update member cache */ if (isset($this->request['period']) and isset($this->request['change'])) { IPSMember::setToMemberCache($this->memberData, array('vncPrefs' => $vncPrefs)); } IPSDebug::addMessage(var_export($vncPrefs, true)); IPSDebug::addMessage('Using: ' . IPSSearchRegistry::get('in.period')); /* Can we do this? */ if (IPSLib::appIsSearchable(IPSSearchRegistry::get('in.search_app'), 'vnc') || IPSLib::appIsSearchable(IPSSearchRegistry::get('in.search_app'), 'active')) { /* Can't do a specific unread search, so */ if (IPSSearchRegistry::get('in.period') == 'unread' && !IPSLib::appIsSearchable(IPSSearchRegistry::get('in.search_app'), 'vncWithUnreadContent')) { IPSSearchRegistry::set('in.period', 'lastvisit'); } /* Perform the search */ $this->searchController->viewNewContent(); /* Get count */ $count = $this->searchController->getResultCount(); /* Get results which will be array of IDs */ $results = $this->searchController->getResultSet(); /* Get templates to use */ $template = $this->searchController->fetchTemplates(); /* Fetch sort details */ $sortDropDown = $this->searchController->fetchSortDropDown(); /* Fetch sort details */ $sortIn = $this->searchController->fetchSortIn(); /* Reset for template */ $this->_resetRequestParameters(); if (IPSSearchRegistry::get('in.start') > 0 and !count($results)) { $new_url = 'app=core&module=search&do=viewNewContent&period=' . IPSSearchRegistry::get('in.period') . '&userMode=' . IPSSearchRegistry::get('in.userMode') . '&search_app=' . IPSSearchRegistry::get('in.search_app') . '&sid=' . $this->request['_sid']; $new_url .= '&st=' . (IPSSearchRegistry::get('in.start') - IPSSearchRegistry::get('opt.search_per_page')) . '&search_app_filters[' . IPSSearchRegistry::get('in.search_app') . '][searchInKey]=' . $this->request['search_app_filters'][IPSSearchRegistry::get('in.search_app')]['searchInKey']; $this->registry->output->silentRedirect($this->settings['base_url'] . $new_url); } /* Parse result set */ $results = $this->registry->output->getTemplate($template['group'])->{$template}['template']($results, IPSSearchRegistry::get('opt.searchType') == 'titles' || IPSSearchRegistry::get('opt.noPostPreview') ? 1 : 0); /* Build pagination */ $links = $this->registry->output->generatePagination(array('totalItems' => $count, 'itemsPerPage' => IPSSearchRegistry::get('opt.search_per_page'), 'currentStartValue' => IPSSearchRegistry::get('in.start'), 'baseUrl' => 'app=core&module=search&do=viewNewContent&period=' . IPSSearchRegistry::get('in.period') . '&userMode=' . IPSSearchRegistry::get('in.userMode') . '&search_app=' . IPSSearchRegistry::get('in.search_app') . '&sid=' . $this->request['_sid'] . $this->_returnSearchAppFilters())); /* Showing */ $showing = array('start' => IPSSearchRegistry::get('in.start') + 1, 'end' => IPSSearchRegistry::get('in.start') + IPSSearchRegistry::get('opt.search_per_page') > $count ? $count : IPSSearchRegistry::get('in.start') + IPSSearchRegistry::get('opt.search_per_page')); } else { $count = 0; $results = array(); } /* Add Debug message */ IPSDebug::addMessage("View New Content Matches: " . $count); /* Check for sortIn */ if (count($sortIn) && !$this->request['search_app_filters'][$this->request['search_app']]['searchInKey']) { $this->request['search_app_filters'][$this->request['search_app']]['searchInKey'] = $sortIn[0][0]; } /* Output */ $this->title = $this->lang->words['new_posts_title']; $this->registry->output->addNavigation($this->lang->words['new_posts_title'], ''); $this->output .= $this->registry->output->getTemplate('search')->newContentView($results, $links, $count, $sortDropDown, $sortIn, IPSSearchRegistry::get('set.resultCutToDate')); }
/** * Formats / grabs extra data for results * Takes an array of IDS (can be IDs from anything) and returns an array of expanded data. * * @param array $ids Ids * @param array $followData Retrieve the follow meta data * @return array */ public function processFollowedResults($ids, $followData = array()) { /* Topics? */ if (IPSSearchRegistry::get('in.followContentType') == 'topics') { IPSSearchRegistry::set('set.returnType', 'tids'); return $this->processResults($ids, $followData); } return $ids; }
/** * Perform the search * Populates $this->_count and $this->_results * * @return nothin' */ public function viewNewContent() { IPSSearchRegistry::set('opt.searchTitleOnly', true); IPSSearchRegistry::set('in.period_in_seconds', false); /* Hard fix mobile app users to VNC based on ACP default VNC method */ if ($this->member->isMobileApp) { IPSSearchRegistry::set('in.period', $this->settings['default_vnc_method']); } /* Do we have a period? */ switch (IPSSearchRegistry::get('in.period')) { case 'today': default: $date = 86400; // 24 hours break; case 'week': $date = 604800; // 1 week break; case 'weeks': $date = 1209600; // 2 weeks break; case 'month': $date = 2592000; // 30 days break; case 'months': $date = 15552000; // 6 months break; case 'year': $date = 31536000; // 365 days break; case 'lastvisit': $date = time() - intval($this->memberData['last_visit']); break; case 'unread': $date = false; break; } /* Set date up */ IPSSearchRegistry::set('in.period_in_seconds', $date); /* Run the search */ $results = $this->SEARCH->viewNewContent(); /* Set data */ $this->_count = intval($results['count']); $this->_results = $this->_rawResults = $results['resultSet']; /* Now format results */ if (count($this->_results)) { $this->_results = $this->_rawResults = $this->FORMAT->processResults($this->_results); /* Now generate HTML */ $this->_results = $this->FORMAT->parseAndFetchHtmlBlocks($this->_results); } }
/** * Builds the where portion of a search string * * @param string $search_term The string to use in the search * @param bool $searchType Search only title records * @return string */ protected function _buildCommentsWhereStatement($search_term, $searchType = null) { /* INI */ $where_clause = array(); $searchType = $searchType === null ? IPSSearchRegistry::get('opt.searchType') : $searchType; $sort_order = IPSSearchRegistry::get('in.search_sort_order'); if ($search_term) { if ($searchType == 'titles') { $where_clause[] = $this->DB->buildSearchStatement('s.status_content', $search_term, true, false, false); } else { if ($searchType == 'content') { $where_clause[] = $this->DB->buildSearchStatement('r.reply_content', $search_term, true, false, false); } else { /* Set vars */ IPSSearch::$ask = 'status_date'; IPSSearch::$aso = strtolower($sort_order); IPSSearch::$ast = 'numerical'; /* Find topic ids that match */ $tids = array(); $pids = array(); $this->DB->build(array('select' => "s.status_id, s.status_date", 'from' => 'member_status_updates s', 'where' => $this->_buildCommentsWhereStatement($search_term, 'titles'), 'order' => 's.status_date ' . $sort_order, 'limit' => array(0, IPSSearchRegistry::get('set.hardLimit')))); $i = $this->DB->execute(); /* Grab the results */ while ($row = $this->DB->fetch($i)) { $_rows[$row['status_id']] = $row; } /* Sort */ if (count($_rows)) { usort($_rows, array("IPSSearch", "usort")); foreach ($_rows as $id => $row) { $tids[] = $row['status_id']; } } /* Set vars */ IPSSearch::$ask = 'reply_date'; IPSSearch::$aso = strtolower($sort_order); IPSSearch::$ast = 'numerical'; $this->DB->build(array('select' => "r.reply_id, r.reply_date, r.reply_status_id as status_id", 'from' => array('member_status_replies' => 'r'), 'add_join' => array(array('select' => 's.status_id, s.status_member_id, s.status_author_id', 'from' => array('member_status_updates' => 's'), 'where' => 's.status_id=r.reply_status_id', 'type' => 'left')), 'where' => $this->_buildCommentsWhereStatement($search_term, 'content'), 'order' => IPSSearch::$ask . ' ' . IPSSearch::$aso, 'limit' => array(0, IPSSearchRegistry::get('set.hardLimit')))); $i = $this->DB->execute(); /* Grab the results */ while ($row = $this->DB->fetch($i)) { $tids[] = $row['status_id']; $pids[] = $row['reply_id']; } if (count($pids)) { IPSSearchRegistry::set('_internal.replyIds', $pids); } $where_clause[] = '( s.status_id IN (' . (count($tids) ? implode(',', $tids) : 0) . ') )'; } } } /* Add in AND where conditions */ if (isset($this->whereConditions['AND']) && count($this->whereConditions['AND'])) { $where_clause = array_merge($where_clause, $this->whereConditions['AND']); } /* ADD in OR where conditions */ if (isset($this->whereConditions['OR']) && count($this->whereConditions['OR'])) { $where_clause[] = '( ' . implode(' OR ', $this->whereConditions['OR']) . ' )'; } /* Date Restrict */ if ($this->search_begin_timestamp && $this->search_end_timestamp) { $where_clause[] = $this->DB->buildBetween($searchType == 'content' ? "r.reply_date" : "s.status_date", $this->search_begin_timestamp, $this->search_end_timestamp); } else { if ($this->search_begin_timestamp) { $where_clause[] = $searchType == 'content' ? "r.reply_date > {$this->search_begin_timestamp}" : "s.status_date > {$this->search_begin_timestamp}"; } if ($this->search_end_timestamp) { $where_clause[] = $searchType == 'content' ? "r.reply_date < {$this->search_end_timestamp}" : "s.status_date < {$this->search_end_timestamp}"; } } /* Build and return the string */ return implode(" AND ", $where_clause); }
/** * Perform the viewNewContent search * Populates $this->_count and $this->_results * * @access public * @return array */ public function viewNewContent() { //----------------------------------------- // Init //----------------------------------------- IPSSearchRegistry::set('in.search_sort_by', 'date'); IPSSearchRegistry::set('in.search_sort_order', 'desc'); IPSSearchRegistry::set('opt.searchType', 'titles'); IPSSearchRegistry::set('opt.noPostPreview', true); //----------------------------------------- // Set time limit //----------------------------------------- if (IPSSearchRegistry::get('in.period_in_seconds') !== false) { $this->search_begin_timestamp = IPS_UNIX_TIME_NOW - IPSSearchRegistry::get('in.period_in_seconds'); } else { $this->search_begin_timestamp = intval($this->memberData['last_visit']) ? intval($this->memberData['last_visit']) : IPS_UNIX_TIME_NOW; } //----------------------------------------- // Only content we are following? //----------------------------------------- if (IPSSearchRegistry::get('in.vncFollowFilterOn') and $this->memberData['member_id']) { require_once IPS_ROOT_PATH . 'sources/classes/like/composite.php'; /*noLibHook*/ $like = classes_like::bootstrap('calendar', 'events'); $followedEvents = $like->getDataByMemberIdAndArea($this->memberData['member_id']); $followedEvents = $followedEvents === null ? array() : array_keys($followedEvents); if (!count($followedEvents)) { return array('count' => 0, 'resultSet' => array()); } else { $this->whereConditions['AND'][] = "c.event_id IN(" . implode(',', $followedEvents) . ")"; } } //----------------------------------------- // Only content we have participated in? //----------------------------------------- if (IPSSearchRegistry::get('in.userMode')) { switch (IPSSearchRegistry::get('in.userMode')) { default: case 'all': $_eventIds = $this->_getEventIdsFromComments(); if (count($_eventIds)) { $this->whereConditions['AND'][] = "(c.event_member_id=" . $this->memberData['member_id'] . " OR c.event_id IN(" . implode(',', $_eventIds) . "))"; } else { $this->whereConditions['AND'][] = "c.event_member_id=" . $this->memberData['member_id']; } break; case 'title': $this->whereConditions['AND'][] = "c.event_member_id=" . $this->memberData['member_id']; break; } } return $this->search(); }