Exemplo n.º 1
0
 public function getPages()
 {
     $blog = new ActiveRecord();
     $num = $blog->size();
     $pages = $blog->pickout($num - 5, 5);
     $result = array();
     for ($i = 0; $i < 5; $i++) {
         $result[$i] = array('title' => $pages[4 - $i]->title, 'url' => "/?page={$pages[4 - $i]->pagenum}");
     }
     return $result;
 }
Exemplo n.º 2
0
<?php

require_once 'activerecord.php';
$ar = new ActiveRecord();
$ar->connectPdo('blogdb', 'blog', $_POST['username'], $_POST['password']);
$postid = $ar->size() + 1;
$ar->pagenum = $postid;
$ar->author = $_POST['username'];
$ar->date = date('Y/m/d');
$ar->title = $_POST['title'];
$ar->text = nl2br($_POST['text']);
try {
    $ar->save();
} catch (Exception $e) {
    echo $e->getMessage();
    return;
}
$ar->connectPdo('blogdb', 'categorytable', $_POST['username'], $_POST['password']);
$categories = explode(',', $_POST["category"]);
foreach ($categories as $category) {
    $ar->postid = $postid;
    $ar->category = $category;
    try {
        $ar->save();
    } catch (Exception $e) {
        echo $e->getMessage();
        $ar->connectPdo('blogdb', 'blog', $_POST['username'], $_POST['password']);
        $postid = $ar->size();
        $ar->delete($postid);
        return;
    }
Exemplo n.º 3
0
<?php

define('SMARTY_DIR', '/usr/share/php/smarty3/');
require_once 'activerecord.php';
require_once SMARTY_DIR . 'Smarty.class.php';
$smarty = new Smarty();
$smarty->template_dir = '/srv/smarty/templates';
$smarty->compile_dir = '/srv/smarty/templates_c';
$smarty->config_dir = '/srv/smarty/configs';
$smarty->cache_dir = '/srv/smarty/cache';
$blog = new ActiveRecord();
$blog->connectPdo('blogdb', 'blog', 'readonly', 'readonly');
$num = $blog->size();
$pages = $blog->pickout($num - 10, 10);
$items = array();
$category = new ActiveRecord();
$category->connectPdo('blogdb', 'categorytable', 'readonly', 'readonly');
$categories = $category->find($num - 2)->category;
for ($i = 0; $i < 10; $i++) {
    $categorystr = $category->find($num - (9 - $i))->category;
    $datetime = new DateTime($pages[9 - $i]->date);
    $items[$i] = array('title' => $pages[9 - $i]->title, 'link' => "http://pakutoma.pw/?page={$pages[9 - $i]->pagenum}", 'category' => $categorystr, 'description' => mb_substr(str_replace("\n", " ", strip_tags($pages[9 - $i]->text)), 0, 40) . '...', 'pubDate' => $datetime->format(DATE_RSS));
}
$smarty->assign('items', $items);
$smarty->display('rss.tpl');
Exemplo n.º 4
0
            $data = $archiveview->getPages($archive);
            if (!isset($data[0]->pagenum)) {
                echo "データが存在しません。";
                return;
            }
            $latest = new LatestPages();
            $category = new Category();
            $archive = new Archive();
            foreach (array_reverse($data) as $page) {
                $main[] = array('title' => $page->title, 'date' => $page->date, 'text' => mb_substr($page->text, 0, mb_strpos($page->text, "<br />")), 'pagenum' => $page->pagenum);
            }
            $smarty->assign('title', 'アーカイブ:' . $_GET['archive']);
        } else {
            $blog = new ActiveRecord();
            $blog->connectPdo('blogdb', 'blog', 'readonly', 'readonly');
            $data = $blog->find($blog->size());
            if (!isset($data->pagenum)) {
                echo "データが存在しません。";
                return;
            }
            $latest = new LatestPages();
            $category = new Category();
            $archive = new Archive();
            $main[] = array('title' => $data->title, 'date' => $data->date, 'text' => $data->text);
            $smarty->assign('prev', $blog->find($blog->size() - 1));
        }
    }
}
$smarty->assign('main', $main);
$smarty->assign('latest', $latest->getPages());
$smarty->assign('category', $category->getCategory());