Пример #1
0
 public function sendTemplate($keyword, $email, $tags = array(), $language = '')
 {
     loader::model('system/emailtemplates');
     if (!$language) {
         $language = config::item('language_id', 'system');
     }
     if (is_numeric($language)) {
         $language = config::item('languages', 'core', 'keywords', $language);
     } elseif (!in_array($language, config::item('languages', 'core', 'keywords'))) {
         return false;
     }
     if (!($template = config::item($keyword . '_' . $language, '_system_emails_cache'))) {
         if (!($template = $this->cache->item('core_email_template_' . $keyword . '_' . $language))) {
             $template = $this->emailtemplates_model->prepareTemplate($keyword, $language);
             if (count($template) == 3) {
                 if ($template[$keyword]['active']) {
                     $template = array('subject' => $template[$keyword]['subject'], 'message_html' => utf8::trim($template['header']['message_html'] . $template[$keyword]['message_html'] . $template['footer']['message_html']), 'message_text' => utf8::trim($template['header']['message_text'] . "\n\n" . $template[$keyword]['message_text'] . "\n\n" . $template['footer']['message_text']));
                 } else {
                     $template = 'none';
                 }
             } else {
                 error::show('Could not fetch email template from the database: ' . $keyword);
             }
             $this->cache->set('core_email_template_' . $keyword . '_' . $language, $template, 60 * 60 * 24 * 30);
         }
         config::set(array($keyword . '_' . $language => $template), '', '_system_emails_cache');
     }
     $retval = true;
     if (is_array($template) && $template) {
         $retval = $this->sendEmail($email, $template['subject'], $template['message_text'], $template['message_html'], $tags);
     }
     return $retval;
 }
Пример #2
0
 /**
  * static method used to log an error and optionally show it also
  * @param string $message the error message to show
  * @param bool $show whether or not to also show the error on screen
  * @param int $http_code the HTTP status code to respond with
  */
 static function log($message, $show = false, $http_code = 500)
 {
     $maverick = \maverick\maverick::getInstance();
     //$caller = debug_backtrace();
     if ($maverick->get_config('config.error_detail')) {
         $message .= error::generate_call_trace();
     }
     if ($maverick->get_config('config.log_errors')) {
         $log_date = date("y-m-d");
         error_log("\n\n{$message}", 3, MAVERICK_LOGSDIR . "error-{$log_date}.log");
     }
     if ($show) {
         error::show(nl2br($message), $http_code);
     }
 }
Пример #3
0
 public function run()
 {
     $shash = uri::segment(3);
     // Verify security string
     if (!$shash || strcmp($shash, config::item('cron_shash', 'system')) !== 0) {
         error::show('Invalid security string.');
     }
     if (strcmp(config::item('cron_last_run', 'system'), date('Ymd', date_helper::now())) === 0) {
         error::show('You may run this file only once per day.');
     }
     // Action hook
     hook::action('cron/run');
     echo "Performed tasks:<br/>";
     echo implode(" <br/>\n", $this->cron_model->getLog());
     $this->cron_model->finalize();
     exit;
 }
Пример #4
0
 /**
  * Index, this is the fuction that run when the page open in the base routing
  * @return [View] All the controller routing functions  returns a view, a view is a template with need to know vars
  */
 function login()
 {
     $email = $_POST['username'];
     $pass = $_POST['password'];
     if ($name != "" && $pass != "") {
         $users = $this->em->getRepository('user')->findBy(array('email' => $email));
         $user = $users[0];
         if ($user != "") {
             if ($user->checkPass($pass)) {
                 $user->updateToken();
                 $user->saveDefs();
                 $this->em->persist($user);
                 $this->em->flush();
                 $errors = error::show("Login efectuado com successo", "success");
                 goToUrl("/");
             } else {
                 $errors = error::show("Username ou password errado", "danger");
             }
         } else {
             $errors = error::show("Username ou password errado", "danger");
         }
     }
     return $this->view->make('login', ["error" => $errors['error'], "type" => $errors['type']])->render();
 }
Пример #5
0
 /**
  * the main workhorse of the maverick class - this performs tasks like fetching views from cache to bypass the rest of the framework,
  * handles route pre-parsing if that's set up, sets up any initial database connections if requested in the config and calls the 
  * first controller matched by the requested route
  */
 public function build()
 {
     // load from the cache if that is on and this is a GET request
     if ($this->get_config('cache.on') !== false && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET') {
         $hash = $this->get_request_route_hash();
         $headers = \maverick\cache::fetch("{$hash}_headers");
         $view = \maverick\cache::fetch($hash);
         if ($headers) {
             $headers = json_decode($headers);
             foreach ($headers as $header) {
                 header($header);
             }
         }
         if ($view) {
             die($view);
         }
     }
     /*if(strlen($this->get_config('config.route_preparser') ) )
     		$this->route_preparser();*/
     $this->get_request_uri();
     $this->db = new \stdClass();
     if ($this->get_config('lang.active') === true) {
         $this->set_lang_culture();
     }
     // look at routes to find out which route the requested path best matches
     require_once MAVERICK_BASEDIR . 'routes.php';
     // initialise base db object if the config exists, the engine is not an empty string, and the required parameters exist
     if (strlen($this->get_config('db.engine')) && $this->check_required_fields($this->get_config('db'), array('engine', 'host', 'database', 'username', 'password'))) {
         $dbname = $this->get_config('db.database');
         $dbhost = $this->get_config('db.host');
         $dbuser = $this->get_config('db.username');
         $dbpass = $this->get_config('db.password');
         $this->db->pdo = $pdo = new \PDO("mysql:dbname={$dbname};host={$dbhost}", $dbuser, $dbpass, array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"));
     }
     // locate and initiate call to controller responsible for the requested route
     if (!empty($this->controller)) {
         if ($this->check_class_method_exists($this->controller['controller_name'], $this->controller['method'], $this->controller['controller'])) {
             $this->controller['controller']->{$this->controller['method']}($this->controller['args']);
         } else {
             \error::show("controller '{$this->controller['controller_name']}' or method '{$this->controller['method']}' not found");
         }
     } else {
         // throw a 404 - either look to see if an explicit route accounts for this, or throw some kind of default one
         $error_controller = $this->get_error_route(404);
         if ($this->check_class_method_exists($error_controller['controller_name'], $error_controller['method'], $this->controller['controller'])) {
             // add the error controller details in as the main controller details for consistency later on
             list($this->controller['controller_name'], $this->controller['method'], $this->controller['protocol'], $this->controller['args']) = array($error_controller['controller_name'], $error_controller['method'], 'any', null);
             $this->controller['controller']->{$this->controller['method']}();
         } else {
             \error::show("404", 404);
         }
     }
 }
Пример #6
0
 public function export($lang, $cache = false)
 {
     $path = DOCPATH . 'languages/' . $lang . '/';
     // Prepend this line in generated files
     $prefix = '// Do not edit this file unless you know what you are doing';
     // Get language data
     $language = $this->getLanguageData($lang, '', true);
     // Loop through language plugins
     foreach ($language as $plugin => $sections) {
         // Content array
         $content = array();
         // Loop through language sections
         foreach ($sections as $section => $groups) {
             $content[$section] = array();
             // Loop through plugins content
             foreach ($groups as $group => $types) {
                 $content[$section][$group] = array();
                 // Loop through control panel and client types
                 foreach ($types as $type => $lang) {
                     // Does section have any values?
                     if ($lang) {
                         $content[$section][$group][$type] = array();
                         // Loop through language strings
                         foreach ($lang as $keyword => $name) {
                             $content[$section][$group][$type][] = "'" . $keyword . "' => \"" . str_replace(array("\r", "\n", '"'), array('', '\\n', '\\"'), $name) . "\"";
                         }
                         $content[$section][$group][$type] = "\t\t'" . $type . "' => array(\n\t\t\t\t" . implode(",\n\t\t\t\t", $content[$section][$group][$type]) . "\n\t\t\t),\n";
                     }
                 }
                 $content[$section][$group] = "\t'" . $group . "' => array(\n\t" . implode("\t", $content[$section][$group]) . "\t\t),\n";
             }
             $content[$section] = "\t'" . $section . "' => array(\n\t" . implode("\t", $content[$section]) . "\t)";
         }
         $content = "<?php\n" . $prefix . "\n\$language = array(\n" . implode(",\n", $content) . "\n);";
         $filename = $path . $plugin . '.php';
         if (!@file_put_contents($filename, $content)) {
             error::show('Could not save the file: ' . $filename . ' Make sure the "' . $path . '" folder exists and is writable.');
         }
         @chmod($filename, octdec(config::item('file_chmod')));
     }
     return true;
 }
Пример #7
0
 /**
  * run the rules attached to this instance and apply them to the submitted data
  * populating the internal errors array with any errors found
  * @return bool
  */
 public static function run()
 {
     $v = validator::getInstance();
     $app = \maverick\maverick::getInstance();
     // run through the rules and apply them to any data that exists in the $_REQUEST array
     foreach ($v->rules as $field => $rules) {
         if (!is_array($rules)) {
             $rules = (array) $rules;
         }
         // cast the single string rules to an array to make them the same to work with as groups of rules
         foreach ($rules as $rule) {
             $params = explode(':', $rule);
             $rule_method = "rule_{$params[0]}";
             $rule = $params[0];
             if (method_exists($v, $rule_method)) {
                 $params = array_slice($params, 1);
                 if (!$v->{$rule_method}($field, $params)) {
                     // look up an error message for this and push it into the errors array
                     $error_string = vsprintf($app->get_config("validator.{$rule}"), array_merge((array) $field, $params));
                     if (!isset($v->errors[$field])) {
                         $v->errors[$field] = array();
                     }
                     $v->errors[$field][] = $error_string;
                 }
             } else {
                 error::show("the validation rule {$params[0]} does not exist");
             }
         }
     }
     return !count($v->errors);
 }
Пример #8
0
 public function offline()
 {
     // Get page
     if (!($page = $this->pages_model->getPage('site/offline', 'in_view'))) {
         error::show404();
     }
     // Do we have views enabled?
     if (config::item('page_views', 'pages')) {
         // Update views counter
         $this->pages_model->updateViews($page['page_id']);
     }
     // Show offline error
     error::show($page['data_body'], 200, $page['data_title']);
 }
Пример #9
0
 protected function readStylesheet($path, $file, $level = 1)
 {
     // Trim paths
     $path = rtrim($path, '/');
     $file = ltrim($file, '/');
     // Can we read css file?
     if (($content = @file_get_contents($path . '/' . $file)) === false) {
         error::show('Could not read style sheet file: ' . $path . '/' . $file);
     }
     // Parse css file
     $output = $this->parseStylesheet($content);
     // Find all @import tags
     preg_match_all('/@import url\\(["\']?([^"\']+)["\']?\\);/i', $output, $imports);
     // Do we have any @import tags?
     if (isset($imports[1]) && $imports[1] && $level <= 5) {
         // Loop through @import tags
         foreach ($imports[1] as $index => $import) {
             // Read imported css file
             $content = $this->readStylesheet($path, $import, $level + 1);
             // Replace @import tag with css output
             $output = str_replace($imports[0][$index], $content, $output);
         }
     }
     return trim($output);
 }
Пример #10
0
 /**
  * use object buffering to build up the views into a single string and either return or echo it
  * optionally output any headers that have been added to the view instance
  * @param bool $echo whether to echo the view or return it as a string
  * @param bool $with_headers if set to true and $echo is also set to true, then send headers to the browser, otherwise do nothing
  * @return string
  */
 public static function render($echo = true, $with_headers = false)
 {
     $v = view::getInstance();
     $app = \maverick\maverick::getInstance();
     $view_file_path = MAVERICK_VIEWSDIR . "/{$v->view}.php";
     if (!file_exists($view_file_path)) {
         error::show("View '{$v->view}' does not exist");
     } else {
         ob_start();
         include $view_file_path;
         $view = ob_get_contents();
         ob_end_clean();
         if ($app->get_config('config.view_parsing') !== false) {
             $view = $v->parse_view($view);
         }
         // this just stores the view if the config value is set to cache it
         if ($app->get_config('cache.on') !== false) {
             $hash = $app->get_request_route_hash();
             \maverick\cache::store($hash, $view);
             if ($with_headers) {
                 \maverick\cache::store("{$hash}_headers", json_encode($v->headers));
             }
         }
         if ($with_headers) {
             foreach ($v->headers as $header) {
                 header($header);
             }
             // teapot
             if (isset($v->original_headers['status']) && $v->original_headers['status'] == 418 && $app->get_config('config.teapot') !== false) {
                 $teapot = \helpers\html\html::load_snippet(\MAVERICK_BASEDIR . 'vendor/maverick/teapot.html', array());
                 $view = preg_replace('/<body/', "<body>{$teapot}", $view, 1);
             }
         }
         if ($echo) {
             echo $view;
         } else {
             return $view;
         }
     }
 }