コード例 #1
0
ファイル: Page.php プロジェクト: kemosabhay/Lightning
 public static function getSitemapUrls()
 {
     $urls = array();
     // Load the pages.
     $web_root = Configuration::get('web_root');
     $pages = static::selectAllPages();
     foreach ($pages as $p) {
         if ($p['last_update'] == 0) {
             $p['last_update'] = time();
         }
         switch ($p['frequency']) {
             case 0:
                 $fr = "daily";
                 break;
             case 1:
                 $fr = "weekly";
                 break;
             case 2:
                 $fr = "monthly";
                 break;
             case 3:
                 $fr = "annually";
                 break;
         }
         $urls[] = array('loc' => $web_root . "/{$p['url']}.html", 'lastmod' => date('Y-m-d', $p['last_update']), 'changefreq' => $fr, 'priority' => $p['priority'] / 100);
     }
     return $urls;
 }
コード例 #2
0
ファイル: Server.php プロジェクト: kemosabhay/Lightning
 /**
  * Initialize the object.
  */
 public function __construct()
 {
     parent::__construct();
     $this->action_namespace = Configuration::get('communicator.server.action_namespace', 'Source\\Actions');
     $this->verbose = Configuration::get('communicator.server.debug', false);
     $this->shutdown_function = Configuration::get('communicator.server.debug');
 }
コード例 #3
0
ファイル: Contact.php プロジェクト: kemosabhay/Lightning
 /**
  * Send a posted contact request to the site admin.
  */
 public function postSendMessage()
 {
     // Make sure the sender's email address is valid.
     if (!($sender_email = Request::post('email', 'email'))) {
         Messenger::error('Please enter a valid email address.');
         return $this->get();
     }
     if (!ReCaptcha::verify()) {
         Messenger::error('You did not correctly enter the captcha code.');
         return $this->get();
     }
     $subject = Configuration::get('contact.subject');
     $body = "\nName: {$_POST['name']}\nEmail: {$sender_email}\nMessage:\n{$_POST['message']}";
     $to_addresses = Configuration::get('contact.to');
     $mailer = new Mailer();
     foreach ($to_addresses as $to) {
         $mailer->to($to);
     }
     $sent = $mailer->from($sender_email)->subject($subject)->message($body)->send();
     if (!$sent) {
         Messenger::error('Your message could not be sent. Please try again later');
         return $this->get();
     } else {
         // Send an email to to have them test for spam.
         if ($auto_responder = Configuration::get('contact.auto_responder')) {
             $auto_responder_mailer = new Mailer();
             $result = $auto_responder_mailer->sendOne($auto_responder, UserModel::loadByEmail($sender_email) ?: new UserModel(array('email' => $sender_email)));
             if ($result && Configuration::get('contact.spam_test')) {
                 // Set the notice.
                 Navigation::redirect('/message', array('msg' => 'spam_test'));
             }
         }
         Navigation::redirect('/message', array('msg' => 'contact_sent'));
     }
 }
コード例 #4
0
ファイル: CSS.php プロジェクト: kemosabhay/Lightning
    public static function render() {
        $output = '';

        foreach (self::$included_files as &$file) {
            if (empty($file['rendered'])) {
                $file_name = $file['file'] . '?v=' . Configuration::get('minified_version', 0);
                // TODO: add $file[1] for media type. media="screen"
                $output .= '<link rel="stylesheet" type="text/css" href="' . $file_name . '" />';
                $file['rendered'] = true;
            }
        }

        if (!empty(self::$inline_styles)) {
            $output .= '<style>';
            foreach (self::$inline_styles as &$style) {
                if (empty($style['rendered'])) {
                    $output .= $style . "\n\n";
                    $style['rendered'] = true;
                }
            }
            $output .= '</style>';
        }

        return $output;
    }
コード例 #5
0
ファイル: Google.php プロジェクト: kemosabhay/Lightning
 public static function renderLinks()
 {
     $settings = Configuration::get('social.google');
     if (!empty($settings['like'])) {
         JS::add('https://apis.google.com/js/platform.js', true);
         $output = '<g:plusone size="medium" annotation="none"></g:plusone>';
         return $output;
     }
 }
コード例 #6
0
ファイル: Cache.php プロジェクト: kemosabhay/Lightning
 protected static function getType($ttl = self::TEMPORARY, $size = self::MEDIUM)
 {
     if ($ttl == self::TEMPORARY) {
         // Static Cache
         return new StaticCache();
     } elseif ($ttl == self::PERMANENT) {
         if ($class = Configuration::get('cache.permanent.handler')) {
             return new $class();
         } else {
             return new FileCache();
         }
     }
 }
コード例 #7
0
ファイル: Facebook.php プロジェクト: kemosabhay/Lightning
 /**
  * Render the like and share links.
  */
 public static function renderLinks()
 {
     $settings = Configuration::get('social.facebook');
     if (!empty($settings['share']) || !empty($settings['like'])) {
         JS::startup("!function(d, s, id) {\n  var js, fjs = d.getElementsByTagName(s)[0];\n  if (d.getElementById(id)) return;\n  js = d.createElement(s); js.id = id;\n  js.src = '//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.3';\n  fjs.parentNode.insertBefore(js, fjs);\n}(document, 'script', 'facebook-jssdk');");
         Template::getInstance()->addFooter('<div id="fb-root"></div>');
         $output = '';
         if (!empty($settings['share'])) {
             $output .= '<div class="fb-share-button" data-layout="button"></div>';
         }
         if (!empty($settings['like']) && !empty($settings['page'])) {
             $output .= '<div class="fb-like" data-href="https://facebook.com/' . $settings['page'] . '" data-layout="button" data-action="like" data-show-faces="false" data-share="false"></div>';
         }
         return $output;
     }
 }
コード例 #8
0
ファイル: Track.php プロジェクト: kemosabhay/Lightning
 /**
  * The main page handler, outputs a 1x1 pixel image.
  */
 public function get()
 {
     if ($t = Request::get('t', 'encrypted')) {
         // Track an encrypted link.
         if (!Tracker::trackLink($t)) {
             Logger::error('Failed to track encrypted link: ' . Encryption::aesDecrypt($t, Configuration::get('tracker.key')));
         }
     } elseif (Configuration::get('tracker.allow_unencrypted') && ($tracker = Request::get('tracker', 'int'))) {
         // Track an unencrypted link.
         $user = Request::get('user', 'int') ?: ClientUser::createInstance()->id;
         $sub = Request::get('sub', 'int');
         Tracker::trackEventID($tracker, $sub, $user);
     }
     // Output a single pixel image.
     header('Content-Type: image/png');
     echo base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=');
     exit;
 }
コード例 #9
0
 public function get()
 {
     ClientUser::requireAdmin();
     $template = Template::getInstance();
     $config_files = Config::getConfigurations();
     $config_data = array();
     foreach ($config_files as $source => $file) {
         $config_data[$source] = Config::getConfigurationData($file);
     }
     foreach ($config_data as $source => &$config) {
         array_walk_recursive($config, function (&$val) use($source) {
             if (!is_array($val)) {
                 $val = array('#source' => array($source), '#value' => array($val));
             }
         });
     }
     $config_data = call_user_func_array('array_merge_recursive', $config_data);
     $output = '<ul>' . $this->processSettingsForm($config_data) . '</ul>';
     $template->set('rendered_content', $output);
 }
コード例 #10
0
ファイル: Splash.php プロジェクト: kemosabhay/Lightning
 public function get()
 {
     $page = Request::getLocation();
     $template_page = Configuration::get('splash.pages.' . $page);
     // No template found.
     if (empty($template_page) || is_array($template_page) && empty($template_page['template'])) {
         Output::error('Page not found.');
     } else {
         $this->page = is_array($template_page) ? $template_page['template'] : $template_page;
     }
     // Add any CSS or JS files.
     if (is_array($template_page)) {
         if (!empty($template_page['css'])) {
             CSS::add($template_page['css']);
         }
         if (!empty($template_page['js'])) {
             JS::add($template_page['js']);
         }
     }
 }
コード例 #11
0
ファイル: User.php プロジェクト: kemosabhay/Lightning
 /**
  * Validates POST data (email, password and confirmation).
  * 
  * @param string $email
  * @param string $pass
  *
  * @return boolean
  */
 protected function validateData($email, $pass)
 {
     // Default value
     $result = TRUE;
     // Are all fields filled?
     if (is_null($email) or is_null($pass)) {
         Messenger::error('Please fill out all the fields');
         $result = FALSE;
     }
     // Is email correct?
     if ($email === FALSE) {
         Messenger::error('Please enter a valid email');
         $result = FALSE;
     }
     // Are passwords strong enough? Check its length
     $min_password_length = Configuration::get('user.min_password_length');
     if (strlen($pass) < $min_password_length) {
         Messenger::error("Passwords must be at least {$min_password_length} characters");
         $result = FALSE;
     }
     return $result;
 }
コード例 #12
0
ファイル: OptIn.php プロジェクト: kemosabhay/Lightning
 public function post()
 {
     if ($name = Request::post('name', '', '', '')) {
         $name_parts = explode(' ', $name, 2);
         $name = array('first' => $name_parts[0]);
         if (!empty($name_parts[1])) {
             $name['last'] = $name_parts[1];
         }
     } else {
         // Add the user to the system.
         $name = array('first' => Request::post('first', '', '', ''), 'last' => Request::post('last', '', '', ''));
     }
     $email = Request::post('email', 'email');
     $user = User::addUser($email, $name);
     // Add the user to the mailing list.
     $default_list = Configuration::get('mailer.default_list');
     $mailing_list = Request::post('list_id', 'int', null, $default_list);
     if (!empty($mailing_list)) {
         $user->subscribe($mailing_list);
     }
     Navigation::redirect(Request::post('redirect') ?: '/message?msg=optin');
 }
コード例 #13
0
ファイル: bootstrap.php プロジェクト: kemosabhay/Lightning
 /**
  * A custom class loader.
  *
  * @param string $classname
  */
 public static function classAutoloader($classname)
 {
     // TODO: This can probably be optimized.
     if (empty(self::$loadedClasses[$classname]) && $classname != 'Lightning\\Tools\\Configuration' && $classname != 'Lightning\\Tools\\Data') {
         if (!self::$loaded) {
             // Load the class definitions.
             self::$classes = Configuration::get('classes');
             self::$overridable = Configuration::get('overridable');
             self::$loaded = true;
         }
         if (!empty(self::$classes[$classname])) {
             // Load an override class and override it.
             $overridden_name = 'Overridden\\' . $classname;
             self::$overrides[$overridden_name] = $overridden_name;
             // Load the Lightning version in the Overridden namespace.
             self::loadClassFile($classname);
             // Load the overidden version in the Source namespace.
             self::loadClassFile(self::$classes[$classname]);
             // Alias the Lightning namespace to the Source namespace.
             class_alias(self::$classes[$classname], $classname);
             self::$loadedClasses[$classname] = $classname;
             return;
         }
         if (isset(self::$overrides[$classname])) {
             return;
         }
         $class_file = str_replace('Overridable\\', '', $classname);
         if (isset(self::$overridable[$classname]) || isset(self::$overridable[$class_file])) {
             self::loadClassFile($class_file);
             self::$loadedClasses[$class_file] = $class_file;
             class_alias(self::$overridable[$class_file], $class_file);
             return;
         }
     }
     self::$loadedClasses[$classname] = $classname;
     self::loadClassFile($classname);
 }
コード例 #14
0
ファイル: User.php プロジェクト: kemosabhay/Lightning
 /**
  * Registers user
  * 
  * @param string $email email
  * @param string $pass password
  * @return Array
  *   When successful:
  *      [Status, new user id]
  *   When not:
  *      [Status, error short code]
  *
  * @todo This should return the user object, with other data contained inside.
  */
 public static function register($email, $pass)
 {
     // Save current user for further anonymous check
     $user = ClientUser::getInstance();
     $previous_user = $user->id;
     // Try to create a user or abort with error message
     $res = self::create($email, $pass);
     if ($res['success']) {
         self::login($email, $pass);
         $user = ClientUser::getInstance();
         $user->subscribe(Configuration::get('mailer.default_list'));
         // Merge with a previous anon user if necessary.
         if ($previous_user != 0) {
             // TODO: This should only happen if the user is a placeholder.
             $user->merge_users($previous_user);
         }
         // Success
         return ['success' => true, 'data' => ['user_id' => ClientUser::getInstance()->id]];
     } else {
         // Error
         return ['success' => false, 'error' => $res['error']];
     }
 }
コード例 #15
0
ファイル: CLI.php プロジェクト: kemosabhay/Lightning
 /**
  * Create the object and set the logger.
  */
 public function __construct()
 {
     Logger::setLog(Configuration::get('cli.log'));
 }
コード例 #16
0
ファイル: CMS.php プロジェクト: kemosabhay/Lightning
 public static function initSettings()
 {
     if (!isset(self::$settings)) {
         self::$settings = Configuration::get('cms', []) + ['location' => 'images'];
     }
 }
コード例 #17
0
ファイル: Page.php プロジェクト: kemosabhay/Lightning
    /**
     * Prepare the output and tell the template to render.
     */
    public function output() {
        // Send globals to the template.
        $template = Template::getInstance();

        if (!empty($this->page)) {
            $template->set('content', $this->page);
        }

        $template->set('google_analytics_id', Configuration::get('google_analytics_id'));

        // TODO: These should be called directly from the template.
        $template->set('errors', Messenger::getErrors());
        $template->set('messages', Messenger::getMessages());

        $template->set('site_name', Configuration::get('site.name'));
        $template->set('blog', Blog::getInstance());
        JS::set('active_nav', $this->nav);
        $template->render($this->template);
    }
コード例 #18
0
ファイル: Random.php プロジェクト: kemosabhay/Lightning
 public function __construct()
 {
     $this->engine = Configuration::get('random_engine');
 }
コード例 #19
0
ファイル: Database.php プロジェクト: kemosabhay/Lightning
 /**
  * Create a database instance with the default database.
  *
  * @return Database
  *   The database object.
  */
 public static function createInstance()
 {
     return new self(Configuration::get('database'));
 }
コード例 #20
0
ファイル: RestClient.php プロジェクト: kemosabhay/Lightning
 /**
  * Initialize some vars.
  */
 function __construct($server_address)
 {
     $this->serverAddress = $server_address;
     $this->verbose = Configuration::get('debug', false);
 }
コード例 #21
0
ファイル: FileCache.php プロジェクト: kemosabhay/Lightning
 public function __construct()
 {
     $this->directory = Configuration::get('temp_dir');
     parent::__construct();
 }
コード例 #22
0
ファイル: Twitter.php プロジェクト: kemosabhay/Lightning
 /**
  * Render the follow and tweet links.
  */
 public static function renderLinks()
 {
     $settings = Configuration::get('social.twitter');
     if (!empty($settings['follow']) || !empty($settings['share'])) {
         // Add the initialization script.
         JS::startup("!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');");
         $return = '';
         if (!empty($settings['share'])) {
             $via = !empty($settings['account']) ? ' data-via="' . $settings['account'] . '"' : '';
             $related = !empty($settings['share-hashtag']) ? ' data-related="' . $settings['share-hashtag'] . '"' : '';
             $return .= '<a href="https://twitter.com/share" class="twitter-share-button" data-count="none"' . $via . $related . ' >Tweet</a>';
         }
         if (!empty($settings['follow']) && !empty($settings['account'])) {
             $return .= '<a href="https://twitter.com/' . $settings['account'] . '" class="twitter-follow-button" data-show-count="false">Follow @' . $settings['account'] . '</a>';
         }
     }
     return $return;
 }
コード例 #23
0
 public function relativeFilename($absoluteUrl)
 {
     $remoteName = self::getRemoteName($this->root);
     $remoteName[0] = Configuration::get('containers.' . $remoteName[0] . '.url');
     return str_replace($remoteName[0] . '/' . $remoteName[1] . '/', '', $absoluteUrl);
 }
コード例 #24
0
ファイル: Page.php プロジェクト: kemosabhay/Lightning
 public function get()
 {
     $user = ClientUser::getInstance();
     $template = Template::getInstance();
     $request = Request::getLocation();
     $content_locator = empty($request) ? 'index' : Request::getFromURL('/(.*)\\.html$/') ?: '404';
     // Determine if the user can edit this page.
     $template->set('editable', $user->isAdmin());
     // Set the page template.
     $template->set('content', 'page');
     // LOAD PAGE DETAILS
     if ($full_page = $this->loadPage($content_locator)) {
         header('HTTP/1.0 200 OK');
         if (Configuration::get('page.modification_date') && $full_page['last_update'] > 0) {
             header("Last-Modified: " . gmdate("D, d M Y H:i:s", $full_page['last_update']) . " GMT");
         }
     } elseif ($this->new) {
         $full_page['title'] = '';
         $full_page['keywords'] = '';
         $full_page['description'] = '';
         $full_page['url'] = '';
         $full_page['body'] = 'This is your new page.';
         $full_page['layout'] = 0;
         $full_page['site_map'] = 1;
         CKEditor::init();
         JS::startup('lightning.page.edit();');
     } elseif ($full_page = $this->loadPage('404')) {
         header('HTTP/1.0 404 NOT FOUND');
         $full_page['url'] = Request::get('page');
         $template->set('page_blank', true);
     } else {
         header('HTTP/1.0 404 NOT FOUND');
         $full_page['title'] = 'Lightning';
         $full_page['keywords'] = 'Lightning';
         $full_page['description'] = 'Lightning';
         $full_page['url'] = '';
         $full_page['body'] = 'Your site has not been set up.';
         $full_page['layout'] = 0;
         $full_page['site_map'] = 1;
         $template->set('page_blank', true);
     }
     // Replace special tags.
     if (!$user->isAdmin()) {
         $matches = array();
         preg_match_all('|{{.*}}|', $full_page['body'], $matches);
         foreach ($matches as $match) {
             if (!empty($match)) {
                 $match_clean = trim($match[0], '{} ');
                 $match_clean = explode('=', $match_clean);
                 switch ($match_clean[0]) {
                     case 'template':
                         $sub_template = new Template();
                         $full_page['body'] = str_replace($match[0], $sub_template->render($match_clean[1], true), $full_page['body']);
                         break;
                 }
             }
         }
     }
     // PREPARE FORM DATA CONTENTS
     foreach (array('title', 'keywords', 'description') as $meta_data) {
         $full_page[$meta_data] = Scrub::toHTML($full_page[$meta_data]);
         if (!empty($full_page[$meta_data])) {
             Configuration::set('page_' . $meta_data, str_replace("*", Configuration::get('page_' . $meta_data), $full_page[$meta_data]));
         }
     }
     if ($full_page['url'] == "" && isset($_GET['page'])) {
         $full_page['url'] = $_GET['page'];
     } else {
         $full_page['url'] = Scrub::toHTML($full_page['url'], ENT_QUOTES);
     }
     $template->set('page_header', $full_page['title']);
     $template->set('full_page', $full_page);
     $template->set('full_width', $full_page['layout'] == 1);
 }
コード例 #25
0
ファイル: Session.php プロジェクト: kemosabhay/Lightning
 public function blank_session()
 {
     Output::clearCookie(Configuration::get('session.cookie'));
 }
コード例 #26
0
ファイル: User.php プロジェクト: kemosabhay/Lightning
 public function loginRedirect($page = null, $params = array())
 {
     $redirect = Request::post('redirect', 'urlencoded') ?: Request::query('redirect');
     if ($redirect && !preg_match('|^[/?]user|', $redirect)) {
         Navigation::redirect($redirect, $params);
     } elseif (!empty($page)) {
         Navigation::redirect($page, $params);
     } else {
         Navigation::redirect(Configuration::get('user.login_url'), $params);
     }
 }
コード例 #27
0
ファイル: JS.php プロジェクト: kemosabhay/Lightning
    /**
     * Output all the JS functions including inline, startup and resource files.
     *
     * @return string
     *   The rendered output.
     */
    public static function render() {
        $output = '';
        if (!self::$inited) {
            $output = '<script language="javascript">lightning={"vars":' . json_encode(self::$vars) . '};</script>';
            self::$vars = array();
            self::$inited = true;
        } elseif (!empty(self::$vars)) {
            $output = '<script language="javascript">$.extend(true, lightning.vars, ' . json_encode(self::$vars) . ');</script>';
        }

        // Include JS files.
        foreach (self::$included_scripts as &$file) {
            $file_name = $file['file'];
            if ($file['versioning']) {
                $concatenator = strpos($file['file'], '?') !== false ? '&' : '?';
                $file_name .= $concatenator . 'v=' . Configuration::get('minified_version', 0);
            }
            if (empty($file['rendered'])) {
                $output .= '<script language="javascript" src="' . $file_name . '" ' . (!empty($file['async']) ? 'async defer' : '');
                if (!empty($file['id'])) {
                    $output .= ' id="' . $file['id'] . '"';
                }
                $output .= '></script>';
                $file['rendered'] = true;
            }
        }

        if (!empty(self::$inline_scripts) || !empty(self::$startup_scripts)) {
            $output .= '<script language="javascript">';
            // Include inline scripts.
            foreach (self::$inline_scripts as $script) {
                if (empty($script['rendered'])) {
                    $output .= $script['script'] . "\n\n";
                    $script['rendered'] = true;
                }
            }

            // Include ready scripts.
            if (!empty(self::$startup_scripts)) {
                $output .= '$(document).ready(function() {';
                foreach (self::$startup_scripts as &$script) {
                    if (empty($script['rendered'])) {
                        $output .= $script['script'] . ';';
                        $script['rendered'] = true;
                    }
                }
                $output .= '})';
            }
            $output .= '</script>';
        }

        return $output;
    }
コード例 #28
0
ファイル: Singleton.php プロジェクト: kemosabhay/Lightning
 protected static function getStaticName()
 {
     $class = get_called_class();
     $class = str_replace('Overridable\\', '', $class);
     if (!isset(self::$overrides)) {
         self::$overrides = array_flip(Configuration::get('classes', []));
     }
     return !empty(self::$overrides[$class]) ? self::$overrides[$class] : $class;
 }
コード例 #29
0
ファイル: Template.php プロジェクト: kemosabhay/Lightning
 public function setCache($page, $ttl = null, $size = null)
 {
     $ttl = $ttl ?: Configuration::get('page.cache.ttl') ?: Cache::MONTH;
     $size = $size ?: Configuration::get('page.cache.size') ?: Cache::MEDIUM;
     $this->cache[$page] = array('ttl' => $ttl, 'size' => $size);
 }
コード例 #30
0
// ini_set('display_errors', 1);
/*
To make it easy to configure CKFinder, the $baseUrl and $baseDir can be used.
Those are helper variables used later in this config file.
*/
/*
$baseUrl : the base path used to build the final URL for the resources handled
in CKFinder. If empty, the default value (/userfiles/) is used.

Examples:
	$baseUrl = 'http://example.com/ckfinder/files/';
	$baseUrl = '/userfiles/';

ATTENTION: The trailing slash is required.
*/
$baseUrl = \Lightning\Tools\Configuration::get('ckfinder.content');
/*
$baseDir : the path to the local directory (in the server) which points to the
above $baseUrl URL. This is the path used by CKFinder to handle the files in
the server. Full write permissions must be granted to this directory.

Examples:
	// You may point it to a directory directly:
	$baseDir = '/home/login/public_html/ckfinder/files/';
	$baseDir = 'C:/SiteDir/CKFinder/userfiles/';

	// Or you may let CKFinder discover the path, based on $baseUrl.
	// WARNING: resolveUrl() *will not work* if $baseUrl does not start with a slash ("/"),
	// for example if $baseDir is set to  http://example.com/ckfinder/files/
	$baseDir = resolveUrl($baseUrl);