function checkDB(){ loadIntClass('sql_query'); $sql = new Sql_query('templates'); $num = $sql->numRows('name', $this->_templateName); if($num === 1 && file_exists($this->_path.$this->_filename)){ $sql->simpleQuery('UPDATE `templates` SET `rep`=\'1\' WHERE `name`=\''.$this->_templateName.'\''); if($this->copyFile($_FILES['Filedata']['tmp_name'], $this->_path.$this->_templateName.'.temp.php')){ die('REPLACE/'.$this->_templateName); } else{ die('The file exists already, and the server was unable to temporarily save the file to assess if you wanted to replace. Please try uploading again.'); } } else if($this->copyFile($_FILES['Filedata']['tmp_name'], $this->_path.$this->_filename)){ $sql->simpleQuery('INSERT INTO `templates` (name, css, rep, date) VALUES ( \''.$this->_templateName.'\', \'0\', \'0\', \''.time().'\')'); $sql->disconnect(); $this->getCSS(); } else{ die('The file was not successfully saved. Please try uploading again.'); } }
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 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 __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 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.'".'); }