function __construct($post, $filter = 'ALL', $sort = 'none', $DESC = true){ if(session_check()) { $this->_sort = $sort; $this->_DESC = $DESC; loadIntClass('sql_query'); $sql = new Sql_query('comments'); $this->_comments = $sql->getComments($post,$filter); } else{ die('Your session has expired. Please <a href="'.ADMIN_URL.'/logout" target="_self">login</a> again in order to submit your post.'); } }
function __destruct(){ loadIntClass('sql_query'); $Aut = new Sql_query('authors'); $aut_arr = $Aut->selectAll(); for($i=0; $i < count($aut_arr); ++$i){ if($this->_author === $aut_arr[$i]['Author']['author']){ die('This author already exists. If they are not showing up in your slection menu check the documentation for add_new_author.'); } } $Aut->simpleQuery('INSERT INTO `authors` (author) VALUES(\''.$this->_author.'\')'); die('yes'); }
function cron_set(){ loadIntClass('cron_job'); if(!$this->_publish && $this->_postdate > time()){ $arr1 = array('time'=>$this->_postdate,'command'=>'republish_post','parameters'=>array($this->_slug)); $cron1 = new Cron_job($arr1); } $cache = new Sql_query('posts'); $cacheNum = $cache->query('SELECT * FROM `posts` WHERE `cachepub`=\'1\''); for($i = 0; $i < count($cacheNum); ++$i){ $arr2 = array('time'=>time(),'command'=>'republish_post','parameters'=>array($cacheNum[$i]['Post']['slug'])); $cron2 = new Cron_job($arr2); } }
function logout(){ $pName = hash("sha512",$_COOKIE['username']); loadIntClass('sql_query'); $class = new Sql_query('users'); $userDb = $class->selectWhere('user',$pName); $userDb = $userDb['User']; if($pName === $userDb['user']) { $class->simpleQuery("UPDATE `users` SET `loggedin`='0', `logtime`='0'' WHERE `user`='".$pName."'"); $class->disconnect(); return true; } else{ return false; } }
function getCSS(){ require(ROOT.DS.MAIN.DS.'library'.DS.'simple_html_dom.php'); $html = file_get_html($this->_path.$this->_filename); $stylesheets = $html->find('link[rel=stylesheet]'); $this->_css = ''; $first = true; foreach($stylesheets as $value){ $this->_css .= $first ? '' : ','; $this->_css .= $value->href; $first = false; } loadIntClass('sql_query'); $sql = new Sql_query('templates'); $sql->simpleQuery('UPDATE `templates` SET `css`=\''.$this->_css.'\' WHERE `name`=\''.$this->_templateName.'\''); die('SUCCESS/'.$this->_templateName.'/'.time()); }
function template(){ loadIntClass('sql_query'); $posts = new Sql_query('posts'); $num = $posts->selectWhere('slug',$this->_uri); if($num != 0){ if(file_exists(ROOT.DS.MAIN.DS.'reflex'.DS.'templates'.DS.$this->_template.'.php')){ $posts->simpleQuery('UPDATE `posts` SET `template`=\''.$this->_template.'\' WHERE `slug`=\''.$this->_uri.'\''); die('yes'); } else{ die('It seems that the template does not exist anymore.'); } } else{ die('The server could not find the post that you selected.'); } }
function __construct(){ if(array_key_exists('post',$_POST) && session_check()) { $this->_post = $_POST['post'] === 'AP' ? 'ALL' : $_POST['post']; if($this->_post !== '_index_'){ str_replace('_','/',$this->_post); } $filter = $_POST['post'] === 'AP' ? array('pending','spam') : 'ALL'; loadIntClass('get_comments'); $comm = new Get_comments($this->_post, $filter); $this->_comments = $comm->commentsArr(); echo $this->write(); exit; } else{ die('Your session has expired. Please <a href="'.ADMIN_URL.'/logout" target="_self">login</a> again in order to add your category.'); } }
function writeRSS(){ $rsshead = '<?xml version="1.0" encoding="UTF-8" ?> <rss version="2.0"> <channel> <title>'.RSS_TITLE.'</title> <description>'.RSS_DESCRIPTION.'</description> <language>en-us</language> <copyright>Copyright (C) '.date('Y').' '.THIS_DOMAIN.'</copyright> <link>http://'.THIS_DOMAIN.'/'.RSS_URI.'</link> <lastBuildDate>'.date('D, d M Y H:i:s T').'</lastBuildDate>'; loadIntClass('sql_query'); $sql = new Sql_query('posts'); $postArr = $sql->query('SELECT * FROM `posts` WHERE `publish`=\'1\''); $count = count($postArr); if($count === 0){ die('There are no posts'); } reset($postArr); $latest =$postArr[0]['Post']['publishdate']; $rssbody=''; for($i = 0; $i < $count;++$i){ $p = $postArr[$i]['Post']; if($p['slug'] === '_index_') $p['slug'] =''; $link = 'http://'.THIS_DOMAIN.'/'.($p['category'] !=='none'?$p['category'].'/':'').$p['slug']; $rssbody .= ' <item> <title>'.$p['title'].'</title> <description>'.$p['description'].'</description> <link>'.$link.'</link> <guid isPermaLink="true">'.$link.'</guid> <pubDate>'.date('D, d M Y H:i:s T',intval($p['publishdate'])).'</pubDate> </item> '; if(intval($latest)<intval($p['publishdate'])){ $latest = $p['publishdate']; } } $rsshead.=' <pubDate>'.date('D, d M Y H:i:s T',intval($latest)).'</pubDate>'; $rssbody.='</channel> </rss>'; header("Content-Type: application/rss+xml"); echo $rsshead,$rssbody; exit; }
function unpublish(){ loadIntClass('sql_query'); $posts = new Sql_query('posts'); $num = $posts->numRows('slug',$this->_uri); if($num != 0){ if(file_exists(ROOT.DS.MAIN.DS.'reflex'.DS.'documents'.DS.$this->_loc.'.php') || file_exists(ROOT.DS.MAIN.DS.'reflex'.DS.'documents'.DS.'_categories_'.DS.$this->_loc.'.php')){ $post_arr = $posts->selectWhere('slug',$this->_uri); $post_arr = $post_arr['Post']; if($post_arr['category'] == 'none'){ if(unlink(ROOT.DS.MAIN.DS.'reflex'.DS.'documents'.DS.$this->_loc.'.php')){ $posts->simpleQuery('UPDATE `posts` SET `publish`=\'0\' WHERE `slug`=\''.$this->_uri.'\''); die('yes'); } else{ die('The server failed to delete the post you selected.'); } } else{ if(unlink(ROOT.DS.MAIN.DS.'reflex'.DS.'documents'.DS.'_categories_'.DS.$this->_loc.'.php')){ $posts->simpleQuery('UPDATE `posts` SET `publish`=\'0\' WHERE `slug`=\''.$this->_uri.'\''); die('yes'); } else{ die('The server failed to delete the post you selected.'); } } } else{ $post_arr = $posts->selectWhere('slug',$this->_uri); $post_arr = $post_arr['Post']; if($post_arr['publish'] == 0){ die('yes'); } else{ $posts->simpleQuery('UPDATE `posts` SET `publish`=\'0\' WHERE `slug`=\''.$this->_uri.'\''); die('yes'); } } } else{ die('The server could not find the post that you selected.'); } }
function republish() { loadIntClass('sql_query'); $posts = new Sql_query('posts'); $num = $posts->numRows('slug',$this->_uri); if($num !== 0){ $post_arr = $posts->selectWhere('slug',$this->_uri); $post_arr = $post_arr['Post']; $this->_post = $post_arr['post']; $this->_title = $post_arr['title']; $this->_slug = $post_arr['slug']; $this->_description = $post_arr['description']; $this->_template = $post_arr['template']; $this->_category = $post_arr['category']; $this->_author = $post_arr['author']; $this->_commentbool = $post_arr['commentbool']; $this->_pingbacks = $post_arr['pingbacks']; $this->_pingbool = $post_arr['pingbool']; $this->_publish = $post_arr['publish']; $this->_cachepub = $post_arr['cachepub']; ob_start(); require(ROOT.DS.MAIN.DS.'reflex'.DS.'templates'.DS.$this->_template.'.php'); $html_string = ob_get_clean(); $html_string = str_replace('<php>','<?php ',$html_string); $html_string = str_replace('</php>',' ?>',$html_string); if($this->_category == 'none'){ $fileloc = fopen(ROOT.DS.MAIN.DS.'reflex'.DS.'documents'.DS.$this->_slug.'.php', 'w'); fwrite($fileloc,$html_string); fclose($fileloc); } else{ $fileloc = fopen(ROOT.DS.MAIN.DS.'reflex'.DS.'documents'.DS.'_categories_'.$this->_category.DS.$this->_slug.'.php', 'w'); fwrite($fileloc,$html_string); fclose($fileloc); } $posts->simpleQuery('UPDATE `posts` SET `publish`=\'1\' WHERE `slug`=\''.$this->_slug.'\''); die('yes'); } else{ die('The server could not find the post that you selected.'); } }
function __destruct(){ loadIntClass('sql_query'); $Cat = new Sql_query('categories'); $cat_arr = $Cat->selectAll(); for($i=0; $i < count($cat_arr); ++$i){ if($this->_category === $cat_arr[$i]['Categorie']['category']){ die('This category already exists. If it is not showing up in your slection menu check the documentation for add_new_category.'); } } if(is_dir(ROOT.DS.MAIN.DS.'reflex'.DS.'documents'.DS.'_categories_'.DS.$this->_category)){ die('This category already exists. If it is not showing up in your slection menu check the documentation for add_new_category.'); } $Cat->simpleQuery('INSERT INTO `categories` (category) VALUES(\''.$this->_category.'\')'); $Cat->disconnect(); if(!mkdir(ROOT.DS.MAIN.DS.'reflex'.DS.'documents'.DS.'_categories_'.DS.$this->_category)){ die('The server failed to write the folder. Check the documentation for add_new_category.'); } die('yes'); }
function __construct($uri){ if(session_check()) { $this->_uri = $uri; loadIntClass('sql_query'); $this->_query = new Sql_query('posts'); $num = $this->_query->numRows('slug',$this->_uri); if($num !== 0){ $this->loadUp(); $this->buffer(); $this->outPut(); } else{ die('No such post exists in the database.'); } } else{ die('Your session has expired. Please <a href="'.ADMIN_URL.'/logout" target="_self">login</a> again in order to submit your post.'); } }
function session_check() { if(array_key_exists('username', $_COOKIE)){ loadIntClass('sql_query'); $pName = hash("sha512",$_COOKIE['username']); $sql = new Sql_query('users'); $thisDB = $sql->selectAll(); $userexists = false; $int = 0; for($i = 0; $i<count($thisDB); ++$i){ if($pName === $thisDB[$i]['User']['user']) $userexists = true; $int = $i; } if($userexists) { if(intval($thisDB[$int]['User']['loggedin'])===1) { if(intval($thisDB[$int]['User']['logtime'])>time()){ return true; } else{ $sql->simpleQuery("UPDATE `users` SET `loggedin`='0', `logtime`='0'' WHERE `user`='".$pName."'"); $sql->disconnect(); return false; } } else{ $sql->simpleQuery("UPDATE `users` SET `logtime`='0' WHERE `user`='".$pName."'"); $sql->disconnect(); return false; } } else{ setcookie('username',$_COOKIE['username'], time()-60*60*24); return false; } } else{ return false; } }
function checkSet(){ global $cronJobs; $count = count($cronJobs); if($count === 0) return; for($i = 0; $i < $count; ++$i){ $c = $cronJobs[$i]; if(time()>$c['time']){ $params = ''; $first = true; for($t = 0; $t < count($c['parameters']); ++$t){ if(!$first) $params .= ','; $first = false; $params .= '\''.$c['parameters'][$t].'\''; } loadIntClass($c['command']); eval('new '.ucwords($c['command']).'('.$params.');'); unset($cronJobs[$i]); } } }
function db_check(){ loadIntClass('sql_query'); $sql = new Sql_query('templates'); $sql->simpleQuery('SELECT * FROM `templates` WHERE `name`=\''.$this->_template.'\' AND `rep`=\'1\''); $num = $sql->getNumRows(); $sql->freeResult(); if($num === 0){ die('The server was unable to find any templates approved for replacement'); } else if($this->_replace){ $sql1 = new Sql_query('templates'); $sql1->simpleQuery('UPDATE `templates` SET `rep`=\'0\' WHERE `name`=\''.$this->_template.'\''); $this->replace_template(); } else{ $sql2 = new Sql_query('templates'); $sql2->simpleQuery('UPDATE `templates` SET `rep`=\'0\' WHERE `name`=\''.$this->_template.'\''); unlink($this->_path.$this->_template.'.temp.php'); die('NOTHING'); } }
function delete(){ loadIntClass('sql_query'); $posts = new Sql_query('posts'); $num = $posts->numRows('slug',$this->_uri); if($num !== 0){ $post_arr = $posts->selectWhere('slug',$this->_uri); $post_arr = $post_arr['Post']; if($post_arr['category'] == 'none'){ @unlink(ROOT.DS.MAIN.DS.'reflex'.DS.'documents'.DS.$this->_uri.'.php'); $posts->simpleQuery('DELETE FROM `posts` WHERE `slug`=\''.$this->_uri.'\''); die('yes'); } else{ @unlink(ROOT.DS.MAIN.DS.'reflex'.DS.'documents'.DS.'_categories_'.DS.$this->_uri.'.php'); $posts->simpleQuery('DELETE FROM `posts` WHERE `slug`=\''.$this->_uri.'\''); die('yes'); } } else{ die('The server could not find the post that you selected.'); } }
function session_create(){ if(array_key_exists('username', $_POST) && array_key_exists('password', $_POST)){ $pName = hash("sha512",$_POST['username']); $pPass = hash("sha512",$_POST['password']); loadIntClass('sql_query'); $sql = new Sql_query('users'); $thisDB = $sql->selectAll(); $userexists = false; $int = 0; for($i = 0; $i<count($thisDB); ++$i){ if($pName === $thisDB[$i]['User']['user']) $userexists = true; $int = $i; } if($userexists){ if($thisDB[$int]['User']['password'] === $pPass){ if(!array_key_exists('username', $_COOKIE)){ //One year setcookie('username',$_POST['username'],time()+60*60*24*365,'/'); } $time = time()+60*60; $sql->simpleQuery("UPDATE `users` SET `loggedin`='1', `logtime`='".$time."' WHERE `user`='".$pName."'"); $sql->disconnect(); return true; } else{ return false; } } else{ return false; } } else{ return false; } }
function republish($post){ loadIntClass('republish_post'); new Republish_post($post); }
<?php if(array_key_exists('view',$_GET)){ $post = $_GET['view'] !== '_index_' ? str_replace('_','/',$_GET['view']) : $_GET['view']; loadIntClass('preview_post'); new Preview_post($post); } else{ die('You need to specify a post to preview. The URL should look like this: "http://'.THIS_DOMAIN.'/'.ADMIN_URL.'/preview?view=example-post. If your url does look like that right now then there is something wrong with your server.'); }
<?php $postKey = $this->_postName === '' ? 'index' : $this->_postName; $docArray = array( 'index' => array('title' => 'Create a New Post', 'css' => 'newpost'), 'posts' => array('title'=>'Browse Your Posts','css'=>'posts'), 'templates' => array('title'=>'Browse your Templates','css'=>'templates'), 'upload-files' => array('title'=>'Upload/Browse Your Files','css'=>'media'), 'comments' => array('title'=>'Browse Your Comments','css'=>'comments'), 'settings' => array('title'=>'Adjust Your Settings','css'=>'settings'), ); loadIntClass('sql_query'); $header_posts = new Sql_query('posts'); $unpublished_i = $header_posts->numRows('publish','0'); $comments = new Sql_query('comments'); $unapproved_i = $comments->numRows('approved','pending'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Reflexion - <? echo $docArray[$postKey]['title']?></title> <base href="<? echo 'http://'.THIS_DOMAIN.'/';?>" /> <link rel="stylesheet" href="css/admin/reset.css" /> <link rel="stylesheet" href="css/admin/<? echo $docArray[$postKey]['css']?>.css" /> </head> <body> <div id="header"> <div id="logo"></div> <p class="alternate"> <? if($postKey !== 'comments'){
/** Main Call and URL Decomposer Function **/ function callHook(){ global $uri; if(preg_match('/^$/', $uri)) { $postName = '_index_'; } else if(preg_match('/^'.ADMIN_URL.'$/',$uri)) { $uriArray = explode('/',$uri); $category = $uriArray[0]; array_shift($uriArray); $postName = ''; } else if(preg_match('/^'.ADMIN_URL.'\/[[:alnum:]]+-*[[:alnum:]-]*$/',$uri)) { $uriArray = explode('/',$uri); $category = $uriArray[0]; array_shift($uriArray); $postName = $uriArray[0]; } else if(preg_match('/^'.ACTION_VAR.'\_[[:alnum:]_]+_*[[:alnum:]_]*$/',$uri)) { $urlArray = explode('_',$uri,2); $actionName = $uriArray[0]; array_shift($uriArray); $postName = $uriArray[0]; } else if(preg_match('/^'.INTERNAL_ACTION.'\_[[:alnum:]_]+_*[[:alnum:]_]*$/',$uri)) { $uriArray = explode('_',$uri,2); $actionName = $uriArray[0]; array_shift($uriArray); $postName = $uriArray[0]; } else if(preg_match('/^'.PINGBACK.'$/', $uri) || preg_match('/^'.PINGBACK.'$/', strtolower($uri))) { $postName = '_pingback_'; $pingUp = false; if(!preg_match('/^'.PINGBACK.'$/', $uri)) $pingUp = true; } else if(preg_match('/^'.RSS_URI.'$/', $uri) || preg_match('/^'.RSS_URI.'$/', strtolower($uri))){ $postName = '_rssfeed_'; $rssUp = false; if(!preg_match('/^'.RSS_URI.'$/', $uri)) $rssUp = true; } else if(preg_match('/^[[:alnum:]]+-*[[:alnum:]-]*$/', $uri)) { $uriArray = explode('/',$uri); $postName = $uriArray[0]; $category = ''; } /*else if(URL_STATE === 'day-name' && preg_match('/^[0-9]{4}\/{1}[0-9]{2}\/{1}[0-9]{2}\/[[:alnum:]]+-*[[:alnum:]-]*$/', $uri)) { $uriArray = explode('/', $uri); $category = $uriArray[0].'_'; array_shift($uriArray); $category .= $uriArray[0].'_'; array_shift($uriArray); $category .= $uriArray[0]; array_shift($uriArray); $postName = $uriArray[0]; } else if(URL_STATE === 'month-name' && preg_match('/^[0-9]{4}\/{1}[0-9]{2}\/[[:alnum:]]+-*[[:alnum:]-]*$/', $uri)) { $uriArray = explode('/', $uri); $category = $uriArray[0].'_'; array_shift($uriArray); $category .= $uriArray[0]; array_shift($uriArray); $postName = $uriArray[0]; }*/ else if(URL_STATE === 'category-name' && preg_match('/^[[:alnum:]]+-*[[:alnum:]-]*\/[[:alnum:]]+-*[[:alnum:]-]*$/', $uri)) { $uriArray = explode('/', $uri); $category = $uriArray[0]; array_shift($uriArray); $postName = $uriArray[0]; } else { $postName = 'GO_TO_404_ERROR_PAGE'; } if($postName === '_pingback_') { if($pingUp) { $pageURL = 'http'; $pageURL .= '://'.THIS_DOMAIN.'/'.strtolower($uri); header ('HTTP/1.1 301 Moved Permanently'); header ('Location: '.$pageURL); exit; } else{ require(ROOT.DS.MAIN.DS.'library'.DS.'pingbackserver.php'); new PingbackServer(); } } else if($postName === '_rssfeed_') { if($rssUp) { $pageURL = 'http'; $pageURL .= '://'.THIS_DOMAIN.'/'.strtolower($uri); header ('HTTP/1.1 301 Moved Permanently'); header ('Location: '.$pageURL); exit; } else{ require(ROOT.DS.MAIN.DS.'library'.DS.'rss.php'); new Rss_feed(); } } else if(isset($actionName) && $actionName == INTERNAL_ACTION) { loadIntClass($postName); $postName = ucwords($postName); new $postName; } else if (isset($actionName) && $actionName == ACTION_VAR) { $postName = ucwords($postName); new $postName; } else if(isset($category) && isset($postName)) { new Controller($postName, $category); } else { new Controller($postName, false); } }