示例#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
 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
 /**
  * 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
 /**
  * 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
function adminPostTypes()
{
    $types = ['post', 'page'];
    return \Kanso\Filters::apply('adminPostTypes', $types);
}