コード例 #1
0
ファイル: secure.php プロジェクト: radekstepan/zenchat
 public function logout()
 {
     $user = Fari_User::getCredentials();
     Fari_Message::notify("Thanks for the visit {$user}.");
     Fari_User::signOut();
     $this->redirect('/secure/');
 }
コード例 #2
0
ファイル: users.php プロジェクト: radekstepan/zenchat
 public static function add($username, $password, $realname)
 {
     // escape input
     $username = Fari_Escape::html($username);
     $password = Fari_Escape::html($password);
     $realname = Fari_Escape::html(Fari_Decode::javascript($realname));
     // verify that credentials are provided in a valid form
     if (!empty($username) && ctype_alnum($username) && strlen($username) <= 10) {
         if (!empty($password) && ctype_alnum($password) && strlen($password) <= 10) {
             if (!empty($realname) && strlen($realname) <= 100) {
                 // all OK, db insert
                 Fari_Db::insert('users', array('username' => $username, 'password' => sha1($password), 'realname' => $realname));
                 Fari_Message::success("Welcome {$realname}!");
                 return TRUE;
             } else {
                 Fari_Message::fail("Please provide a valid real name.");
             }
         } else {
             Fari_Message::fail("Please provide a valid password.");
         }
     } else {
         Fari_Message::fail("Please provide a valid username.");
     }
     return FALSE;
 }
コード例 #3
0
 public function index($param)
 {
     // get installed CSS themes
     $files = Fari_File::listing('/public');
     $themes = array();
     foreach ($files as $file) {
         $css = end(explode('/', $file['path']));
         // its cheap
         if ($file['type'] == 'file' && substr($css, -4) == '.css') {
             $themes[] = substr($css, 0, -4);
         }
     }
     natsort(&$themes);
     $this->view->themes = $themes;
     // are we saving changes?
     if ($_POST) {
         $css = Fari_Escape::text($_POST['css']);
         $title = Fari_Escape::text($_POST['title']);
         Fari_Db::update('settings', array('value' => $css), array('name' => 'theme'));
         Fari_Db::update('settings', array('value' => $title), array('name' => 'title'));
         Fari_Message::success('Settings change successful.');
     }
     $this->view->messages = Fari_Message::get();
     $this->view->settings = Fari_Db::toKeyValues(Fari_Db::select('settings', 'name, value'), 'name');
     $this->view->display('settings');
 }
コード例 #4
0
ファイル: shoutbox.php プロジェクト: radekstepan/zenchat
 public function _init()
 {
     // is user authenticated?
     if (!Fari_User::isAuthenticated('realname')) {
         $this->redirect('/secure/');
         die;
     }
     // get user's credentials
     $this->view->user = Fari_User::getCredentials();
     // get messages for us
     $this->view->system = Fari_Message::get();
 }
コード例 #5
0
ファイル: blog.php プロジェクト: radekstepan/PumpedBlog
 public function logout()
 {
     Fari_User::signOut();
     Fari_Message::success('Goodbye');
     $this->redirect('/blog/login/');
 }
コード例 #6
0
ファイル: register.php プロジェクト: radekstepan/zenchat
 public function _init()
 {
     // get messages for us
     $this->view->system = Fari_Message::get();
 }
コード例 #7
0
ファイル: new.php プロジェクト: radekstepan/Knowledgebase
 public function index($param)
 {
     // are we saving?
     if ($_POST) {
         $success = TRUE;
         // save categories, sources & types
         $category = Fari_Escape::text($_POST['category']);
         $categorySlug = Fari_Escape::slug($category);
         $source = Fari_Escape::text($_POST['source']);
         $sourceSlug = Fari_Escape::slug($source);
         $type = Fari_Escape::text($_POST['type']);
         $typeSlug = Fari_Escape::slug($type);
         if (empty($category)) {
             Fari_Message::fail('The category can\'t be empty.');
             $success = FALSE;
         } else {
             $result = Fari_Db::selectRow('hierarchy', 'key', array('value' => $category, 'type' => 'category'));
             if (empty($result)) {
                 Fari_Db::insert('hierarchy', array('value' => $category, 'slug' => $categorySlug, 'type' => 'category'));
             }
         }
         if (empty($source)) {
             Fari_Message::fail('The source can\'t be empty.');
             $success = FALSE;
         } else {
             $result = Fari_Db::selectRow('hierarchy', 'key', array('value' => $source, 'type' => 'source'));
             if (empty($result)) {
                 Fari_Db::insert('hierarchy', array('value' => $source, 'slug' => $sourceSlug, 'type' => 'source'));
             }
         }
         if (empty($type)) {
             Fari_Message::fail('The category can\'t be empty.');
             $success = FALSE;
         } else {
             $result = Fari_Db::selectRow('hierarchy', 'key', array('value' => $type, 'type' => 'type'));
             if (empty($result)) {
                 Fari_Db::insert('hierarchy', array('value' => $type, 'type' => 'type'));
             }
         }
         if ($success) {
             $title = Fari_Escape::text($_POST['title']);
             if (empty($title)) {
                 Fari_Message::fail('The title can\'t be empty.');
             } else {
                 $slug = Fari_Escape::slug($_POST['title']);
                 // unique slug/title
                 $result = Fari_Db::selectRow('kb', 'id', array('slug' => $slug));
                 if (!empty($result)) {
                     Fari_Message::fail('The title is not unique.');
                 } else {
                     $text = Fari_Escape::quotes($_POST['textarea']);
                     // convert title & main text to its stems and add lowercase originals better matches)
                     $titleStems = Knowledge::stems($title) . ' ' . strtolower($title);
                     $stems = Knowledge::stems($text) . ' ' . strtolower($text);
                     $tags = Fari_Escape::text($_POST['tags']);
                     $category = Fari_Escape::text($_POST['category']);
                     $source = Fari_Escape::text($_POST['source']);
                     $type = Fari_Escape::text($_POST['type']);
                     $comments = Fari_Escape::text($_POST['comments']);
                     $date = Fari_Escape::text($_POST['date']);
                     // date
                     if (!Fari_Filter::isDate($date)) {
                         Fari_Message::fail('The date is not in the correct format.');
                     } else {
                         // INSERT
                         Fari_Db::insert('kb', array('title' => $title, 'slug' => $slug, 'text' => $text, 'tags' => $tags, 'category' => $category, 'categorySlug' => $categorySlug, 'source' => $source, 'sourceSlug' => $sourceSlug, 'type' => $type, 'stems' => $stems, 'comments' => $comments, 'date' => $date, 'titleStems' => $titleStems, 'starred' => 'empty'));
                         Fari_Message::success('Saved successfully.');
                         $this->redirect('/text/edit/' . $slug);
                         die;
                     }
                 }
             }
         }
     }
     // fetch categories, sources & types
     $this->view->categories = $categories = Fari_Db::select('hierarchy', 'key, value', array('type' => 'category'), 'slug ASC');
     $this->view->sources = $sources = Fari_Db::select('hierarchy', 'key, value', array('type' => 'source'), 'slug ASC');
     $this->view->types = $types = Fari_Db::select('hierarchy', 'key, value', array('type' => 'type'), 'value ASC');
     // form if save failed...
     $this->view->saved = $_POST;
     // get all messages
     $this->view->messages = Fari_Message::get();
     $this->view->display('new');
 }
コード例 #8
0
ファイル: text.php プロジェクト: radekstepan/Knowledgebase
 public function edit($slug)
 {
     $slug = Fari_Escape::text($slug);
     // are we saving?
     if ($_POST) {
         $success = TRUE;
         // save categories, sources & types
         $category = Fari_Escape::text($_POST['category']);
         $categorySlug = Fari_Escape::slug($category);
         $source = Fari_Escape::text($_POST['source']);
         $sourceSlug = Fari_Escape::slug($source);
         $type = Fari_Escape::text($_POST['type']);
         $typeSlug = Fari_Escape::slug($type);
         if (empty($category)) {
             Fari_Message::fail('The category can\'t be empty.');
             $success = FALSE;
         } else {
             $result = Fari_Db::selectRow('hierarchy', 'key', array('value' => $category, 'type' => 'category'));
             if (empty($result)) {
                 Fari_Db::insert('hierarchy', array('value' => $category, 'slug' => $categorySlug, 'type' => 'category'));
             }
         }
         if (empty($source)) {
             Fari_Message::fail('The source can\'t be empty.');
             $success = FALSE;
         } else {
             $result = Fari_Db::selectRow('hierarchy', 'key', array('value' => $source, 'type' => 'source'));
             if (empty($result)) {
                 Fari_Db::insert('hierarchy', array('value' => $source, 'slug' => $sourceSlug, 'type' => 'source'));
             }
         }
         if (empty($type)) {
             Fari_Message::fail('The category can\'t be empty.');
             $success = FALSE;
         } else {
             $result = Fari_Db::selectRow('hierarchy', 'key', array('value' => $type, 'type' => 'type'));
             if (empty($result)) {
                 Fari_Db::insert('hierarchy', array('value' => $type, 'type' => 'type'));
             }
         }
         if ($success) {
             $text = Fari_Escape::quotes($_POST['textarea']);
             // convert main text to stems & add the lowercase original to it (better matches)
             $stems = Knowledge::stems($text) . ' ' . strtolower($text);
             $tags = Fari_Escape::text($_POST['tags']);
             $category = Fari_Escape::text($_POST['category']);
             $source = Fari_Escape::text($_POST['source']);
             $type = Fari_Escape::text($_POST['type']);
             $comments = Fari_Escape::text($_POST['comments']);
             $date = Fari_Escape::text($_POST['date']);
             // date
             if (!Fari_Filter::isDate($date)) {
                 Fari_Message::fail('The date is not in the correct format.');
             } else {
                 // INSERT
                 Fari_Db::update('kb', array('text' => $text, 'comments' => $comments, 'date' => $date, 'tags' => $tags, 'category' => $category, 'categorySlug' => $categorySlug, 'source' => $source, 'sourceSlug' => $sourceSlug, 'type' => $type, 'stems' => $stems), array('slug' => $slug));
                 Fari_Message::success('Saved successfully.');
             }
         }
     }
     // fetch categories, sources & types
     $this->view->categories = $categories = Fari_Db::select('hierarchy', 'key, value', array('type' => 'category'), 'slug ASC');
     $this->view->sources = $sources = Fari_Db::select('hierarchy', 'key, value', array('type' => 'source'), 'slug ASC');
     $this->view->types = $types = Fari_Db::select('hierarchy', 'key, value', array('type' => 'type'), 'value ASC');
     // form
     $saved = Fari_Db::selectRow('kb', '*', array('slug' => $slug));
     $saved['textarea'] = $saved['text'];
     // for reuse...
     $this->view->saved = $saved;
     // get all messages
     $this->view->messages = Fari_Message::get();
     $this->view->display('edit');
 }