public function __construct() { if ($this->loggedIn()) { $user = Model_User::Get($_SESSION['typef_user']['userid']); } else { if (isset($_COOKIE['typef_userid']) && isset($_COOKIE['typef_passhash'])) { $user = Model_User::Get($_COOKIE['typef_userid']); if ($user->exists()) { if ($user['passhash'] == $_COOKIE['typef_passhash']) { if ($row = $rs->fetch_array()) { // Log in user and update cookie $row = $user->getArray(false); unset($row['salt']); unset($row['hashtype']); $_SESSION['typef_user'] = $row; setcookie('typef_username', $row['username'], time() + 60 * 60 * 24 * 30, '/'); setcookie('typef_passhash', $row['passhash'], time() + 60 * 60 * 24 * 30, '/'); Typeframe::Log("{$row['username']} logged in via cookie"); } } } } } if ($this->loggedIn()) { $user['lastrequest'] = Typeframe::Now(); $user->save(); } }
public function load() { $this->_data = array(); $host = 'http://' . $_SERVER['SERVER_NAME']; // This will retrieve all the content pages. if (Typeframe::Registry()->application('Content')) { $query = "SELECT uri, nickname,\tapplication FROM #__page"; $rs = Typeframe::Database()->prepare($query); $rs->execute(); while ($data = $rs->fetch_array()) { $this->_data[] = array('page' => $host . TYPEF_WEB_DIR . $data['uri'], 'uri' => $data['uri'], 'name' => $data['nickname'] != '' ? $data['nickname'] : $data['uri'], 'application' => $data['application']); } } // And the news pages. if (Typeframe::Registry()->application('News')) { $select = new BuildSql_Select(); $select->table('#__news n'); $select->leftJoin('#__news_category ncat', 'ncat.categoryid = n.categoryid'); $select->field('n.*'); $select->field('ncat.categoryname'); $select->group('n.newsid'); $select->order('n.pubdate DESC'); $select->where('n.pubdate <= ?', Typeframe::Now()); $rs = $this->db()->prepare($select->query()); $rs->execute(); while ($row = $rs->fetch_array()) { $uri = News::GetCategoryUri($row['categoryid']) . '/' . ($row['encodedtitle'] ? $row['encodedtitle'] : $row['newsid']); $this->_data[] = array('page' => $host . TYPEF_WEB_DIR . $uri, 'uri' => $uri, 'name' => $row['title'], 'application' => $row['categoryname']); } } }
public function output(Pagemill_Data $data, Pagemill_Stream $stream) { $this->pluginTemplate = '/news/feed.plug.html'; $default = array('limit' => 5, 'categoryid' => null); $settings = array_merge($default, $this->attributes()); $articles = new Model_News_Article(); if (!is_null($settings['categoryid'])) { if (!is_array($settings['categoryid'])) { $settings['categoryid'] = array($settings['categoryid']); } if (!in_array(0, $settings['categoryid'])) { $articles->where('categoryid IN ?', $settings['categoryid']); } } $articles->where('pubdate <= ?', Typeframe::Now()); $articles->where('expdate >= ? OR expdate = ? OR expdate IS NULL', Typeframe::Now(), '0000-00-00 00:00:00'); $articles->where('status = ?', 'published'); $articles->limit($settings['limit']); $data = $data->fork(); $data['header'] = $settings['header']; $data['articles'] = $articles; parent::output($data, $stream); }
/** * Log a user action to the database. * @param string $action. * @param string $fulldesc The full description of the event [optional]. */ public static function Log($action, $fulldesc = false) { if (!$fulldesc) { $fulldesc = $action; } // Also addin the source URL, as that may change and reveal important information. if (isset($_SERVER['HTTP_HOST'])) { $fulldesc .= "\n" . 'Source URL: ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; if (isset($_SERVER['HTTP_REFERER'])) { $fulldesc .= "\n" . 'Referrer URL: ' . $_SERVER['HTTP_REFERER']; } } else { $fulldesc .= "\nN/a"; } $log = Model_Log::Create(); $log['userid'] = Typeframe::User()->get('userid'); $log['ipaddress'] = @$_SERVER['REMOTED_ADDR']; $log['package'] = Typeframe::CurrentPage() ? Typeframe::CurrentPage()->application()->package() : ''; $log['application'] = Typeframe::CurrentPage() ? Typeframe::CurrentPage()->application()->name() : ''; $log['action'] = $action; $log['logdate'] = Typeframe::Now(); $log['fulldesc'] = $fulldesc; $log->save(); }
// save typing below $typef_app_dir = Typeframe::CurrentPage()->applicationUri(); // get category id, if any //$categoryid = News::GetCategoryId(); $settings = Typeframe::CurrentPage()->settings(); // set category id in template //$pm->setVariable('categoryid', $settings['categoryid']); // get articles; limit to this category and valid publication date $articles = new Model_News_Article(); $categories = new Model_News_Category(); if (isset($settings['categoryid']) && is_array($settings['categoryid']) && count($settings['categoryid']) && !in_array(0, $settings['categoryid'])) { $articles->where('news.categoryid IN ?', $settings['categoryid']); $categories->where('categoryid IN ?', $settings['categoryid']); } $articles->where('pubdate <= ?', Typeframe::Now()); $articles->where('expdate > ? OR expdate = ? OR expdate IS NULL', Typeframe::Now(), '0000-00-00 00:00:00'); $articles->where('status = ?', 'published'); $total = $articles->count(); // set up pagination $perpage = !empty($settings['perpage']) ? $settings['perpage'] : 20; $pag = Pagination::Calculate($total, $perpage); $articles->paginate($pag['page'], $pag['perpage']); $pm->setVariable('pagination', $pag); $settings = Typeframe::CurrentPage()->settings(); // add articles, pagination to template $pm->setVariable('news', $articles); //$pm->setVariableArray(Pagination::Calculate($articles->getTotal(), // $perpage, $articles->getCurrentPage())); // get categories; limit to the given parent category //$categories = new News_Category_Factory(); $categories = new Model_News_Category();
public function update($record) { if ($this->_overwrite || !$record[$this->_field]) { $record[$this->_field] = Typeframe::Now(); } }
<?php /** * Typeframe News application * * client-side rss controller */ // set the appropriate content type header('Content-Type: application/rss+xml'); // set the template Typeframe::SetPageTemplate('/news/rss.xml'); // add title, description, link, and lastbuild date to template $pm->setVariable('title', TYPEF_TITLE); $pm->setVariable('description', TYPEF_TITLE . ' News'); $pm->setVariable('link', 'http://' . $_SERVER['HTTP_HOST']); $pm->setVariable('lastbuild', date('D, d M Y H:i:s T')); // get articles; limit to published if non-admin $articles = new Model_News_Article(); $articles->where('pubdate <= ?', Typeframe::Now()); $articles->limit('0, 10'); // add articles to template $pm->setVariable('items', $articles);
<?php if (TYPEF_NEWS_OVERDUE_ALERT > 0) { $rs = $db->prepare('SELECT COUNT(*) AS totalpublished FROM #__news WHERE pubdate <= ?'); $totalpublished = $rs->execute_fetch_value(Typeframe::Now()); if ($totalpublished == 0) { $pm->addLoop('admin_alerts', array('application' => 'News', 'message' => 'No news articles have been published yet.', 'url' => TYPEF_WEB_DIR . '/admin/news/add')); return; } $rs = $db->prepare('SELECT MAX(pubdate) AS lastpubdate FROM #__news WHERE pubdate <= ?'); $last = $rs->execute_fetch(Typeframe::Now()); $diff = (strtotime(Typeframe::Now()) - strtotime($last['lastpubdate'])) / (60 * 60 * 24); if ($diff > TYPEF_NEWS_OVERDUE_ALERT) { $pm->addLoop('admin_alerts', array('application' => 'News', 'message' => 'It has been ' . floor($diff) . ' days since your last published news article.', 'url' => TYPEF_WEB_DIR . '/admin/news/add')); } }