private function contact() { $isSent = Request::get(0, VAR_URI) == 'send'; $options = array('name' => array(Validator::MESSAGE => 'Der Name muss mindestens 5 und darf maximal 150 Zeichen lang sein.', Validator::MIN_LENGTH => 5, Validator::MAX_LENGTH => 150), 'email' => array(Validator::MESSAGE => 'Die E-Mail-Adresse ist nicht korrekt.', Validator::CALLBACK => Validator::CB_MAIL), 'message' => array(Validator::MESSAGE => 'Die Nachricht entspricht nicht den Vorgaben (mindestens 10 Zeichen, maximal 1000 Zeichen).', Validator::MIN_LENGTH => 10, Validator::MAX_LENGTH => 1000), 'title' => array(Validator::MESSAGE => 'Der Titel entspricht nicht den Vorgaben (mindestens 5 Zeichen, maximal 100 Zeichen).', Validator::MIN_LENGTH => 5, Validator::MAX_LENGTH => 100)); $this->enableClientFormValidation($options); // Don't validate the captcha via ajax as the session would end if (Config::get('captcha.enable')) { Core::loadClass('Core.Security.ReCaptcha'); $options['recaptcha_response_field'] = array(Validator::MESSAGE => 'Der Sicherheitscode wurde nicht korrekt eingegeben.', Validator::CALLBACK => 'cb_captcha_check'); } $data = array_fill_keys(array_keys($options), ''); $data['name'] = iif(Me::get()->loggedIn(), Me::get()->getName()); $data['email'] = iif(Me::get()->loggedIn(), Me::get()->getEmail()); $this->breadcrumb->add('Kontakt'); $this->header(); if ($isSent) { extract(Validator::checkRequest($options)); if (count($error) > 0) { CmsPage::error($error); } else { CmsTools::sendMail(Config::get('general.email'), $data['title'], $data['message'], $data['email'], $data['name']); CmsPage::ok('Die Anfrage wurde erfolgreich verschickt. Vielen Dank!'); $data['title'] = ''; $data['message'] = ''; } } $tpl = Response::getObject()->appendTemplate('Cms/contact/contact'); $tpl->assign('data', $data); if (Config::get('captcha.enable')) { $tpl->assign('captcha', recaptcha_get_html(Config::get('captcha.public_key')), false); } $tpl->output(); $this->footer(); }
public static function sendMail($to, $title, $message, $from = null, $fromName = null, $attachments = array()) { Core::loadClass('Core.Net.Mail.PHPMailer'); $mail = new PHPMailer(); $mail->AddAddress($to); $mail->Body = $message; $mail->CharSet = Config::get('intl.charset'); $mail->Subject = $title; if ($from != null) { $mail->From = $from; } else { $mail->From = Config::get('general.email'); } if ($fromName != null) { $mail->FromName = $fromName; } else { $mail->FromName = Config::get('general.title'); } if (count($attachments) > 0) { foreach ($attachments as $file) { $mail->AddAttachment($file); } } if (Config::get('core.debug') == 1) { var_dump($to, $title, $message, $from, $fromName, $attachments); } else { $mail->Send(); } }
public static final function getInstance() { $class = get_called_class(); if (empty(self::$objects[$class])) { Core::loadClass('Core.Util.Utility'); self::$objects[$class] = Utility::createClassInstance($class, func_get_args()); } return self::$objects[$class]; }
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @package Core * @subpackage Kernel * @author Matthias Mohr * @copyright Copyright (c) 2004-2010, Viscacha.org * @license http://www.gnu.org/licenses/lgpl-2.1.txt GNU Lesser General Public License */ Core::loadClass('Core.Kernel.InfoException'); /** * Exception for Core class. * * @package Core * @subpackage Kernel * @author Matthias Mohr * @copyright Copyright (c) 2004-2010, Viscacha.org * @since 1.0 */ class CoreException extends InfoException { private $data; /**
* You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * For any suggestions or bug report please contact me: guinux@cosmoplazza.com * * @package Core * @subpackage Net * @author GuinuX <*****@*****.**> * @author Matthias Mohr * @copyright Copyright (C) 2002 - 2003 by GuinuX * @version 1.1 (Released: 06-20-2002, Last Modified: 06-10-2003) * @license http://www.gnu.org/licenses/lgpl-2.1.txt GNU Lesser General Public License */ Core::loadClass('Core.Net.HTTP.HTTPClientHeader'); /** * A HTTP client class - HTTPClientResponseHeader * * @package Core * @subpackage Net * @author GuinuX <*****@*****.**> * @author Matthias Mohr * @since 1.0 */ class HTTPClientResponseHeader extends HTTPClientHeader { protected $cookiesHeaders; public function __construct() {
<?php Core::loadClass('Core.Cache.CacheItem'); /** * The CacheServer manages the CacheItems. * * @package Core * @subpackage Cache * @author Matthias Mohr * @since 1.0 */ class CacheServer { private $cachedir; private $sourcedir; private $data; /** * Constructs a new Cache Manager. In this class all loaded CacheItems will be cached. * * @param string Path to the cache data folder * @param string Path to the cache source folder {@see CacheServer::setSourceDir()} **/ public function __construct($cachedir = 'data/cache/', $sourcedir = 'Core.Cache.Items') { $this->cachedir = $cachedir; $this->data = array(); $this->setSourceDir($sourcedir); } /** * Sets the default source diretory for cache files. *
/** * Loads the class with the given class name from the index. * * @param string Class Name * @param boolean Try to rebuild on failure * @throws ClassManagerException */ public function loadFile($className, $rebuildOnError = true) { if (array_key_exists($className, $this->index) == true) { $filename = $this->index[$className]; if(file_exists($filename) == true) { include_once($filename); } else { // Class name is indexed, but no source file available $error = array( "ClassManager index seems to be outdated. ". "File for class '{$className}' not found: ".$filename, 1 ); } } else { // No class with this name indexed $error = array("ClassManager has no class with name {$className} indexed.", 2); } if ($rebuildOnError == true) { // Force a rebuild as the index seems to be invalid $this->deleteCache(); $this->loadIndex(); $this->loadFile($className, false); } else { // Rebuild failed, throw exception Core::loadClass('Core.Kernel.ClassManagerException'); $e = new ClassManagerException($error[0], $error[1]); $e->setIndex($this->index); throw $e; } }
<?php Core::loadClass('Cms.CmsModuleObject'); /** * This is a general Admin module object. All admin modules should extend it. * * @package Cms * @author Matthias Mohr * @since 1.0 * @abstract */ abstract class AdminModuleObject extends CmsModuleObject { const MENU_FILE = './data/admincp.php'; protected $menu; public function __construct($package = 'Cms') { parent::__construct($package); $this->scriptFiles[URI::build('client/scripts/jquery/jquery.admin.js')] = 'text/javascript'; $this->scriptFiles[URI::build('client/scripts/admin.js')] = 'text/javascript'; $this->cssFiles[URI::build('client/styles/admin.css')] = 'all'; $this->loadMenu(); $this->breadcrumb->add('Administrationsbereich', URI::build('cms/admin')); } protected function header() { parent::header(); $tpl = Response::getObject()->appendTemplate("/Cms/admin/header"); $tpl->assign('menu', $this->menu, false); $tpl->output(); }
<?php Core::loadClass("Cms.Auth.GuestUser"); /** * This is a registered user. * * @package Cms * @subpackage Auth * @author Matthias Mohr * @since 1.0 */ class User { protected $data; protected $acl; public function __construct(array $data) { $fields = UserUtils::getTableFields(); foreach ($fields as $f => $default) { if (!isset($data[$f])) { Core::throwError("User data is incomplete. Field {$f} is missing."); $data[$f] = $default; } } // Special case: Birthday -> Parse it into chunks if (strpos($data['birth'], '-') === false) { $data['birth'] = '0000-00-00'; } $bday = explode('-', $data['birth']); $data['birthday'] = intval($bday[2]); $data['birthmonth'] = intval($bday[1]);
<?php Core::loadClass("Cms.Auth.Authentication"); /** * Session handling and more. * * @package Cms * @subpackage Auth * @author Matthias Mohr * @since 1.0 */ class Session { private $sid; private $ip; private $auth; private $settings; private $me; // Singleton private static $instance = NULL; public static function getObject() { if (self::$instance === NULL) { self::$instance = new self(); } return self::$instance; } private function __clone() { } private function __construct()
$file = $classManager->loadFile($className); if ($file == null) { Core::throwError('Class "{$className}" not found', INTERNAL_ERROR); } } // Load class Config Core::loadClass('Core.Util.Config'); // Load class validator (for SystemEnvironment) Core::loadClass('Core.Security.Validator'); // Load class SystemEnvironment Core::loadClass('Core.System.SystemEnvironment'); // Load classes for Files and Folders (often used) Core::loadClass('Core.FileSystem.File'); Core::loadClass('Core.FileSystem.Folder'); // Load ModuleObject class (each module needs it) Core::loadClass('Core.ModuleObject'); /** * Checks whether the specified number is a natural number (or an id). * * An natural number is an integer greater than 0. (1,2,3,4,5,...,100,...) * * @param int Number to check * @return boolean true if the parameter is an id, false if not. **/ function is_id($x) { return is_numeric($x) == true && $x > 0 ? intval($x) == $x : false; } /** * Chacks a comparison and returns the first parameter for true, the second parameter for false. *
<?php Core::loadClass('Core.System.SystemEnvironment'); /** * Some static utilities for the file system. * * @package Core * @subpackage FileSystem * @author Matthias Mohr * @since 1.0 */ class FileSystem { /** * Returns canonicalized absolute pathname to a file or directory. * * This works with non-existant paths. For directories there won't be a trailing slash. * * LICENSE: * This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @author Michael Wallner <*****@*****.**> * @copyright 2004-2005 Michael Wallner * @license PHP License 3.0 http://www.php.net/license/3_0.txt * @link http://pear.php.net/package/File * @param string Path to canonicalize to absolute path * @param string Directory Seperator (default: Value from DIRECTORY_SEPERATOR)
<?php Core::loadClass('Core.Security.Hash'); Core::loadClass('Cms.Auth.User'); /** * Authentication (login / logout) * * @package Cms * @subpackage Auth * @author Matthias Mohr * @since 1.0 */ class Authentication { protected function setCookie($email = '', $pw = '') { if (empty($email) || empty($pw)) { Response::getObject()->sendCookie('udata', "", 0, true); } else { // Cookie-Laufzeit: 365 Tage Response::getObject()->sendCookie('udata', "{$email}|{$pw}", 60 * 60 * 24 * 365, true); } } private function loginAsGuest() { return new GuestUser(); } public function loginWithCookies() { // Try to login with user data from cookie $udata = Request::getObject()->getCookie('udata');
<?php Core::loadClass('Core.Net.IDNA'); /** * Class to validate several types of data. * * @package Core * @subpackage Net * @author Matthias Mohr * @since 1.0 */ class NetTools { public static function normalizeHost($host) { $idna = new IDNA(); $host = SystemEnvironment::toUtf8($host); $host = $idna->encode($host); return $host; } public static function fsockopen($host, $port, $timeout) { $host = self::normalizeHost($host); $fp = @fsockopen($host, $port, $errno, $errstr, $timeout); return array($fp, $errno, $errstr, $host); } public static function checkMX($host) { if (empty($host)) { return false; }
<?php /** * Simple text implementation for custom fields. * * @package Cms * @subpackage DataFields * @author Matthias Mohr * @since 1.0 */ Core::loadClass('Core.Security.ReCaptcha'); class CustomCaptcha extends CustomField { public function getTypeName() { return 'Captcha'; } public function getClassPath() { return 'Cms.DataFields.Types.CustomCaptcha'; } public function getDbDataType() { return null; } public function getInputCode($data = null) { return recaptcha_get_html(Config::get('captcha.public_key')); } public function getOutputCode($data = null) {
<?php Core::loadClass('Core.Net.NetTools'); Core::loadClass('Core.Net.IPv4'); /** * Class to validate several types of data. * * Some parts of this code are from Zend Framework 1.5! * * @package Core * @subpackage Util * @author Matthias Mohr * @since 1.0 */ class Validator { /** * Fehlermeldung (only for checkAll() / checkRequest()) */ const MESSAGE = 1; /** * Minimale Länge */ const MIN_LENGTH = 2; /** * Maximale Länge */ const MAX_LENGTH = 3; /** * Regulärer Ausdruck */
<?php Core::loadClass('Core.ExceptionData'); /** * Exception for IP error. * * @package Core * @subpackage DB * @author Matthias Mohr * @since 1.0 */ class IPException extends ExceptionData { /** * Constructs the QueryException. * * @param string Database error message * @param int Database error number (default: 0) */ public function __construct() { parent::__construct('No valid IPv4 found for the user.', 1); } }
public function register() { $action = Request::get(1, VAR_URI); $min_year = date('Y') - 110; $max_year = date('Y') - 8; $countries = CmsTools::getCountries(); $options = $this->getFieldValidation($countries, $min_year, $max_year); $this->enableClientFormValidation($options); $this->breadcrumb->add('Registrieren'); $this->header(); if (Me::get()->loggedIn()) { CmsPage::error('Sie sind bereits registriert!'); } else { // Don't validate the captcha via ajax as the session would end if (Config::get('captcha.enable')) { Core::loadClass('Core.Security.ReCaptcha'); $options['recaptcha_response_field'] = array(Validator::MESSAGE => 'Der Sicherheitscode wurde nicht korrekt eingegeben.', Validator::CALLBACK => 'cb_captcha_check'); } $error = array(); $data = array_fill_keys(array_keys($options), ''); if ($action == 'send') { extract(Validator::checkRequest($options)); if (count($error) > 0) { CmsPage::error($error); } else { // Insert data $dt = new DT(); $dt->setDate($data['birthyear'], $data['birthmonth'], $data['birthday']); $data['birth'] = $dt->dbDate(); $data['pw1'] = Hash::generate($data['pw1']); $data['group_id'] = UserPages::DEFAULT_MEMBER_GID; $data['regdate'] = time(); if (Config::get('security.validate_registered_email') == 1) { $data['active'] = 0; $data['verification'] = Hash::getRandom(); } else { $data['active'] = 1; $data['verification'] = ''; } $db = Database::getObject(); $db->query("\n\t\t\t\t\t\tINSERT INTO <p>user\n\t\t\t\t\t\t(forename, surname, pw, group_id, email, gender, birth, city, country, regdate, active, verification)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t(<forename>, <surname>, <pw1>, <group_id:int>, <email>, <gender>, <birth>, <city>, <country>, <regdate:int>, <active:int>, <verification>)\n\t\t\t\t\t", $data); $mid = $db->insertID(); $tpl = Response::getObject()->getTemplate('Cms/mails/register' . iif(!$data['active'], '_confirm')); $tpl->assign('mid', $mid, false); $tpl->assign('name', UserUtils::getSalutation($data['gender'], $data['forename'], $data['surname']), false); $tpl->assign('data', $data, false); CmsTools::sendMail($data['email'], 'Betätigung der Anmeldung bei ' . Config::get('general.title'), $tpl->parse()); CmsPage::ok("Sie haben sich erfolgreich registriert." . iif(!$data['active'], ' Bitte aktivieren Sie Ihren Account, in dem Sie auf den Link klicken, der Ihnen an Ihre E-Mail-Adresse geschickt wurde.'), URI::build('Cms/user/login')); } } if ($action != 'send' || count($error) > 0) { $tpl = Response::getObject()->appendTemplate('Cms/user/register'); $tpl->assign('data', $data); $tpl->assign('r_birthday', range(1, 31)); $tpl->assign('r_birthmonth', range(1, 12)); $tpl->assign('r_birthyear', range($min_year, $max_year)); $tpl->assign('countries', $countries); if (Config::get('captcha.enable')) { $tpl->assign('captcha', recaptcha_get_html(Config::get('captcha.public_key')), false); } $tpl->output(); } } $this->footer(); }
<?php Core::loadInterface('Core.DB.DbDriver'); Core::loadClass('Core.DB.Database'); /** * Database driver for MySQL. * * This dirver is primary for older MySQL installations, mysql extension is used. * * @package Core * @subpackage DB * @author Matthias Mohr * @since 1.0 */ class MySQL extends Database implements DbDriver { /** * Initializes the class and the variables. * * No connection will be established. Use the methods connect() and selectDB() to open a connection. */ public function __construct() { parent::__construct(); $this->system = 'MySQL'; } /** * Destructs the class. The method disconnect is called. **/ public function __destruct() {
<?php Core::loadClass('Core.FileSystem.CHMOD'); Core::loadClass('Core.FileSystem.FileSystem'); /** * Folder functions. * * @package Core * @subpackage FileSystem * @author Matthias Mohr * @since 1.0 */ class Folder { /** * Given Path to folder. * @var string */ private $path; /** * Creates a new object of type Folder. * * The folder given as parameter must not exist. * The folder can be a relative or a absolute path. * * @param string Path to a folder. */ public function __construct($dir) { if (is_file($dir)) { $dir = dirname($dir);
<?php Core::loadClass('Core.Util.Template.Template'); Core::loadClass('Cms.Util.CmsTools'); Core::loadClass('Cms.Util.Breadcrumb'); Core::loadClass('Cms.Auth.Session'); /** * This is a general module object. All modules should extend it. * * @package Core * @author Matthias Mohr * @since 1.0 * @abstract */ abstract class ModuleObject { /** * Contains name of this module. * @var string */ protected $module; /** * Contains name of the package. * @var string */ protected $package; /** * Constructs a new ModuleObject. * * Note: Before you call this constructor, you have to set the variable $module! **/
define('VISCACHA_LOGS_DIR', 'data/logs/'); define('VISCACHA_UPLOAD_DIR', 'data/upload/'); define('VISCACHA_CONFIG_FILE', 'data/config.php'); define('VISCACHA_ERROR_CSS_FILE', 'client/error.css'); define('VISCACHA_JS_DIR', 'client/js/'); define('VISCACHA_DESIGN_DIR', 'client/designs/'); define('VISCACHA_SOURCE_DIR', 'source/'); // Get the script start time for benchmarks $scriptStart = microtime(true); // Boot the object oriented system... require_once('source/Core/Kernel/class.Core.php'); require_once('source/Core/Kernel/function.core.php'); // Load the class manager for autoload support Core::loadClass('Core.Kernel.ClassManager'); // Register autoloader spl_autoload_register('ClassManager::autoload'); // Store temporary entries (Registry like) - Namespace: temp Config::setConfigHandler(new TempConfig(), 'temp'); // Load/Write entries from a native php array in file data/config.php - Namespace: base Config::setConfigHandler(new PHPConfig(VISCACHA_CONFIG_FILE), 'base'); // Load/Write entries from a database table named config - Namespace: core // Config::setConfigHandler(new DBConfig('config'), 'core'); // set the script start and cwd to temp config Config::set('temp.benchmark.start', $scriptStart); Config::set('temp.system.cwd', getcwd()); // see FileSystem::resetWorkdingDir() for more information
/** * 自动加载 */ function __autoload($classname) { Core::loadClass($classname); }