Пример #1
0
 public function exec()
 {
     $db = Core::getDb();
     $user = Core::getUser();
     $path = explode("/", $this->objectId);
     $albumId = 0;
     $pictureId = 0;
     if (count($path) == 2) {
         list($albumId, $pictureId) = $path;
     } else {
         if (count($path) == 1) {
             list($albumId) = $path;
         }
     }
     if ($albumId) {
         $album = new \Kiki\Album($albumId);
         if ($album->id()) {
             $this->template = 'pages/default';
             $this->status = 200;
             $this->title = "Album: " . $album->title();
             $this->content = $album->show($pictureId);
             return true;
         }
     }
     return false;
 }
Пример #2
0
 public function exec()
 {
     $db = \Kiki\Core::getDb();
     $user = \Kiki\Core::getUser();
     if (!$this->objectId) {
         $this->objectId = 'index';
     }
     // Find page under this section through subcontroller.
     // TODO: also find subsections, instead of defining full paths in
     // sections db...  the latter is faster, but then the base paths are not
     // properly normalised.  Both should be possible.
     $this->subController = \Kiki\Router::findPage($this->objectId, $this->instanceId);
     if ($this->subController) {
         $this->subController->exec();
     } else {
         if ($this->objectId == 'index') {
             $section = new \Kiki\Section($this->instanceId);
             $this->status = 200;
             $this->template = 'pages/autoindex';
             $this->title = sprintf(_("Index of %s"), $section->title());
             $q = $db->buildQuery("SELECT cname,title FROM articles a, objects o WHERE a.object_id=o.object_id AND o.section_id=%d AND visible=true", $this->instanceId);
             $rs = $db->query($q);
             if ($db->numRows($rs) == 0) {
                 $this->template = 'pages/autoindex-empty';
                 return;
             }
             $this->content = "<ul>";
             while ($o = $db->fetchObject($rs)) {
                 $this->content .= sprintf('<li><a href="%s">%s</a></li>', $o->cname, $o->title);
             }
             $this->content .= "</ul>";
         }
     }
 }
Пример #3
0
 public function __construct($id = 0)
 {
     $this->db = \Kiki\Core::getDb();
     $this->id = $id;
     if ($this->id) {
         $this->load();
     } else {
         $this->reset();
     }
 }
Пример #4
0
 /**
  * Retrieves a tinyURL for a full URL. Tries a lookup first and creates a
  * new tinyURL upon failure.
  *
  * @param string $url URL of the resource
  *
  * @return string tinyURL for the resource
  */
 public static function get($url)
 {
     $db = Core::getDb();
     $q = $db->buildQuery("select id from tinyurl where url='%s'", $url);
     $id = $db->getSingleValue($q);
     if (!$id) {
         $id = TinyUrl::insert($url);
     }
     $host = Config::$tinyHost ? Config::$tinyHost : $_SERVER['SERVER_NAME'];
     // TODO: support HTTPS
     return sprintf("http://%s/%03s", $host, Base62::encode($id));
 }
Пример #5
0
 public function __construct($id = 0, $kikiUserId = 0)
 {
     $this->db = \Kiki\Core::getDb();
     if ($this->externalId = $id) {
         $this->load($kikiUserId);
         if (!$kikiUserId) {
             $this->loadKikiUserIds();
         }
     } else {
         $this->identify();
         $this->load();
         $this->loadKikiUserIds();
     }
 }
Пример #6
0
 public function fallback()
 {
     $parts = parse_url($this->objectId);
     if (!isset($parts['path'])) {
         return false;
     }
     $kikiFile = Core::getInstallPath() . "/htdocs/" . $parts['path'];
     if (file_exists($kikiFile)) {
         $ext = Storage::getExtension($kikiFile);
         switch ($ext) {
             case 'css':
             case 'gif':
             case 'jpg':
             case 'js':
             case 'png':
                 $this->altContentType = Storage::getMimeType($ext);
                 $this->template = null;
                 $this->status = 200;
                 $this->content = file_get_contents($kikiFile);
                 return true;
                 break;
             case 'php':
                 Log::debug("PHP file {$kikiFile}");
                 $this->status = 200;
                 $this->template = 'pages/default';
                 $user = Core::getUser();
                 $db = Core::getDb();
                 include_once $kikiFile;
                 return true;
                 break;
             case '':
                 if (file_exists($kikiFile . "index.php")) {
                     Log::debug("PHP index file {$kikiFile}" . "index.php");
                     $this->status = 200;
                     $this->template = 'pages/default';
                     $user = Core::getUser();
                     $db = Core::getDb();
                     include_once $kikiFile . "index.php";
                     return true;
                 }
                 break;
             default:
         }
         Log::debug("unsupported extension {$ext} for kiki htdocs file {$kikiFile}");
     } else {
         Log::debug("non-existing kikiFile {$kikiFile}");
     }
     return false;
 }
Пример #7
0
 public function exec()
 {
     $db = \Kiki\Core::getDb();
     $user = \Kiki\Core::getUser();
     $article = new \Kiki\Article($this->instanceId);
     $this->title = $article->title();
     $template = \Kiki\Template::getInstance();
     $template->append('stylesheets', \Kiki\Config::$kikiPrefix . "/scripts/prettify/prettify.css");
     if ($article->visible() || $article->userId() == $user->id()) {
         $this->title = $article->title();
         $this->status = 200;
         $this->template = 'pages/default';
         $template = new \Kiki\Template('content/pages-single');
         $template->assign('page', $article->templateData());
         $this->content = $template->fetch();
     }
 }
Пример #8
0
 public function exec()
 {
     $db = Core::getDb();
     $user = Core::getUser();
     $q = $db->buildQuery("select id from events where cname='%s'", $this->objectId);
     $eventId = $db->getSingleValue($q);
     if ($eventId) {
         $event = new Event($eventId);
         if ($event->id()) {
             $this->template = 'pages/event';
             $this->status = 200;
             $this->title = "Event: " . $event->title();
             $this->content = $event->content();
             return true;
         }
     }
     return false;
 }
Пример #9
0
            if ($error) {
                echo "<p>Please upgrade manually.</p>\n";
                echo "</li>\n";
                break;
            } else {
                $db->query("update config set value='{$version}' where `key`='dbVersion'");
                echo "</li>\n";
            }
        }
        echo "</li>\n";
    }
} else {
    if (Config::$dbUser) {
        if ($db->connected()) {
            echo "<li>Database tables not installed.</li>\n";
            $file = Core::getInstallPath() . "/db/core.sql";
            echo "<li>Running install script <tt>{$file}</tt>:\n";
            $error = Status::sourceSqlFile($db, $file);
            if ($error) {
                echo "<p>Please install manually.</p>\n";
            }
            echo "</li>\n";
        } else {
            echo "<li>Database connection failed. Please check your configuration (<tt>" . Config::configFile() . "</tt>).</li>\n";
        }
    } else {
        echo "<li>Database not configured. Please create/edit <tt>" . Config::configFile() . "</tt>, see <tt>config.php-sample</tt> for an example.</li>\n";
    }
}
echo "</ul>\n";
$this->content = ob_get_clean();
Пример #10
0
 public function content($fullHTML = true)
 {
     // Log::debug( "begin template engine" );
     // TODO: don't always auto-include html framework, desired template
     // output could just as well be another format (json, xml, ...)
     $content = null;
     if ($fullHTML) {
         $content = "{include 'html'}" . PHP_EOL;
         $content .= "{include 'head'}" . PHP_EOL;
     }
     if (!$this->template) {
         $this->template = 'pages/default';
     }
     // Log::beginTimer( "Template::content ". $this->template );
     // Don't load a template when setContent has been used.
     $content .= $this->content ? $this->content : file_get_contents($this->file($this->template)) . PHP_EOL;
     if ($fullHTML) {
         $content .= "{include 'html-end'}";
     }
     $this->content = $content;
     // Log::debug( "content: ". $this->content );
     $this->data['kiki']['flashBag'] = array('notice' => \Kiki\Core::getFlashBag()->get('notice', false), 'warning' => \Kiki\Core::getFlashBag()->get('warning', false), 'error' => \Kiki\Core::getFlashBag()->get('error', false));
     $this->normalise($this->data);
     $this->preparse();
     $this->parse();
     if ($this->cleanup) {
         $this->cleanup();
     }
     // Log::debug( "done parsing" );
     // Log::debug( "content: ". $this->content );
     // Log::endTimer( "Template::content ". $this->template );
     if ($fullHTML) {
         \Kiki\Core::getFlashBag()->reset();
     }
     return $this->content;
 }
Пример #11
0
 public function exec()
 {
     $db = Core::getDb();
     $user = Core::getUser();
     $template = Template::getInstance();
     $template->append('stylesheets', \Kiki\Config::$kikiPrefix . "/scripts/prettify/prettify.css");
     $q = $db->buildQuery("SELECT id FROM articles a LEFT JOIN objects o ON o.object_id=a.object_id WHERE o.section_id=%d AND ((o.visible=1 AND o.ctime<=now()) OR o.user_id=%d) ORDER BY o.ctime DESC LIMIT 10", $this->instanceId, $user->id());
     $articleIds = $db->getObjectIds($q);
     $articles = array();
     foreach ($articleIds as $articleId) {
         $article = new Article($articleId);
         $articles[] = array('url' => $article->url(), 'title' => $article->title());
     }
     $template->assign('latestArticles', $articles);
     if (preg_match('/^page-([\\d]+)$/', $this->objectId, $matches) && isset($matches[1])) {
         $this->objectId = null;
         $currentPage = $matches[1];
     }
     if (isset($this->objectId) && $this->objectId) {
         $matches = array();
         if (preg_match('/^socialupdate-([\\d]+)$/', $this->objectId, $matches) && isset($matches[1])) {
             $updateId = $matches[1];
             $update = new SocialUpdate($updateId);
             if (!$update->id()) {
                 return;
             }
             $this->status = 200;
             $this->title = \Kiki\Misc::textSummary($update->body(), 50);
             $this->template = 'pages/default';
             $template = new Template('content/socialupdates-single');
             $template->assign('update', $update->templateData());
             $this->content = $template->fetch();
             return;
         }
         $article = new Article(0, $this->objectId);
         if ($article->id() && $article->sectionId() == $this->instanceId && ($article->visible() || $article->userId() == $user->id())) {
             $this->status = 200;
             $this->title = $article->title();
             $this->template = 'pages/default';
             $template = new Template('content/articles-single');
             $GLOBALS['articleAlbumId'] = $article->albumId();
             $template->assign('article', $article->templateData());
             $this->content = $template->fetch();
         } else {
             // $this->template = 'pages/default';
             // $template = new Template( 'content/articles-404' );
             // $this->content = $template->fetch();
             return false;
         }
     } else {
         $section = new \Kiki\Section($this->instanceId);
         $itemsPerPage = 25;
         if (!isset($currentPage)) {
             $currentPage = 1;
         }
         $this->status = 200;
         $this->title = $section->title();
         $this->template = 'pages/default';
         $this->content = null;
         // MultiBanner::articles( $section->id() );
         $article = new Article();
         $update = new SocialUpdate();
         $q = $db->buildQuery("SELECT count(*) FROM objects WHERE type IN ('%s', '%s', '%s', '%s') AND section_id=%d AND ((visible=1 AND ctime<=now()) OR user_id=%d)", 'Article', 'Kiki\\Article', 'SocialUpdate', 'Kiki\\SocialUpdate', $this->instanceId, $user->id());
         $totalPosts = $db->getSingleValue($q);
         $paging = new \Kiki\Paging();
         $paging->setCurrentPage($currentPage);
         $paging->setItemsPerPage($itemsPerPage);
         $paging->setTotalItems($totalPosts);
         $q = $db->buildQuery("SELECT object_id, ctime, type FROM objects WHERE type IN ('%s', '%s', '%s', '%s') AND section_id=%d AND ( (visible=1 AND ctime<=now()) OR user_id=%d) ORDER BY ctime DESC LIMIT %d,%d", 'Article', 'Kiki\\Article', 'SocialUpdate', 'Kiki\\SocialUpdate', $this->instanceId, $user->id(), $paging->firstItem() - 1, $itemsPerPage);
         $rs = $db->query($q);
         while ($o = $db->fetchObject($rs)) {
             switch ($o->type) {
                 case 'Article':
                 case 'Kiki\\Article':
                     $article->reset();
                     $article->setObjectId($o->object_id);
                     $article->load();
                     $template = new Template('content/articles-summary');
                     $template->assign('article', $article->templateData());
                     $this->content .= $template->fetch();
                     break;
                 case 'SocialUpdate':
                 case 'Kiki\\SocialUpdate':
                     $update->reset();
                     $update->setObjectId($o->object_id);
                     $update->load();
                     $template = new Template('content/socialupdates-summary');
                     $template->assign('update', $update->templateData());
                     $this->content .= $template->fetch();
                     break;
                 default:
             }
         }
         $this->content .= $paging->html();
     }
 }
Пример #12
0
#!/usr/bin/php -q
<?php 
/**
* @file console.php
* 
* Console front-end for the website.
* 
* Currently hardcoded to print_r the template data for any given (GET) URL
* passing through the router, for debugging purposes.  Should be extended to
* handle specific CLI templates for scripting output and even input
* processing for specific actions to link web-actions and script-actions
* closer together.
* 
* @author Rob Kaper <http://robkaper.nl/>
* @section license_sec License
* Released under the terms of the MIT license.
*/
use Kiki\Core;
$_SERVER['SERVER_NAME'] = isset($argv[1]) ? $argv[1] : die('SERVER_NAME argument missing' . PHP_EOL);
$_SERVER['REQUEST_URI'] = isset($argv[2]) ? $argv[2] : die('REQUEST_URI argument missing' . PHP_EOL);
$_SERVER['SCRIPT_URL'] = $_SERVER['REQUEST_URI'];
require_once preg_replace('~/bin/(.*)\\.php~', '/lib/init.php', __FILE__);
$_SERVER['HTTP_HOST'] = $_SERVER['SERVER_NAME'];
$_SERVER['SERVER_PROTOCOL'] = null;
include_once Core::getInstallPath() . "/htdocs/router.php";
Пример #13
0
            $album->setTitle($article->title());
            $album->save();
        }
    }
    if (isset($_POST['json'])) {
        $response = array();
        $response['formId'] = $_POST['formId'];
        $response['articleId'] = $article->id();
        if ($showAsPage) {
            $template = new Template('content/pages-single');
            $template->assign('page', $article->templateData());
        } else {
            $template = new Template('content/articles-single');
            $template->assign('article', $article->templateData());
        }
        $response['article'] = $template->fetch();
        $response['errors'] = $errors;
        header('Content-type: application/json');
        echo json_encode($response);
        exit;
    }
    if (!count($errors)) {
        \Kiki\Core::getFlashBag()->add('notice', sprintf("Article '%s' saved succesfully. (id: %d, cname: %s)", $article->title(), $article->id(), $article->cname()));
        Router::redirect($_SERVER['HTTP_REFERER'], 303);
        exit;
    }
    $template = Template::getInstance();
    $template->load('pages/admin');
    $template->assign('content', "fouten bij opslaan:<pre>" . print_r($errors, true) . "</pre>");
    echo $template->content();
}
Пример #14
0
 public function verifyAction()
 {
     $this->status = 200;
     $this->template = 'pages/default';
     $this->title = _("Verify account");
     $template = new \Kiki\Template('content/account-verify');
     $errors = array();
     $warnings = array();
     $user = \Kiki\Core::getUser();
     $token = isset($_GET['token']) ? $_GET['token'] : null;
     if (empty($token)) {
         $errors[] = "Auth token missing.";
     } else {
         // Get user by auth token.
         $verifyUserId = $user->getIdByToken($token);
         if (!$verifyUserId) {
             $errors[] = "Invalid auth token. Auth tokens expire. [Send new verification e-mail]";
         } else {
             $verifyUser = new \Kiki\User($verifyUserId);
             $verifyUser->setIsVerified(true);
             $verifyUser->save();
             if ($user->id() && $user->id() != $verifyUser->id()) {
                 $warnings[] = sprintf("Because you verified account <strong>%s</strong> (%d), you are no longer logged in as <strong>%s</strong> (%d).", $verifyUser->email(), $verifyUser->id(), $user->email(), $user->id());
             } else {
                 Auth::setCookie($verifyUser->id());
                 $user = $verifyUser;
                 \Kiki\Core::setUser($verifyUser);
                 $mainTemplate = \Kiki\Template::getInstance();
                 $mainTemplate->assign('user', $user->templateData());
             }
         }
     }
     $template->assign('warnings', $warnings);
     $template->assign('errors', $errors);
     $this->content = $template->fetch();
     return true;
 }