Example #1
0
 /**
  * Create cipher key.
  *
  * @return string
  */
 public function setKey()
 {
     if (!$this->key) {
         $this->key = md5(sha1(Config::getSetting('cipher_key')));
     }
     return $this->key;
 }
Example #2
0
 /**
  * Connect to database.
  *
  * @return void
  */
 public function connect()
 {
     try {
         $this->dbh = new PDO(Config::getSetting('db_type') . ':unix_socket=/var/run/mysqld/mysqld.sock;dbname=' . Config::getSetting('db_name') . ';host=' . Config::getSetting('db_host'), Config::getSetting('db_user'), Config::getSetting('db_pass'));
         $this->query("SET CHAR SET UTF8");
     } catch (PDOException $e) {
         echo 'Connection failed: ' . $e->getMessage();
     }
 }
Example #3
0
 /**
  * Parse template and send mail.
  *
  * @param string $to Send to this address.
  *
  * @return boolean
  */
 public function sendMail($to, $subject, $from = null, $fromname = null)
 {
     $this->From = $from ? $from : Config::getSetting('mail_from');
     $this->FromName = $fromname ? $fromname : Config::getSetting('mail_from_name');
     $this->Subject = $subject;
     $this->IsHTML(true);
     $this->Body = $this->fetchTemplate();
     $this->AddAddress($to);
     return $this->Send();
 }
 /**
  * Main Constructor
  *
  * @access	public
  * @return	void
  */
 public function __construct()
 {
     $this->setRichness(Config::getSetting('functionalRichness'));
     if (\DynamicPageListHooks::isLikeIntersection()) {
         $this->data['ordermethod'] = ['default' => 'categoryadd', 'values' => ['categoryadd', 'lastedit', 'none']];
         $this->data['order'] = ['default' => 'descending', 'values' => ['ascending', 'descending']];
         $this->data['mode'] = ['default' => 'unordered', 'values' => ['none', 'ordered', 'unordered']];
         $this->data['userdateformat'] = ['default' => 'Y-m-d: '];
         $this->data['allowcachedresults']['default'] = 'true';
     }
 }
Example #5
0
 /**
  * Save data to cache.
  *
  * @param string  $key   Data to save as.
  * @param mixed   $value Data to save.
  * @param boolean $db    Cache to database.
  *
  * @return void
  */
 public static function saveData($key, $value, $db = false)
 {
     $cache = Cache::getInstance();
     $cache->data[$key] = $value;
     if ($key != 'ModelCachingFields' && $db && Config::getSetting('cache_to_database', false, false) && Clockwork::isModuleLoaded('Data/Database')) {
         $lifespan = $db === true ? 0 : $db;
         if (($obj = Caching::create($key, '*`key`')) === false) {
             $obj = new Caching();
         }
         $obj->set('key', $key)->set('value', serialize($value))->set('object', is_object($value) ? get_class($value) : '')->set('lifespan', $lifespan)->save();
     }
 }
Example #6
0
 /**
  * Send message. Omit parameters to get defaults form Config.
  *
  * @param string $from     From email address.
  * @param string $fromname From name.
  * @param string $bcc      Send message BCC to this address.
  *
  * @return boolean
  */
 public function send($from = null, $fromname = null, $bcc = null)
 {
     $this->mailer->From = $from ? $from : Config::getSetting('mail_from');
     $this->mailer->FromName = $fromname ? $fromname : Config::getSetting('mail_from_name');
     $this->mailer->Subject = $this->subject;
     $this->mailer->IsHTML(true);
     $this->mailer->Body = $this->message;
     $this->mailer->AddAddress($this->to);
     if ($bcc) {
         $this->mailer->AddBCC($bcc);
     }
     return $this->mailer->Send();
 }
Example #7
0
 /**
  * Return logged in user
  *
  * @return object|boolean
  */
 public static function getUser($check = true)
 {
     if ($check && self::isLoggedIn() || !$check) {
         if (($user = Cache::loadData(static::$sessionKey)) === null) {
             $class = static::$className;
             if (($user = $class::create(sanitize($_SESSION[static::$sessionKey]), "*SHA1(MD5(CONCAT('" . Config::getSetting('salt') . "',  id)))")) !== false) {
                 Cache::saveData(static::$sessionKey, $user);
             } else {
                 unset($_SESSION[static::$sessionKey]);
                 redirect();
             }
         }
         return $user;
     } else {
         return false;
     }
 }
Example #8
0
 /**
  * Return a value.
  *
  * @param string  $key Value to return.
  * @param boolean $ret Set to true to return Date object instead of formatted date.
  *
  * @return mixed
  */
 public function get($key, $ret = false)
 {
     if ($ret !== -1 && ($field = $this->getFields($key)) && preg_match('/(date)/i', $field['Type'])) {
         if (isset($this->values[$key])) {
             if (Config::getSetting('check_empty_date')) {
                 if ($field['Type'] == 'datetime' && $this->values[$key] == '0000-00-00 00:00:00' || $field['Type'] == 'date' && $this->values[$key] == '0000-00-00') {
                     return null;
                 }
             }
             if (Clockwork::isModuleLoaded('Date')) {
                 $date = new Date($this->values[$key]);
                 if ($ret) {
                     return $date;
                 } else {
                     return $date->format();
                 }
             }
         } else {
             return null;
         }
     }
     return isset($this->values[$key]) ? $this->values[$key] : null;
 }
 public function formatCategoryList($iStart, $iCount)
 {
     for ($i = $iStart; $i < $iStart + $iCount; $i++) {
         $aArticles[] = $this->mArticles[$i]->mLink;
         $aArticles_start_char[] = $this->mArticles[$i]->mStartChar;
         $this->filteredCount = $this->filteredCount + 1;
     }
     if (count($aArticles) > Config::getSetting('categoryStyleListCutoff')) {
         return "__NOTOC____NOEDITSECTION__" . \CategoryViewer::columnList($aArticles, $aArticles_start_char);
     } elseif (count($aArticles) > 0) {
         // for short lists of articles in categories.
         return "__NOTOC____NOEDITSECTION__" . \CategoryViewer::shortList($aArticles, $aArticles_start_char);
     }
     return '';
 }
Example #10
0
 function getFileURL()
 {
     if ($this->type == 'image') {
         // we get the area instance
         $url = SITE_WEB_DIRECTORY . MEDIA_BASE_DIRECTORY . '/' . $this->area_id . '/' . $this->filename;
     } else {
         if ($this->access == 'STREAMING') {
             include_class('config');
             $conf = new Config();
             $streamingAudioServerURL = $conf->getSetting('streamingAudioServerURL');
             $url = $streamingAudioServerURL . '/' . basename($this->protected_filename, Media::getExtension($this->protected_filename)) . 'pls';
         } else {
             $url = SITE_WEB_DIRECTORY . MEDIA_ORIGINALS_DIRECTORY . '/' . date('Ymd', strtotime($this->date_time)) . '/' . $this->filename_original;
         }
     }
     return $url;
 }
Example #11
0
 /**
  * Throw an error and exit if needed
  *
  * @param string $error
  * @param int    $level      (optional, default = self::ERROR_FATAL)
  * @param int    $traceLevel (optional, default = 0)
  *
  * @return void
  */
 public static function throwError($error, $level = self::ERROR_FATAL, $traceLevel = 0)
 {
     if (!Config::getSetting('debug')) {
         return false;
     }
     $errors = array(0 => 'FATAL CLOCKWORK ERROR', 1 => 'CLOCKWORK WARNING');
     $trace = debug_backtrace();
     $trace = $trace[$traceLevel];
     if (isset($error[$level])) {
         echo '<br /><b>' . $errors[$level] . ':</b> ' . $error . ' in <b>' . $trace['file'] . '</b> on line <b>' . $trace['line'] . '</b><br />';
     } else {
         self::throwError('Invalid error level', self::ERROR_WARNING, 1);
     }
     if ($level == self::ERROR_FATAL) {
         exit;
     }
 }
Example #12
0
 /**
  * Return [const]_[path|dir].
  * @author Jelle van der Coelen
  * @package Clockwork/Library/Path
  *
  * @param string $location Location to append to dir.
  * @param string $const    Constant to use.
  * @param string $type     Type of constant to use (path|dir).
  *
  * @return string
  */
 function path($location = '', $const = 'root', $type = 'path')
 {
     return Config::getSetting($const . '_' . $type) . $location;
 }
Example #13
0
 /**
  * Setup Twig template engine
  *
  * @return void
  */
 public function setupTwig()
 {
     Twig_Autoloader::register(true);
     if (!is_dir($this->basedir . 'template/')) {
         Clockwork::throwError('Template directory (' . $this->basedir . 'template/) does not exists');
     }
     $paths = [$this->basedir . 'template/', APP_DIR . 'template/'];
     $plugins = Clockwork::getInstance()->loadedPlugins;
     foreach ($plugins as $plugin) {
         if (is_dir($plugin->dir() . 'template/')) {
             $paths[] = $plugin->dir() . 'template/';
         }
     }
     $loader = new Twig_Loader_Filesystem($paths);
     $this->twig = new Twig_Environment($loader, array('cache' => Config::getSetting('twig_cache') ? appdir('template/cache/') : false));
     $functions = get_defined_functions();
     foreach ($functions['user'] as $function) {
         if (strpos(strtolower($function), 'twig') === false) {
             $this->twig->addFunction(new Twig_SimpleFunction($function, $function));
         }
     }
     $this->twig->addFunction(new Twig_SimpleFunction('PluginLoader', [Clockwork::getInstance(), 'pluginLoader']));
 }
Example #14
0
 /**
  * Add a join.
  *  
  * @param string  $table  Table name to join on
  * @param string  $on     Where to join on.
  * @param string  $type   Type of join
  * @param boolean $prefix Prefix table with db_table_prefix from config.
  * @param boolean $reset  Clear all joins.
  *
  * @return self
  */
 public function join($table, $on, $type = 'INNER', $prefix = true, $reset = false)
 {
     if ($reset) {
         $this->join = array();
     }
     $this->join[] = $type . " JOIN " . ($prefix ? Config::getSetting('db_table_prefix') : '') . $table . " " . $this->alias($table) . " on " . $on;
     return $this;
 }
Example #15
0
 /**
  * Clean and test 'namespace' parameter.
  *
  * @access	public
  * @param	string	Option passed to parameter.
  * @return	boolean	Success
  */
 public function _namespace($option)
 {
     global $wgContLang;
     $extraParams = explode('|', $option);
     foreach ($extraParams as $parameter) {
         $parameter = trim($parameter);
         $namespaceId = $wgContLang->getNsIndex($parameter);
         if ($namespaceId === false || is_array(Config::getSetting('allowedNamespaces')) && !in_array($parameter, Config::getSetting('allowedNamespaces'))) {
             //Let the user know this namespace is not allowed or does not exist.
             return false;
         }
         $data = $this->getParameter('namespace');
         $data[] = $namespaceId;
         $data = array_unique($data);
         $this->setParameter('namespace', $data);
         $this->setSelectionCriteriaFound(true);
     }
     return true;
 }
include 'layout/header.php';
?>

<div id="breadcrumb">
	<a href="index.php">Audition&nbsp;&#62;</a>&nbsp;<a href="admin.php">Administer Audition&nbsp;&#62;</a>&nbsp;Streaming Audio Setup
</div>
<?php 
$u = User::getCurrent();
if (!$u->isAdmin()) {
    Error::outputDialog('Return to Main Menu', 'index.php', 'Only an administrator may access administrator options.');
} else {
    if (db::isError($er)) {
        $er->outputList();
    }
    if (($_GET['task'] == 'edit' || $_GET['task'] == 'update') && User::isAdmin()) {
        $streamingAudioFilesPath = $_POST ? $_POST['streamingAudioFilesPath'] : $conf->getSetting('streamingAudioFilesPath');
        $streamingAudioServerURL = $_POST ? $_POST['streamingAudioServerURL'] : $conf->getSetting('streamingAudioServerURL');
        ?>
	
	<h1>edit streaming audio information:</h1>
	<div class="inset">
	<form id="edit_entry" action="<?php 
        echo $PHP_SELF;
        ?>
?task=update" method="post">
	<div class="edit-form">
	<strong>Path to Files</strong><br/>Note: This path must be writeable by the web server. Audio files configured for streaming will be placed in this location. <strong>Do not include a trailing slash on the directory path.</strong><br/>
	<input type="text" class="text" name="streamingAudioFilesPath" value="<?php 
        echo $streamingAudioFilesPath;
        ?>
" />
Example #17
0
 /**
  * Work through processed parameters and check for potential issues.
  *
  * @access	private
  * @return	void
  */
 private function doQueryErrorChecks()
 {
     /**************************/
     /* Parameter Error Checks */
     /**************************/
     $totalCategories = 0;
     if (is_array($this->parameters->getParameter('category'))) {
         foreach ($this->parameters->getParameter('category') as $comparisonType => $operatorTypes) {
             foreach ($operatorTypes as $operatorType => $categoryGroups) {
                 foreach ($categoryGroups as $categories) {
                     $totalCategories += count($categories);
                 }
             }
         }
     }
     if (is_array($this->parameters->getParameter('notcategory'))) {
         foreach ($this->parameters->getParameter('notcategory') as $comparisonType => $operatorTypes) {
             foreach ($operatorTypes as $operatorType => $categories) {
                 $totalCategories += count($categories);
             }
         }
     }
     //Too many categories.
     if ($totalCategories > Config::getSetting('maxCategoryCount') && !Config::getSetting('allowUnlimitedCategories')) {
         $this->logger->addMessage(\DynamicPageListHooks::FATAL_TOOMANYCATS, Config::getSetting('maxCategoryCount'));
         return false;
     }
     //Not enough categories.(Really?)
     if ($totalCategories < Config::getSetting('minCategoryCount')) {
         $this->logger->addMessage(\DynamicPageListHooks::FATAL_TOOFEWCATS, Config::getSetting('minCategoryCount'));
         return false;
     }
     //Selection criteria needs to be found.
     if (!$totalCategories && !$this->parameters->isSelectionCriteriaFound()) {
         $this->logger->addMessage(\DynamicPageListHooks::FATAL_NOSELECTION);
         return false;
     }
     //ordermethod=sortkey requires ordermethod=category
     //Delayed to the construction of the SQL query, see near line 2211, gs
     //if (in_array('sortkey',$aOrderMethods) && ! in_array('category',$aOrderMethods)) $aOrderMethods[] = 'category';
     $orderMethods = (array) $this->parameters->getParameter('ordermethod');
     //Throw an error in no categories were selected when using category sorting modes or requesting category information.
     if ($totalCategories == 0 && (in_array('categoryadd', $orderMethods) || $this->parameters->getParameter('addfirstcategorydate') === true)) {
         $this->logger->addMessage(\DynamicPageListHooks::FATAL_CATDATEBUTNOINCLUDEDCATS);
         return false;
     }
     //No more than one type of date at a time!
     //@TODO: Can this be fixed to allow all three later after fixing the article class?
     if (intval($this->parameters->getParameter('addpagetoucheddate')) + intval($this->parameters->getParameter('addfirstcategorydate')) + intval($this->parameters->getParameter('addeditdate')) > 1) {
         $this->logger->addMessage(\DynamicPageListHooks::FATAL_MORETHAN1TYPEOFDATE);
         return false;
     }
     // the dominant section must be one of the sections mentioned in includepage
     if ($this->parameters->getParameter('dominantsection') > 0 && count($this->parameters->getParameter('seclabels')) < $this->parameters->getParameter('dominantsection')) {
         $this->logger->addMessage(\DynamicPageListHooks::FATAL_DOMINANTSECTIONRANGE, count($this->parameters->getParameter('seclabels')));
         return false;
     }
     // category-style output requested with not compatible order method
     if ($this->parameters->getParameter('mode') == 'category' && !array_intersect($orderMethods, ['sortkey', 'title', 'titlewithoutnamespace'])) {
         $this->logger->addMessage(\DynamicPageListHooks::FATAL_WRONGORDERMETHOD, 'mode=category', 'sortkey | title | titlewithoutnamespace');
         return false;
     }
     // addpagetoucheddate=true with unappropriate order methods
     if ($this->parameters->getParameter('addpagetoucheddate') && !array_intersect($orderMethods, ['pagetouched', 'title'])) {
         $this->logger->addMessage(\DynamicPageListHooks::FATAL_WRONGORDERMETHOD, 'addpagetoucheddate=true', 'pagetouched | title');
         return false;
     }
     // addeditdate=true but not (ordermethod=...,firstedit or ordermethod=...,lastedit)
     //firstedit (resp. lastedit) -> add date of first (resp. last) revision
     if ($this->parameters->getParameter('addeditdate') && !array_intersect($orderMethods, ['firstedit', 'lastedit']) && ($this->parameters->getParameter('allrevisionsbefore') || $this->parameters->getParameter('allrevisionssince') || $this->parameters->getParameter('firstrevisionsince') || $this->parameters->getParameter('lastrevisionbefore'))) {
         $this->logger->addMessage(\DynamicPageListHooks::FATAL_WRONGORDERMETHOD, 'addeditdate=true', 'firstedit | lastedit');
         return false;
     }
     // adduser=true but not (ordermethod=...,firstedit or ordermethod=...,lastedit)
     /**
      * @todo allow to add user for other order methods.
      * The fact is a page may be edited by multiple users. Which user(s) should we show? all? the first or the last one?
      * Ideally, we could use values such as 'all', 'first' or 'last' for the adduser parameter.
      */
     if ($this->parameters->getParameter('adduser') && !array_intersect($orderMethods, ['firstedit', 'lastedit']) && !$this->parameters->getParameter('allrevisionsbefore') && !$this->parameters->getParameter('allrevisionssince') && !$this->parameters->getParameter('firstrevisionsince') && !$this->parameters->getParameter('lastrevisionbefore')) {
         $this->logger->addMessage(\DynamicPageListHooks::FATAL_WRONGORDERMETHOD, 'adduser=true', 'firstedit | lastedit');
         return false;
     }
     if ($this->parameters->getParameter('minoredits') && !array_intersect($orderMethods, ['firstedit', 'lastedit'])) {
         $this->logger->addMessage(\DynamicPageListHooks::FATAL_WRONGORDERMETHOD, 'minoredits', 'firstedit | lastedit');
         return false;
     }
     /**
      * If including the Uncategorized, we need the 'dpl_clview': VIEW of the categorylinks table where we have cl_to='' (empty string) for all uncategorized pages. This VIEW must have been created by the administrator of the mediawiki DB at installation. See the documentation.
      */
     if ($this->parameters->getParameter('includeuncat')) {
         //If the view is not there, we can't perform logical operations on the Uncategorized.
         if (!$this->DB->tableExists('dpl_clview')) {
             $sql = 'CREATE VIEW ' . $this->tableNames['dpl_clview'] . " AS SELECT IFNULL(cl_from, page_id) AS cl_from, IFNULL(cl_to, '') AS cl_to, cl_sortkey FROM " . $this->tableNames['page'] . ' LEFT OUTER JOIN ' . $this->tableNames['categorylinks'] . ' ON ' . $this->tableNames['page'] . '.page_id=cl_from';
             $this->logger->addMessage(\DynamicPageListHooks::FATAL_NOCLVIEW, $this->tableNames['dpl_clview'], $sql);
             return false;
         }
     }
     //add*** parameters have no effect with 'mode=category' (only namespace/title can be viewed in this mode)
     if ($this->parameters->getParameter('mode') == 'category' && ($this->parameters->getParameter('addcategories') || $this->parameters->getParameter('addeditdate') || $this->parameters->getParameter('addfirstcategorydate') || $this->parameters->getParameter('addpagetoucheddate') || $this->parameters->getParameter('incpage') || $this->parameters->getParameter('adduser') || $this->parameters->getParameter('addauthor') || $this->parameters->getParameter('addcontribution') || $this->parameters->getParameter('addlasteditor'))) {
         $this->logger->addMessage(\DynamicPageListHooks::WARN_CATOUTPUTBUTWRONGPARAMS);
     }
     //headingmode has effects with ordermethod on multiple components only
     if ($this->parameters->getParameter('headingmode') != 'none' && count($orderMethods) < 2) {
         $this->logger->addMessage(\DynamicPageListHooks::WARN_HEADINGBUTSIMPLEORDERMETHOD, $this->parameters->getParameter('headingmode'), 'none');
         $this->parameters->setParameter('headingmode', 'none');
     }
     //The 'openreferences' parameter is incompatible with many other options.
     if ($this->parameters->isOpenReferencesConflict() && $this->parameters->getParameter('openreferences') === true) {
         $this->logger->addMessage(\DynamicPageListHooks::FATAL_OPENREFERENCES);
         return false;
     }
     return true;
 }
Example #18
0
 /**
  * Constructor.
  *
  * Provide a Query object to run this query and return found objects.
  * Provide an integer to look for this ID (or $column).
  * Provide an array to create an new object filled with these values.
  *
  * @param mixed $mixed  What to get?
  * @param mixed $column Column to search in.
  *
  * @return void
  */
 public function __construct($mixed = null, $column = 'id')
 {
     //set modelname
     $this->modelName = get_called_class();
     //set table name
     if (empty($this->tableName)) {
         $this->tableName = Config::getSetting('db_table_prefix') . strtolower($this->modelName);
     }
     //cache fields
     parent::__construct();
     //determine action
     if ($mixed !== null) {
         if (is_object($mixed) && get_class($mixed) == 'Query' && Clockwork::isModuleLoaded('Data/Query')) {
             if ($column == 1) {
                 $this->values = $mixed->from(substr($this->tableName, strlen(Config::getSetting('db_table_prefix'))), null, true, true)->limit(1)->run(1);
                 if (empty($this->values)) {
                     $this->setError(404, 'Object not found');
                 }
             } else {
                 $this->objects = $this->createObjects($mixed->from(substr($this->tableName, strlen(Config::getSetting('db_table_prefix'))), null, true, true)->run());
             }
         } else {
             if (is_array($mixed)) {
                 foreach ($mixed as $key => $value) {
                     $this->set($key, $value);
                 }
             } else {
                 if (Clockwork::isModuleLoaded('Data/Query')) {
                     $query = new Query();
                     $this->values = $query->from(strtolower($this->modelName))->where($column . " = '" . $mixed . "'")->run(1);
                     if (empty($this->values)) {
                         $this->setError(404, 'Object not found');
                     }
                 }
             }
         }
     }
 }
Example #19
0
    try {
        CSRF::check($_POST['CSRF-key']);
    } catch (Exception $e) {
        unset($_POST);
        $_POST = [];
    }
}
// --- locale
if (Config::getSetting('locale', false)) {
    setlocale(LC_ALL, Config::getSetting('locale'));
}
// --- Login
if (Clockwork::isModuleLoaded('Login') && !defined('CW_CRON') && !defined('CW_SKIP_LOGIN')) {
    new Login();
    $_loginpage = Config::getSetting('login_loginpage', false, false) ? Config::getSetting('login_loginpage') : 'login/';
    $_allowed = Config::getSetting('login_no_login', false, false) ? Config::getSetting('login_no_login') : [];
    $_allowed[] = $_loginpage;
    if (!Login::getUser() && !in_array(substr(strpos($_SERVER['REQUEST_URI'], '?') !== false ? stristr($_SERVER['REQUEST_URI'], '?', true) : $_SERVER['REQUEST_URI'], 1), $_allowed)) {
        redirect($_loginpage);
    }
}
// --- app
if (!defined('CW_CRON') && !defined('CW_OVERRIDE_TEMPLATE')) {
    if (Config::getSetting('load_template_engine', false, true) && !isset($template)) {
        $template = new Template();
        include_once APP_DIR . 'index.php';
        $template->loadFromURL();
    } else {
        include_once APP_DIR . 'index.php';
    }
}
Example #20
0
 /**
  * Return a hashed string.
  * @author Jelle van der Coelen
  * @package Clockwork/Library/General
  *
  * @param string  $str  String to hash.
  * @param boolean $salt Include salt.
  *
  * @return string
  */
 function hashStr($str, $salt = false)
 {
     return hash(Config::getSetting('hash_algo', false, 'sha512'), ($salt ? Config::getSetting('salt') : '') . $str);
 }