Connected){ require_once('class/mysql.class.php'); $Mysql = new Mysql; $Mysql->connect(); } //////////////////////////////////// //// GET SITE SETTINGS //// //////////////////////////////////// $sql = "SELECT `id`, `name`, `active`, `longvalue`, `value`, `group` FROM `".ZEB_MYSQL_PREFIX."_settings`"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { $settings[$row['name']]['id'] = $row['id']; $settings[$row['name']]['name'] = $row['name']; $settings[$row['name']]['active'] = $row['active']; $settings[$row['name']]['longvalue'] = $row['longvalue']; $settings[$row['name']]['value'] = $row['value']; $settings[$row['name']]['group'] = $row['group']; } //////////////////////////////////// //// ADDONS //// //////////////////////////////////// $run_sifr = false; ?>formatTime('W d F Y H:i', '20101221103000'); //Outputs for example; tuesday 21 december 2010 10:30 echo $myTime->formatTime('W d F Y H:i'); //Outputs todays date in format above //Settings $myTime->Language = 'en'; //Default is sv (Swedish) //Accepted languages; sv, dk, no, en, de, es, fr //Standard Formats $myTime->standardFormat('usDate'); //Outputs the US standar date format, juni 24, 2009 $myTime->standardFormat('usTime'); //Outputs the US standar time format, 8:56 AM //Other presets; euDate, euTime, usDate, usTime //Return time until a specific date $myTime->timeUntil([date], [unit]); //unit can be; day, hour, minute, second //time should be in Rawtime format, YmdHis History: 2010-12-21 Version 3.0 Changes: - Reduced number of date() calls by plenty. - Class do not make any settings or calls on construct. - Removed support for alot settings params. - All calls should now, instead, use the functions with it's correct params. */ class makeTime{ public $Language = 'sv'; public $Timestamp = ''; function __construct(){ } //Restuns date in new format private function returnDate($f = ''){ switch ($f) { case 'Y': $date = date('Y', $this->Timestamp); //Year as 4 digits, 2009 break; case 'y': $date = date('y', $this->Timestamp); //Year as 2 digits, 09 break; case 'm': $date = date('m', $this->Timestamp); //Month with leading zero, 01 break; case 'n': $date = date('n', $this->Timestamp); //Month without leading zero, 1 break; case 'F': $date = $this->month_as_txt(date('n', $this->Timestamp)); //Month as text, January break; case 'f': $date = mb_substr($this->month_as_txt(date('n', $this->Timestamp)), 0, 3, 'UTF8'); //Month as 3 chr text, Jan break; case 'U': $date = date('W', $this->Timestamp); break; case 'd': $date = date('d', $this->Timestamp); //Day with leading zero, 01 break; case 'j': $date = date('j', $this->Timestamp); //Day without leading zero, 1 break; case 'W': $date = $this->day_as_txt(date('w', $this->Timestamp)); //Day as text, monday break; case 'w': $date = mb_substr($this->day_as_txt(date('w', $this->Timestamp)), 0, 3, 'UTF8'); //Day as 3 chr text, mon break; case 'H': $date = date('H', $this->Timestamp); //Hour in 24-hour format with leading zero break; case 'h': $date = date('h', $this->Timestamp); //Hour in 12-hour format with leading zero break; case 'G': $date = date('G', $this->Timestamp); //Hour in 24-hour format without leading zero break; case 'g': $date = date('g', $this->Timestamp); //Hour in 12-hour format without leading zero break; case 'i': $date = date('i', $this->Timestamp); //Minute with leading zero break; case 's': $date = date('s', $this->Timestamp); //Second with leading zero break; case 'a': $date = date('a', $this->Timestamp); //Lowercase Ante meridiem and Post meridiem, pm or am break; case 'A': $date = date('A', $this->Timestamp); //Uppercase Ante meridiem and Post meridiem, PM or AM break; case 'r': $date = date('r', $this->Timestamp); // break; } if(!empty($date)){ return $date; } else { return false; } } //Returns month as text from int private function month_as_txt($month){ $monthtxt['sv'] = array('', 'januari', 'februari', 'mars', 'april', 'maj', 'juni', 'juli', 'augusti', 'september', 'oktober', 'november', 'december'); $monthtxt['dk'] = array('', 'januar', 'februar', 'marts', 'april', 'maj', 'juni', 'juli', 'august', 'september', 'oktober', 'november', 'december'); $monthtxt['no'] = array('', 'januari', 'februari', 'mars', 'april', 'maj', 'juni', 'juli', 'augusti', 'september', 'oktober', 'november', 'desember'); $monthtxt['en'] = array('', 'january', 'february', 'mach', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'); $monthtxt['de'] = array('', 'januar', 'februar', 'märz', 'april', 'mai', 'juni', 'juli', 'august', 'september', 'october', 'november', 'dezember'); $monthtxt['es'] = array('', 'enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre'); $monthtxt['fr'] = array('', 'janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'); if($monthtxt[$this->Language][$month] != ''){ return $monthtxt[$this->Language][$month]; } else { return false; } } //Returns day as text from int private function day_as_txt($day){ $daytxt['sv'] = array('söndag', 'måndag', 'tisdag', 'onsdag', 'torsdag', 'fredag', 'lördag'); $daytxt['dk'] = array('søndag', 'mandag', 'tirsdag', 'onsdag', 'torsdag', 'fredag', 'lørdag'); $daytxt['no'] = array('søndag', 'mandag', 'tirsdag', 'onsdag', 'torsdag', 'fredag', 'lørdag'); $daytxt['en'] = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'); $daytxt['de'] = array('sonntag', 'montag', 'dienstag', 'mittwoch', 'donnerstag', 'freitag', 'samstag'); $daytxt['es'] = array('domingo', 'lunes', 'martes', 'miércoles', 'jueves', 'viernes', 'sábado'); $daytxt['fr'] = array('dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'); if($daytxt[$this->Language][$day] != ''){ return $daytxt[$this->Language][$day]; } else { return false; } } //Makes a unix timestamp private function timestamp($Rawtime = '', $addToYear = 0, $addToMonth = 0, $addToDay = 0, $addToHour = 0, $addToMinute = 0, $addToSecond = 0){ if(empty($Rawtime)){ $Rawtime = date('YmdHis'); } $this->Timestamp = mktime((int)mb_substr($Rawtime, 8, 2, 'UTF8')+$addToHour,(int)mb_substr($Rawtime, 10, 2, 'UTF8')+$addToMinute,0+$addToSecond,(int)mb_substr($Rawtime, 4, 2, 'UTF8')+$addToMonth,(int)mb_substr($Rawtime, 6, 2, 'UTF8')+$addToDay,mb_substr($Rawtime, 0, 4, 'UTF8')+$addToYear); return $this->Timestamp; } //Format time public function formatTime($Format = '', $Rawtime = '', $addToYear = '', $addToMonth = '', $addToDay = '', $addToHour = '', $addToMinute = '', $addToSecond = '') { if(empty($Format)){ return false; } if(empty($Rawtime)){ $Rawtime = date('YmdHis'); } $this->timestamp($Rawtime, $addToYear, $addToMonth, $addToDay, $addToHour, $addToMinute, $addToSecond); $f = array('y', 'Y', 'm', 'n', 'F', 'f', 'd', 'j', 'W', 'w', 'H', 'h', 'G', 'g', 'i', 's', 'A', 'a', 'r', 'U'); $Date = $Format; for($i = 0; $i < sizeof($f); $i++){ $Date = str_replace($f[$i], '\\\\'.$f[$i].'\\\\', $Date); } for($i = 0; $i < sizeof($f); $i++){ if(strpos($Date, '\\\\'.$f[$i].'\\\\') !== false){ $Date = str_replace('\\\\'.$f[$i].'\\\\', $this->returnDate($f[$i]), $Date); } } return $Date; } //Makes some standard formats public function standardFormat($format, $Rawtime = ''){ if(empty($Rawtime)){ $Rawtime = date('YmdHis'); } $this->timestamp($Rawtime); switch ($format) { case 'usDate': //ex. June 22, 2009 return $this->formatTime('F d, Y'); case 'usTime': //ex. 9:27 AM return $this->formatTime('g:i A'); case 'euDate': //ex. 22 June, 2009 return $this->formatTime('j F, Y'); case 'euTime': //ex. 21:27 return $this->formatTime('H:i'); case 'RFC2822': //ex. 21:27 return $this->formatTime('r'); } } //Return time until in chosen unit public function timeUntil($Rawtime = '', $unit = 'day'){ if(empty($Rawtime)){ $Rawtime = date('YmdHis'); } $this->timestamp($Rawtime); $until = ((mktime(mb_substr($Rawtime, 8, 2, 'UTF8'),mb_substr($Rawtime, 10, 2, 'UTF8'),0,mb_substr($Rawtime, 4, 2, 'UTF8'),mb_substr($Rawtime, 6, 2, 'UTF8'),mb_substr($Rawtime, 0, 4, 'UTF8')) - time())); $second = (int)($until); $minute = (int)($second / 60); $hour = (int)($minute / 60); $day = (int)($hour / 24); if($unit == 'second'){ return $second; } else if($unit == 'minute'){ return $minute; } else if($unit == 'hour'){ return $hour; } else if($unit == 'day'){ return $day; } } } ?>IsSMTP(); // telling the class to use SMTP } try { if($settings['mail_smtp_adress']['value'] != '' && $settings['mail_dontusesmtp']['value'] != 1){ $zeb_sendmail->Host = $settings['mail_smtp_adress']['value']; $zeb_sendmail->Port = $settings['mail_smtp_port']['value']; if($settings['mail_smtp_user']['value'] != '' && $settings['mail_dontusesmtp']['value'] != 1){ $zeb_sendmail->Username = $settings['mail_smtp_user']['value']; if($settings['mail_smtp_password']['value'] != '' && $settings['mail_dontusesmtp']['value'] != 1){ $zeb_sendmail->SMTPAuth = true; $zeb_sendmail->Password = $settings['mail_smtp_password']['value']; } } } $zeb_sendmail->AddReplyTo($_POST['from_email'], $_POST['from_email']); $zeb_sendmail->SetFrom($_POST['from_email'], $_POST['from_email']); $zeb_sendmail->AddAddress($_POST['to_email'], $_POST['to_email']); $zeb_sendmail->CharSet = "utf-8"; $zeb_sendmail->Subject = $_POST['email_subject']; $email_body = ''.$subject.''; $email_body .= '
'; $email_body .= '
'; $email_body .= ""; foreach( $_REQUEST as $key=>$value){ if($key != 'PHPSESSID' && $key != 'submit_form'){ $email_body .= "\n"; } } $email_body .= "
"; $email_body .= $key; $email_body .= ":  "; $value = addslashes($value); $value = str_replace("\n", "
", $value); $email_body .= $value ; $email_body .= "
"; $email_body .= '
'; $email_body .= 'Skickad från ip: '.$_SERVER['REMOTE_ADDR'].' den '.date('y.m.d - G:i').''; $zeb_sendmail->MsgHTML($email_body); $zeb_sendmail->Send(); } catch (phpmailerException $e) { echo $e->errorMessage(); //Pretty error messages from PHPMailer } catch (Exception $e) { echo $e->getMessage(); //Boring error messages from anything else! } } ?>DbTable = ZEB_MYSQL_PREFIX.'_page'; $this->getFields(); } public function debug(){ if(!empty($this->Debug)){ $string = sizeof($this->Debug).' ERRORS'; for($i = 0; $i < sizeof($this->Debug); $i++){ $string .= '; '.$this->Debug[$i]; } return $string; } else { return false; } } public function update($array = array()){ if(!empty($array)){ $this->setProperties($array); } if(!empty($this->Page['id'])){ $this->getMissing(); if($this->checkFields()){ $current_name = $this->getValue('name'); if($this->Page['name'] != $current_name){ $this->Page['url'] = $this->generateUrl($this->Page['name']); $sql = "UPDATE `".$this->DbTable."` SET `childof` = '".mysql_real_escape_string($this->Page['url'])."' WHERE `childof` = '".$this->friendlyUrl($current_name)."'"; mysql_query($sql) or die(mysql_error()); } $arrayKeys = array_keys($this->Page); if($this->Page['childof'] == 'NULL'){ $this->Page['childof'] = ''; } if($this->Page['expiredate'] == 'NULL'){ $this->Page['expiredate'] = ''; } for($i = 0; $i < sizeof($arrayKeys); $i++){ $sql = "UPDATE `".$this->DbTable."` SET `".$arrayKeys[$i]."` = '".mysql_real_escape_string($this->Page[$arrayKeys[$i]])."' WHERE `id` = '".$this->Page['id']."' LIMIT 1"; mysql_query($sql) or die(mysql_error()); } } else { $this->Debug[$this->DebugCounter] = '#' . $this->DebugCounter . ': Some fields contains errors.'; $this->DebugCounter++; return false; } } else { $this->Debug[$this->DebugCounter] = '#' . $this->DebugCounter . ': Can not update row without id.'; $this->DebugCounter++; return false; } return true; } public function deleteSingelId($id){ $sql = "DELETE FROM `".$this->DbTable."` WHERE `id` = '".$id."' LIMIT 1"; mysql_query($sql) or die(mysql_error()); } public function delete($id){ $sql = "SELECT `id`, `url`, `name` FROM `".$this->DbTable."` WHERE `id` = '".$id."'"; $result = mysql_query($sql); if ($row = mysql_fetch_assoc($result)) { $page['id'] = $row['id']; $page['url'] = $row['url']; $page['name'] = $row['name']; } if(!empty($page)){ $tree = $this->getTree($page['url']); $x = 0; $feedback[$x]['name'] = $page['name']; $feedback[$x]['id'] = $page['id']; $x++; for($i = 0; $i < sizeof($tree); $i++){ $sql = "DELETE FROM `".$this->DbTable."` WHERE `id` = '".$tree[$i]['id']."' LIMIT 1"; mysql_query($sql) or die(mysql_error()); $feedback[$x]['name'] = $tree[$i]['name']; $feedback[$x]['id'] = $tree[$i]['id']; $x++; } $sql = "DELETE FROM `".$this->DbTable."` WHERE `id` = '".$page['id']."' LIMIT 1"; mysql_query($sql) or die(mysql_error()); return $feedback; } else { $this->Debug[$this->DebugCounter] = '#' . $this->DebugCounter . ': No page found to delete.'; $this->DebugCounter++; return false; } } public function create($array = array()){ if(!empty($array)){ $this->setProperties($array); } if($this->checkFields()){ $sql = "INSERT INTO `".$this->DbTable."` (`name`, `url`, `childof`, `publishdate`, `expiredate`, `editdate`, `html`, `hide`) VALUES ('".$this->Page['name']."', '".$this->Page['url']."', '".$this->Page['childof']."', '".$this->Page['publishdate']."', '".$this->Page['expiredate']."', '".$this->Page['editdate']."', '".$this->Page['html']."', '".$this->Page['hide']."') "; mysql_query($sql) or die(mysql_error()); $this->Page['id'] = mysql_insert_id(); return $this->Page['id']; } else { $this->Debug[$this->DebugCounter] = '#' . $this->DebugCounter . ': Field check failed.'; $this->DebugCounter++; return false; } } public function createWithId($array = array()){ if(!empty($array)){ $this->setProperties($array); } if($this->checkFields()){ $sql = "INSERT INTO `".$this->DbTable."` (`id`, `name`, `url`, `childof`, `publishdate`, `expiredate`, `editdate`, `html`, `hide`, `shell`) VALUES ('".$this->Page['id']."', '".$this->Page['name']."', '".$this->Page['url']."', '".$this->Page['childof']."', '".$this->Page['publishdate']."', '".$this->Page['expiredate']."', '".$this->Page['editdate']."', '".$this->Page['html']."', '".$this->Page['hide']."', '".$this->Page['shell']."') "; mysql_query($sql) or die(mysql_error()); $this->Page['id'] = mysql_insert_id(); return $this->Page['id']; } else { $this->Debug[$this->DebugCounter] = '#' . $this->DebugCounter . ': Field check failed.'; $this->DebugCounter++; return false; } } public function open($id){ if(is_numeric($id)){ $field = 'id'; } else { $field = 'url'; } $sql = "SELECT * FROM `".$this->DbTable."` WHERE `".$field."` = '".$id."' LIMIT 1"; $result = mysql_query($sql); if($row = mysql_fetch_assoc($result)) { for($i = 0; $i < sizeof($this->FieldName); $i++){ $page[$this->FieldName[$i]] = $row[$this->FieldName[$i]]; } $page['children'] = $this->checkForChildren($page['url']); $page['fullurl'] = $this->getRealUrl($page['url']); return $page; } else { $this->Debug[$this->DebugCounter] = '#' . $this->DebugCounter . ': Page not found.'; $this->DebugCounter++; return false; } } public function getUrl($id){ $sql = "SELECT `url` FROM `".$this->DbTable."` WHERE `id` = '".$id."' LIMIT 1"; $result = mysql_query($sql); if($row = mysql_fetch_assoc($result)) { $page['url'] = $row['url']; $page['fullurl'] = $this->getRealUrl($page['url']); return $page; } else { $this->Debug[$this->DebugCounter] = '#' . $this->DebugCounter . ': Page not found.'; $this->DebugCounter++; return false; } } public function moveUp($id){ $currentPage = $this->open($id); unset($currentPage['children']); $sql = "SELECT `id` FROM `".$this->DbTable."` WHERE `id` < '".$id."' && `childof` = '".$currentPage['childof']."' ORDER BY id DESC LIMIT 1"; $result = mysql_query($sql); if($row = mysql_fetch_assoc($result)) { $nextPage = $this->open($row['id']); } if(!empty($nextPage)){ unset($nextPage['children']); $this->deleteSingelId($currentPage['id']); $this->deleteSingelId($nextPage['id']); $currentId = $currentPage['id']; $nextId = $nextPage['id']; $currentPage['id'] = $nextId; $nextPage['id'] = $currentId; $this->createWithId($currentPage); $this->createWithId($nextPage); $pagesChanged[0]['name'] = $currentPage['name']; $pagesChanged[1]['name'] = $nextPage['name']; $pagesChanged[0]['id'] = $currentPage['id']; $pagesChanged[1]['id'] = $nextPage['id']; return $pagesChanged; } else { return false; } } public function moveDown($id){ $currentPage = $this->open($id); unset($currentPage['children']); $sql = "SELECT `id` FROM `".$this->DbTable."` WHERE `id` > '".$id."' && `childof` = '".$currentPage['childof']."' ORDER BY id ASC LIMIT 1"; $result = mysql_query($sql); if($row = mysql_fetch_assoc($result)) { $nextPage = $this->open($row['id']); } if(!empty($nextPage)){ unset($nextPage['children']); $this->deleteSingelId($currentPage['id']); $this->deleteSingelId($nextPage['id']); $currentId = $currentPage['id']; $nextId = $nextPage['id']; $currentPage['id'] = $nextId; $nextPage['id'] = $currentId; $this->createWithId($currentPage); $this->createWithId($nextPage); $pagesChanged[0]['name'] = $currentPage['name']; $pagesChanged[1]['name'] = $nextPage['name']; $pagesChanged[0]['id'] = $currentPage['id']; $pagesChanged[1]['id'] = $nextPage['id']; return $pagesChanged; } else { return false; } } public function setProperties($array = array()){ $this->Page = $array; } public function getTree($url){ $sql = "SELECT `id`, `url`, `name` FROM `".$this->DbTable."` WHERE `childof` = '".$url."'"; $result = mysql_query($sql); $i = 0; while ($row = mysql_fetch_assoc($result)) { $tree[$i]['id'] = $row['id']; $tree[$i]['name'] = $row['name']; $tree[$i]['url'] = $row['url']; if($this->checkForChildren($tree[$i]['url']) > 0){ unset($tmp); $tmp = $this->getTree($tree[$i]['url']); for($x = 0; $x < sizeof($tmp); $x++){ $i++; $tree[$i]['id'] = $tmp[$x]['id']; $tree[$i]['url'] = $tmp[$x]['url']; $tree[$i]['name'] = $tmp[$x]['name']; } } $i++; } return $tree; } public function getNextPageWithContent($url){ $array = $this->getNextPageWithContentLoop($url); for($i = 0; $i < sizeof($array); $i++){ if($array[$i]['shell'] != 1){ return $array[$i]; } } } private function getNextPageWithContentLoop($url){ $sql = "SELECT `id`, `url`, `name`, `shell` FROM `".$this->DbTable."` WHERE `childof` = '".$url."' && `hide` != 1 && (`publishdate` < '".date('YmdHis')."' || `publishdate` = '' || `publishdate` = 00000000000000) && (`expiredate` > '".date('YmdHis')."' || `expiredate` = '' || `expiredate` = 00000000000000) ORDER BY `id` ASC"; $result = mysql_query($sql); $i = 0; while ($row = mysql_fetch_assoc($result)) { $tree[$i]['id'] = $row['id']; $tree[$i]['name'] = $row['name']; $tree[$i]['url'] = $row['url']; $tree[$i]['shell'] = $row['shell']; if($tree[$i]['shell'] != 1){ return $tree; } if($this->checkForChildren($tree[$i]['url']) > 0 && $tree[$i]['shell'] == 1){ unset($tmp); $tmp = $this->getNextPageWithContentLoop($tree[$i]['url']); for($x = 0; $x < sizeof($tmp); $x++){ $i++; $tree[$i]['id'] = $tmp[$x]['id']; $tree[$i]['url'] = $tmp[$x]['url']; $tree[$i]['name'] = $tmp[$x]['name']; $tree[$i]['shell'] = $tmp[$x]['shell']; } } $i++; } return $tree; } public function getParentTree($id, $sort = true){ $array = $this->getParentTreeLoop($id); array_shift($array); if($sort){ $array = array_reverse($array); } return $array; } private function getParentTreeLoop($id){ $sql = "SELECT `id`, `childof`, `url` FROM `".$this->DbTable."` WHERE `id` = '".$id."' LIMIT 1"; $result = mysql_query($sql); $i = 0; if ($row = mysql_fetch_assoc($result)) { $tree[$i]['id'] = $row['id']; $tree[$i]['childof'] = $row['childof']; $tree[$i]['url'] = $row['url']; if(!empty($tree[$i]['childof'])){ unset($tmp); $parentid = $this->getValueByUrl('id', $tree[$i]['childof']); $tmp = $this->getParentTreeLoop($parentid); for($x = 0; $x < sizeof($tmp); $x++){ $i++; $tree[$i]['id'] = $tmp[$x]['id']; $tree[$i]['childof'] = $tmp[$x]['childof']; $tree[$i]['url'] = $tmp[$x]['url']; } } } return $tree; } public function possibleParents($id){ $thisPage = $this->open($id); $treeArray = $this->getTree($thisPage['url']); $exclude = "WHERE"; $exclude .= " `id` != '" . $thisPage['id'] . "'"; for($i = 0; $i < sizeof($treeArray); $i++){ $exclude .= " && `id` != '" . $treeArray[$i]['id'] . "'"; } $sql = "SELECT * FROM `".$this->DbTable."` ".$exclude." ORDER BY `name` DESC"; $result = mysql_query($sql); echo 'SQL: '.$sql; $x = 0; while($row = mysql_fetch_assoc($result)) { for($i = 0; $i < sizeof($this->FieldName); $i++){ $page[$x][$this->FieldName[$i]] = $row[$this->FieldName[$i]]; } $page[$x]['children'] = $this->checkForChildren($page[$x]['url']); $x++; } return $page; } public function getPages($childof = ''){ $sql = "SELECT `id`, `childof`, `url`, `hide` FROM `".$this->DbTable."` WHERE `childof` = '".$childof."' ORDER BY `childof`, `id`"; $result = mysql_query($sql); $x = 0; while ($row = mysql_fetch_assoc($result)) { for($i = 0; $i < sizeof($this->FieldName); $i++){ $pages[$x][$this->FieldName[$i]] = $row[$this->FieldName[$i]]; } $pages[$x]['children'] = $this->getPages($pages[$x]['url']); $pages[$x]['fullurl'] = $this->getRealUrl($pages[$x]['url']); $x++; } return $pages; } public function getPagesByChildof($childof = ''){ $sql = "SELECT * FROM `".$this->DbTable."` WHERE `childof` = '".$childof."' ORDER BY `childof`, `id`"; $result = mysql_query($sql); $x = 0; while ($row = mysql_fetch_assoc($result)) { for($i = 0; $i < sizeof($this->FieldName); $i++){ $pages[$x][$this->FieldName[$i]] = $row[$this->FieldName[$i]]; } $pages[$x]['children'] = $this->checkForChildren($pages[$x]['url']); $pages[$x]['fullurl'] = $this->getRealUrl($pages[$x]['url']); $x++; } return $pages; } public function getAllPages(){ $sql = "SELECT * FROM `".$this->DbTable."` ORDER BY `childof`, `id`"; $result = mysql_query($sql); $x = 0; while ($row = mysql_fetch_assoc($result)) { for($i = 0; $i < sizeof($this->FieldName); $i++){ $pages[$x][$this->FieldName[$i]] = $row[$this->FieldName[$i]]; } $pages[$x]['fullurl'] = $this->getRealUrl($pages[$x]['url']); $x++; } return $pages; } private function checkForChildren($url){ $query = mysql_query("SELECT COUNT(*) FROM `".$this->DbTable."` WHERE `childof` = '".$url."' "); list($number) = mysql_fetch_row($query); return $number; } private function areChilrenHidden($url){ $query = mysql_query("SELECT COUNT(*) FROM `".$this->DbTable."` WHERE `childof` = '".$url."' && `hide` = 0"); list($number) = mysql_fetch_row($query); return $number; } private function getFields(){ $sql = "SELECT * FROM `".$this->DbTable."` LIMIT 0"; $result = mysql_query($sql); $num_fields = mysql_num_fields($result); for($i = 0; $i < $num_fields; $i++){ $meta = mysql_fetch_field($result, $i); $this->FieldName[$i] = $meta->name; } } private function checkFields(){ if($this->Page['name'] == ''){ $this->Debug[$this->DebugCounter] = '#' . $this->DebugCounter . ': Missing name input.'; $this->DebugCounter++; return false; } if($this->Page['url'] == ''){ $this->Page['url'] = $this->generateUrl($this->Page['name']); } if($this->Page['publishdate'] == ''){ $this->Page['publishdate'] = date('YmdHis'); } if($this->Page['publishdate'] != ''){ if(strlen($this->Page['publishdate']) != 14){ $this->Debug[$this->DebugCounter] = '#' . $this->DebugCounter . ': Wrong lenght in publishdate.'; $this->DebugCounter++; return false; } } if($this->Page['expiredate'] != '' && $this->Page['expiredate'] != 'NULL'){ if(strlen($this->Page['expiredate']) != 14){ $this->Debug[$this->DebugCounter] = '#' . $this->DebugCounter . ': Wrong lenght in expiredate.'; $this->DebugCounter++; return false; } } $this->Page['editdate'] = date('YmdHis'); if($this->Page['hide'] == ''){ $this->Page['hide'] = 0; } if($this->Page['hide'] != ''){ if($this->Page['hide'] != 0 && $this->Page['hide'] != 1){ $this->Page['hide'] = 0; } } return true; } private function getMissing(){ $sql = "SELECT * FROM `".$this->DbTable."` WHERE `id` = '".$this->Page['id']."' LIMIT 1"; $result = mysql_query($sql); if ($row = mysql_fetch_assoc($result)) { for($i = 0; $i < sizeof($this->FieldName); $i++){ if(empty($this->Page[$this->FieldName[$i]]) && !is_numeric($this->Page[$this->FieldName[$i]])){ $this->Page[$this->FieldName[$i]] = $row[$this->FieldName[$i]]; } } } } public function getValue($field, $id = ''){ if(empty($id)){ $id = $this->Page['id']; } $sql = "SELECT `".$field."` FROM `".$this->DbTable."` WHERE `id` = '".$id."' LIMIT 1"; $result = mysql_query($sql); if ($row = mysql_fetch_assoc($result)) { return $row[$field]; } else { return false; } } public function getValueByUrl($field, $url = ''){ if(empty($url)){ $url = $this->Page['id']; } $sql = "SELECT `".$field."` FROM `".$this->DbTable."` WHERE `url` = '".$url."' LIMIT 1"; $result = mysql_query($sql); if ($row = mysql_fetch_assoc($result)) { return $row[$field]; } else { return false; } } private function generateUrl($name){ $url = $this->friendlyUrl($name); $url_tmp = $url; $postfix = 0; do{ if($postfix != 0){ $url_tmp = $url.'-'.$postfix; } $postfix++; } while($this->checkIfUrlExist($url_tmp)); $url = $url_tmp; return $url; } private function friendlyUrl($string){ $string = mb_strtolower($string, 'UTF-8'); $string = trim($string); $replacement = array( "å"=>"a", "ä"=>"a", "å"=>"a", "ö"=>"o", "ø"=>"o", "æ"=>"ae", "å"=>"a", "ä"=>"a", "ö"=>"o", "ø"=>"o", "æ"=>"ae", "é"=>"e", "è"=>"e", "á"=>"a", "&"=>"och", "?"=>"", "!"=>"", '"'=>"", "'"=>"", "#"=>"", "¤"=>"", "$"=>"", "@"=>"at", "£"=>"", "/"=>"", "\\"=>"", "("=>"", ")"=>"", "+"=>"", "-"=>"", "*"=>"", "."=>"", ","=>"", "_"=>"-", "<"=>"", ">"=>"", "|"=>"", "%"=>"", "§"=>"", "½"=>"", " "=>"-" ); foreach($replacement as $i=>$u) { $string = str_replace($i,$u,$string); } return $string; } private function checkIfUrlExist($url){ $sql = "SELECT `url` FROM ".$this->DbTable." WHERE `url` = '".$url."' LIMIT 1"; $result = mysql_query($sql); $num_rows = mysql_num_rows($result); if($num_rows == 0){ return false; } else { return true; } } private function getRealUrl($url = ''){ if(empty($url)){ $url = $this->Page['url']; } $protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http'; $string = $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $string = substr($string, 0, strpos($string, '/admin/')+1) . '?p=' . $url; return $string; } public function firstPage(){ $sql = "SELECT `id` FROM `".$this->DbTable."` ORDER BY `id` ASC LIMIT 1"; $result = mysql_query($sql); if($row = mysql_fetch_assoc($result)) { return $row['id']; } else { return false; } } public function firstPageUrl(){ $sql = "SELECT `url` FROM `".$this->DbTable."` ORDER BY `id` ASC LIMIT 1"; $result = mysql_query($sql); if($row = mysql_fetch_assoc($result)) { return $row['url']; } else { return false; } } public function getPage($url = ''){ if(empty($url)){ $url = $this->firstPage(); } $page = $this->open($url); return $page; } public function printActiveTreeLoop($childof, $parents = array(), $current_id, $root = false, $lvl = 0){ $sql = "SELECT * FROM `".$this->DbTable."` WHERE `childof` = '".$childof."' && `hide` != 1 && (`publishdate` < '".date('YmdHis')."' || `publishdate` = '' || `publishdate` = 00000000000000) && (`expiredate` > '".date('YmdHis')."' || `expiredate` = '' || `expiredate` = 00000000000000) ORDER BY `childof`, `id`"; $result = mysql_query($sql); $x = 0; if($lvl == 0){ echo '