コード例 #1
0
ファイル: Mailer.php プロジェクト: kanso-cms/cms
 /**
  * Send Kanso's default email
  *
  * This function sends HTML emails with a default body. 
  * The idea here is to have a single function that sends emails throughout
  * the application to ensure consistency.
  *
  * @param  string    $emailTo         The email address to send the email to
  * @param  string    $emailFrom       The name of the sender
  * @param  string    $emailSender     The email address of the sender
  * @param  string    $emailSubject    The subject of the email
  * @param  string    $emailMessage    The message to be sent
  * @return bool
  */
 public static function sendHTMLEmail($emailTo, $emailFrom, $emailSender, $emailSubject, $emailMessage)
 {
     $data = ['subject' => $emailSubject, 'message' => $emailMessage];
     $email_body = \Kanso\Templates\Templater::getTemplate($data, 'EmailBody');
     $email_headers = 'MIME-Version: 1.0' . "\r\n";
     $email_headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
     $email_headers .= 'From: ' . $emailSender . ' <' . $emailFrom . '>' . "\r\n";
     # Fire the email event
     \Kanso\Events::fire('htmlEmailSend', [$emailTo, $emailFrom, $emailSender, $emailSubject, $emailMessage]);
     # Filter the email body
     $email_body = \Kanso\Filters::apply('emailBody', $email_body);
     return mail($emailTo, $emailSubject, $email_body, $email_headers);
 }
コード例 #2
0
ファイル: GetController.php プロジェクト: kanso-cms/cms
 private function validateSettingsRequest()
 {
     # Save a local Environment
     $env = \Kanso\Kanso::getInstance()->Environment;
     # Valid tabs
     $availableTabs = ['account', 'author', 'kanso', 'users', 'tools'];
     # Filter the tabs
     $availableTabs = \Kanso\Filters::apply('adminSettingsTabs', $availableTabs);
     # Save the url locally
     $url = $env['REQUEST_URL'];
     # Is this a request for an article edit or a new article?
     $request = str_replace($env['HTTP_HOST'] . '/admin/settings/', "", $url);
     # Get the slug
     $slug = trim($request, '/');
     # Validate the requested tab
     return in_array($slug, $availableTabs);
 }
コード例 #3
0
ファイル: PostController.php プロジェクト: kanso-cms/cms
 /**
  * Validate the request 
  *
  * Note this function is envoked directly from the router for all POST
  * requests to the admin panel. It validates the request with the refferer
  * and public key signature (if applicatible) and calls the main dispatcher
  *
  * @return mixed
  */
 public function validate()
 {
     # Set the request to false
     $validRequest = false;
     # Only ajax requests are allowed, with a valid HTTP ajax header
     if (!\Kanso\Kanso::getInstance()->Request->isAjax()) {
         $validRequest = false;
     }
     # A valid user must exist
     if (!$this->user) {
         \Kanso\Kanso::getInstance()->Response->setStatus(404);
         return;
     }
     # Get the POST variables
     $this->postVars = \Kanso\Kanso::getInstance()->Request->fetch();
     # Ajax requests all carry the same key/value of "ajaxRequest", which
     # indicates what to dispatch
     if (!isset($this->postVars['ajaxRequest'])) {
         $validRequest = false;
     }
     # Validate that the request came from the admin panel
     # All ajax request must have both a refferer and a reffer
     # in the clients session
     if (!$this->validateReferrer()) {
         $validRequest = false;
     }
     # If this is a request for a public key we can serve the client
     # their key/salt
     if ($this->postVars['ajaxRequest'] === 'public_key') {
         $validRequest = true;
     } else {
         if ($this->validateKeySignature()) {
             $validRequest = true;
         }
     }
     # If the request was invalid, respond with a 404.
     if (!$validRequest) {
         \Kanso\Kanso::getInstance()->Response->setStatus(404);
         return;
     }
     # Dispatch the request
     $response = $this->dispatchRequest();
     # Filter the response
     $response = \Kanso\Filters::apply('adminAjaxResponse', $response);
     # If the request was processed, return a valid JSON object
     if ($response || is_array($response)) {
         $Response = \Kanso\Kanso::getInstance()->Response;
         $Response->setheaders(['Content-Type' => 'application/json']);
         $Response->setBody(json_encode(['response' => 'processed', 'details' => $response]));
         return;
     }
     # 404 on fallback
     \Kanso\Kanso::getInstance()->Response->setStatus(404);
 }
コード例 #4
0
ファイル: Settings.php プロジェクト: kanso-cms/cms
 /**
  * Save the current config to disk and update Kanso's config.
  *
  * @param  boolean    $throwError   Should the function return an error code or filter the config
  * 
  * @return boolean|integer
  */
 private function save($throwError = false)
 {
     # Fire the event
     \Kanso\Events::fire('configChange', $this->tempConfig);
     # Validate the config if needed
     if ($throwError) {
         $validation = $this->validateConfig();
         if (is_integer($validation) && in_array($validation, $this->responseCodes)) {
             $this->tempConfig = $this->configData;
             return $validation;
         }
     }
     # Filter the config internally
     $config = $this->filterConfig();
     # Filter the config
     $config = \Kanso\Filters::apply('configChange', $config);
     # Encode and save the config
     file_put_contents($this->configPath, "<?php\nreturn\n" . var_export($config, true) . ";?>");
     # Check if the user has changed the permalinks structure
     $changedPermalinks = $config['KANSO_PERMALINKS_ROUTE'] !== $this->configData['KANSO_PERMALINKS_ROUTE'];
     # Check if the user has changed use cache
     $changedCache = $config['KANSO_USE_CACHE'] !== $this->configData['KANSO_USE_CACHE'];
     # Check if the CDN has change - so the cache needs to be update
     $changedCache = $config['KANSO_USE_CDN'] !== $this->configData['KANSO_USE_CDN'] && $config['KANSO_USE_CACHE'] === true ? true : $changedCache;
     # Set the local config
     $this->configData = $config;
     $this->tempConfig = $config;
     # If permalinks were changed, we need to update every post in the DB
     if ($changedPermalinks) {
         $this->updatePostPermalinks();
     }
     # Clear the cache as well
     if ($changedCache) {
         \Kanso\Kanso::getInstance()->Cache->clearCache();
     }
     # Update Kanso
     \Kanso\Kanso::getInstance()->Config = $config;
     if ($throwError) {
         return $this->responseCodes['success'];
     }
     return true;
 }
コード例 #5
0
ファイル: Kanso.php プロジェクト: kanso-cms/cms
 /**
  * Constructor
  *
  * @param  array $userSettings Associative array of application settings
  */
 public function __construct($UserSettings = null)
 {
     # Check if the apllication is installed
     $this->isInstalled = !file_exists(__DIR__ . '/Install.php') && file_exists(__DIR__ . '/Config.php');
     # Halt if the application is not installed
     if (!$this->isInstalled) {
         return;
     }
     # Setup IoC container
     $this->Container = new \Kanso\Helper\Container();
     # Default settings
     $this->Container->singleton('Settings', function () {
         return new \Kanso\Config\Settings();
     });
     # Initialize application configuration
     $this->Container['Config'] = $this->Settings->get();
     # Default environment
     $this->Container->singleton('Environment', function () {
         return \Kanso\Environment::extract();
     });
     # Default headers
     $this->Container->singleton('Headers', function () {
         return \Kanso\Http\Headers::extract();
     });
     # Default request
     $this->Container->singleton('Request', function () {
         return new \Kanso\Http\Request();
     });
     # Default response
     $this->Container->singleton('Response', function () {
         return new \Kanso\Http\Response();
     });
     # Default databse
     $this->Container->singleton('Database', function () {
         return new \Kanso\Database\Database();
     });
     # Default Gatekeeper
     $this->Container->singleton('Gatekeeper', function () {
         return new \Kanso\Auth\Gatekeeper();
     });
     # Default Session
     $this->Container->singleton('Session', function () {
         return new \Kanso\Auth\Session();
     });
     # Default GUMP
     $this->Container->set('Validation', function () {
         return new \Kanso\Utility\GUMP();
     });
     # Default router
     $this->Container->singleton('Router', function () {
         return new \Kanso\Router\Router();
     });
     # Default Query
     $this->Container->singleton('Query', function () {
         return new View\Query();
     });
     # Default view
     $this->Container->singleton('View', function () {
         return \Kanso\View\View::getInstance();
     });
     # Default view
     $this->Container->singleton('Cache', function () {
         return new \Kanso\Cache\Cache();
     });
     # Default Events
     $this->Container->singleton('Events', function () {
         return \Kanso\Events::getInstance();
     });
     # Default Filters
     $this->Container->singleton('Filters', function () {
         return \Kanso\Filters::getInstance();
     });
     # Default Articlekeeper
     $this->Container->singleton('Bookkeeper', function () {
         return new \Kanso\Articles\Bookkeeper();
     });
     # Default Comment manager
     $this->Container->singleton('Comments', function () {
         return new Kanso\Comments\CommentManager();
     });
     # Default FileSystem
     $this->Container->singleton('FileSystem', function () {
         return new Kanso\Utility\FileSystem();
     });
     # Default Humanizer
     $this->Container->singleton('Humanizer', function () {
         return new Kanso\Utility\Humanizer();
     });
     # Default Mailer
     $this->Container->singleton('Mailer', function () {
         return new Kanso\Utility\Mailer();
     });
     # Make default if first instance
     if (is_null(static::getInstance())) {
         $this->setName('default');
     }
     # Start the session immediately
     $this->dispatchSession();
     # Default this is not an admin request
     $this->is_admin = false;
     # Include the active theme's plugins.php file if it exists
     $plugins = $this->Environment['KANSO_THEME_DIR'] . DIRECTORY_SEPARATOR . $this->Config['KANSO_THEME_NAME'] . DIRECTORY_SEPARATOR . 'plugins.php';
     if (file_exists($plugins)) {
         require_once $plugins;
     }
 }
コード例 #6
0
ファイル: functions.php プロジェクト: kanso-cms/cms
function adminPostTypes()
{
    $types = ['post', 'page'];
    return \Kanso\Filters::apply('adminPostTypes', $types);
}