function module($strinfo, $vars = null) { if (count(ModuleManager::$_order) > 0) { $mod = ModuleManager::$_order[count(ModuleManager::$_order) - 1]; ModuleManager::$_modules[$mod]['modinfo'] = $strinfo; if ($vars != null) { foreach ($vars as $key => $var) { ModuleManager::$_modules[$mod][$key] = $var; } // Load dependencies if (isset($vars['depends']) && is_array($vars['depends'])) { $deps = (array) $vars['depends']; foreach ($vars['depends'] as $dep) { ModuleManager::load($dep); } } } } else { Console::warn("Module reported modinfo '%s' without being requested?", $string); } }
<?php ModuleManager::load('lepton.graphics.filter'); /** * WatermarkImageFilter applies a watermark on top of an image. The * watermark could (should?) be a transparent PNG image. The x and y values * passed to the constructor allows for positioning around the image edge. * If a positive number is used, this is seen as relative to the left or * top edge of the image. If a negative number is used, it is instead seen * as relative to the right or bottom edge of the image. * * @author Christopher Vagnetoft <*****@*****.**> */ class WatermarkImageFilter extends ImageFilter { const POS_RELATIVE = 0; const POS_ABSOLUTE = 1; const POS_CENTERED = 2; private $hwatermark; private $placement; private $width; private $height; private $x; private $y; /** * @param int $x The X offset (positive values from left, negative from right) * @param int $y The Y offset (positive valeus from top, negative from bottom) * @param string $watermark The watermark image to apply * @param int $placement The placement method to use */ function __construct($x, $y, $watermark, $placement = WatermarkImageFilter::POS_RELATIVE)
<?php ModuleManager::load('lepton.mvc.forms'); class FormController extends Controller { var $gbform = array('name' => 'required', 'email' => 'validate email required', 'website' => 'validate website optional', 'message' => 'required'); function savepost() { $post = new WebForm($this->gbform); if (!$post->isValid()) { // Form is invalid, post it back to the user to allow correction } else { $db = new DatabaseConnection(); $db->insertRow("INSERT INTO guestbook (name,email,website,message) VALUES (%s,%s,%s,%s)", $post->name, $post->email, $post->website, $post->message); } } }
<?php ModuleManager::load('lepton.google.charting'); // // This is an example controller. You can modify this file as you see // fit. For more information, see the documentation. // class DefaultController extends Controller { function index() { View::load('default/index.php'); } function smarty() { View::load('index.tpl'); } function chart() { $ds = new DataSet(null); $c = new GChart($ds, 300, 200); $c->render(); } function upload() { if (request::isPost()) { $file = request::post('userfile'); printf('<p>%s</p>', $file); $dest = APP_PATH . 'cache/image.jpg'; printf('<p>%s</p>', $dest); if ($file->save($dest)) {
/** * */ static function load($module, $optional = false) { // Check if the path is globbed if (strpos($module, '*') == strlen($module) - 1) { $path = self::_mangleModulePath($module); Console::debugEx(LOG_EXTENDED, __CLASS__, "Looking for modules matching %s from %s", $module, $path); $f = glob($path); sort($f); $failed = false; foreach ($f as $file) { if (!ModuleManager::load(str_replace('*', basename($file, '.php'), $module))) { $failed = true; } } return !$failed; } // Check if the module is already loaded if (ModuleManager::has($module)) { logger::debug("Already loaded %s.", $module); return true; } // Otherwise mangle the path $path = self::_mangleModulePath($module); /* if (file_exists(APP_PATH.$modpath)) { $path = APP_PATH.$modpath; } elseif (file_exists(SYS_PATH.$modpath)) { $path = SYS_PATH.$modpath; } else { $path = null; } */ if ($path) { if (file_exists(basename($path, '.php') . '.class.php')) { $path = basename($path, '.php') . '.class.php'; } if (file_exists($path)) { self::$_lastmodule = $module; Console::debugEx(LOG_BASIC, __CLASS__, "Loading %s (%s).", $module, str_replace(BASE_PATH, '', $path)); try { ModuleManager::$_modules[strtolower($module)] = array(); ModuleManager::$_order[] = strtolower($module); // Console::debugEx(LOG_DEBUG2,__CLASS__," path = %s", $path); require $path; array_pop(ModuleManager::$_order); } catch (ModuleException $e) { Console::debugEx(LOG_BASIC, __CLASS__, "Exception loading %s!", $module); throw $e; return false; } return true; } else { throw new ModuleException("Could not load module " . $module . ": Path not found"); return false; } } else { Console::debugEx(LOG_BASIC, __CLASS__, "Failed to load %s.", $module); return false; } }
<?php ModuleManager::load('lepton.net.sockets'); class HttpConnection { }
function package($op = null, $pkgname = null) { ModuleManager::load('lepton.utils.l2package'); switch ($op) { case 'install': $pm = new L2PackageManager(); $pkg = new L2Package($pkgname); $pm->installPackage($pkg); break; case 'remove': $pm = new L2PackageManager(); $pkg = new L2Package($pkgname); $pm->removePackage($pkg); break; case 'list': $pm = new L2PackageManager(); $pm->listPackages(); break; default: Console::writeLn(__astr("\\b{Package}: Manage packages (l2p)")); Console::writeLn(__astr(" package \\b{install} \\u{package.l2p} Installs a package")); Console::writeLn(__astr(" package \\b{remove} \\u{package} Removes a package")); Console::writeLn(__astr(" package \\b{list} [\\u{package}] List packages")); Console::writeLn(__astr(" package \\b{info} [\\u{package}] Show information on packages")); Console::writeLn(__astr(" package \\b{find} [\\u{filename}] Find package that owns file")); Console::writeLn(__astr(" package \\b{update} [\\u{package}|\\b{all}] List packages")); Console::writeLn(); } }
<?php ModuleManager::load('lepton.ui.curses.widget'); /** * * */ class CursesDialog extends CursesContainer { private $_x, $_y, $_w, $_h; private $_title; private $_text; private $_wh; /** * */ function __construct($x, $y, $w, $h, $title, $text) { $this->_x = $x; $this->_y = $y; $this->_w = $w; $this->_h = $h; $this->_title = $title; $this->_text = $text; $this->_wh = ncurses_newwin($this->_h, $this->_w, $this->_y, $this->_x); Console::debug("Created window with handle %xd", $this->_wh); } function __destruct() { Console::debug("Deleting window with handle %xd", $this->_wh); ncurses_delwin($this->_wh);
<?php ModuleManager::load('lepton.fs.fs'); class FsContainer { protected $_contents = array(); public $_size = null; public function __construct($paths = null) { if (is_array($paths)) { foreach ($paths as $path) { $this->add($path); } } } public function recalculateSize() { $this->_size = 0; foreach ($this->_contents as $p) { $o = FsObject::get($p); $this->_size += $o->getSize(); } return $this->_size; } public function add($path) { if (FsObject::exists($path)) { $this->_contents[] = $path; } if ($this->_size == null) { $this->_size = 0;
<?php define('NCC_FRAME', 1); define('NCC_TEXT', 2); define('NCC_TITLE', 3); define('NCC_MORE', 4); ModuleManager::load('lepton.ui.curses.*'); /** * * */ abstract class CursesApplication extends ConsoleApplication { protected $workspace; protected $children; protected $topmost; /** * */ function __construct() { ncurses_init(); if (ncurses_has_colors()) { ncurses_start_color(); ncurses_init_pair(NCC_FRAME, NCURSES_COLOR_BLACK, NCURSES_COLOR_BLUE); ncurses_init_pair(NCC_TEXT, NCURSES_COLOR_WHITE, NCURSES_COLOR_BLUE); ncurses_init_pair(NCC_TITLE, NCURSES_COLOR_YELLOW, NCURSES_COLOR_BLUE); ncurses_init_pair(NCC_MORE, NCURSES_COLOR_WHITE, NCURSES_COLOR_BLUE); ncurses_curs_set(0); } $this->workspace = ncurses_newwin(0, 0, 0, 0);
<?php ModuleManager::checkExtension('ncurses', true); ModuleManager::load('lepton.ui.curses.application');
<?php ModuleManager::load('lepton.mvc.router'); ModuleManager::load('lepton.mvc.controller'); class DefaultRouter extends Router { function routeRequest() { $controller = $this->getSegment(0); $method = $this->getSegment(1); $arguments = $this->getSegmentSlice(2); Controller::invoke($controller, $method, $arguments); } }
<?php /** * Lepton Smarty-based Blog Controller * * Renders your blogs in full color with the use of Smarty templates! */ ModuleManager::load('lepton.cms.*'); ModuleManager::load('lepton.mvc.viewhandler.smarty'); class BlogController extends Controller { /** * */ function __request($method = null, $args = null) { switch ($method) { case 'tag': call_user_func_array(array($this, 'showtag'), $args); break; case 'category': call_user_func_array(array($this, 'category'), $args); break; case 'video': call_user_func_array(array($this, 'video'), $args); break; case 'image': call_user_func_array(array($this, 'image'), $args); break; case 'post': call_user_func_array(array($this, 'posts'), $args);
<?php module("SOAP Web Service Query Library"); ModuleManager::load('lepton.web.serviceconsumer'); class SoapServiceConsumer extends ServiceConsumer { const XSI_NS = "http://www.w3.org/2001/XMLSchema-instance"; const _NULL_ = "xxx_replacedduetobrokephpsoapclient_xxx"; protected $mustParseNulls = false; protected $serviceurl; protected $headers = array(); public function __construct($serviceurl, $username = null, $password = null) { $this->serviceurl = $serviceurl; $this->client = new SoapClient($this->serviceurl); if ($username && $password) { // Prepare SoapHeader parameters $auth = array('Username' => $username, 'Password' => $password); $this->headers[] = new SoapHeader($this->serviceurl, 'UserCredentials', $auth); $this->client->__setSoapHeaders($this->headers); } } public function addHeader($name, $value) { $this->headers[] = new SoapHeader($this->serviceurl, $name, $value); $this->client->__setSoapHeaders($this->headers); } public function __destruct() { unset($soapClient); }
<?php /** * @file index.php * * Lepton/NG: MVC Application Entrypoint * * Part of Lepton/NG - (c) 2010, Noccy Labs * Distributed under the GNU GPL v3 * * NOTE: * You probably don't have to change anything in here. Just make sure your * configuration is correct (located in your app/config directory) * * @license GPL v2 * @author Christopher Vagnetoft <*****@*****.**> */ // Load configuration and the base system. require 'sys/base.php'; // debug::enable(); // Initialize an MVC application to handle the request for us ModuleManager::load('lepton.base.mvc'); Lepton::run('MvcApplication', 'app');
<?php module("Database Connection Manager"); ModuleManager::load('lepton.db.driver'); ModuleManager::load('lepton.db.drivers.*'); class DatabaseException extends BaseException { } /** * @brief Database manager, takes care of pooling connections. * * @author Christopher Vagnetoft <*****@*****.**> */ abstract class DatabaseManager { private static $pool = array(); /** * * @param string $group The group to access * @return DatabaseConnection The connection */ static function getConnection($group = 'default') { if (!isset(self::$pool[$group])) { Console::debugEx(LOG_DEBUG1, __CLASS__, "PoolConnectGroup(%s)", $group); self::$pool[$group] = self::poolConnectGroup($group); } return self::$pool[$group]; } /** *