function delete(){
		loadIntClass('sql_query');
		$sql = new Sql_query('comments');
		$array = $sql->query('SELECT * FROM `comments` WHERE `id`=\''.$this->_id.'\'');
		$sql->simpleQuery('DELETE FROM `comments` WHERE `id`=\''.$this->_id.'\'');
		$this->republish($array[0]['Comment']['post_slug']);
		die('SUCCESS');
	}
	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 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 __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 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 getCSS(){
		require(ROOT.DS.MAIN.DS.'library'.DS.'simple_html_dom.php');
		$html = file_get_html($this->_path.$this->_template.'.php');
		$stylesheets = $html->find('link[rel=stylesheet]');
		$this->_css = '';
		$first = true;
		foreach($stylesheets as $value){
			$this->_css .= $first ? '' : ',';
			$this->_css .= $value->href;
			$first = false;
		}
		$sql = new Sql_query('tempaltes');
		$sql->simpleQuery('UPDATE `templates` SET `css`=\''.$this->_css.'\', `date`=\''.time().'\' WHERE `name`=\''.$this->_template.'\'');
		die('SUCCESS/'.$this->_template.'/'.time());
	}
Beispiel #7
0
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 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 __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 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 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 db_create($directory) {
		$commentbool = $this->_commentbool ? 1 : 0;
		
		$publish = $this->_publish ? 1 : 0;
		
		$pingbool = $this->_pingbool ? 1 : 0;
		
		$cachepub = $this->_cachepub ? 1 : 0;
		
		$time = time();
		$posts = new Sql_query('posts');
		$num =  $posts->numRows('slug',$this->_slug);
		if($num !== 0){
			$posts->simpleQuery('UPDATE `posts`
				SET `title`=\''.$this->_title.'\',
				`description`=\''.$this->_description.'\,
				`template`=\''.$this->_template.'\',
				`category`=\''.$this->_category.'\',
				`author`=\''.$this->_author.'\',
				`commentbool`=\''.$commentbool.'\',
				`publish`=\''.$publish.'\',
				`post`=\''.$this->_post.'\',
				`pingbool`=\''.$pingbool.'\',
				`publishdate`=\''.$time.'\',
				`cachepub`=\''.$cachepub.'\,
				`comments_off`=\''.$this->_commentsdate.'\'
			WHERE `slug`=\''.$this->_slug.'\'');
			$posts->disconnect();
		}
		else{
			$posts->simpleQuery('INSERT INTO `posts` (title, slug, description, template, category, author, commentbool, publish, post, pingbool, publishdate, cachepub, comments_off) VALUES (
				\''.$this->_title.'\',
				\''.$this->_slug.'\',
				\''.$this->_description.'\',
				\''.$this->_template.'\',
				\''.$this->_category.'\',
				\''.$this->_author.'\',
				\''.$commentbool.'\',
				\''.$publish.'\',
				\''.$this->_post.'\',
				\''.$pingbool.'\',
				\''.$time.'\',
				\''.$cachepub.'\',
				\''.$this->_commentsdate.'\')');
			$posts->disconnect();
		}
	
		$string_url = 'http://'.THIS_DOMAIN.'/';
		$string_url .= $this->_category === 'none' ? ($this->_slug ==='_index_' ? '' : $this->_slug) : $this->_category.'/'.$this->_slug;
		if($this->_publish=='true'){
			$this->publish($directory,$string_url);
		}
		die('Your new post has been saved. Simply go to Posts, when you\'re ready to publish it. When it is published its url will be "'.$string_url.'".');
	}