$twhere .= " t.tag='" . trim(rss_real_escape_string($ttkn)) . "' or"; } $twhere .= " 1=0"; $sql = "select fid, count(*) as cnt from " . getTable('metatag') . " m " . "inner join " . getTable('tag') . " t on t.id = m.tid " . " where ({$twhere}) " . " and m.ttype = 'item'" . " group by fid order by 2 desc"; $res = rss_query($sql); $ids = array(); while ((list($id, $cnt) = rss_fetch_row($res)) && $cnt >= count($tarr)) { $ids[] = $id; } $gotsome = count($ids) > 0; $taggedItems = new PaginatedItemList(); if ($gotsome) { $sqlWhere = " i.id in (" . implode(",", $ids) . ") "; // include deprecated feeds while showing tags. $taggedItems->populate($sqlWhere, "", 0, -1, ITEM_SORT_HINT_MIXED, true); $rtags = relatedTags($tarr); $related = array(); foreach ($rtags as $rtag => $cnt) { $relLbl = "<a href=\"" . getPath() . "" . (getConfig('rss.output.usemodrewrite') ? "tag/{$rtag}" : "tags.php?tag={$rtag}") . "" . "\">{$rtag}</a>"; $relPlus = array_key_exists($rtag, $taggedItems->allTags); if ($relPlus) { $relLbl .= sprintf(' [<a title="%d %s %s \'%s %s %s"\' href="%s+%s">+</a>]', $cnt, $cnt > 1 ? __('items') : __('item'), $cnt > 1 || $cnt == 0 ? __('tagged') : __('tagged'), htmlspecialchars($hrTag, ENT_QUOTES), __('and'), htmlspecialchars($rtag, ENT_QUOTES), getPath(getConfig('rss.output.usemodrewrite') ? "tag/{$rtag}" : "tags.php?tag={$rtag}"), htmlspecialchars($urlTag, ENT_QUOTES)); " [<a " . "title=\"{$cnt} " . ($cnt > 1 ? __('items') : __('item')) . " " . ($cnt > 1 || $cnt == 0 ? __('tagged') : __('tagged')) . " '" . htmlspecialchars($hrTag, ENT_QUOTES) . " " . __('and') . " " . htmlspecialchars($rtag, ENT_QUOTES) . "'\" " . "href=\"" . getPath() . "" . (getConfig('rss.output.usemodrewrite') ? "tag/{$rtag}" : "tags.php?tag={$rtag}") . "" . "+" . $urlTag . "\">+</a>]"; } $idx = $relPlus ? $taggedItems->allTags[$rtag] : 0; $related["{$idx}" . "_" . "{$rtag}"] = $relLbl . ""; } krsort($related); } // done! Render some stuff if (array_key_exists('rss', $_REQUEST)) {
function testRelatedTags() { $r = relatedTags(new folksoQuery(array(), array('folksotag' => 'tagone'), array()), $this->dbc, $this->fks); $this->assertIsA($r, folksoResponse, 'This is not my beautiful folksoResponse object'); $this->assertEqual($r->status, 204, 'There should not be any related tags: ' . $r->status . $r->body()); $this->expectError(); $baddb = relatedTags(new folksoQuery(array(), array('folksotag' => 'tagone'), array()), new folksoDBconnect('localhost', 'hoohaa', 'hoohaa', 'hoohaa'), $this->fks2); $this->assertIsA($baddb, folksoResponse, 'Object creation problem with bad DB'); $this->assertEqual($baddb->status, 500, 'Incorrect http status: ' . $baddb->status); }