Esempio n. 1
0
 public static function run()
 {
     self::prepare();
     // if installer - skipping configuration etc, just loading controller and generating
     if (self::$appType == self::Installer) {
         include BundlesPath . 'installer/installer.controller.php';
         self::$controllerName = 'installer';
         self::$controller = $controller = new Installer_Controller();
         $controller->bundleName = 'installer';
         $controller->installer();
         $controller->generate();
         return;
     }
     // indexing modules (if debug or admin logged)
     if (defined('WM_Debug') || Users::isLogged()) {
         self::indexModules();
     }
     // if ACP - checking if logged in
     if (self::$appType == self::Admin && !Users::isLogged()) {
         SiteRedirect('#/users/login/' . base64_encode(self::$requestURL));
         exit;
     }
     // auto-loading extensions
     new FrontendLibraries();
     if (self::$appType == self::Admin) {
         new Sblam();
     }
     // Atom feed shortut
     if (self::$segments == array('feed') && self::$format == 'atom') {
         self::$segments = array('blog', 'feed');
     }
     // blog posts shortcut
     if (count(self::$segments) >= 3 && is_numeric(self::$segments[0]) && is_numeric(self::$segments[1])) {
         self::$segments = array('blog', '_post', self::$segments[2]);
     }
     // loading controller and generating
     self::loadController();
     self::$controller->generate();
 }
 function nav_save_action($id, $action)
 {
     $id = (int) $id;
     $action = strtolower($action);
     // validating action
     if (!in_array($action, array('top', 'up', 'down', 'bottom', 'delete', 'add'))) {
         $action = false;
     }
     // composing $nav
     foreach ($_POST as $key => $value) {
         list($key, $i) = explode('_', $key);
         $nav_post[$i]->{$key} = $value;
     }
     // filtering $nav
     foreach ($nav_post as $item) {
         $item->name = trim($item->name);
         $item->url = trim($item->url);
         $item->relative = isset($item->relative);
         $item->title = trim($item->title);
         if (empty($item->title)) {
             $item->title = null;
         }
         $nav[] = $item;
     }
     // performing action if necessary
     if ($action == 'top' || $action == 'bottom') {
         // recreating array, omiting given item
         foreach ($nav as $i => $item) {
             if ($i != $id) {
                 $nav2[] = $item;
             }
         }
         // adding given item on top or bottom
         if ($action == 'top') {
             array_unshift($nav2, $nav[$id]);
         } else {
             array_push($nav2, $nav[$id]);
         }
         $nav = $nav2;
     } elseif ($action == 'up') {
         // swapping items
         $item = $nav[$id];
         $nav[$id] = $nav[$id - 1];
         $nav[$id - 1] = $item;
     } elseif ($action == 'down') {
         // swapping items
         $item = $nav[$id];
         $nav[$id] = $nav[$id + 1];
         $nav[$id + 1] = $item;
     } elseif ($action == 'delete') {
         // recreating array, omiting given item
         foreach ($nav as $i => $item) {
             if ($i != $id) {
                 $nav2[] = $item;
             }
         }
         $nav = $nav2;
     } elseif ($action == 'add') {
         $item = new stdClass();
         $item->name = '';
         $item->url = '';
         $item->relative = true;
         $item->title = '';
         $nav[] = $item;
     }
     // saving and redirecting
     $textMenu = array();
     foreach ($nav as $item) {
         $textMenu[] = array($item->name, $item->url, $item->relative, $item->title);
     }
     Watermelon::$config->textMenus = array($textMenu);
     Config::set('wmelon.wmelon', Watermelon::$config);
     SiteRedirect('options/nav');
 }
Esempio n. 3
0
 public function fallBack()
 {
     if (empty($this->errors)) {
         return;
     }
     $_SESSION['Form_' . $this->formID] = serialize($this);
     SiteRedirect($this->fallbackPage);
 }
Esempio n. 4
0
 public static function bulkActionSubmit($controller, $ids, $backPage, $actionClosure, $messageClosure = null)
 {
     $ids = IDs($ids);
     // if empty
     if (empty($ids)) {
         SiteRedirect($controller);
     }
     // deleting
     $actionClosure($ids, Watermelon::$controller->model);
     // message
     if ($messageClosure !== null) {
         $message = $messageClosure(count($ids));
         Watermelon::$controller->displaySuccessNotice($message);
     }
     // redirecting
     $backPage = base64_decode($backPage);
     $backPage = empty($backPage) ? $controller : $backPage;
     SiteRedirect($backPage);
 }
 function editSubmit_action($id, $backPage)
 {
     $id = (int) $id;
     // checking if exists
     if (!$this->model->commentData($id)) {
         SiteRedirect('comments');
     }
     // editing
     $form = Form::validate('wmelon.comments.editComment', 'comments/edit/' . $id . '/' . $backPage);
     $data = $form->get();
     $this->model->editComment($id, $data->content);
     // redirecting
     $this->displaySuccessNotice('Zaktualizowano komentarz');
     $backPage = base64_decode($backPage);
     $backPage = empty($backPage) ? 'comments' : $backPage;
     SiteRedirect($backPage);
 }
Esempio n. 6
0
 public static function postComment($id, $type, $backPage)
 {
     if (empty($id) || empty($type) || empty($backPage)) {
         Watermelon::displayNoPageFoundError();
         return;
     }
     if (!in_array($type, array('blogpost', 'page'))) {
         Watermelon::displayNoPageFoundError();
         return;
     }
     //--
     $model = new Comments_Model();
     $backPage = base64_decode($backPage);
     $form = Form::validate('wmelon.comments.addComment', $backPage)->get();
     // testing for spam and adding
     if (!Users::isLogged()) {
         // testing for spam
         $commentStatus = Sblam::test('content', 'name', 'email', 'website');
         // remembering user's data
         $_SESSION['wmelon.comments.name'] = $form->name;
         $_SESSION['wmelon.comments.email'] = $form->email;
         $_SESSION['wmelon.comments.website'] = $form->website;
         // assigning "visibility token" (token user needs to have in session to see his own comments, even if not approved)
         if (isset($_SESSION['wmelon.comments.visibilityToken'])) {
             $visibilityToken = $_SESSION['wmelon.comments.visibilityToken'];
         } else {
             $visibilityToken = $form->name . $form->email . mt_rand();
             $visibilityToken = md5($visibilityToken);
             $visibilityToken = substr($visibilityToken, 16);
             $_SESSION['wmelon.comments.visibilityToken'] = $visibilityToken;
         }
         // adding comment
         switch ($commentStatus) {
             case 0:
             case 1:
             case -1:
                 $model->postComment($id, $type, $form->name, $form->email, $form->website, $form->content, false, $visibilityToken);
                 Watermelon::displayNotice('Twój komentarz zostanie sprawdzony zanim zostanie publicznie pokazany');
                 break;
             case -2:
                 $commentID = $model->postComment($id, $type, $form->name, $form->email, $form->website, $form->content, true, $visibilityToken);
                 Watermelon::displaySuccessNotice('Dodano komentarz');
                 $backPage .= '#comment-' . $commentID;
                 break;
             case 2:
                 Watermelon::displayError('Filtr uznał twój komentarz za spam. ' . Sblam::reportLink());
                 break;
         }
     } else {
         $commentID = $model->postComment_logged($id, $type, $form->content);
         $backPage .= '#comment-' . $commentID;
     }
     SiteRedirect($backPage);
 }
Esempio n. 7
0
 public function index_action()
 {
     $page = (int) $this->params->page;
     // page number
     $page = $page < 1 ? 1 : $page;
     // page=1, if specified page<1
     $postsObj = $this->model->posts($page);
     $posts = array();
     // if page is not 1, and there are no posts (page is invalid), redirect to 0 page
     if ($page != 1 && $postsObj->empty) {
         SiteRedirect('blog');
     }
     // adding data to posts
     foreach ($postsObj as $i => $post) {
         // omiting 11th post
         if ($i == 10) {
             continue;
         }
         // edit/delete links
         $post->editHref = '%/blog/edit/' . $post->id . '?backTo=site';
         $post->deleteHref = '%/blog/trash/' . $post->id . '/' . base64_encode('#/');
         // URL to post
         $post->url = '$/' . date('Y/m', $post->published) . '/' . $post->name;
         // is draft
         $post->draft = $post->status == 'draft';
         // post creation human-readable date
         $post->published_human = HumanDate($post->published, true, true);
         // comments counter - visible (approved) comments for users, all comments - for admin
         if (!Users::isLogged()) {
             $approvedComments = $post->approvedCommentsCount;
             if ($approvedComments > 0) {
                 $post->comments = ', ' . $approvedComments;
                 $post->comments .= ' ' . pl_inflect($approvedComments, 'komentarzy', 'komentarz', 'komentarze');
             }
         } else {
             // counters
             $approvedComments = $post->approvedCommentsCount;
             $allComments = $post->commentsCount;
             $unapprovedComments = $allComments - $approvedComments;
             // all comments counter
             if ($allComments > 0) {
                 $post->comments = ', ' . $allComments . ' ' . pl_inflect($allComments, 'komentarzy', 'komentarz', 'komentarze');
             }
             // unapproved comments counter
             if ($unapprovedComments > 0) {
                 $post->comments .= ' <a href="' . $post->url . '#comments" class="important">(' . $unapprovedComments . ' do sprawdzenia!)</a>';
             }
         }
         // content
         if ($post->summary === null) {
             $post->content = Textile::textile($post->content);
         } else {
             $post->summary = Textile::textile($post->summary . ' <em>[...]</em>');
         }
         //--
         $posts[] = $post;
     }
     // displaying
     $this->noHeader = true;
     $view = View('posts');
     $view->posts = $posts;
     $view->page = $page;
     $view->anotherPage = $postsObj->rows == 11;
     // whether there is another page
     $view->previousPage = $page == 2 ? '$/blog' : '$/blog?page=' . ($page - 1);
     // URL for previous page
     $view->nextPage = '$/blog?page=' . ($page + 1);
     // URL for next page
     $view->display();
 }
Esempio n. 8
0
 function logout_action()
 {
     Users::logout();
     SiteRedirect();
 }
Esempio n. 9
0
 function editSubmit_action($id)
 {
     $id = (int) $id;
     $backTo = isset($this->params->backTo) ? '?backTo=' . $this->params->backTo : '';
     // checking if exists
     $postData = $this->model->postData_id($id);
     if (!$postData) {
         SiteRedirect('blog');
     }
     // editing
     $form = Form::validate('wmelon.blog.editPost', 'blog/edit/' . $id . $backTo);
     $data = $form->get();
     $this->model->editPost($id, $data->title, $data->content, $data->summary, $data->allowComments);
     // updating status (if 'Publish' button selected)
     if (isset($_POST['submit_publish'])) {
         $this->model->publish($id);
         $this->displaySuccessNotice('Opublikowano wpis');
     }
     // redirecting
     $this->displaySuccessNotice('Zaktualizowano wpis');
     SiteRedirect('blog/edit/' . $id . $backTo);
 }
Esempio n. 10
0
 function editSubmit_action($id, $backPage)
 {
     $id = (int) $id;
     $backTo = $this->params->backTo == 'site' ? '?backTo=site' : '';
     // checking if exists
     if (!$this->model->pageData_id($id)) {
         SiteRedirect('pages');
     }
     // editing
     $form = Form::validate('wmelon.pages.editPage', 'pages/edit/' . $id . $backTo);
     $data = $form->get();
     $this->model->editPage($id, $data->title, $data->name, $data->content);
     // redirecting
     $this->displaySuccessNotice('Zaktualizowano stronę');
     SiteRedirect('pages/edit/' . $id . $backTo);
 }