-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrender.php
More file actions
99 lines (81 loc) · 3.58 KB
/
render.php
File metadata and controls
99 lines (81 loc) · 3.58 KB
1
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?
/*
Wyświetl zwykłą stronę
*/
require_once "common.php";
/* Get content class */
function co($id, $table = "content", $type = false)
{
global $S;
if(!$type) $type = vsql::get("SELECT type FROM {$table} WHERE deleted = 0 AND id = " . vsql::quote($id), "type");
if(!preg_match('/^[a-z_]+$/', $type)) die("ERR Invalid content type: " . $type);
if(!file_exists("classes/content/{$type}.php")) die("ERR Unknown content type: " . $type);
$classname = "content_" . $type;
return new $classname($S);
}
function dispatch_object($id, $type = false)
{
co($id, "content", $type)->render_object($id, $_REQUEST["q"]);
exit;
}
function dispatch_category($id, $type = false)
{
co($id, "categories", $type)->render_category($id, $_REQUEST["q"]);
exit;
}
$S = get_Smarty();
$S->registerResource('cat', new tpl_cat_loader());
$S->registerResource('art', new tpl_art_loader());
$S->assign("request", $_REQUEST);
$S->assign("req", $_REQUEST);
$q = $_REQUEST["q"];
$m = array();
/* Obsługa różnych składni */
/* Odnośniki do starego systemu */
if(preg_match('/.*(news|article)\.acs$/', $q, $m))
if(!($q = vsql::get("SELECT id FROM content WHERE deleted = 0 AND legacy_id = " . vsql::quote($_REQUEST["id"]), "id", 0)))
fail(404, "Nieznany artykuł z poprzedniego systemu: ". $_REQUEST["id"]);
/* Cyfry oznaczające identyfikator obiektu */
if(is_numeric($q))
dispatch_object($q);
/* Ścieżka kategorii zakończona numerem plus ew. rozszerzeniem/rozszerzeniami */
else if(preg_match('#^([a-z][a-z0-9_]*/)*([0-9]+)(\.[a-z0-9.]+)?$#i', $q, $m))
dispatch_object($m[2]);
/* Ścieżka kategorii zakończona skrótem */
else if(preg_match('#^(([a-z][a-z0-9_]*/)*)([a-z][0-9a-z_.~-]*)/?$#', $q, $m) || $q == "/" || $q == "")
{
if($q == "" || $q == "/")
$m = array(1 => "/", 3 => "/");
if(substr($q, -1) == "?")
$q = substr($q, 0, strlen($q) - 1);
$S->assign("urlpath", $catpath = trim($m[1], "/"));
if($o = vsql::get($query = "SELECT a.id, a.type
FROM content AS a
JOIN category_map AS cm ON cm.article = a.id AND cm.main = 1
JOIN categories AS cat ON cat.id = cm.category
WHERE cat.path = " . vsql::quote("/" . $catpath) .
" AND a.short = " . vsql::quote(trim($m[3], "/")) .
" AND a.deleted = 0 LIMIT 1"))
dispatch_object($o["id"], $o["type"]);
$S->assign("urlpath", $catpath = "/" . trim($q, "/"));
if($o = vsql::get($qry = "SELECT cat.id, cat.type
FROM categories AS cat
WHERE cat.path = " . vsql::quote($catpath) .
" ORDER BY cat.id DESC LIMIT 1"))
dispatch_category($o["id"], $o["type"]);
}
/* Ścieżka kategorii zakończona username */
else if(preg_match('#^(([a-z][a-z0-9_]*/)*)~([a-zA-Z0-9_.]+)$#', $q, $m))
{
if(!isset($_REQUEST["category"]))
$_REQUEST["category"] = vsql::get("SELECT id FROM categories WHERE path = " . vsql::quote("/" . trim($m[2], "/")), "id");
co($m[3], "users", "user")->render_object($m[3], $q);
exit;
}
/* Club name */
else if(preg_match('#^_([a-zA-Z0-9_.]+)$#', $q, $m))
{
co($m[1], "members", "member")->render_object($m[1], $q);
exit;
}
fail(404, "Nieznana składnia zasobu: $q");