Example #1
3
 protected function __construct()
 {
     $this->mail = new PHPMailer_Mail();
     $Config = Clap::getService('Config');
     if ($Config->getOr('MAIL', 'from_address', false, $address)) {
         $this->mail->setFrom($address, utf8_decode($Config->getOr('MAIL', 'from_name', '')));
     }
     if ($Config->getOr('MAIL', 'reply_to', false, $reply)) {
         $this->mail->AddReplyTo($reply);
     }
     if ($Config->getOr('MAIL', 'is_html', false, $html)) {
         $this->mail->IsHTML($html);
     }
     $this->mail->CharSet = 'ISO-8859-15';
     // 'utf8';
 }
Example #2
2
 public function getFiles($name)
 {
     if (!isset($this->datas[$name])) {
         throw new Exception('Cannot create FileUpload Object with name "' . $name . '", no input (of type "file") has been submited with this name');
         return false;
     }
     $SFileUpload = Clap::getService('FileUpload');
     // Simple upload (return a FileUpload object) :
     if (isset($this->datas[$name]['name'])) {
         if ($SFileUpload->instanceExists($name)) {
             return $SFileUpload->getInstance($name);
         } else {
             $inst = $SFileUpload->getNew($name, $this->datas[$name]);
             $inst->setInstanceId($name);
             return $inst;
         }
     }
     // Multiple upload (return an Array) :
     $result = array();
     foreach ($this->datas[$name] as $index => $datas) {
         $id = $name . '[' . $index . ']';
         if ($SFileUpload->instanceExists($id)) {
             $result[] = $SFileUpload->getInstance($id);
         } else {
             $inst = $SFileUpload->getNew($id, $datas);
             $inst->setInstanceId($id);
             $result[] = $inst;
         }
     }
     return $result;
 }
Example #3
2
 public function getErrorPage($type = 404)
 {
     $param = 'page_error_' . $type;
     $page = $this->get('ERRORS', $param, true);
     if (!Clap::getService('Cache')->fileExists($page)) {
         throw new Exception('Config file "' . $this->configFile . '" invalid, [ERRORS]:' . $param . ' : file "' . $page . '" not found');
     }
     return $page;
 }
Example #4
1
 public function save()
 {
     if ($this->active && $this->update) {
         $Root = Clap::getService('Site')->getRootPath();
         $datas = array_keys($this->files);
         sort($datas);
         file_put_contents($Root . '/' . self::FILE_EXISTS_PATH, implode(PHP_EOL, $datas));
     }
 }
Example #5
0
 protected function __construct()
 {
     $this->Site = Clap::getService('Site');
     $this->Cache = Clap::getService('Cache');
     $this->Config = Clap::getService('Config');
     $this->cdsi = $this->Config->get('SESSION', 'clap_datas_index', true);
     $this->loadLang();
 }
Example #6
0
 static function getTemplate()
 {
     $Site = Clap::getService('Site');
     $siteUrl = $Site->getSiteUrl();
     $pageUrl = $Site->getPageUrl();
     $controller = $Site->getPage();
     $errdir = 'pages/controllers/errors/';
     $pageViews = array($siteUrl => 'index.html');
     $errorViews = array($errdir . 'not-found.php' => 'errors/not-found.html', $errdir . 'forbidden.php' => 'errors/forbidden.html', $errdir . 'script-error.php' => 'errors/script-error.html');
     if (isset($errorViews[$controller])) {
         return $errorViews[$controller];
     }
     if (isset($pageViews[$pageUrl])) {
         return $pageViews[$pageUrl];
     }
     throw new Exception("Unable to find a template for this page URL");
 }
Example #7
0
 public function render(array $datas = array(), $compress = false)
 {
     $Site = Clap::getService('Site');
     $Lang = Clap::getService('Lang');
     $t = microtime(true);
     $infos = array('_SITE' => array('url' => $Site->getUrl(), 'page' => $Site->getPage(), 'baseurl' => $Site->getSiteUrl(), 'baseurl_encoded' => $Site->getSiteUrl(true), 'hosturl' => $Site->getHostUrl(), 'route' => $Site->getRoutePage(), 'lang' => $Lang->getCode()), '_SESSION' => $_SESSION, '_POST' => $_POST, '_GET' => $_GET);
     $datas = array_replace_recursive($infos, $datas);
     $render = self::$twig->render($this->file, $datas);
     $mailto = preg_quote('mailto:');
     // $render = preg_replace('`(href|src|action)="~/?([^"]*)"`i', '$1="'.$Site->getSiteUrl(true).'$2"', $render);
     // $render = preg_replace('`(href|src|action)="((?!https?://|mailto:|'.$mailto.'|#|/|./|../|").*)"`Uis', '$1="'.$Site->getSiteUrl(true).'$2"', $render);
     $render = preg_replace("`<!--[ ]+?(?!\\[if).+-->`Uis", '', $render);
     if ($compress) {
         $render = preg_replace("`\\s+\n`", "\n", $render);
         $render = str_replace("\t", "", $render);
     }
     self::$time = microtime(true) - $t;
     self::$exec++;
     return $render;
 }
Example #8
0
<?php

/*** Script ***/
$Tag = Clap::getService('Tag');
$options = array(1 => 'a', 2 => 'b', 3 => 'c', 4 => 'd');
function optionAttrs($index, $value)
{
    if ($index % 2 == 0) {
        return array('disabled' => 'disabled', 'style' => 'color:red;');
    }
    return array();
}
$select = $Tag->getNew('select', array('name' => 'selectname'), array('options' => $options, 'useIndex' => true, 'firstOption' => array('' => '-'), 'OptionAttrsCallback' => 'optionAttrs'));
echo $select;
/*** Template ***/
Page::displayTemplate();
Example #9
0
 public static function getService($service, $user = false)
 {
     $service = $user ? $service : 'Clap_' . $service;
     if (isset(self::$instances[$service])) {
         return self::$instances[$service];
     }
     $file = Clap::classFileExists($service);
     if ($file['found'] || class_exists($service)) {
         if (is_a($service, 'Clap_ServiceInstance', true)) {
             return self::$instances[$service] = $service::getService();
         } else {
             if (is_a($service, 'Clap_ServiceSingleton', true)) {
                 return $service::getService(self::$instances, $service);
             } else {
                 throw new Exception('Class "' . $service . '" does not extends neither "Clap_ServiceInstance" nor "Clap_ServiceSingleton"');
             }
         }
     } else {
         throw new Exception('Unable to load class "' . $file['class'] . '", classfile "' . $file['path'] . '" was not found');
     }
     return false;
 }
Example #10
0
 public function prepare($sql)
 {
     if ($this->PDO == null) {
         throw new Exception("Database has been disconnected, use reconnect() to reconnect to database first");
         return false;
     }
     $sql = trim($sql);
     $SQuery = Clap::getService('Query');
     if ($SQuery->instanceExists($sql)) {
         $inst = $SQuery->getInstance($sql);
     } else {
         $inst = $SQuery->getNew($this, $this->PDO, $sql);
         $inst->setInstanceId($sql);
     }
     return $inst;
 }
Example #11
0
 public function close($msg = '')
 {
     global $_SITE;
     $this->closing = true;
     if ($msg != '') {
         echo $msg;
     }
     if (Clap::isClassLoaded('Clap_Database')) {
         $exec = Clap_Database::$exec;
         $time = Clap_Database::$time;
         $SqlTime = str_pad(round(array_sum($time), 3), 5, '0') . 's';
         foreach ($time as &$t) {
             if ($t != 0) {
                 $t = str_pad(round($t, 4), 6, '0');
             }
         }
         $SQLDatas = $exec['connect'] . ' connexion' . ($exec['connect'] > 1 ? 's' : '') . ' (' . $time['connect'] . 's), ' . $exec['parse'] . '/' . $exec['request'] . ' quer' . ($exec['request'] > 1 ? 'ies' : 'y') . ' (formating : ' . $time['parse'] . 's, requesting : ' . $time['request'] . 's)';
     } else {
         $SQLDatas = 'No database connexion has been loaded on this page';
         $SqlTime = '0.000s';
     }
     if (Clap::isClassLoaded('Clap_Template')) {
         $exec = Clap_Template::$exec;
         $time = Clap_Template::$time == 0 ? 0 : str_pad(round(Clap_Template::$time, 3), 5, '0');
         $TwigTime = $time . 's';
     } else {
         $TwigTime = '0.000s';
     }
     $TotalTime = str_pad(round(microtime(true) - $_SITE['EXEC-TIME'], 3), 5, '0');
     $ClapTime = str_pad(round($TotalTime - $TwigTime - $SqlTime, 3), 5, '0');
     // Write debug datas at the end of HTML source :
     if (!$this->redirecting && !$this->ajax && pathinfo($this->page, PATHINFO_EXTENSION) == 'php') {
         echo "\n\n<!-- \n\n" . " URL : \"" . $this->getUrl() . "\",\n\n" . " BaseUrl : \"" . $this->getSiteUrl() . "\", \n\n" . " Route : \"" . $this->getRoutePage() . "\", \n\n" . ($this->getRoutePage() != $this->getPage() ? " Redirection : \"" . $this->getPage() . "\", \n\n" : '') . " Language : \"" . $this->Lang->getCode() . "\", \n\n" . " Cache : " . ($this->Cache->isActive() ? 'Enabled' : 'Disabled') . ", \n\n" . " Config : \"" . $this->Config->getConfigFile() . "\", \n\n" . " SQL : " . $SQLDatas . ", \n\n" . " Execution : Twig (" . $TwigTime . "), SQL (" . $SqlTime . "), Framework (" . $ClapTime . "s) >> Total (" . $TotalTime . "s) \n\n" . "-->\n";
     }
     // On redirect, some services have to close early :
     if ($this->redirecting) {
         Clap::getService('Session')->close();
         $this->Cache->save();
         if ($this->redirectCode != false) {
             header('Location: ' . $this->redirectUrl, $this->redirectCode);
         } else {
             header('Location: ' . $this->redirectUrl);
         }
     }
     // Send Contents & Headers to browser :
     if (!headers_sent() && ob_get_level() > 0) {
         while (ob_get_level() > 1) {
             ob_end_flush();
         }
         $content = ob_get_contents();
         ob_clean();
         echo $content;
         header('Content-length: ' . ob_get_length());
         ob_flush();
         flush();
         ob_end_flush();
     }
     exit;
     // Classes are destructed after the content have been flushed.
 }
Example #12
0
 protected function __construct()
 {
     $this->db = Clap::getService('Database')->getInstance();
 }
Example #13
0
<?php 
### { INIT EXEC TIME } ###
$_SITE['EXEC-TIME'] = microtime(true);
### { KERNEL INCLUSION } ###
require_once 'server/libraries/Clap/Clap.php';
### { CLAP LOADER } ###
Clap::init();
Example #14
0
 private static function redirectError()
 {
     $Config = Clap::getService('Config');
     $Site = Clap::getService('Site');
     try {
         $pagefile = $Config->get('ERRORS', 'page_error_php', true);
     } catch (Exception $e) {
         $Site->close($e->getMessage());
     }
     self::$fatalError = true;
     try {
         if (Clap::getService('Cache')->fileExists($pagefile)) {
             ob_clean();
             set_error_handler('Clap_Error::errorHandler');
             $Site->insert($pagefile);
             $Site->close();
         } else {
             throw new Exception('Controller "' . $pagefile . '" is missing (check param [ERRORS]:page_error_php in "' . $Config->getConfigFile() . '"), cannot load default error page');
         }
     } catch (Exception $e) {
         self::exceptionHandler($e);
     }
 }