public function getPages($category) { $blog = new ActiveRecord(); $blog->connectPdo('blogdb', 'categorytable', 'readonly', 'readonly'); $data = $blog->findFromKey('category', $category); $ids = array(); foreach ($data as $row) { $ids[] = $row->postid; } $blog->connectPdo('blogdb', 'blog', 'readonly', 'readonly'); $result = array(); foreach ($ids as $pagenum) { $result[] = $blog->find($pagenum); } return $result; }
public function getCategory() { $blog = new ActiveRecord(); $blog->connectPdo('blogdb', 'categorytable', 'readonly', 'readonly'); $categories = $blog->getValueList('category'); $result = array(); foreach (array_reverse($categories) as $category) { $result[] = array('title' => $category, 'url' => sprintf("/?category=%s", urlencode($category))); } return $result; }
public function getPages($archive) { $blog = new ActiveRecord(); $blog->connectPdo('blogdb', 'blog', 'readonly', 'readonly'); $result = $blog->findLike('date', sprintf("%s/%s", explode('-', $archive)[0], explode('-', $archive)[1]) . '%'); $pagenum_arr = array(); foreach ($result as $page) { $pagenum_arr[] = $page->pagenum; } array_multisort($pagenum_arr, SORT_ASC, $result); return $result; }
private function getAllMonths() { $blog = new ActiveRecord(); $blog->connectPdo('blogdb', 'blog', 'readonly', 'readonly'); $dates = $blog->getValueList('date'); foreach ($dates as $date) { $ym[] = explode('/', $date)[0] . "-" . explode('/', $date)[1]; } $ym = array_unique($ym); asort($ym); foreach ($ym as $date) { $result[] = ["year" => explode('-', $date)[0], "month" => explode('-', $date)[1]]; } return $result; }
<?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; }
<?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');
$archiveview = new ArchiveView(); $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());