cleanup
[mirrors/Kyberia-bloodline.git] / wwwroot / nodes.php
1 <?php
2
3 //requiring main config file with path/database etc. constants
4 require_once('config/config.inc');
5
6 //Ask for auth if enabled...
7 //if(isset($realm) && isset($users)) require_once(INCLUDE_DIR.'http_auth.php');
8
9 //PATH_INFO Debug (usefull when messing with mod_rewrite)
10 //echo($_SERVER['PATH_INFO']."\n<pre>");
11 //var_dump(preg_split('/\//', $_SERVER['PATH_INFO'])); die();
12 //output buffering forcing (mx)
13
14 if (!empty($_POST['FORCE_OB']) && $_POST['FORCE_OB'] == 'true') ob_start();
15
16 //header("Location: http://web.archive.org/web/20020925021139/http://kyberia.sk");
17 //echo "je to uz uplne v pici. vsetky data su stratene, prajem pekny den :)";
18 //exit;
19
20 //starting timer for benchmarking purposes
21 $timer_start=Time()+SubStr(MicroTime(),0,8);
22 //setting PHPSESSID cookie and starting user session
23 session_start();
24
25 error_reporting(1);
26 //$_SESSION['debugging']=1;
27 //unset($_SESSION['debugging']);
28 //Well... we should make some event
29 //or JavaScript page to turning this on/off...
30 //exit;
31
32
33 if ($_SESSION['debugging']) {
34
35 error_reporting(E_ALL);
36 echo 'GET VARIABLES::<br/>';
37 print_r($_GET);
38 echo 'POST VARIABLES::<br/>';
39 print_r($_POST);
40 echo '<b>SESSION VARIABLES::</b><br/>';
41 print_r($_SESSION);
42 }
43
44 @ini_set('magic_quotes_gpc' , 'off');
45 if(get_magic_quotes_gpc()) {
46 die("Error: magic_quotes_gpc needs to be disabled! F00K!\n");
47 }
48
49 //Smarty from DB
50 $smarty_resource = 'kyberia';
51 //$smarty_resource = ''; //same as 'file' (fallback)
52 /* I have moved old templates to DB using following lame script:
53 * for i in *.tpl; do j=$(echo "$i" | cut -d . -f 1);
54 echo UPDATE nodes SET node_content = "'$(php -r
55 "echo mysql_escape_string(file_get_contents('$i'));")'" WHERE
56 node_id = "'$j'" COLLATE utf8_bin LIMIT '1;';
57 done | mysql --user=kyberia --password=PASSSSSSS kyberia
58 * In future we should have some mechanism for distributing templates
59 * because they are very important part of kyberia source...
60 */
61
62 //Path info (Experimental - this replaced most of mod_rewrites...)
63 @$PATH_INFO=trim($_SERVER[PATH_INFO]);
64 if($PATH_INFO != '') {
65 $PATH_CHUNKS = preg_split('/\//', $PATH_INFO);
66 if(isset($PATH_CHUNKS[1])) switch($PATH_CHUNKS[1]) {
67 case 'k':
68 if(isset($PATH_CHUNKS[2]) && $PATH_CHUNKS[2] != '') $_GET['node_kid'] = $PATH_CHUNKS[2];
69 if(isset($PATH_CHUNKS[3]) && $PATH_CHUNKS[3] != '') $_GET['template_kid'] = $PATH_CHUNKS[3];
70 break;
71 case 'id':
72 if(isset($PATH_CHUNKS[2]) && $PATH_CHUNKS[2] != '') $_GET['node_id'] = $PATH_CHUNKS[2];
73 if(isset($PATH_CHUNKS[3]) && $PATH_CHUNKS[3] != '') $_GET['template_id'] = $PATH_CHUNKS[3];
74
75 //Base36 fascism redirect
76 if($_GET['template_id'] == 'download') break; //Fix ugly download hack...
77 if(!count($_POST)) {
78 header('Location: /k/'.base_convert($_GET['node_id'], 10, 36).
79 (isset($_GET['template_id'])?'/'.base_convert($_GET['template_id'], 10, 36):'')
80 );
81 die("Base36 fascism...\n");
82 // If you want to be a fascist
83 // you have to die imediatelly...
84 }
85
86 break;
87 default:
88 if($PATH_CHUNKS[1] != '') $_GET['node_name'] = $PATH_CHUNKS[1];
89 if(isset($PATH_CHUNKS[2]) && $PATH_CHUNKS[2] != '') $_GET['template_kid'] = $PATH_CHUNKS[2];
90 break;
91 }
92 }
93 if(
94 (!isset($_GET['node_kid']) || trim($_GET['node_kid']) == '') &&
95 (!isset($_GET['node_id']) || trim($_GET['node_id']) == '')
96 ) $_GET['node_kid'] = 1;
97
98 //Base36 http://en.wikipedia.org/wiki/Base_36 (Initial support only :-)
99 if(isset($_GET['node_kid'])) $_GET['node_id'] = base_convert($_GET['node_kid'], 36, 10);
100 if(isset($_GET['template_kid'])) $_GET['template_id'] = base_convert($_GET['template_kid'], 36, 10);
101
102 if (isset($_SERVER['HTTP_REFERER'])) {
103 preg_match('/(k|id)\/([0-9]*)\//',$_SERVER['HTTP_REFERER'],$ref_match);
104 $referer_id=$ref_match[1];
105 }
106
107 //connecting to database and creating universal $db object
108 //require_once(INCLUDE_DIR.'senate.inc'); // in config already
109 require_once(INCLUDE_DIR.'log.inc');
110 require_once(INCLUDE_DIR.'ubik.inc');
111 require_once(INCLUDE_DIR.'nodes.inc');
112 require_once(INCLUDE_DIR.'error_messages.inc');
113 require_once(INCLUDE_DIR.'database.inc');
114 require_once(INCLUDE_DIR.'transports.inc');
115
116 $db = new CLASS_DATABASE();
117
118 if (!empty($_GET['template_id'])) {
119 $template_id=$_GET['template_id'];
120 } else {
121 $template_id=false;
122 }
123
124 //initializing node methods
125 if (!empty($_GET['node_name'])) {
126 $node = nodes::redirByName($_GET['node_name']);
127 } elseif (!empty($_GET['node_id'])) {
128 $node = nodes::getNodeById($_GET['node_id'],
129 (isset($_SESSION['user_id']))?$_SESSION['user_id']:'');
130 }
131
132 //XXX Paths are wrong (!)
133 //loading smarty template engine and setting main parameters
134 require(SMARTY_DIR.'Smarty.class.php');
135 $smarty = new Smarty;
136 require(INCLUDE_DIR.'smarty/resource.kyberia.php');
137 $smarty->default_resource_type=$smarty_resource;
138
139 //$smarty->php_handling = SMARTY_PHP_REMOVE; //XXX
140 $smarty->template_dir = TEMPLATE_DIR;
141 //echo TEMPLATE_DIR.TEMPLATE_SET;
142 //echo $smarty->template_dir;
143 $smarty->compile_dir = SYSTEM_DATA.'templates_c/';
144 $smarty->config_dir = SMARTY_DIR.'configs/'; //XXX neexistuje
145 $smarty->cache_dir = SMARTY_DIR.'cache/';
146 $smarty->plugins_dir = SMARTY_PLUGIN_DIR ;
147 if ($_SESSION['debugging']) $smarty->debugging=true;
148
149 // initializing variables
150 // preg_replace prevents LFI
151 if (empty($_POST['event'])) $event='display';
152 else $event= preg_replace( "![^a-zA-Z0-9_]+!", "", $_POST['event']);
153
154
155 if ($_SESSION['debugging']) {
156 echo "<pre><b>NODE::";
157 print_r($node);
158 echo "</pre>";
159 }
160
161 if ((isset($_SESSION['user_id']) && ($node['node_creator']==$_SESSION['user_id']))) {
162 $node['node_permission']='owner';
163 }
164
165 if (isset($_SESSION['cube_vector']) && ($_SESSION['cube_vector'])) {
166 if (strpos($node['node_vector'],$_SESSION['cube_vector'])===false) {
167 echo "node::".$node['node_vector'];
168 echo "cube_Vector::".$_SESSION['cube_vector'];
169 echo "you are out of allowed cwbe. access forbidden";
170 die();
171 }
172 }
173
174 //if not existent node show our own 404
175 if (empty($node)) {
176 $nodes= nodes::getNodesByName($_GET['node_name']);
177 if ($nodes) {
178 $smarty->assign('nodes',$nodes);
179 $content=$smarty->display('404.tpl');
180 die();
181 }
182 elseif ($_SESSION['user_id']) {
183 $smarty->assign('node_name',$_GET['node_name']);
184 $content=$smarty->display("modules/addnode.tpl");
185 }
186 }
187
188 //modifying node glass pearl //XXX WTF
189 //if (is_array($children_types[$node['node_type']])) {
190 // $smarty->assign('children_types',$children_types[$node['node_type']]);
191 //}
192
193 //smarty->assign('types',$types);
194 //$node['node_type']=$types[$node['node_type']];
195
196 @include_once(INCLUDE_DIR.'mail_rss.inc'); //haluz...
197
198 //checking permissions
199 function _checkPermissions()
200 {
201 global $permissions, $node;
202 require(INCLUDE_DIR.'permissions.inc');
203 $permissions=permissions::checkPermissions($node);
204 $permissions['h']=permissions::isHierarch($node);
205 }
206 _checkPermissions();
207
208 //entering the node (executing the eventz)
209 if (($permissions['r']) || ($event != 'register')) {
210 //performing node_events (based on update/insert/delete db queries)
211 if ($event) {
212 require(INCLUDE_DIR.'eventz.inc');
213 }
214 }
215
216 if (isset($_POST['FORCE_OB'])) ob_end_flush(); //output buffering forcing (mx)
217
218 ?>
This page took 0.94948 seconds and 4 git commands to generate.