<?php define_default('FILTERS_PATH', realpath(ROOT . '../workspace') . '/application/filters/'); class Filter { protected $contentType; protected $info; public function __construct($name) { $name = dash($name); $this->info = json_decode(file_get_contents(FILTERS_PATH . "{$name}.json")); $this->contentType = new ContentType($this->info->contentType); } // function __construct // Executes the filter public function run($params = array()) { // And array of conditions to pass to the database $conditions = array(); // If the filter has any parameters specified if (property_exists($this->info, 'params')) { foreach ($this->info->params as $param) { $name = dash($param->name); // If no value for the parameter was passed in, use the // filters's specified default value if (array_key_exists($name, $params)) { $conditions[$name] = $params[$name]; } else { $conditions[$name] = $param->default; } }
* @access public * @return boolean True if defined successfully or not. */ function define_default($name, $value) { defined($name) or define($name, $value); } ///// Some defaults that you can override in config.php ////// define_default('FEED_FETCH_TIMEOUT', 45); // How may seconds to wait for response when requesting feed from a site define_default('FEED_FETCH_NO_CACHE_TIMEOUT', 15); // How may seconds to wait for response when requesting feed from a // site when that feed wasn't cached before define_default('FILE_FETCH_TIMEOUT', 45); // Default timeout when fetching files from remote sites define_default('FILE_FETCH_CONNECT_TIMEOUT', 15); // How many seconds to wait for initial response from website when // fetching files from remote sites if (DB_TYPE == "pgsql") { define('SUBSTRING_FOR_DATE', 'SUBSTRING_FOR_DATE'); } else { define('SUBSTRING_FOR_DATE', 'SUBSTRING'); } /** * Return available translations names. * * @access public * @return array A array of available translations. */ function get_translations() {
<?php define_default('DAEMON_UPDATE_LOGIN_LIMIT', 30); define_default('DAEMON_FEED_LIMIT', 500); define_default('DAEMON_SLEEP_INTERVAL', 120); function update_feedbrowser_cache() { $result = db_query("SELECT feed_url, site_url, title, COUNT(id) AS subscribers\n\t \t\tFROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf\n\t\t\t\tWHERE tf.feed_url = ttrss_feeds.feed_url\n\t\t\t\tAND (private IS true OR auth_login != '' OR auth_pass != '' OR feed_url LIKE '%:%@%/%'))\n\t\t\t\tGROUP BY feed_url, site_url, title ORDER BY subscribers DESC LIMIT 1000"); db_query("BEGIN"); db_query("DELETE FROM ttrss_feedbrowser_cache"); $count = 0; while ($line = db_fetch_assoc($result)) { $subscribers = db_escape_string($line["subscribers"]); $feed_url = db_escape_string($line["feed_url"]); $title = db_escape_string($line["title"]); $site_url = db_escape_string($line["site_url"]); $tmp_result = db_query("SELECT subscribers FROM\n\t\t\t\tttrss_feedbrowser_cache WHERE feed_url = '{$feed_url}'"); if (db_num_rows($tmp_result) == 0) { db_query("INSERT INTO ttrss_feedbrowser_cache\n\t\t\t\t\t(feed_url, site_url, title, subscribers) VALUES ('{$feed_url}',\n\t\t\t\t\t\t'{$site_url}', '{$title}', '{$subscribers}')"); ++$count; } } db_query("COMMIT"); return $count; } /** * Update a feed batch. * Used by daemons to update n feeds by run. * Only update feed needing a update, and not being processed * by another process. *
<?php define_default('OPERATORS_PATH', realpath(ROOT . 'operators') . '/'); class Operator { protected $type; public function __construct($type) { require_once OPERATORS_PATH . dash($type) . "/operator.php"; $this->type = $type; } public function operate($params) { $class = $this->className(); $results = $class::operate($params); return $results; } protected function className() { return camel_case($this->type) . 'Operator'; } }
<?php define_default('DAEMON_UPDATE_LOGIN_LIMIT', 30); define_default('DAEMON_FEED_LIMIT', 500); define_default('DAEMON_SLEEP_INTERVAL', 120); define_default('_MIN_CACHE_IMAGE_SIZE', 1024); function calculate_article_hash($article, $pluginhost) { $tmp = ""; foreach ($article as $k => $v) { if ($k != "feed" && isset($v)) { $tmp .= sha1("{$k}:" . (is_array($v) ? implode(",", $v) : $v)); } } return sha1(implode(",", $pluginhost->get_plugin_names()) . $tmp); } function update_feedbrowser_cache() { $result = db_query("SELECT feed_url, site_url, title, COUNT(id) AS subscribers\n\t \t\tFROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf\n\t\t\t\tWHERE tf.feed_url = ttrss_feeds.feed_url\n\t\t\t\tAND (private IS true OR auth_login != '' OR auth_pass != '' OR feed_url LIKE '%:%@%/%'))\n\t\t\t\tGROUP BY feed_url, site_url, title ORDER BY subscribers DESC LIMIT 1000"); db_query("BEGIN"); db_query("DELETE FROM ttrss_feedbrowser_cache"); $count = 0; while ($line = db_fetch_assoc($result)) { $subscribers = db_escape_string($line["subscribers"]); $feed_url = db_escape_string($line["feed_url"]); $title = db_escape_string($line["title"]); $site_url = db_escape_string($line["site_url"]); $tmp_result = db_query("SELECT subscribers FROM\n\t\t\t\tttrss_feedbrowser_cache WHERE feed_url = '{$feed_url}'"); if (db_num_rows($tmp_result) == 0) { db_query("INSERT INTO ttrss_feedbrowser_cache\n\t\t\t\t\t(feed_url, site_url, title, subscribers) VALUES ('{$feed_url}',\n\t\t\t\t\t\t'{$site_url}', '{$title}', '{$subscribers}')"); ++$count;
<?php // Default the default location of the templates define_default('TEMPLATES_PATH', realpath(ROOT . '../workspace') . '/templates/pages/'); // Default the default location of the helpers define_default('HELPERS_PATH', realpath(ROOT . '../workspace') . '/templates/helpers/'); // Go ahead and include the global helpers, if they exists if (file_exists(HELPERS_PATH . 'global.php')) { require HELPERS_PATH . 'global.php'; } class Template extends View { private static $current; // Hold the layout currently being processed private $layout; // Holds the name of the instance's layout public function __construct($file, $values = array()) { self::$current = $this; // Include the template's helper functions, if there are any if (file_exists(HELPERS_PATH . "{$file}.php")) { require HELPERS_PATH . "{$file}.php"; } $position = strpos($file, '/'); if ($position === FALSE) { $this->file = TEMPLATES_PATH . $file . '.php'; } elseif ($position === 0) { $this->file = TEMPLATES_PATH . substr($file, 1) . '.php'; } else { $this->file = TEMPLATES_PATH . $file . '.php'; }
<?php define_default('HELPERS_PATH', APPLICATION_PATH . 'helpers/'); class Dispatcher { public static $routes = array(); public static function dispatch() { // Include the routes require CONFIG_PATH . 'routes.php'; // Grab the controller/action stack for request $request = self::request(); try { // Make an instance of the controller's class $class = new ReflectionClass(camel_case($request['controller'])); $controller = $class->newInstance(); // Try and include the global helper file require_if_exists(APPLICATION_PATH . 'helpers/global.php'); // Require the helper files for the controller $helpers = explode('>', $request['controller']); $helper_string = ''; foreach ($helpers as $helper) { $helper_string .= "/{$helper}"; $helper_file = HELPERS_PATH . $helper_string . '.php'; require_if_exists($helper_file); } // Execute the action $method = $class->getMethod($request['action']); $result = $method->invokeArgs($controller, $request['arguments']); } catch (ReflectionException $e) { // ob_end_clean();
set_include_path(dirname(__FILE__) . "/include" . PATH_SEPARATOR . get_include_path()); declare (ticks=1); chdir(dirname(__FILE__)); define('DISABLE_SESSIONS', true); require_once "version.php"; require_once "config.php"; require_once "autoload.php"; require_once "functions.php"; require_once "rssfuncs.php"; // defaults define_default('PURGE_INTERVAL', 3600); // seconds define_default('MAX_CHILD_RUNTIME', 1800); // seconds define_default('MAX_JOBS', 2); define_default('SPAWN_INTERVAL', DAEMON_SLEEP_INTERVAL); // seconds require_once "sanity_check.php"; require_once "db.php"; require_once "db-prefs.php"; if (!function_exists('pcntl_fork')) { die("error: This script requires PHP compiled with PCNTL module.\n"); } $master_handlers_installed = false; $children = array(); $ctimes = array(); $last_checkpoint = -1; function reap_children() { global $children; global $ctimes;
<?php define_default('MAIL_PATH', '/mail'); class Mail { public $from; public $subject; public $to; private $view; public function __construct($file, $values = array()) { $this->view = new View(MAIL_PATH . "/{$file}", $values); } // Magic method for getting view variables public function __get($name) { return $this->view->__get($name); } // function __get // Magic method for setting view variables public function __set($name, $value) { $this->view->__set($name, $value); } // function __set private function body() { return $this->view->render(); } // function body // Grabs the data for a view
<?php define_default('CSS_PATH', ROOT . 'media/css/'); Dispatcher::match('_css/(.+)', 'less/process/$1');
<?php define_default('VIEW_PATH', APPLICATION_PATH . 'views/'); class View { // The view's variables protected $data = array(); // Our file protected $file; public static function auto($values = array()) { $request = Dispatcher::request(); $file = str_replace('>', '/', $request['controller']) . '/' . $request['action']; return new self($file, $values); } public function __construct($file, $values = array()) { $request = Dispatcher::request(); $position = strpos($file, '/'); if ($position === FALSE) { $this->file = VIEW_PATH . str_replace('>', '/', $request['controller']) . '/' . $file . '.php'; } elseif ($position === 0) { $this->file = VIEW_PATH . substr($file, 1) . '.php'; } else { $this->file = VIEW_PATH . $file . '.php'; } $this->set($values); } // function __construct // Magic method for getting view variables public function __get($name)
<?php define_default('FIELDS_PATH', realpath(ROOT . 'fields') . '/'); class Field { protected $info; protected $name; protected $params; protected $type; public function __construct($name, $type, $params = FALSE) { require_once FIELDS_PATH . dash($type) . "/field.php"; $this->name = $name; $this->params = $params; $this->type = $type; } // function __construct private function className() { return camel_case($this->type) . 'Field'; } // Returns the columns needed for the field public function columns() { $columns = array(); $class = $this->className(); foreach ($class::columns($this->params) as $column) { $name = dash($this->name); if (array_key_exists('suffix', $column)) { $name .= '-' . dash($column['suffix']); }
<?php define_default('CONTENT_TYPES_PATH', realpath(ROOT . '../workspace') . '/application/content-types/'); class ContentType { protected $db; protected $info; public function __construct($name) { $this->info = json_decode(file_get_contents(CONTENT_TYPES_PATH . "{$name}.json")); $this->db = new Database(); } // function __construct // Returns all of the available content types public static function all() { return array_map(function ($file) { return json_decode(file_get_contents($file)); }, glob(CONTENT_TYPES_PATH . '*.json')); } // function all // Returns an array of all of the fields private function fields() { return array_merge($this->info->fields->left, $this->info->fields->right, $this->info->fields->hidden); } // function fields // Creates a new row for a content type public function createRecord($values = array()) { // Run the before events
<?php require dirname(__FILE__) . '/csspp/csspp.php'; define_default('CSS_BASE_PATH', realpath(ROOT)); class AssetProcessor extends Controller { // Action for processing stylesheets public function css() { $file = $this->get('file'); $csspp = new CSSPP($file, CSS_BASE_PATH); // Include CSS that was marked for inclusion in the session if (array_key_exists('stylesheets', $_SESSION)) { foreach (array_unique($_SESSION['stylesheets']) as $stylesheet) { $csspp->append("@include '{$stylesheet}';\n"); } unset($_SESSION['stylesheets']); } header('Content-type: text/css'); echo $csspp; } } // class Asset_Processor
<?php // Defines which version of Dispatch we're dealing with define('DISPATCH_VERSION', '0.5'); // Include the system helpers require SYSTEM_PATH . 'helpers.php'; // Define the defaults needed for Autoloader class to work define_default('CONTROLLERS_PATH', APPLICATION_PATH . 'controllers/'); define_default('MODELS_PATH', APPLICATION_PATH . 'models/'); define_default('MODULES_PATH', ROOT . 'modules/'); define_default('START_TIME', microtime(TRUE)); class Autoloader { // Defines the top-level paths to search in public static $paths = array(CONTROLLERS_PATH, MODELS_PATH, SYSTEM_PATH); // Autoloader public static function load($name) { foreach (self::$paths as $path) { $file = $path . '/' . self::filename($name) . '.php'; if (require_if_exists($file)) { return TRUE; } } } // function load public static function module($name) { $path = MODULES_PATH . $name; self::$paths[] = $path; require_if_exists($path . '/init.php');
<?php define_default('PAGES_PATH', realpath(ROOT . '../workspace') . '/application/pages/'); class Page { protected $info; protected $params; public function __construct($name, $params = array()) { $name = dash(str_replace(' :: ', '/', $name)); $this->info = json_decode(file_get_contents(PAGES_PATH . "{$name}.json")); $this->params = $params; } // function __construct // Returns all of the pages // TODO: See if we can use the directory structure to determine parents public static function all() { // Array for holding pages $pages = array(); // Find all of the pages $dir = new RecursiveDirectoryIterator(PAGES_PATH, RecursiveIteratorIterator::SELF_FIRST); $iterator = new RecursiveIteratorIterator($dir); // Load all of the pages' info foreach ($iterator as $file) { $pages[] = json_decode(file_get_contents($file)); } return $pages; } // function all // Returns a page object for a given URI