Example #1
0
 public function testDate()
 {
     $site = $this->siteInstance();
     $page = new Page($site, '1-a');
     $this->assertEquals(1355270400, $page->date());
     $this->assertEquals('2012-12-12', $page->date('Y-m-d'));
     $this->assertEquals('2012-12-12', $page->date('Y-m-d', 'date'));
     $this->assertEquals('2012-12-12', $page->date('Y-m-d', 'created'));
 }
Example #2
0
 public function testDate()
 {
     $site = $this->siteInstance();
     $page = new Page($site, '1-a');
     $this->assertEquals(1355270400, $page->date());
     $this->assertEquals('2012-12-12', $page->date('Y-m-d'));
     $this->assertEquals('2012-12-12', $page->date('Y-m-d', 'date'));
     $this->assertEquals('2012-12-12', $page->date('Y-m-d', 'created'));
     // switch the date handler
     $kirby = $this->kirbyInstance(array('date.handler' => 'strftime'));
     $site = $this->siteInstance($kirby);
     $page = new Page($site, '1-a');
     $this->assertEquals(1355270400, $page->date());
     $this->assertEquals('2012-12-12', $page->date('%Y-%m-%d'));
     $this->assertEquals('2012-12-12', $page->date('%Y-%m-%d', 'date'));
     $this->assertEquals('2012-12-12', $page->date('%Y-%m-%d', 'created'));
 }
Example #3
0
function buildPage($key)
{
    global $dbPages;
    global $dbUsers;
    global $Parsedown;
    global $Site;
    // Page object, content from FILE.
    $Page = new Page($key);
    if (!$Page->isValid()) {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying build the page from file with key: ' . $key);
        return false;
    }
    // Page database, content from DATABASE JSON.
    $db = $dbPages->getPageDB($key);
    if (!$db) {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying build the page from database with key: ' . $key);
        return false;
    }
    // Foreach field from DATABASE.
    foreach ($db as $field => $value) {
        $Page->setField($field, $value);
    }
    // Content in raw format
    $contentRaw = $Page->content();
    $Page->setField('contentRaw', $Page->content(), true);
    // Parse markdown content.
    $content = Text::pre2htmlentities($contentRaw);
    // Parse pre code with htmlentities
    $content = $Parsedown->text($content);
    // Parse Markdown.
    $content = Text::imgRel2Abs($content, HTML_PATH_UPLOADS);
    // Parse img src relative to absolute.
    $Page->setField('content', $content, true);
    // Pagebrake
    $explode = explode(PAGE_BREAK, $content);
    $Page->setField('breakContent', $explode[0], true);
    $Page->setField('readMore', !empty($explode[1]), true);
    // Date format
    $pageDate = $Page->date();
    $Page->setField('dateRaw', $pageDate, true);
    $pageDateFormated = $Page->dateRaw($Site->dateFormat());
    $Page->setField('date', $pageDateFormated, true);
    // User object
    $username = $Page->username();
    $Page->setField('user', $dbUsers->getUser($username));
    return $Page;
}
Example #4
0
function build_page($key)
{
    global $dbPages;
    global $dbUsers;
    global $Parsedown;
    global $Site;
    // Page object, content from FILE.
    $Page = new Page($key);
    if (!$Page->isValid()) {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying build the page from file with key: ' . $key);
        return false;
    }
    // Page database, content from DATABASE JSON.
    $db = $dbPages->getDb($key);
    if (!$db) {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying build the page from database with key: ' . $key);
        return false;
    }
    // Foreach field from DATABASE.
    foreach ($db as $field => $value) {
        $Page->setField($field, $value);
    }
    // Content in raw format
    $contentRaw = $Page->content();
    $Page->setField('contentRaw', $Page->content(), true);
    // Parse markdown content.
    $content = Text::pre2htmlentities($contentRaw);
    // Parse pre code with htmlentities
    $content = $Parsedown->text($content);
    // Parse Markdown.
    $content = Text::imgRel2Abs($content, HTML_PATH_UPLOADS);
    // Parse img src relative to absolute.
    $Page->setField('content', $content, true);
    // Date format
    $pageDate = $Page->date();
    $Page->setField('dateRaw', $pageDate, true);
    $pageDateFormated = $Page->dateRaw($Site->dateFormat());
    $Page->setField('date', $pageDateFormated, true);
    // Parse username for the page.
    if ($dbUsers->userExists($Page->username())) {
        $user = $dbUsers->getDb($Page->username());
        $Page->setField('authorFirstName', $user['firstName'], false);
        $Page->setField('authorLastName', $user['lastName'], false);
    }
    return $Page;
}
 public static function _date($attributes)
 {
     return Page::date(isset($attributes['format']) ? $attributes['format'] : 'Y-m-d');
 }
Example #6
0
 /**
  * Get Blog Post Date
  *
  *  <code> 
  *      echo Blog::getPostDate();
  *  </code>
  *
  * @param  string $format Date format
  * @return string
  */
 public static function getPostDate($format = 'Y-m-d')
 {
     return Page::date($format);
 }