PageRenderTime 65ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/lib/lib_pixie.php

http://pixie-cms.googlecode.com/
PHP | 283 lines | 237 code | 0 blank | 46 comment | 81 complexity | eb3b7972e388f32ff3975fc164fea7b7 MD5 | raw file
  1. <?php
  2. if (!defined('DIRECT_ACCESS')) {
  3. header('Location: ../../');
  4. exit();
  5. }
  6. /**
  7. * Pixie: The Small, Simple, Site Maker.
  8. *
  9. * Licence: GNU General Public License v3
  10. * Copyright (C) 2010, Scott Evans
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see http://www.gnu.org/licenses/
  24. *
  25. * Title: lib_pixie
  26. *
  27. * @package Pixie
  28. * @copyright 2008-2010 Scott Evans
  29. * @author Scott Evans
  30. * @author Sam Collett
  31. * @author Tony White
  32. * @author Isa Worcs
  33. * @link http://www.getpixie.co.uk
  34. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3
  35. *
  36. */
  37. // ------------------------------------------------------------------
  38. // set up pixie and let the magic begin
  39. function pixie() {
  40. global $s, $m, $x, $p, $rel_path, $staticpage, $style, $site_url, $page_display_name, $page_type, $page_id, $syle, $clean_urls, $default_page;
  41. $request = $_SERVER['REQUEST_URI'];
  42. if ($style) {
  43. $request = str_replace("?style={$style}", "", $request);
  44. }
  45. $site_url_last = $site_url{strlen($site_url) - 1};
  46. if ($site_url_last != '/') {
  47. $site_url = $site_url . '/';
  48. }
  49. if ($clean_urls == 'yes') {
  50. // if the request contains a ? then this person is accessing with a dirty URL and is handled accordingly
  51. if (strpos($request, '?s=') !== FALSE) {
  52. $rel_path = './';
  53. } else {
  54. //this is directory level of your installation. check autofind works!?!?
  55. $url = explode('/', $request);
  56. $count = count($url);
  57. $site_url_x = str_replace('http://', "", $site_url);
  58. $temp = explode('/', $site_url_x);
  59. $install = count($temp);
  60. $dir_level = $install - 2;
  61. if ($dir_level < 0) {
  62. $dir_level = 0;
  63. }
  64. if (isset($url[$dir_level + 1])) {
  65. $s = strtolower($url[$dir_level + 1]);
  66. } else {
  67. $s = NULL;
  68. }
  69. if (isset($url[$dir_level + 2])) {
  70. $m = strtolower($url[$dir_level + 2]);
  71. } else {
  72. $m = NULL;
  73. }
  74. if (isset($url[$dir_level + 3])) {
  75. $x = strtolower($url[$dir_level + 3]);
  76. } else {
  77. $x = NULL;
  78. }
  79. if (isset($url[$dir_level + 4])) {
  80. $p = strtolower($url[$dir_level + 4]);
  81. } else {
  82. $p = NULL;
  83. }
  84. switch ($count) {
  85. case $dir_level + 3:
  86. $rel_path = '../';
  87. break;
  88. case $dir_level + 4:
  89. $rel_path = '../../';
  90. break;
  91. case $dir_level + 5:
  92. $rel_path = '../../../';
  93. break;
  94. case $dir_level + 6:
  95. $rel_path = '../../../../';
  96. break;
  97. default:
  98. $rel_path = './';
  99. break;
  100. }
  101. }
  102. } else {
  103. $rel_path = './';
  104. }
  105. if ((!isset($s)) or (!$s)) {
  106. $last = $default_page{strlen($default_page) - 1};
  107. $default = explode('/', $default_page);
  108. if (isset($default['0'])) {
  109. $s = sterilise_txt($default['0']);
  110. } else {
  111. $s = NULL;
  112. }
  113. if (isset($default['1'])) {
  114. $m = sterilise_txt($default['1']);
  115. } else {
  116. $m = NULL;
  117. }
  118. if (isset($default['2'])) {
  119. $x = sterilise_txt($default['2']);
  120. } else {
  121. $x = NULL;
  122. }
  123. if (isset($default['3'])) {
  124. $p = sterilise_txt($default['3']);
  125. } else {
  126. $p = NULL;
  127. }
  128. }
  129. $s = public_check_404($s);
  130. if ((isset($s)) && ($s == '404')) {
  131. $m = "";
  132. $x = "";
  133. $p = "";
  134. }
  135. if ($m == 'rss') {
  136. if (isset($s)) {
  137. $rss = public_check_rss($s);
  138. }
  139. if (!$rss) {
  140. $s = '404';
  141. $m = "";
  142. $x = "";
  143. $p = "";
  144. }
  145. }
  146. if (isset($s)) {
  147. $page_type = check_type($s);
  148. }
  149. if ($page_type == 'dynamic') {
  150. $style = $page_type;
  151. } else if ($page_type == 'static') {
  152. $style = $s;
  153. $m = "";
  154. $x = "";
  155. $p = "";
  156. } else if ($s == '404') {
  157. $style = '404';
  158. } else {
  159. $style = $s;
  160. }
  161. function resolver($string) {
  162. $string = str_replace('-', 'BREAK', $string);
  163. $string = preg_replace('/[^a-zA-Z0-9]/', "", $string);
  164. $string = str_replace('BREAK', '-', $string);
  165. return $string;
  166. }
  167. $s = resolver($s);
  168. $m = resolver($m);
  169. $x = resolver($x);
  170. $p = resolver($p);
  171. $page_id = get_page_id($s);
  172. $page_hits = safe_field('page_views', 'pixie_core', "page_name='$s'");
  173. $page_display_name = safe_field('page_display_name', 'pixie_core', "page_name='$s'");
  174. safe_update('pixie_core', "page_views = $page_hits + 1", "page_name = '$s'");
  175. }
  176. // ------------------------------------------------------------------
  177. // Build the navigation dynamically or build it from specified array
  178. function build_navigation() {
  179. global $s, $site_url, $nested_nav, $lang;
  180. $check_pages = safe_rows('*', 'pixie_core', "public = 'yes' and in_navigation = 'yes' and page_name not in ('404','rss') order by page_order asc");
  181. $num = count($check_pages);
  182. $current_dir = current_dir();
  183. echo '<h3>' . $lang['navigation'] . "</h3>\n\t\t\t\t<ul id=\"navigation_1\">\n";
  184. $i = 0;
  185. $first = TRUE; // first link
  186. $last = FALSE; // last link
  187. while ($i < $num) {
  188. $out = $check_pages[$i];
  189. $page_display_name = $out['page_display_name'];
  190. $page_name = $out['page_name'];
  191. $page_type = $out['page_type'];
  192. if ($i == ($num - 1))
  193. $last = TRUE;
  194. if ($s == $page_name) {
  195. if ($page_type == 'dynamic') {
  196. $includestr = 'dynamic';
  197. } else {
  198. $includestr = $page_name;
  199. }
  200. if (($nested_nav == 'yes') && (file_exists("admin/blocks/block_{$includestr}_nav.php"))) {
  201. echo "\t\t\t\t\t<li id=\"li_1_$page_name\"><a href=\"" . createURL($page_name) . "\" title=\"$page_display_name\" id=\"navigation_1_$page_name\" class=\"nav_current_1 replace\">$page_display_name<span></span></a>\n";
  202. include('admin/blocks/block_' . $includestr . '_nav.php');
  203. } else {
  204. echo "\t\t\t\t\t<li id=\"li_1_$page_name\" class=\"nav_current_li_1" . ($first ? ' first' : "") . ($last ? ' last' : "") . "\"><a href=\"" . createURL($page_name) . "\" title=\"$page_display_name\" id=\"navigation_1_$page_name\" class=\"nav_current_1 replace\">$page_display_name<span></span></a></li>\n";
  205. $first = FALSE;
  206. }
  207. } else {
  208. echo "\t\t\t\t\t<li id=\"li_1_$page_name\"" . ($first ? " class=\"first\"" : "") . ($last ? " class=\"last\"" : "") . "><a href=\"" . createURL($page_name) . "\" title=\"$page_display_name\" id=\"navigation_1_$page_name\" class=\"replace\">$page_display_name<span></span></a></li>\n";
  209. $first = FALSE;
  210. }
  211. $i++;
  212. }
  213. echo "\t\t\t\t</ul>\n";
  214. }
  215. // ------------------------------------------------------------------
  216. // Build and include the blocks for this page
  217. function build_blocks() {
  218. global $s;
  219. extract(safe_row('*', 'pixie_core', "page_name = '$s'"));
  220. $blocks = explode(" ", $page_blocks);
  221. for ($count = 0; $count < (count($blocks)); $count++) {
  222. $current = $blocks[$count];
  223. $current = str_replace(" ", "", $current);
  224. if (file_exists("admin/blocks/block_{$current}.php")) {
  225. include("admin/blocks/block_{$current}.php");
  226. echo "\n";
  227. }
  228. }
  229. }
  230. // ------------------------------------------------------------------
  231. // Build a header bar for logged in users
  232. function build_head() {
  233. global $site_url, $date_format;
  234. if (isset($_COOKIE['pixie_login'])) {
  235. list($username, $cookie_hash) = explode(',', $_COOKIE['pixie_login']);
  236. $nonce = safe_field('nonce', 'pixie_users', "user_name='$username'");
  237. if (md5($username . $nonce) == $cookie_hash) {
  238. $privs = safe_field('privs', 'pixie_users', "user_name='$username'");
  239. $realname = safe_field('realname', 'pixie_users', "user_name='$username'");
  240. $GLOBALS['pixie_user'] = $username;
  241. $user_count = mysql_num_rows(safe_query('select * from ' . PFX . 'pixie_log_users_online'));
  242. $user_count = $user_count - 1;
  243. echo "<div id=\"admin_header\">
  244. <h1>Hello ";
  245. if (isset($realname)) {
  246. echo firstword($realname);
  247. }
  248. echo "</h1>
  249. <div id=\"admin_header_text\"><p>" . safe_strftime($date_format, time() + tz_offset()) . ". Currently your site has $user_count visitor(s) online.</p></div>
  250. <div id=\"admin_header_controls\"><p><a href=\"" . $site_url . "admin/\" title=\"Goto Pixie\">Pixie</a><a href=\"" . $site_url . "admin/?s=logout&amp;tool=home\" title=\"Logout of pixie\">Logout</a></p></div>
  251. </div>\n";
  252. /* Needs language */
  253. }
  254. }
  255. }
  256. // ------------------------------------------------------------------
  257. // Build title for current page
  258. function build_title() {
  259. global $site_name, $page_display_name, $page_type, $s, $m, $x, $p;
  260. // will probably need support for child pages!
  261. if ($page_type == 'dynamic' && $m == 'permalink') {
  262. $post_title = safe_field('title', 'pixie_dynamic_posts', "post_slug = '$x'");
  263. if ($post_title) {
  264. echo "$site_name - $page_display_name - $post_title";
  265. } else {
  266. echo "$site_name";
  267. /* escaping other language characters can cause an error. */
  268. }
  269. } else if ($m == 'tag') {
  270. if ($p) {
  271. echo "$site_name - $page_display_name - Tag - " . simplify(squash_slug($x)) . " - Page $p";
  272. } else {
  273. echo "$site_name - $page_display_name - Tag - " . simplify(squash_slug($x));
  274. }
  275. } else if ($m == 'page') {
  276. echo "$site_name - $page_display_name - " . simplify($m) . " " . simplify($x);
  277. } else if ($m) {
  278. echo "$site_name - $page_display_name - " . simplify($m);
  279. } else {
  280. echo "$site_name - $page_display_name";
  281. }
  282. }
  283. ?>