Gazelle/classes/alias.class.php

78 lines
1.9 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
class ALIAS {
function convert($str) {
return trim(substr(preg_replace('/[^a-z0-9]/', '', strtolower(htmlentities($str))), 0, 50));
}
//Alternative approach with potential.
function flush() {
2013-08-28 23:08:41 +00:00
$QueryID = G::$DB->get_query_id();
G::$DB->query("
2013-06-06 08:01:03 +00:00
SELECT Alias, ArticleID
FROM wiki_aliases");
2013-08-28 23:08:41 +00:00
$Aliases = G::$DB->to_array('Alias');
G::$DB->set_query_id($QueryID);
G::$Cache->cache_value('wiki_aliases', $Aliases, 3600 * 24 * 14); // 2 weeks
2011-03-28 14:21:28 +00:00
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
function to_id($Alias) {
2013-08-28 23:08:41 +00:00
$Aliases = G::$Cache->get_value('wiki_aliases');
2013-04-20 08:01:01 +00:00
if (!$Aliases) {
2013-08-28 23:08:41 +00:00
$QueryID = G::$DB->get_query_id();
G::$DB->query("
2013-06-06 08:01:03 +00:00
SELECT Alias, ArticleID
FROM wiki_aliases");
2013-08-28 23:08:41 +00:00
$Aliases = G::$DB->to_array('Alias');
G::$DB->set_query_id($QueryID);
G::$Cache->cache_value('wiki_aliases', $Aliases, 3600 * 24 * 14); // 2 weeks
2011-03-28 14:21:28 +00:00
}
return $Aliases[$this->convert($Alias)]['ArticleID'];
}
/*
function flush() {
}
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
function to_id($Alias) {
$Alias = $this->convert($Alias);
2013-08-28 23:08:41 +00:00
G::$DB->query("
2013-06-06 08:01:03 +00:00
SELECT ArticleID
FROM wiki_aliases
WHERE Alias LIKE '$Alias'");
2013-08-28 23:08:41 +00:00
list($ArticleID) = G::$DB->next_record();
2011-03-28 14:21:28 +00:00
return $ArticleID;
}
*/
2012-12-11 08:00:18 +00:00
function article($ArticleID, $Error = true) {
2013-08-28 23:08:41 +00:00
$Contents = G::$Cache->get_value('wiki_article_'.$ArticleID);
2013-04-20 08:01:01 +00:00
if (!$Contents) {
2013-08-28 23:08:41 +00:00
$QueryID = G::$DB->get_query_id();
G::$DB->query("
2013-04-20 08:01:01 +00:00
SELECT
2011-03-28 14:21:28 +00:00
w.Revision,
w.Title,
w.Body,
w.MinClassRead,
w.MinClassEdit,
w.Date,
w.Author,
u.Username,
GROUP_CONCAT(a.Alias),
GROUP_CONCAT(a.UserID)
2013-04-20 08:01:01 +00:00
FROM wiki_articles AS w
2011-03-28 14:21:28 +00:00
LEFT JOIN wiki_aliases AS a ON w.ID=a.ArticleID
LEFT JOIN users_main AS u ON u.ID=w.Author
2013-04-20 08:01:01 +00:00
WHERE w.ID='$ArticleID'
GROUP BY w.ID");
2013-08-28 23:08:41 +00:00
if (!G::$DB->has_results() && $Error) {
2013-04-20 08:01:01 +00:00
error(404);
}
2013-08-28 23:08:41 +00:00
$Contents = G::$DB->to_array();
G::$DB->set_query_id($QueryID);
G::$Cache->cache_value('wiki_article_'.$ArticleID, $Contents, 3600 * 24 * 14); // 2 weeks
2011-03-28 14:21:28 +00:00
}
return $Contents;
}
}
?>