Example #1
0
 /**
  * Class constructor
  *
  * @param   boolean  $exceptions  PHPMailer should throw external exceptions? [Optional]
  */
 public function __construct($exceptions = TRUE)
 {
     require_once Kohana::find_file('vendor/PHPMailer', 'PHPMailerAutoload');
     // Create phpmailer object
     $this->_mail = new PHPMailer($exceptions);
     // Set some defaults
     $this->_mail->setFrom(Config::get('site.site_email', '*****@*****.**'), Template::getSiteName());
     $this->_mail->WordWrap = 70;
     $this->_mail->CharSet = Kohana::$charset;
     $this->_mail->XMailer = Gleez::getVersion(FALSE, TRUE);
     $this->_mail->setLanguage(I18n::$lang);
     $this->_mail->Debugoutput = 'error_log';
 }
Example #2
0
 /**
  * Sending mails
  *
  * @since 1.0.0  First time this method was introduced
  * @since 1.1.0  Added jQuery Textarea Characters Counter Plugin
  *
  * @link  http://roy-jin.appspot.com/jsp/textareaCounter.jsp
  *
  * @uses  Request::query
  * @uses  Route::get
  * @uses  Route::uri
  * @uses  URL::query
  * @uses  URL::site
  * @uses  Validation::rule
  * @uses  Config::get
  * @uses  Config::load
  * @uses  Assets::js
  */
 public function action_mail()
 {
     $this->title = __('Contact us');
     $config = Config::load('contact');
     Assets::js('textareaCounter', 'media/js/jquery.textareaCounter.plugin.js', array('jquery'), FALSE, array('weight' => 10));
     Assets::js('greet/form', 'media/js/greet.form.js', array('textareaCounter'), FALSE, array('weight' => 15));
     //Add schema.org support
     $this->schemaType = 'ContactPage';
     // Set form destination
     $destination = !is_null($this->request->query('destination')) ? array('destination' => $this->request->query('destination')) : array();
     // Set form action
     $action = Route::get('contact')->uri(array('action' => $this->request->action())) . URL::query($destination);
     // Get user
     $user = User::active_user();
     // Set mail types
     $types = $config->get('types', array());
     $view = View::factory('contact/form')->set('destination', $destination)->set('action', $action)->set('config', $config)->set('types', $types)->set('user', $user)->bind('post', $post)->bind('errors', $this->_errors);
     // Initiate Captcha
     if ($config->get('use_captcha', FALSE) and !$this->_auth->logged_in()) {
         $captcha = Captcha::instance();
         $view->set('captcha', $captcha);
     }
     if ($this->valid_post('contact')) {
         $post = Validation_Contact::factory($this->request->post());
         if ($post->check()) {
             // Create the email subject
             $subject = __('[:category] :subject', array(':category' => $types[$post['category']], ':subject' => Text::plain($post['subject'])));
             // Create the email body
             $body = View::factory('email/contact')->set('name', $post['name'])->set('body', $post['body'])->set('config', Config::load('site'))->render();
             // Create an email message
             $email = Email::factory()->to(Text::plain($this->_config->get('site_email', '*****@*****.**')), __('Webmaster :site', array(':site' => Template::getSiteName())))->subject($subject)->from($post['email'], Text::plain($post['name']))->message($body, 'text/html');
             // @todo message type should be configurable
             // Send the message
             $email->send();
             Log::info(':name sent an e-mail regarding :cat', array(':name' => Text::plain($post['name']), ':cat' => $types[$post['category']]));
             Message::success(__('Your message has been sent.'));
             // Always redirect after a successful POST to prevent refresh warnings
             $this->request->redirect(Route::get('contact')->uri(), 200);
         } else {
             $this->_errors = $post->errors('contact', TRUE);
         }
     }
     $this->response->body($view);
 }
Example #3
0
 /**
  * Tags view
  *
  * @throw HTTP_Exception_404
  */
 public function action_tag()
 {
     $config = Config::load('blog');
     $id = (int) $this->request->param('id', 0);
     $tag = ORM::factory('tag', array('id' => $id, 'type' => 'blog'));
     if (!$tag->loaded()) {
         throw HTTP_Exception::factory(404, 'Tag ":tag" Not Found', array(':tag' => $id));
     }
     $this->title = __(':title', array(':title' => Text::ucfirst($tag->name)));
     $view = View::factory('blog/list')->set('teaser', TRUE)->set('config', $config)->bind('rss_link', $rss_link)->bind('pagination', $pagination)->bind('posts', $posts);
     $posts = $tag->posts;
     if (!ACL::check('administer tags') and !ACL::check('administer content')) {
         $posts->where('status', '=', 'publish');
     }
     $total = $posts->reset(FALSE)->count_all();
     if ($total == 0) {
         Log::info('No blogs found.');
         $this->response->body(View::factory('blog/none'));
         return;
     }
     $rss_link = Route::get('rss')->uri(array('controller' => 'blog', 'action' => 'tag', 'id' => $tag->id));
     $pagination = Pagination::factory(array('current_page' => array('source' => 'cms', 'key' => 'page'), 'total_items' => $total, 'items_per_page' => $config->get('items_per_page', 15), 'uri' => $tag->url));
     $posts = $posts->order_by('created', 'DESC')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all();
     $this->response->body($view);
     // Set the canonical and shortlink for search engines
     if ($this->auto_render) {
         Meta::links(URL::canonical($tag->url, $pagination), array('rel' => 'canonical'));
         Meta::links(Route::url('blog', array('action' => 'tag', 'id' => $tag->id), TRUE), array('rel' => 'shortlink'));
         Meta::links(Route::url('rss', array('controller' => 'blog', 'action' => 'tag', 'id' => $tag->id), TRUE), array('rel' => 'alternate', 'type' => 'application/rss+xml', 'title' => Template::getSiteName() . ' : ' . $tag->name));
     }
 }
Example #4
0
<h1><?php 
echo __('Hello!');
?>
</h1>

<p><?php 
echo __(':name sent a message using the contact form at :site.', array(':name' => Text::plain($name), ':site' => URL::site('contact', TRUE)));
?>
</p>

<?php 
echo Text::markup($body);
?>
<br>
<hr>
<p>
	<?php 
echo __('Best Regards');
?>
,<br>
	<?php 
echo $config->get('site_url', 'www.gleezcms.org');
?>
<br>
	<?php 
echo Template::getSiteName();
?>
</p>
Example #5
0
 /**
  * Execute a request with cURL
  *
  * @param   string  $url
  * @param   mixed   $parameters
  * @param   string  $http_method
  * @param   array   $http_headers
  * @param   int     $form_content_type
  * @return  array
  * @throws  OAuth2_Client_Exception
  */
 protected function _execute_request($url, $parameters = array(), $http_method = self::HTTP_METHOD_GET, array $http_headers = NULL, $form_content_type = self::HTTP_FORM_CONTENT_TYPE_MULTIPART)
 {
     $curl_options = array(CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_SSL_VERIFYPEER => TRUE, CURLOPT_CUSTOMREQUEST => $http_method);
     switch ($http_method) {
         case self::HTTP_METHOD_POST:
             $curl_options[CURLOPT_POST] = TRUE;
             /* No break */
         /* No break */
         case self::HTTP_METHOD_PUT:
         case self::HTTP_METHOD_PATCH:
             /**
              * Passing an array to CURLOPT_POSTFIELDS will encode the data as multipart/form-data,
              * while passing a URL-encoded string will encode the data as application/x-www-form-urlencoded.
              * http://php.net/manual/en/function.curl-setopt.php
              */
             if (is_array($parameters) && self::HTTP_FORM_CONTENT_TYPE_APPLICATION === $form_content_type) {
                 $parameters = http_build_query($parameters, NULL, '&');
             }
             $curl_options[CURLOPT_POSTFIELDS] = $parameters;
             break;
         case self::HTTP_METHOD_HEAD:
             $curl_options[CURLOPT_NOBODY] = TRUE;
             /* No break */
         /* No break */
         case self::HTTP_METHOD_DELETE:
         case self::HTTP_METHOD_GET:
             if (is_array($parameters)) {
                 $url .= '?' . http_build_query($parameters, NULL, '&');
             } elseif ($parameters) {
                 $url .= '?' . $parameters;
             }
             break;
         default:
             break;
     }
     $curl_options[CURLOPT_URL] = $url;
     if (is_array($http_headers)) {
         $header = array();
         foreach ($http_headers as $key => $parsed_url_value) {
             $header[] = "{$key}: {$parsed_url_value}";
         }
         $curl_options[CURLOPT_HTTPHEADER] = $header;
     }
     // Init cURL
     $ch = curl_init();
     // Set CURL options
     curl_setopt_array($ch, $curl_options);
     // Https handling
     if (!empty($this->certificate_file)) {
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
         curl_setopt($ch, CURLOPT_CAINFO, $this->certificate_file);
     } else {
         // Bypass SSL verification
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     }
     if (!empty($this->curl_options)) {
         curl_setopt_array($ch, $this->curl_options);
     }
     //Github checks for useragent header
     curl_setopt($ch, CURLOPT_USERAGENT, Template::getSiteName());
     $result = curl_exec($ch);
     $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
     if ($curl_error = curl_error($ch)) {
         throw new OAuth2_Client_Exception($curl_error, array(), OAuth2_Client_Exception::E_CURL_ERROR);
     } else {
         $json_decode = json_decode($result, TRUE);
     }
     curl_close($ch);
     return $this->_last_response = array('result' => $json_decode === NULL ? $result : $json_decode, 'code' => $http_code, 'content_type' => $content_type);
 }
Example #6
0
 /**
  * Loads the template View object, if it is direct request
  *
  * @return  void
  * @throws  Http_Exception_415  If none of the accept-types are supported
  */
 public function before()
 {
     // Execute parent::before first
     parent::before();
     if ($this->bare == FALSE) {
         // Load the config
         $this->_config = Config::load('site');
         if (Kohana::$profiling) {
             // Start a new benchmark token
             $this->_benchmark = Profiler::start('Gleez', ucfirst($this->request->controller()) . ' Controller');
         }
         // Test whether the current request is command line request
         if (Kohana::$is_cli) {
             $this->_ajax = FALSE;
             $this->auto_render = FALSE;
         }
         // Test whether the current request is the first request
         if (!$this->request->is_initial()) {
             $this->_internal = TRUE;
             $this->auto_render = FALSE;
         }
         // Test whether the current request is ajax request
         if ($this->request->is_ajax()) {
             $this->_ajax = TRUE;
             $this->auto_render = FALSE;
         }
         // Test whether the current request is jquery mobile request. ugly hack
         if (Request::is_mobile() and $this->_config->get('mobile_theme', FALSE)) {
             $this->_ajax = FALSE;
             $this->auto_render = TRUE;
         }
         // Test whether the current request is datatables request
         if (Request::is_datatables()) {
             $this->_ajax = TRUE;
             $this->auto_render = FALSE;
         }
         $this->response->headers('X-Powered-By', Gleez::getVersion(TRUE, TRUE) . ' (' . Gleez::CODENAME . ')');
         $this->_auth = Auth::instance();
         // Get desired response formats
         $accept_types = Request::accept_type();
         $accept_types = Arr::extract($accept_types, array_keys($this->_accept_formats));
         // Set response format to first matched element
         $this->_response_format = $this->request->headers()->preferred_accept(array_keys($this->_accept_formats));
         $site_name = Template::getSiteName();
         $url = URL::site(NULL, TRUE);
         View::bind_global('site_name', $site_name);
         View::bind_global('site_url', $url);
     }
     if ($this->auto_render && $this->bare == FALSE) {
         // Throw exception if none of the accept-types are supported
         if (!($accept_types = array_filter($accept_types))) {
             throw new Http_Exception_415('Unsupported accept-type', 415);
         }
         // Initiate a Format instance
         $this->_format = Format::instance();
         // Load the template
         $this->template = View::factory($this->template);
         $this->title_separator = $this->_config->get('title_separator', ' | ');
         $this->_widgets = Widgets::instance();
         $this->template->_admin = Theme::$is_admin;
         // Set the destination & redirect url
         $this->_desti = array('destination' => $this->request->uri());
         $this->redirect = $this->request->query('destination') !== NULL ? $this->request->query('destination') : array();
         // Bind the generic page variables
         $this->template->set('site_name', Template::getSiteName())->set('site_slogan', $this->_config->get('site_slogan', __('Innovate IT')))->set('site_url', URL::site(NULL, TRUE))->set('site_logo', $this->_config->get('site_logo', FALSE))->set('sidebar_left', array())->set('sidebar_right', array())->set('column_class', '')->set('main_column', 12)->set('head_title', $this->title)->set('title', $this->title)->set('subtitle', $this->subtitle)->set('icon', $this->icon)->set('schemaType', $this->schemaType)->set('front', FALSE)->set('mission', FALSE)->set('tabs', FALSE)->set('subtabs', FALSE)->set('actions', FALSE)->set('_user', $this->_auth->get_user())->bind('datatables', $this->_datatables);
         // Page Title
         $this->title = ucwords($this->request->controller());
         // Assign the default css files
         $this->_set_default_css();
         // Assign the default js files
         $this->_set_default_js();
         // Set default server headers
         $this->_set_default_server_headers();
         // Set default meta data and media
         $this->_set_default_meta_links();
         $this->_set_default_meta_tags();
         /**
          * Make your view template available to all your other views
          * so easily you could access template variables
          */
         View::bind_global('template', $this->template);
     }
     if (Kohana::$environment === Kohana::DEVELOPMENT) {
         Log::debug('Executing Controller [:controller] action [:action]', array(':controller' => $this->request->controller(), ':action' => $this->request->action()));
     }
 }
Example #7
0
 /**
  * ## Reset password: step 1
  *
  * The form where a user enters the email address he signed up with.
  *
  * @param   array  $data  Values to check
  * @return  boolean
  *
  * @uses    Config::load
  * @uses    Validation::factory
  * @uses    Validation::rule
  * @uses    Auth::instance
  * @uses    Auth::hash
  * @uses    URL::site
  * @uses    Email::factory
  * @uses    Email::subject
  * @uses    Email::to
  * @uses    Email::message
  * @uses    Email::send
  */
 public function reset_password(array &$data)
 {
     $labels = $this->labels();
     $rules = $this->rules();
     $config = Config::load('site');
     $data = Validation::factory($data)->rule('mail', 'not_empty')->rule('mail', 'min_length', array(':value', 4))->rule('mail', 'max_length', array(':value', 254))->rule('mail', 'email')->rule('mail', array($this, 'email_not_available'), array(':validation', ':field'));
     if (!$data->check()) {
         throw new Validation_Exception($data, 'Validation has failed for reset password');
     }
     // Load user data
     $this->where('mail', '=', $data['mail'])->find();
     // Invalid user
     if (!$this->_loaded) {
         throw new Validation_Exception($data, 'Email not found');
     }
     // Token consists of email and the last_login field.
     // So as soon as the user logs in again, the reset link expires automatically
     $time = time();
     $token = Auth::instance()->hash($this->mail . '+' . $this->pass . '+' . $time . '+' . (int) $this->login);
     $url = URL::site(Route::get('user/reset')->uri(array('action' => 'confirm_password', 'id' => $this->id, 'token' => $token, 'time' => $time)), TRUE);
     // Create e-mail body with reset password link
     $body = View::factory('email/confirm_reset_password', $this->as_array())->set('time', $time)->set('url', $url)->set('config', $config);
     // Create an email message
     $email = Email::factory()->subject(__(':site - Reset password for :name', array(':name' => $this->nick, ':site' => Template::getSiteName())))->to($this->mail, $this->nick)->message($body);
     // Send the message
     $email->send();
     return TRUE;
 }
Example #8
0
 /**
  * Set default prepared header for XML document
  *
  * @uses  Arr::get
  * @uses  Route::url
  * @uses  I18n::lang
  * @uses  URL::site
  */
 public function setInfo()
 {
     $this->_info = array('title' => Template::getSiteName(), 'description' => Arr::get($this->_config, 'site_mission', __('Recently added posts')), 'pubDate' => time(), 'generator' => Feed::getGenerator(), 'link' => Route::url('rss', NULL, TRUE), 'copyright' => '2011-' . date('Y') . ' ' . Template::getSiteName(), 'language' => I18n::lang(), 'ttl' => Arr::get($this->_config, 'feed_ttl', Feed::DEFAULT_TTL), 'image' => array('link' => URL::site(NULL, TRUE), 'url' => URL::site(Arr::get($this->_config, 'site_logo', 'media/images/logo.png'), TRUE), 'title' => Template::getSiteName()));
 }