public static function init() { // retrieving API key self::$apiKey = Config::get('wmelon.sblam.apiKey'); // display notice if admin and no API key set if (Watermelon::$appType == Watermelon::Admin && (Watermelon::$segments == array() || Watermelon::$segments == array('blog')) && empty(self::$apiKey)) { Watermelon::displayNotice('Filtr antyspamowy nie będzie działał poprawnie dopóki nie zostanie <a href="$/options/#sblamOptions">skonfigurowany</a>'); } }
function _controllerHandler($pageName) { // getting post data and validating $pageData = $this->model->pageData_name($pageName); if (!$pageData || $pageData->status !== 'published') { Watermelon::displayNoPageFoundError(); return; } // displaying $id = $pageData->id; $pageData->content = Textile::textile($pageData->content); $this->pageTitle = $pageData->title; $this->noHeader = true; $view = View('page'); $view->page = $pageData; $view->commentsView = Comments::commentsView($pageData->id, 'page', '#/' . $pageName, (bool) $pageData->allowComments); $view->editHref = '%/pages/edit/' . $id . '?backTo=site'; $view->deleteHref = '%/pages/trash/' . $id; $view->display(); }
private static function loadController() { // URI stuff self::$controllerName = strtolower(self::$segments[0]); self::$actionName = strtolower(self::$segments[1]); // shortcuts $segments =& self::$segments; $controller =& self::$controllerName; $action =& self::$actionName; // controllers configuration $controllerHandler = 'pages'; $useControllerHandler = false; $useDefaultController = false; // default controller $appType = self::$appType; if ($appType == self::Admin) { $defaultController = 'blog'; } else { $defaultController = self::$config->defaultController; } // determining controller to load if (empty($segments)) { $controller = $defaultController; $useDefaultController = true; } else { // check if controller exists in modules list $controllerDetails = self::controllerDetails($controller, $appType); if ($controllerDetails != false) { array_shift($segments); // shifting controller name out of beginning of segments array } else { // if controller doesn't exist, use controller handler if set, or load error page otherwise if (is_string($controllerHandler)) { $controller = $controllerHandler; $useControllerHandler = true; } else { self::displayNoPageFoundError(); return; } } } // loading controller details if loading default controller, or controller handler (and not controller from URI) if ($useDefaultController || $useControllerHandler) { $controllerDetails = self::controllerDetails($controller, $appType); if ($controllerDetails == false) { self::displayNoPageFoundError(); } } // loading controller list($controllerPath, $bundleName) = $controllerDetails; include $controllerPath; $controllerClassName = $controller . '_Controller'; $controllerObj = new $controllerClassName(); $controllerObj->bundleName = $bundleName; self::$controller = $controllerObj; /// if controller handler is set, run it if ($useControllerHandler) { // note that currently controller handler is hardcoded - pages controller // in future probably it will be somehow changed self::callMethodQuietly($controllerObj, '_controllerHandler', array(implode('/', $segments))); return; } // if action is not specified in URI, run default action if (count($segments) == 0) { $action = 'index'; self::callMethodQuietly($controllerObj, 'index_action'); return; } // if action specified in URI exists, run it $actionName = $action . '_action'; if (method_exists($controllerObj, $actionName)) { array_shift($segments); // shifting action name out of beginning of segments array self::callMethodQuietly($controllerObj, $actionName, $segments); return; } // if action handler exists in loaded controller, run it if (method_exists($controllerObj, '_actionHandler')) { self::callMethodQuietly($controllerObj, '_actionHandler', $segments); return; } // if neither action specified in URI, nor action handler exists self::displayNoPageFoundError(); }
public function displaySuccessNotice($message) { Watermelon::displaySuccessNotice($message); }
public function generate() { // displaying errors (if any) foreach ($this->errors as $error) { if ($this->globalMessages) { Watermelon::displayError($error); } else { $r .= '<div class="error">' . $error . '</div>'; } } $this->errors = array(); // storing form object in session (so that in can be reconstructed on action page) $_SESSION['Form_' . $this->formID] = serialize($this); // extra <form> attributes $attributes = ''; foreach ($this->extraFormAttributes as $attribute => $value) { $attributes .= ' ' . $attribute . '="' . $value . '"'; } // generating $r .= '<form action="' . SiteURL($this->actionPage) . '" method="post"' . $attributes . ">\n"; $r .= '<input type="hidden" name="formID" value="' . $this->formID . '">' . "\n"; // items foreach ($this->items as $item) { if (is_object($item)) { $r .= $item->generate() . "\n"; } else { $r .= $item . "\n"; } } // submit button if ($this->displaySubmitButton) { if (empty($this->submitLabel)) { $submitLabel = ' value="Zapisz"'; } else { $submitLabel = ' value="' . $this->submitLabel . '"'; } $r .= '<label><span></span><input type="submit"' . $submitLabel . '></label>'; } //-- $r .= '</form>'; return $r; }
public function install2() { $this->plainOutput = true; // data $fields = array('dbname', 'dbuser', 'dbpass', 'dbprefix', 'dbhost', 'login', 'pass', 'pass2', 'sitename'); foreach ($fields as $key) { ${$key} = $_POST[$key]; } if (empty($sitename)) { $sitename = 'Mój blog'; } // URL-s $mod_rewrite = $_POST['mod_rewrite'] == 'on'; if ($mod_rewrite) { $siteURL = BaseURL; } else { $siteURL = BaseURL . 'index.php/'; } // connecting with database try { DB::connect($dbhost, $dbname, $dbuser, $dbpass, $dbprefix); } catch (WMException $e) { // creating database if necessary if ($e->getCode() == 'DB:selectError') { DB::query('CREATE DATABASE ' . $dbname); DB::connect($dbhost, $dbname, $dbuser, $dbpass, $dbprefix); } else { throw $e; } } // installing tables in database $tablesSql = file_get_contents(BundlesPath . 'installer/data/structure.sql'); foreach (explode(';', $tablesSql) as $query) { $query = trim($query); if (empty($query)) { continue; } // substituting tables prefix $query = str_replace('`wm_', '`' . $dbprefix, $query); DB::pureQuery($query); } // installing Watermelon's configuration // generating Atom ID for website $atomID = SiteURL . time() . mt_rand(); $atomID = sha1($atomID); // modules $w->modulesList = Watermelon::indexModules(false); $w->defaultController = 'blog'; // other $w->siteURL = $siteURL; $w->systemURL = SystemURL; $w->skin = 'light'; $w->atomID = $atomID; // frontend $textMenus = array(array(array('Blog', '', true, null))); $w->siteName = $sitename; $w->footer = '<small><a href="$/admin">Logowanie</a></small><br>' . 'powered by <strong><a href="https://github.com/radex/Watermelon">Watermelon</a></strong>'; $w->textMenus = $textMenus; $w->headTags = ''; $w->tailTags = ''; // setting config Config::set('wmelon.wmelon', $w); Watermelon::$config = $w; // adding admin's account $salt = substr(sha1(mt_rand()), 0, 16); $adminData = (object) array('login' => strtolower($login), 'salt' => $salt, 'pass' => sha1($pass . $salt), 'nick' => $login); Config::set('wmelon.admin', $adminData); // logging in $_SESSION['wmelon.users.login'] = strtolower($login); $_SESSION['wmelon.users.pass'] = $adminData->pass; // creating cache dirs @mkdir(CachePath . 'textile/'); // warnings supressed so that installation don't fail if cache dirs already exist @mkdir(CachePath . 'textile_restricted/'); // adding sample blog post $postContent = file_get_contents(BundlesPath . 'installer/data/samplePost.txt'); Blog_Model::postPost(true, 'Dzięki za wybranie Watermelona!', $postContent); // saving config.php $configFile = file_get_contents(BundlesPath . 'installer/data/config.php'); $configFile = str_replace('{host}', addslashes($dbhost), $configFile); $configFile = str_replace('{user}', addslashes($dbuser), $configFile); $configFile = str_replace('{pass}', addslashes($dbpass), $configFile); $configFile = str_replace('{name}', addslashes($dbname), $configFile); $configFile = str_replace('{prefix}', addslashes($dbprefix), $configFile); file_put_contents(SystemPath . 'config.php', $configFile); }
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); }
public function _post_action($name) { // getting post data $post = $this->model->postData_name($name); if (!$post) { Watermelon::displayNoPageFoundError(); return; } // checking if published if ($post->status !== 'published') { // displaying notice for admin, or 'not found' if (Users::isLogged()) { $this->displayNotice('Ten wpis nie jest opublikowany. Tylko Ty go możesz zobaczyć.'); } else { Watermelon::displayNoPageFoundError(); return; } } // post $post->content = Textile::textile($post->content); $post->url = '#/' . date('Y/m', $post->published) . '/' . $post->name; // displaying (if exists) $id = $post->id; $this->pageTitle = $post->title; $this->noHeader = true; $view = View('post'); $view->post = $post; $view->commentsView = Comments::commentsView($id, 'blogpost', $post->url, (bool) $post->allowComments); $view->editHref = '%/blog/edit/' . $id . '?backTo=post'; $view->deleteHref = '%/blog/trash/' . $id . '/' . base64_encode('#/'); $view->published_human = HumanDate($post->published, true, true); $view->display(); }
<?php include 'wmelon/core/Watermelon.php'; Watermelon::run();