| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
require_once ('init.php'); |
|---|
| 29 |
|
|---|
| 30 |
function relatedTags($tags) { |
|---|
| 31 |
|
|---|
| 32 |
$twhere = ""; |
|---|
| 33 |
foreach ($tags as $tag) { |
|---|
| 34 |
$tag = rss_real_escape_string($tag); |
|---|
| 35 |
$twhere .= "t.tag='$tag' or "; |
|---|
| 36 |
} |
|---|
| 37 |
$twhere .= "1=0"; |
|---|
| 38 |
|
|---|
| 39 |
$sql = "select fid,tid,m.tdate from ".getTable('metatag') ." m " |
|---|
| 40 |
."inner join " . getTable('tag') . " t on t.id = m.tid where m.ttype = 'item'" |
|---|
| 41 |
." and ($twhere)"; |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
$res = rss_query($sql); |
|---|
| 45 |
$fids = array (); |
|---|
| 46 |
$ctid = -1; |
|---|
| 47 |
while (list ($fid, $tid) = rss_fetch_row($res)) { |
|---|
| 48 |
$fids[] = $fid; |
|---|
| 49 |
$tids[] = $tid; |
|---|
| 50 |
} |
|---|
| 51 |
$fids = array_unique($fids); |
|---|
| 52 |
$tids = array_unique($tids); |
|---|
| 53 |
|
|---|
| 54 |
$rtags = array (); |
|---|
| 55 |
if (count($fids)) { |
|---|
| 56 |
$sql = "select t.tag, count(*) as cnt from ".getTable('metatag') |
|---|
| 57 |
." m left join ".getTable('item')." i on (m.fid=i.id) " |
|---|
| 58 |
." inner join " . getTable('tag')." t on (t.id = m.tid) " |
|---|
| 59 |
." where m.fid in (".implode(",", $fids).")" |
|---|
| 60 |
." and t.id not in (".implode(",", $tids).")"; |
|---|
| 61 |
|
|---|
| 62 |
if (hidePrivate()) { |
|---|
| 63 |
$sql .= " and not(i.unread & ".RSS_MODE_PRIVATE_STATE.") "; |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
$sql .= " group by t.tag order by cnt desc"; |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
$res = rss_query($sql); |
|---|
| 70 |
while ((list ($rtag, $cnt) = rss_fetch_row($res))) { |
|---|
| 71 |
$rtags[$rtag] = $cnt; |
|---|
| 72 |
} |
|---|
| 73 |
} |
|---|
| 74 |
return $rtags; |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
if (array_key_exists('tag', $_GET)) { |
|---|
| 78 |
|
|---|
| 79 |
$tag = strip_tags($_GET['tag']); |
|---|
| 80 |
$twhere = ""; |
|---|
| 81 |
$tarr = explode(" ", $tag); |
|---|
| 82 |
$hrTag = implode(" ".__('and')." ", $tarr); |
|---|
| 83 |
$urlTag = implode("+", $tarr); |
|---|
| 84 |
|
|---|
| 85 |
foreach ($tarr as $ttkn) { |
|---|
| 86 |
$twhere .= " t.tag='".trim(rss_real_escape_string($ttkn))."' or"; |
|---|
| 87 |
} |
|---|
| 88 |
$twhere .= " 1=0"; |
|---|
| 89 |
|
|---|
| 90 |
$sql = "select fid, count(*) as cnt from " . getTable('metatag')." m " |
|---|
| 91 |
."inner join " . getTable('tag')." t on t.id = m.tid " |
|---|
| 92 |
." where ($twhere) " |
|---|
| 93 |
." and m.ttype = 'item'" |
|---|
| 94 |
." group by fid order by 2 desc"; |
|---|
| 95 |
|
|---|
| 96 |
$res = rss_query($sql); |
|---|
| 97 |
$ids = array (); |
|---|
| 98 |
while ((list ($id, $cnt) = rss_fetch_row($res)) && $cnt >= count($tarr)) { |
|---|
| 99 |
$ids[] = $id; |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
$gotsome = count($ids) > 0; |
|---|
| 103 |
$taggedItems = new PaginatedItemList(); |
|---|
| 104 |
if ($gotsome) { |
|---|
| 105 |
|
|---|
| 106 |
$sqlWhere = " i.id in (".implode(",", $ids).") "; |
|---|
| 107 |
|
|---|
| 108 |
$taggedItems->populate($sqlWhere, "", 0, -1, ITEM_SORT_HINT_MIXED, true); |
|---|
| 109 |
|
|---|
| 110 |
$rtags = relatedTags($tarr); |
|---|
| 111 |
$related = array (); |
|---|
| 112 |
foreach ($rtags as $rtag => $cnt) { |
|---|
| 113 |
$relLbl = "<a href=\"".getPath()."" |
|---|
| 114 |
. (getConfig('rss.output.usemodrewrite') ? "tag/$rtag" : "tags.php?tag=$rtag").""."\">$rtag</a>"; |
|---|
| 115 |
|
|---|
| 116 |
$relPlus = array_key_exists($rtag, $taggedItems->allTags); |
|---|
| 117 |
if ($relPlus) { |
|---|
| 118 |
$relLbl .= sprintf( |
|---|
| 119 |
' [<a title="%d %s %s \'%s %s %s"\' href="%s+%s">+</a>]', |
|---|
| 120 |
$cnt, |
|---|
| 121 |
$cnt > 1 ? __('items') : __('item'), |
|---|
| 122 |
$cnt > 1 || $cnt == 0 ? __('tagged') : __('tagged'), |
|---|
| 123 |
htmlspecialchars($hrTag,ENT_QUOTES), |
|---|
| 124 |
__('and'), |
|---|
| 125 |
htmlspecialchars($rtag,ENT_QUOTES), |
|---|
| 126 |
getPath(getConfig('rss.output.usemodrewrite') ? "tag/$rtag" : "tags.php?tag=$rtag"), |
|---|
| 127 |
htmlspecialchars($urlTag,ENT_QUOTES) |
|---|
| 128 |
); |
|---|
| 129 |
|
|---|
| 130 |
" [<a "."title=\"$cnt " |
|---|
| 131 |
. ($cnt > 1 ? __('items') : __('item'))." ". ($cnt > 1 || $cnt == 0 ? __('tagged') : __('tagged'))." '" |
|---|
| 132 |
.htmlspecialchars($hrTag,ENT_QUOTES)." ".__('and')." ".htmlspecialchars($rtag,ENT_QUOTES)."'\" " |
|---|
| 133 |
."href=\"".getPath()."" |
|---|
| 134 |
. (getConfig('rss.output.usemodrewrite') ? "tag/$rtag" : "tags.php?tag=$rtag")."" |
|---|
| 135 |
."+".$urlTag."\">+</a>]"; |
|---|
| 136 |
} |
|---|
| 137 |
$idx = ($relPlus ? $taggedItems->allTags[$rtag] : 0); |
|---|
| 138 |
$related["$idx"."_"."$rtag"] = $relLbl.""; |
|---|
| 139 |
} |
|---|
| 140 |
krsort($related); |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
if (array_key_exists('rss', $_REQUEST)) { |
|---|
| 145 |
rss_require('cls/rdf.php'); |
|---|
| 146 |
|
|---|
| 147 |
$title = _TITLE_." - ".__('Tags')." - ".$hrTag; |
|---|
| 148 |
$baselink = guessTransportProto().$_SERVER['HTTP_HOST'].getPath() |
|---|
| 149 |
. (getConfig('rss.output.usemodrewrite') ? "tag/" : "tags.php?tag="); |
|---|
| 150 |
|
|---|
| 151 |
if ($gotsome) { |
|---|
| 152 |
$rdf = new RDFItemList($taggedItems); |
|---|
| 153 |
} else { |
|---|
| 154 |
$rdf = new RDFItemList(null); |
|---|
| 155 |
} |
|---|
| 156 |
$rdf->baselink = $baselink; |
|---|
| 157 |
$rdf->resource = $urlTag; |
|---|
| 158 |
$rdf->render($title); |
|---|
| 159 |
exit (); |
|---|
| 160 |
} else { |
|---|
| 161 |
|
|---|
| 162 |
//rss_header("Tags " . TITLE_SEP . " " . $hrTag); |
|---|
| 163 |
$GLOBALS['rss']->header = new Header("Tags ".TITLE_SEP." ".$hrTag); |
|---|
| 164 |
$GLOBALS['rss']->feedList = new FeedList(false); |
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
if ($gotsome) { |
|---|
| 169 |
|
|---|
| 170 |
$title = $taggedItems->itemCount." ". ($taggedItems->itemCount > 1 ? __('items') : __('item'))." " |
|---|
| 171 |
. ($taggedItems->itemCount > 1 || $taggedItems->itemCount == 0 ? __('tagged') : __('tagged')) |
|---|
| 172 |
.""." \"".$hrTag."\""; |
|---|
| 173 |
|
|---|
| 174 |
if (count($related)) { |
|---|
| 175 |
$taggedItems->beforeList = "\n<p>".__('Related tags: ')."\n".implode(", \n", $related)."\n</p>\n"; |
|---|
| 176 |
} |
|---|
| 177 |
|
|---|
| 178 |
$taggedItems->setTitle($title); |
|---|
| 179 |
$taggedItems->setRenderOptions(IL_NO_COLLAPSE|IL_TITLE_NO_ESCAPE); |
|---|
| 180 |
$GLOBALS['rss']->appendContentObject($taggedItems); |
|---|
| 181 |
|
|---|
| 182 |
$GLOBALS['rss']->renderWithTemplate('index.php', 'items'); |
|---|
| 183 |
|
|---|
| 184 |
} else { |
|---|
| 185 |
$GLOBALS['rss']->renderWithTemplate('index.php', 'items'); |
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
} |
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
} |
|---|
| 194 |
|
|---|
| 195 |
array_key_exists('alltags', $_GET)) { |
|---|
| 196 |
rss_require('cls/alltags.php'); |
|---|
| 197 |
|
|---|
| 198 |
$GLOBALS['rss']->header = new Header("Tags ".TITLE_SEP." ".__('All Tags')); |
|---|
| 199 |
$GLOBALS['rss']->feedList = new FeedList(false); |
|---|
| 200 |
$allTags = new Tags(); |
|---|
| 201 |
$allTags->setRenderOptions(IL_TITLE_NO_ESCAPE); |
|---|
| 202 |
$GLOBALS['rss']->appendContentObject($allTags); |
|---|
| 203 |
$GLOBALS['rss']->renderWithTemplate('index.php', 'items'); |
|---|
| 204 |
|
|---|
| 205 |
?> |
|---|
| 206 |
|
|---|