Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 2
0
 /**
  * Private Constructor
  *
  * Called from dispatch(), this will initialize the current class
  * variables and other dependancies. It then dispatches the request
  * to the appropriate method or 404 if the method doesn't exist.
  *
  * @param string    $pageRequest    The page type needs to be dispatched    
  */
 public function __construct($pageRequest)
 {
     # Set Kanso's is_admin
     \Kanso\Kanso::getInstance()->is_admin = true;
     # Set Kanso's Query object to 'admin'
     \Kanso\Kanso::getInstance()->Query->filterPosts('admin');
     # Fire the adminInit event
     \Kanso\Events::fire('adminInit');
     # Set the page request type
     $this->pageRequest = $pageRequest;
     # Save the clients login boolean
     $this->isLoggedIn = \Kanso\Kanso::getInstance()->Gatekeeper->isLoggedIn();
     # Save the default homepage URL for redirecting
     $this->adminHomepage = \Kanso\Kanso::getInstance()->Environment['HTTP_HOST'] . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . 'articles' . DIRECTORY_SEPARATOR;
 }
Exemplo n.º 3
0
 /**
  * Delete an article
  *
  * @param  int    $articleID   The article id from the database to be deleted
  */
 public function delete($articleID)
 {
     # Convert the article ID to an integer
     $articleID = (int) $articleID;
     # Get a new Query Builder
     $Query = \Kanso\Kanso::getInstance()->Database->Builder();
     # Find the existing article
     $articleRow = $Query->SELECT('*')->FROM('posts')->WHERE('id', '=', $articleID)->ROW();
     # If it doesn't exist return false
     if (!$articleRow || empty($articleRow)) {
         return false;
     }
     # Remove comments associated with the article
     $Query->DELETE_FROM('comments')->WHERE('post_id', '=', $articleID)->QUERY();
     # Remove the tags associated with the article
     $Query->DELETE_FROM('tags_to_posts')->WHERE('post_id', '=', $articleID)->QUERY();
     # Remove the content associated with the article
     $Query->DELETE_FROM('content_to_posts')->WHERE('post_id', '=', $articleID)->QUERY();
     # Clear the cache
     \Kanso\Kanso::getInstance()->Cache->clearCache($articleRow['slug']);
     # Delete the article entry
     $Query->DELETE_FROM('posts')->WHERE('id', '=', $articleID)->QUERY();
     # If the article was a published page, update kanso's static pages
     if ($articleRow['type'] === 'page' && $articleRow['status'] === 'published') {
         $this->removeFromStaticPages($articleRow['slug']);
     }
     # Fire the article delete event
     \Kanso\Events::fire('articleDelete', $articleRow);
     return true;
 }
Exemplo n.º 4
0
 /**
  * Batch upload multiple images at once
  *
  * @return string|false
  */
 private function batchUploadImages()
 {
     # Validate the user is logged in
     if (!$this->isLoggedIn) {
         return false;
     }
     # Grab the user's row from the session
     # Validate the user is an admin
     $user = \Kanso\Kanso::getInstance()->Session->get('KANSO_ADMIN_DATA');
     if ($user['role'] !== 'administrator') {
         return false;
     }
     # Declare the POST variables locally
     $postVars = $this->postVars;
     # Validate a file was sent
     if (!isset($postVars['file'])) {
         return false;
     }
     foreach ($postVars['file'] as $type => $attributes) {
         # Validate the mime
         if ($type === 'type') {
             foreach ($attributes as $mimeType) {
                 if (!in_array($mimeType, ['image/png', 'image/jpeg', 'image/gif'])) {
                     return 'invalid_mime';
                 }
             }
         } else {
             if ($type === 'size') {
                 foreach ($attributes as $size) {
                     if ($size > 5000000) {
                         return 'invalid_size';
                     }
                 }
             }
         }
     }
     # Declare size suffixes for resizing
     $sizes = ["small", "medium", "large"];
     # Get the environment
     $env = \Kanso\Kanso::getInstance()->Environment;
     # Get the config
     $config = \Kanso\Kanso::getInstance()->Config;
     # Declare config sizes locally
     $configSizes = $config['KANSO_THUMBNAILS'];
     # Destination for event;
     $dest = '';
     # Upload the images
     foreach ($postVars['file']['tmp_name'] as $f => $tmpFile) {
         # Loop through config sizes - maximum is 3 thumbnails
         for ($i = 0; $i < 3; $i++) {
             # Declare the resize
             $size = $configSizes[$i];
             # Grab our image processor
             $Imager = new \Kanso\Utility\Images($tmpFile);
             # Sanitize the file name
             $name = str_replace('.jpeg', '.jpg', htmlentities(str_replace("/", "", stripslashes($postVars['file']['name'][$f]))));
             $ext = substr($name, strrpos($name, '.') + 1);
             $name = substr($name, 0, strrpos($name, '.'));
             # Set the destination and quality
             $dst = $env['KANSO_UPLOADS_DIR'] . '/Images/' . $name . '_' . $sizes[$i] . '.' . $ext;
             $qual = $config['KANSO_IMG_QUALITY'];
             $qual = $ext === 'png' ? $qual / 10 : $qual;
             # If sizes are declared with width & Height - resize to those dimensions
             # otherwise just resize to width;
             if (is_array($size)) {
                 $Imager->crop($size[0], $size[1], true);
             } else {
                 $Imager->resizeToWidth($size, true);
             }
             # Save the file
             $saved = $Imager->save($dst, false, $qual);
             $dest = $dst;
             # Return error if file couldnt be saved
             if (!$saved) {
                 return 'server_error';
             }
         }
     }
     # Fire upload event
     \Kanso\Events::fire('imageUpload', $dest);
     return 'valid';
 }
Exemplo n.º 5
0
 /**
  * Log client out
  *
  * This is responsible for logging a client out of the 
  * admin panel.
  *
  */
 private function logClientOut()
 {
     # Fire the event
     \Kanso\Events::fire('logout', $this->user);
     # Clear the session
     \Kanso\Kanso::getInstance()->Session->clear();
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
 /**
  * Default Not Found handler
  *
  * This method is always called directly from the router when no
  * route was found and a 404 response needs to be sent.
  */
 public function notFound()
 {
     # Call the pre dispatch event
     \Kanso\Events::fire('notFound', [$this->Environment['REQUEST_URI'], time()]);
     # Set the default body
     $body = '<html><head><title>404 Not Found</title></head><body><H1>Not Found</H1><p>The requested document was not found on this server.</P><hr></body></html>';
     # Check that the current theme has a 404 page
     # Set the body to the 404 template
     $errorDoc = $this->Environment['KANSO_THEME_DIR'] . DIRECTORY_SEPARATOR . $this->Config['KANSO_THEME_NAME'] . DIRECTORY_SEPARATOR . '404.php';
     if (file_exists($errorDoc)) {
         $body = $this->View->display($errorDoc);
     }
     # Ajax and requests don't need a body
     # just a 404
     if ($this->Request->isAjax()) {
         $body = '';
     }
     # Set the resoponse and body
     $this->Response->setStatus(404);
     $this->Response->setBody($body);
 }