コード例 #1
0
ファイル: App.php プロジェクト: Kekesed/Kambeng-Blog
 function indexer($f3)
 {
     //post loader
     $posts = new \Model\Post();
     $hasil = array_map(array($posts, 'cast'), $posts->find(array("published=? ORDER BY date_created DESC LIMIT 0,7", 1)));
     #var_dump($hasil);
     $f3->mset(array("template.title" => $f3->get("kekesed.sitename"), "template.content" => "index.html", "fpost" => $hasil[0], "posts" => array_slice($hasil, 1)));
     echo \Template::instance()->render('public/layout.php');
 }
コード例 #2
0
ファイル: postlist.class.php プロジェクト: Niggu/GuestBookly
 /**
  * get the overview over all posts
  * @author Adrian Berger <*****@*****.**>
  * @version 1.0.0
  * @access public
  * @param $database MySQLI Connection
  * @param $template Twig Template
  * @return $content Twig Template File
  */
 public function getList($database, $template)
 {
     $query = 'SELECT `id`, `title`, `content`, `user_id`, `date` FROM `post` ORDER BY `date` DESC;';
     $result = $database->executeQuery($query);
     while ($row = $result->fetch_assoc()) {
         $fetchedResult[] = $row;
     }
     $content = "";
     foreach ($fetchedResult as $postData) {
         $post = new \Model\Post($postData['id'], $postData['title'], $postData['content'], $postData['user_id'], $postData['date']);
         $content .= $post->getOutput($database, $template);
     }
     return $content;
 }
コード例 #3
0
ファイル: Blog.php プロジェクト: Kekesed/Kambeng-Blog
 function Tampil($f3)
 {
     try {
         $post = new \Model\Post();
         $hasil = $post->find(array("uniq_url = ?", $f3->get("PARAMS.id")));
         /* if($post->loaded == 0)
         			return $f3->error(404); */
         #$post = new \Model\Post($f3->get("PARAMS.id"));
     } catch (\Exception $e) {
         return $f3->error(404);
     }
     $f3->mset(array("template.title" => $hasil[0]->title . " // " . $f3->get("kekesed.sitename"), "template.content" => "entry.html", "post.cast" => $hasil[0]->cast(), "post.object" => $hasil[0]));
     echo \Template::instance()->render('public/layout.php');
 }
コード例 #4
0
 /**
  * find the correct cmd, so we know where the user should be send
  * @author Adrian Berger <*****@*****.**>
  * @version 1.0.0
  * @access private
  * @param $database MySQLI Connection
  * @param $template Twig Template
  * @return $content Twig Template File
  */
 public function doHandle($database, $template)
 {
     switch ($this->cmd) {
         case 'json':
             require_once 'Controller/json.class.php';
             $JSON = new \Controller\JsonController();
             $JSON->getData($database);
             die;
             break;
         case 'logout':
             // The complete login is done over the session, so we destroy the complete session to logout the user
             session_unset();
             session_destroy();
             header('Location: ?cmd=login');
             die;
             break;
         case 'login':
             $loginContent = $template->loadTemplate('login.html');
             // if submit is set, the user wants to login, so we try if he can or not
             if (isset($_POST['submit'])) {
                 $user = new \Model\User('', $_POST['username'], '', '', $_POST['password'], '');
                 /* If the login data from the user are correct, we send him to survey, so he can answer the questions
                    if not, we tell him the data are wrong. We don't tell him what is wrong, because it will be
                    easier for hackers to find out correct data */
                 if ($user->checkLogin($database)) {
                     $user->saveUserIsLoggedIn($database);
                     header('Location: ?cmd=overview&message=hello');
                     die;
                 } else {
                     $content = $loginContent->render(array('ERROR_MESSAGE' => 'Login Daten sind falsch', "USERNAME" => $user->getName()));
                 }
             } else {
                 $content = $loginContent->render(array());
             }
             break;
         case 'passwordChange':
             if (isset($_POST['submit'])) {
                 $user = new \Model\User($_SESSION['userId'], '', '', '', $_POST['password'], '');
                 $user->changePassword($database);
                 header('Location: ?cmd=passwordChange&message=changed');
                 die;
             }
             $model = $template->loadTemplate('changePassword.html');
             $message = '';
             if (isset($_GET['message']) && $_GET['message'] == "changed") {
                 $message = "Passwort wurde erfolgreich ge&auml;ndert";
             }
             $content = $model->render(array('MESSAGE' => $message));
             break;
         case 'register':
             $registerContent = $template->loadTemplate('register.html');
             // if submit is set, the user tries to register, so we check if we can register him or not
             if (isset($_POST['submit'])) {
                 $user = new \Model\User('', $_POST['username'], $_POST['firstname'], $_POST['lastname'], $_POST['password'], $_POST['email']);
                 // we check the data again, for users which have turned of javascript in browser
                 $errorData = $user->checkregisterData($database);
                 // if all data are correct, we save the new user and send him to survey, so he can answer the questions
                 if ($errorData == "") {
                     $user->save($database);
                     $user->saveUserIsLoggedIn($database);
                     header('Location: ?cmd=overview&message=hello');
                     die;
                 } else {
                     $content = $registerContent->render(array('ERROR_MESSAGE' => $errorData, 'USERNAME' => $user->getName(), 'FIRSTNAME' => $user->getFirstname(), 'LASTNAME' => $user->getLastname(), 'E_MAIL' => $user->getEmail()));
                 }
             } else {
                 $content = $registerContent->render(array());
             }
             break;
         case 'overview':
             require_once 'htmlpurifier/library/HTMLPurifier.auto.php';
             $config = \HTMLPurifier_Config::createDefault();
             $config->set('HTML.AllowedElements', array('br', 'img', 'p'));
             $config->set('HTML.AllowedAttributes', array('img.src', 'img.alt'));
             $purifier = new \HTMLPurifier($config);
             if (isset($_GET['act']) && isset($_SESSION['userName'])) {
                 switch ($_GET['act']) {
                     case 'edit':
                         $post = new \Model\Post($_GET['id'], '', '', '', '');
                         $post->getById($database);
                         if ($post->getUserId() == $_SESSION['userId']) {
                             if (isset($_POST['submit'])) {
                                 if (isset($_POST['title']) && isset($_POST['content'])) {
                                     $post->setContent($_POST['content']);
                                     $post->setTitle($_POST['title']);
                                     $post->update($database, $purifier);
                                     header('Location: ?cmd=overview&message=edited');
                                     die;
                                 }
                             } else {
                                 $model = $template->loadTemplate('modifyPost.html');
                                 $content = $model->render(array('HEADING' => 'Eintrag bearbeiten', 'TITLE' => $post->getTitle(), 'POSTCONTENT' => $post->getContent(), 'ACT' => 'edit&id=' . $post->getId()));
                             }
                         } else {
                             header('Location: ?cmd=overview');
                             die;
                         }
                         break;
                     case 'delete':
                         $post = new \Model\Post($_GET['id'], '', '', '', '');
                         $post->getById($database);
                         if ($post->getUserId() == $_SESSION['userId']) {
                             $post->delete($database);
                         }
                         header('Location: ?cmd=overview&message=deleted');
                         die;
                         break;
                     case 'add':
                         if (isset($_POST['submit'])) {
                             if (isset($_POST['title']) && isset($_POST['content'])) {
                                 $post = new \Model\Post('', $_POST['title'], $_POST['content'], $_SESSION['userId'], time());
                                 $post->save($database, $purifier);
                                 header('Location: ?cmd=overview&message=added');
                                 die;
                             }
                         }
                         $model = $template->loadTemplate('modifyPost.html');
                         $content = $model->render(array('HEADING' => 'Neuer Eintrag', 'ACT' => 'add'));
                     default:
                         break;
                 }
             } else {
                 $message = '';
                 if (isset($_GET['message']) && isset($_SESSION['userName'])) {
                     switch ($_GET['message']) {
                         case 'deleted':
                             $message = 'Eintrag wurde gel&ouml;scht';
                             break;
                         case 'added':
                             $message = 'Eintrag wurde erstellt';
                             break;
                         case 'edited':
                             $message = 'Eintrag wurde ge&auml;ndert';
                             break;
                         case 'hello':
                             $message = 'Um einen neuen Eintarg zu erstellen, klicken sie auf das Plus oben rechts';
                             break;
                     }
                 } else {
                     if (!isset($_SESSION['infoWindow'])) {
                         $_SESSION['infoWindow'] = 'shown';
                         $message = 'Bitte melden Sie sich an um einen Eintrag zu erstellen';
                     }
                 }
                 $list = new \Model\PostList($database, $template);
                 $model = $template->loadTemplate('postList.html');
                 $content = $model->render(array('POSTS' => $list->getList($database, $template), 'MESSAGE' => $message));
             }
             break;
         default:
             header('Location: ?cmd=overview');
             die;
             break;
     }
     return $content;
 }
コード例 #5
0
ファイル: plugin.php プロジェクト: wells5609/wp-app
 /**
  * Application instance.
  *
  * @var WordPress\App $app
  */
 \WordPress::init($app = new $class($env));
 $app->set('autoloader', function (App $app) {
     return $app->getGlobal('autoloader');
 });
 $app->setShared('env', $env);
 $app->setShared('request', Http\Request::createFromGlobals());
 $app->setShared('restManager', new Rest\Manager());
 $app->setShared('modelManager', new Model\Manager());
 $app->setShared('dataManager', new Data\Manager());
 $app->set('post', function () {
     return Model\Post::instance();
 });
 $app->set('user', function () {
     return Model\User::instance();
 });
 $app->setShared('dbConnection', function (App $app) {
     return new Database\Connection($app->getGlobal('wpdb'));
 });
 if (CLI) {
     $app->setShared('cliRequest', function () {
         return Cli\Request::createFromGlobals();
     });
     $app->setShared('console', function (App $app) {
         return new Cli\Console($app['cliRequest']);
     });
 }
コード例 #6
0
get('about', function () {
    return view('about');
});
get('guid', function () {
    return view('guid');
});
get('posts|posts/<q:\\w+>', function () {
    $post = new Model\Post();
    $q = $_GET['q'];
    $c['status'] = 1;
    if ($q) {
        //$c['title'] =  new \MongoRegex("/$q/i");
        $obj = obj('Model\\Category');
        $rt = $obj->findOne(['slug' => $q]);
        $cid = $rt->id;
        if ($cid) {
            $c['category'] = $cid;
        }
    }
    if ($q) {
        $qurl = "/" . $q;
    }
    $data = $post->page(['url' => '/posts' . $qurl, 'size' => 1, 'sort' => ['created' => -1], 'condition' => $c]);
    return view('posts', $data);
});
get('post/<id:\\w+>', function ($id) {
    $post = new Model\Post();
    $data['data'] = $post->findOne(['slug' => $id]);
    return view('posts_view', $data);
});
get_post('user', 'admin/login@index');
コード例 #7
0
ファイル: PostSeeder.php プロジェクト: sbtkzp/TestProject
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model\Post::create(["user_id" => 1, "title" => "aaaaa", "body" => "aaaaabbbbbbb", "status" => 2, "created_at" => "2015-11-22 00:49:35", "updated_at" => "2015-11-22 01:34:46"]);
 }