PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/CoreCMS/core/functions/session.php

https://github.com/danielhahne/corecms
PHP | 440 lines | 293 code | 84 blank | 63 comment | 51 complexity | 4bf9323d490cb6e0f4b64c88fbb07243 MD5 | raw file
  1. <?php
  2. session_start();
  3. $connection = mysql_connect($db_server, $db_user, $db_pass) or die("Error: Failed to establish connection to database");
  4. mysql_select_db($db_name, $connection) or die("Error: Could not find specified database, check \"database name\" in configuration");
  5. ///////////////////////////////
  6. // VARIABLE DECLARATIONS //
  7. ///////////////////////////////
  8. $theme_path = $root . "themes/" . $theme . "/";
  9. $online_url_path = "/core/";
  10. $online_path = str_replace("http://".$_SERVER['HTTP_HOST'],'',$http);
  11. ///////////////////////////////
  12. // LOAD THEME //
  13. ///////////////////////////////
  14. function secure($s) {
  15. if(get_magic_quotes_gpc()==1) $s = stripslashes($s);
  16. $s = mysql_real_escape_string($s);
  17. return $s;
  18. }
  19. /* went to APIs */
  20. function LOAD_THEME() {
  21. global $theme_path;
  22. GET_STYLES($theme_path);
  23. GET_SCRIPTS($theme_path);
  24. }
  25. function GET_STYLES($path) {
  26. global $theme;
  27. $str = "core/themes/".$theme."/styles/";
  28. $arr = search_folder($path . "styles");
  29. foreach ($arr as $value) {
  30. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$str$value\" />\n";
  31. }
  32. }
  33. function GET_SCRIPTS($path) {
  34. global $theme;
  35. $s = "jquery-";
  36. $str = "core/themes/".$theme."/scripts/";
  37. $arr = search_folder($path . "scripts");
  38. foreach ($arr as $value) {
  39. echo "<script type=\"text/javascript\" src=\"$str$value\"></script>\n";
  40. }
  41. }
  42. /**/
  43. function _encode($str) {
  44. $str = str_replace(" ","+",$str);
  45. return $str;
  46. }
  47. ///////////////////////////////
  48. // DATABASE RETRIVE ENTRIES //
  49. ///////////////////////////////
  50. function LOAD_TAGS($type) {
  51. global $theme_path;
  52. $data = mysql_query("SELECT t.* FROM core_tags t ORDER BY t.tag_position DESC");
  53. if($type == "JAVASCRIPT") {
  54. echo "var tags=new Object();\n";
  55. while($t = mysql_fetch_array($data)) {
  56. $tag_id = $t["tag_id"];
  57. $id_str = "";
  58. $id_str = "tags.tag" . $tag_id . "=";
  59. $entries = mysql_query("SELECT e2t.entry_id FROM core_entry2tag e2t WHERE e2t.tag_id = $tag_id");
  60. if(@mysql_num_rows($entries)>0) {
  61. $id_str = $id_str . "[";
  62. while($e = mysql_fetch_array($entries)) {
  63. $id_str = $id_str . $e["entry_id"] . ",";
  64. }
  65. $id_str = substr($id_str,0,strlen($id_str)-1);
  66. $id_str = $id_str . "];\n";
  67. } else {
  68. $id_str = $id_str . "0;\n";
  69. }
  70. echo $id_str;
  71. }
  72. } else {
  73. while($r = mysql_fetch_array($data)) {
  74. $tag_text = $r["tag_text"];
  75. $tag_id = $r["tag_id"];
  76. require($theme_path . "parts/tag_link.php");
  77. }
  78. }
  79. }
  80. function LOAD_ENTRIES($type) {
  81. global $online_path, $theme_path, $current_tag, $thumb_w, $thumb_h, $root, $date_format, $separator_tags, $show_empty, $nice_permalinks;
  82. $data_entries = mysql_query("SELECT * FROM core_entries e WHERE e.entry_show = 1 ORDER BY e.entry_position DESC");
  83. $absolute_path = "http://andreasklein.org";
  84. while($e = mysql_fetch_array($data_entries)) {
  85. $entry_id = $e["entry_id"];
  86. $entry_title = $e["entry_title"];
  87. // DATE
  88. $date = $e["entry_date"];
  89. $y = substr($t,0,4);
  90. $m = substr($t,5,2);
  91. $d = substr($t,8,2);
  92. $entry_date = date($date_format,mktime(0,0,0,$m,$d,$y));
  93. $entry_position = $e["entry_position"];
  94. $entry_client = $e["entry_client"];
  95. $entry_extra1 = $e["entry_extra1"];
  96. $entry_extra2 = $e["entry_extra2"];
  97. // NEW
  98. $entry_visit_link = $e["entry_visit_link"];
  99. $entry_text = $e["entry_text"];
  100. $entry_new = $e["entry_new"];
  101. $hits = $e["hits"];
  102. if($entry_new == 1) {
  103. $isNew = true;
  104. } else {
  105. $isNew = false;
  106. }
  107. if($nice_permalinks) {
  108. $entry_permalink = "$http".$entry_id;
  109. } else {
  110. $entry_permalink = "$http"."entry=$entry_id";
  111. }
  112. $data_e2t = @mysql_query("SELECT e2t.tag_id FROM core_entry2tag e2t WHERE e2t.entry_id = $entry_id");
  113. $tag_str = "";
  114. while($e2t = @mysql_fetch_array($data_e2t)) {
  115. $tag_id = $e2t["tag_id"];
  116. $data_tags = @mysql_query("SELECT t.tag_text FROM core_tags t WHERE t.tag_id = $tag_id ORDER BY t.tag_position DESC");
  117. while($t = @mysql_fetch_array($data_tags)) {
  118. $tag_text = $t["tag_text"];
  119. $tt_friendly = _encode($tag_text);
  120. $tag_str = $tag_str . "<a class=\"tag-link\" name=\"tag".$tag_id."\" href=\"#tag-".$tt_friendly."\">".$tag_text."</a>".$separator_tags;
  121. }
  122. }
  123. $entry_tags = substr($tag_str,0,strlen($tag_str)-strlen($separator_tags));
  124. /*
  125. * Detect the src of the thumb and send it to phpThumb
  126. */
  127. /*------------------------------
  128. 01 Get entry-thumb
  129. ---------------------------------*/
  130. if($type == "THUMBS") {
  131. $folder = treat_string($entry_title);
  132. $r_str = $root . "user/uploads/" . $folder;
  133. $f_str = "core/user/uploads/" . $folder;
  134. $arr = search_folder($r_str);
  135. if($arr || $show_empty) {
  136. $img = false;
  137. $thumb = false;
  138. foreach($arr as $f) {
  139. if(strstr($f,"_thumb")) {
  140. $thumb = $f;
  141. }
  142. else
  143. {
  144. if(strstr($f,"_slider"))
  145. {
  146. if((!$thumb)) {
  147. $img = $f;
  148. }
  149. }
  150. }
  151. }
  152. if($thumb) {
  153. $entry_thumb = "$f_str/$thumb";
  154. } elseif($img) {
  155. $entry_thumb = "core/functions/phpThumb/phpThumb.php?src=/$online_path/$f_str/$img&w=$thumb_w&h=$thumb_h&zc=1&f=png";
  156. }
  157. require($theme_path . "parts/entry_link_thumbs.php");
  158. }
  159. /*------------------------------
  160. 02 Get the entry-title and link_id
  161. ---------------------------------*/
  162. } elseif($type == "LIST") {
  163. $arr = search_folder($root . "user/uploads/" . treat_string($entry_title));
  164. if($arr || $show_empty) {
  165. require($theme_path . "parts/entry_link.php");
  166. }
  167. /*------------------------------
  168. 03 New functionality for getting just the '_slider' Images
  169. ---------------------------------*/
  170. } elseif($type == "IMAGES") {
  171. $folder = treat_string($entry_title);
  172. $r_str = $root . "user/uploads/" . $folder;
  173. $f_str = "core/user/uploads/" . $folder;
  174. $arr = search_folder($r_str);
  175. if($arr || $show_empty) {
  176. $image = false;
  177. foreach($arr as $f) {
  178. if(strstr($f,"_slider")) {
  179. $image = $f;
  180. $entry_image = "$absolute_path/$f_str/$image";
  181. require($theme_path . "parts/entry_image.php");
  182. }
  183. else
  184. {
  185. //non usable
  186. }
  187. }
  188. }
  189. } // --- end if image
  190. }
  191. }
  192. function LOAD_MENU() {
  193. global $theme_path, $theme;
  194. $pages = mysql_query("SELECT p.* FROM core_pages p ORDER BY p.page_position DESC");
  195. while($p = mysql_fetch_array($pages)) {
  196. if($p["page_title"] != 'home')
  197. {
  198. $url = $p["page_url"];
  199. $title = $p["page_title"];
  200. require($theme_path . "parts/page_link.php");
  201. }
  202. }
  203. }
  204. function LOAD_MEDIA($t) {
  205. global $root,$show_empty;
  206. $folder = treat_string($t);
  207. $arr = search_folder($root . "user/uploads/" . $folder);
  208. if(!$arr && $show_empty == 0) echo("Could not retrieve files.");
  209. else {
  210. foreach ($arr as $value) {
  211. $type = detect_type($value);
  212. $path = $folder . "/" . $value;
  213. // Edit and update for slider-Images
  214. if(!strstr($path,"_thumb") && !strstr($path,"_slider") && !strstr($path,"_hover")) {
  215. show_media($type, $path);
  216. }
  217. }
  218. }
  219. }
  220. function FILE_LOAD($file) {
  221. global $root,$entry_title;
  222. $path = $root . "user/uploads/" . treat_string($entry_title) . "/$file";
  223. if(is_file($path)) {
  224. show_media(detect_type($file),treat_string($entry_title)."/$file");
  225. }
  226. }
  227. /*
  228. function UPDATE_HITS(){
  229. global $entry_id, $entry_hits;
  230. id = secure($id);
  231. if(is_numeric($id)) {
  232. $data = mysql_query("SELECT e.* FROM core_entries e WHERE e.entry_id = $id AND e.entry_show = 1");
  233. $entry_clicks = 0;
  234. if(@mysql_num_rows($data) < 1) {
  235. die("Invalid id, no entry to be shown");
  236. }
  237. while($e = mysql_fetch_array($data)) {
  238. $entry_id = $e['entry_id'];
  239. $entry_hits = $e['hits']+1;
  240. }
  241. mysql_query("UPDATE core_entries e SET
  242. e.hits = $entry_hits
  243. WHERE e.entry_id = $id");
  244. }
  245. }
  246. */
  247. function show_media($type, $path) {
  248. global $theme_path, $root, $http;
  249. $absolute_path = "$http/core/user/uploads/$path";
  250. $full_path = "core/user/uploads/$path";
  251. switch($type) {
  252. case "video":
  253. require($theme_path . "parts/media/video.php");
  254. break;
  255. case "image":
  256. $size = getimagesize($root ."user/uploads/".$path);
  257. $img_x = $size[0]."px";
  258. $img_y = $size[1]."px";
  259. require($theme_path . "parts/media/image.php");
  260. break;
  261. case "sound":
  262. require($theme_path . "parts/media/sound.php");
  263. break;
  264. case "link":
  265. $file = fopen($root . "user/uploads/" . $path, "r");
  266. $read = fread($file,filesize($root . "user/uploads/" . $path));
  267. require($theme_path . "parts/media/link.php");
  268. break;
  269. }
  270. }
  271. function detect_type($obj) {
  272. $str = substr($obj, strrpos($obj,"."));
  273. $image = array(".jpg", ".jpeg", ".png", ".gif", ".tif", ".tiff");
  274. foreach($image as $val) {
  275. if($val == $str) {
  276. return "image";
  277. }
  278. }
  279. $video = array(".mov", ".mpg", ".mp4", ".avi", ".wmv", ".flv");
  280. foreach($video as $val) {
  281. if($val == $str) {
  282. return "video";
  283. }
  284. }
  285. $sound = array(".mp3", ".aac", ".wav", ".aif", ".flac", ".ogg");
  286. foreach($sound as $val) {
  287. if($val == $str) {
  288. return "sound";
  289. }
  290. }
  291. $links = array(".txt");
  292. foreach($links as $val) {
  293. if($val == $str) {
  294. return "link";
  295. }
  296. }
  297. }
  298. function search_folder($dir) {
  299. if(is_dir($dir) == false) {
  300. return false;
  301. }
  302. $arr = scandir($dir);
  303. $res = array();
  304. foreach ($arr as $value) {
  305. if(strlen($value) >= 4) {
  306. array_push($res,$value);
  307. }
  308. }
  309. return($res);
  310. }
  311. function treat_string($str) {
  312. $str = stripcslashes($str);
  313. $a = '\"\'_ ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝßÜüàáâãäåæçèéêëìíîïñòóôõöøùúûýýþÿŔŕ°•¶!¡©"”@#¥£€¢$%‰∞&¶§/\|({[)}]=≠≈?¿±`´^*™:;,.<>≤≥';
  314. $b = '------aaaaaaaceeeeiiiinoooooouuuuysUuaaaaaaaceeeeiiiinoooooouuuyybyrr-------------------------------------------------';
  315. $str = utf8_decode($str);
  316. $str = strtr($str,utf8_decode($a),$b);
  317. $str = strtolower($str);
  318. while(stristr($str, "--")) {
  319. $str = str_replace("--","-",$str);
  320. }
  321. return utf8_encode($str);
  322. }
  323. function get_version() {
  324. //do not alter please.
  325. "<script src='http://core.weareastronauts.org/callhome/checkversion.js' type='text/javascript'></script>";
  326. }
  327. // BACKWARDS COMPABILITY.
  328. // THE FOLLOWING FUNCTIONS ARE TO LET PHP4 USERS UTILIZE CORE,
  329. // IF YOU ARE CERTAIN YOU ARE RUNNING PHP5 AND YOU'RE IN HER
  330. // MESSING AROUND, YOU SHOULD DELETE THESE JUST FOR THE HECK
  331. // OF IT.
  332. if( !function_exists('scandir') ) {
  333. function scandir($directory, $sorting_order = 0) {
  334. $dh = opendir($directory);
  335. while( false !== ($filename = readdir($dh)) ) {
  336. $files[] = $filename;
  337. }
  338. if( $sorting_order == 0 ) {
  339. sort($files);
  340. } else {
  341. rsort($files);
  342. }
  343. return($files);
  344. }
  345. }
  346. // ALRIGHT.. THAT WAS EASIER THAN I THOUGH. THANK YOU GOOGLE.
  347. ?>