/** * Replacement for get_calendar_week_link() * * @param int ID of the linked calendar. * @param int Week. * @return string Calendar Week URL. */ function google_seo_url_calendar_week($cid, $week) { global $settings; if ($settings['google_seo_url_calendars'] && $cid > 0) { $url = google_seo_url_cache(GOOGLE_SEO_CALENDAR, $cid); if ($url) { $week = str_replace('-', 'n', $week); $glue = strpos($url, '?') === false ? '?' : '&'; $url .= "{$glue}action=weekview&week={$week}"; return $url; } } }
function xthreads_forumdisplay_filter() { global $mybb, $foruminfo, $tf_filters, $xt_filters, $threadfield_cache; global $visibleonly, $tvisibleonly, $__xt_visibleonly, $db; $q = ''; $tvisibleonly_tmp = $tvisibleonly; $__xt_visibleonly = $visibleonly; if ($foruminfo['xthreads_inlinesearch']) { global $templates, $lang, $gobutton, $fid, $sortby, $sortordernow, $datecut, $xthreads_forum_filter_form; $searchval = ''; if (!xthreads_empty($mybb->input['search'])) { $qstr = 'subject LIKE "%' . $db->escape_string_like($mybb->input['search']) . '%"'; $visibleonly .= ' AND ' . $qstr; $q .= ' AND t.' . $qstr; $tvisibleonly .= ' AND t.' . $qstr; $searchval = htmlspecialchars_uni($mybb->input['search']); } eval('$GLOBALS[\'searchforum\'] = "' . $templates->get('forumdisplay_searchforum_inline') . '";'); } if (!empty($tf_filters)) { foreach ($tf_filters as $field => &$val) { // $threadfield_cache is guaranteed to be set here $val2 = is_array($val) ? $val : array($val); $fieldname = 'tfd.`' . $db->escape_string($field) . '`'; $filtermode = $threadfield_cache[$field]['allowfilter']; if (!xthreads_empty($threadfield_cache[$field]['multival'])) { // ugly, but no other way to really do this... $qstr = '('; $qor = ''; switch ($filtermode) { case XTHREADS_FILTER_PREFIX: $cfield = xthreads_db_concat_sql(array("\"\n\"", $fieldname)); $qlpre = "%\n"; $qlpost = ''; break; case XTHREADS_FILTER_ANYWHERE: $cfield = $fieldname; $qlpre = $qlpost = ''; break; default: $cfield = xthreads_db_concat_sql(array("\"\n\"", $fieldname, "\"\n\"")); $qlpre = "%\n"; $qlpost = "\n%"; } foreach ($val2 as &$v) { $qstr .= $qor . $cfield . ' LIKE "' . $qlpre . xthreads_forumdisplay_filter_parselike($v, $filtermode) . $qlpost . '"'; if (!$qor) { $qor = ' OR '; } } $qstr .= ')'; } elseif ($threadfield_cache[$field]['datatype'] == XTHREADS_DATATYPE_TEXT) { if ($filtermode == XTHREADS_FILTER_EXACT) { $qstr = $fieldname . ' IN ("' . implode('","', array_map(array($db, 'escape_string'), $val2)) . '")'; } else { $qstr = ''; $qor = ''; foreach ($val2 as &$v) { $qstr .= $qor . $fieldname . ' LIKE "' . xthreads_forumdisplay_filter_parselike($v, $filtermode) . '"'; if (!$qor) { $qor = ' OR '; } } $qstr = '(' . $qstr . ')'; } } else { // numeric filtering $qstr = xthreads_forumdisplay_filter_numericq($val2, $fieldname, $threadfield_cache[$field]['datatype']); } $q .= ' AND ' . $qstr; $tvisibleonly .= ' AND ' . $qstr; } } if (!empty($xt_filters)) { foreach ($xt_filters as $field => &$val) { $fieldname = '`' . $db->escape_string($field) . '`'; $qstr = xthreads_forumdisplay_filter_numericq(is_array($val) ? $val : array($val), $fieldname, XTHREADS_DATATYPE_UINT); $q .= ' AND t.' . $qstr; $tvisibleonly .= ' AND ' . str_replace($fieldname, 't.' . $fieldname, $qstr); $visibleonly .= ' AND ' . $qstr; } } if ($q) { if (!empty($tf_filters)) { global $__xt_tvisibleonly; $__xt_tvisibleonly = $tvisibleonly_tmp . $q; } // and now we have to patch the DB to get proper thread counts... $dbf = $dbt = $dbu = ''; // TODO: the following conditional may change depending on the outcome of this bug: https://github.com/mybb/mybb/issues/1890 if (($GLOBALS['datecut'] <= 0 || $GLOBALS['datecut'] == 9999) && !@$GLOBALS['fpermissions']['canonlyviewownthreads']) { if (!empty($tf_filters)) { $dbf_code = ' $table = "threads t LEFT JOIN {$this->table_prefix}threadfields_data tfd ON t.tid=tfd.tid"; $fields = "COUNT(t.tid) AS threads, 0 AS unapprovedthreads, 0 AS deletedthreads"; $conditions .= " $GLOBALS[__xt_tvisibleonly] $GLOBALS[tuseronly] $GLOBALS[datecutsql2] $GLOBALS[prefixsql2]"; '; } else { $dbf_code = ' $table = "threads"; $fields = "COUNT(tid) AS threads, 0 AS unapprovedthreads, 0 AS deletedthreads"; $conditions .= " $GLOBALS[visibleonly] $GLOBALS[useronly] $GLOBALS[datecutsql] $GLOBALS[prefixsql]"; '; } $dbf = ' static $done_f = false; if(!$done_f && $table == "forums" && ($fields == "threads, unapprovedthreads" || $fields == "threads, unapprovedthreads, deletedthreads")) { $done_f = true; ' . $dbf_code . ' } '; } if (!empty($tf_filters)) { // if filtering by thread fields, we need to patch the counting query to include threadfield data and patch the query to reference the correct tables function xthreads_forumdisplay_filter_fixqcond($conditions) { $repl = array(); foreach (array('useronly' => 'tuseronly', 'visibleonly' => '__xt_tvisibleonly', 'datecutsql' => 'datecutsql2', 'prefixsql' => 'prefixsql2') as $from => $to) { if ($GLOBALS[$from]) { $repl[$GLOBALS[$from]] = $GLOBALS[$to]; } } if (empty($repl)) { return $conditions; } return strtr($conditions, $repl); } $dbt = ' static $done_t = false; if(!$done_t && $table == "threads" && $fields == "COUNT(tid) AS threads") { $done_t = true; $table = "threads t LEFT JOIN {$this->table_prefix}threadfields_data tfd ON t.tid=tfd.tid"; $fields = "COUNT(t.tid) AS threads"; $conditions = xthreads_forumdisplay_filter_fixqcond($conditions); $options = array("limit" => 1); } '; } if ($__xt_visibleonly != $visibleonly && $mybb->user['uid']) { // fix up posts query in MyBB 1.6.4 $dbu = ' static $done_u = false; if(!$done_u && $table == "posts" && ($fields == "tid,uid" || $fields == "DISTINCT tid,uid") && strpos($conditions, $GLOBALS[\'visibleonly\'])) { $done_u = true; $conditions = str_replace($GLOBALS[\'visibleonly\'], $GLOBALS[\'__xt_visibleonly\'], $conditions); } '; } if ($dbf || $dbt || $dbu) { control_object($db, ' function simple_select($table, $fields="*", $conditions="", $options=array()) { ' . $dbt . $dbf . $dbu . ' return parent::simple_select($table, $fields, $conditions, $options); } '); } } // if we have custom filters/inline search, patch the forumdisplay paged URLs + sorter links global $xthreads_forum_filter_args, $page_url_xt; if ($xthreads_forum_filter_args) { // if Google SEO multipage is active, force our URL into that if (function_exists('google_seo_url_cache') && $mybb->settings['google_seo_url_multipage'] && $mybb->settings['google_seo_url_forums']) { // force cache load $gsurl = google_seo_url_cache(GOOGLE_SEO_FORUM, $foruminfo['fid']); $page_url_xt = $xthreads_forum_filter_args; if (strpos($gsurl, '?') === false) { $page_url_xt = '?' . substr($page_url_xt, 1); } // pollute Google SEO's cache with our param $GLOBALS['google_seo_url_cache'][GOOGLE_SEO_FORUM][$foruminfo['fid']] = $gsurl . $page_url_xt; $GLOBALS['sorturl'] .= htmlspecialchars_uni($xthreads_forum_filter_args); } else { // inject URL into multipage using template cache hack global $templates; $tpls = array('multipage_end', 'multipage_nextpage', 'multipage_page', 'multipage_prevpage', 'multipage_start'); foreach ($tpls as &$t) { if (!isset($templates->cache[$t])) { $templates->cache(implode(',', $tpls)); break; } $templates->cache[$t] = str_replace('{$page_url}', '{$page_url}{$GLOBALS[\'page_url_xt\']}', $templates->cache[$t]); } $page_url_xt = htmlspecialchars_uni($xthreads_forum_filter_args); $GLOBALS['sorturl'] .= $page_url_xt; // may need to replace first & with a ? if (($mybb->settings['seourls'] == 'yes' || $mybb->settings['seourls'] == 'auto' && $_SERVER['SEO_SUPPORT'] == 1) && $GLOBALS['sortby'] == 'lastpost' && $GLOBALS['sortordernow'] == 'desc' && ($GLOBALS['datecut'] <= 0 || $GLOBALS['datecut'] == 9999) && !@$GLOBALS['tprefix']) { // && (strpos(FORUM_URL_PAGED, '{page}') === false) - somewhat unsupported, since MyBB hard codes the page 1 elimination behaviour $page_url_xt = '?' . substr($page_url_xt, 5); } } $templates->cache['forumdisplay_threadlist'] = str_replace('<select name="sortby">', '{$xthreads_forum_filter_form}{$xthreads_forum_search_form}<select name="sortby">', $templates->cache['forumdisplay_threadlist']); } }