Example #1
0
 public function post_subscribe()
 {
     \Fuel\Core\Lang::load("global");
     $email = Input::json("email");
     if ($email !== null && preg_match("/^[a-zA-Z0-9.!#\$%&\"*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+\$/", $email) === 1) {
         // Call API
         $api = new \Libraries\Api();
         $return = $api->executeAPIMethod("POST", "newsletters", array("email" => $email));
         // Success/error
         if ($return["code"] == 200) {
             // Success
             $this->jsonSuccess(\Fuel\Core\Lang::get("subscribe_to_newsletter.success"), array("apiReturn" => $return));
         } else {
             if ($return["code"] == 412) {
                 $this->jsonSuccess(\Fuel\Core\Lang::get("subscribe_to_newsletter.already_subscribed"));
             } else {
                 // Error...
                 $this->jsonError(\Fuel\Core\Lang::get("subscribe_to_newsletter.error"));
             }
         }
     } else {
         // Error, not valid...
         $this->jsonError(\Fuel\Core\Lang::get("subscribe_to_newsletter.error"));
     }
 }
Example #2
0
 public static function get_other_language()
 {
     $other_language = ENGLISH_STRING;
     if (\Fuel\Core\Lang::get_lang() == ENGLISH_STRING) {
         $other_language = FRENCH_STRING;
     }
     return $other_language;
 }
Example #3
0
 public static function get($line, array $params = array(), $default = null, $language = null)
 {
     $output = parent::get($line, $params, '__NOT__FOUND__', $language);
     if (!empty($output) && $output != '__NOT__FOUND__') {
         return $output;
     }
     if ($output == '__NOT__FOUND__') {
         $output = $default;
     }
     if (!static::$autosave || !\CMF::$lang_enabled) {
         return $output;
     }
     $language === null and $language = static::get_lang();
     $pos = strpos($line, '.');
     $group = 'common';
     $basename = $line;
     if ($pos === false) {
         if (empty($default)) {
             $default = $line;
         }
         $line = "{$group}.{$line}";
     } else {
         $basename = substr($line, $pos + 1);
         if (empty($default)) {
             $default = $basename;
         }
         $group = substr($line, 0, $pos);
     }
     // Try and load from the DB...
     if (!in_array($group . '_' . $language, static::$loaded)) {
         static::load("{$group}.db", $group, $language, true, true);
         static::$loaded[] = $group . '_' . $language;
     }
     // Don't continue if it's not the 'common' group
     if ($group != 'common') {
         return $output != null ? \Str::tr(\Fuel::value($output), $params) : $default;
     }
     $output = \Arr::get(static::$lines, "{$language}.{$line}");
     if ($output == null) {
         // First try and get from the fallback...
         $output = \Arr::get(static::$lines, static::$fallback[0] . ".{$line}");
         if (!in_array($group, static::$to_save)) {
             static::$to_save[] = $group;
         }
         //if (!empty($default) && $default != $line)
         static::set($line, $default);
         static::set($line, $default, null, static::$fallback[0]);
         if ($output == null) {
             $output = $default;
         }
     }
     return $output != null ? \Str::tr(\Fuel::value($output), $params) : $default;
 }
Example #4
0
 public static function bootstrap()
 {
     //Make sure orm is loaded first as we need this
     \Fuel\Core\Package::load('orm');
     //For fuel v1 add to the finder path
     if (class_exists('\\Fuel\\Core\\Finder')) {
         \Fuel\Core\Finder::instance()->add_path(__DIR__ . DS . '..' . DS . '..');
     }
     \Fuel\Core\Config::load('ethanol', true);
     \Fuel\Core\Config::load('ethanol_permissions', true);
     \Fuel\Core\Lang::load('ethanol', 'ethanol');
     Auth::instance()->register_driver(array('database', 'facebook'));
 }
Example #5
0
 public function post_status()
 {
     $val = Validation::forge();
     $val->add_callable('MyRules');
     $val->add_field('status', Lang::get('label.status'), 'required|valid_category_status');
     $val->add_field('category_id', Lang::get('label.category'), 'required|valid_category');
     if ($val->run()) {
         Model_Base_Category::update($val->validated('category_id'), array('status' => $val->validated('status')));
         $this->data['success'] = true;
     } else {
         $this->data['errors'] = $val->error_message();
     }
     return $this->response($this->data);
 }
Example #6
0
 public function post_update_config()
 {
     $val = Validation::forge();
     $val->add_callable('MyRules');
     $val->add_field('email', Lang::get('label.email'), 'required|valid_email|max_length[255]');
     $val->add_field('telephone', Lang::get('label.telephone'), 'trim|valid_numeric|max_length[12]');
     $val->add_field('address', Lang::get('label.address'), 'trim|max_length[255]');
     $val->add_field('fb_url', Lang::get('label.fb_url'), 'required|valid_url');
     $val->add_field('shop_name', Lang::get('label.shop_name'), 'required|max_length[255]');
     if ($val->run()) {
         $props = array('email' => $val->validated('email'), 'telephone' => $val->validated('telephone'), 'address' => $val->validated('address'), 'fb_url' => $val->validated('fb_url'), 'shop_name' => $val->validated('shop_name'));
         Model_Base_Config::update($props);
         $this->data['success'] = Lang::get($this->controller . '.' . $this->action . '.success');
     } else {
         $this->data['errors'] = $val->error_message();
     }
     return $this->response($this->data);
 }
Example #7
0
 public function before()
 {
     $parentReturn = parent::before();
     \Fuel\Core\Lang::load("global");
     \Fuel\Core\Lang::load("share");
     $this->template->jsVars = new JsVars();
     $this->template->jsVars->addVar("wsUrl", rtrim(Router::get("ws_" . $this->lang), "/") . "/");
     $this->template->jsVars->addVar("baseUrl", \Fuel\Core\Uri::base(FALSE));
     $this->template->css = array("fonts.css", "normalize.css", "definitions.css", "template.css", "sprites/generic.css");
     $this->template->js = array("libs/jquery-2.1.3.min.js", "libs/jquery-ui.min.js", "libs/mustache.js", "template.js");
     $this->template->header = "front_header";
     $this->template->set_global(array("menu_selected" => ""));
     $this->template->footer = "front_footer";
     $this->template->footer_options = array();
     $fbShare = array("share" => FALSE, "siteName" => '', "title" => '', "description" => '', "image" => '');
     $this->template->fbShare = $fbShare;
     return $parentReturn;
 }
Example #8
0
 public function post_signin()
 {
     $val = Validation::forge();
     $val->add_callable('MyRules');
     $val->add_field('email', Lang::get('label.email'), 'required|valid_email|max_length[255]');
     $val->add_field('password', Lang::get('label.password'), 'required|valid_password|min_length[8]|max_length[50]');
     if ($val->run()) {
         $email = $val->validated('email');
         $password = $val->validated('password');
         if (Model_Base_User::admin_login($email, $password)) {
             $this->data['success'] = true;
         } else {
             $this->data['errors']['signin'] = Lang::get($this->controller . '.' . $this->action . '.error');
         }
     } else {
         $this->data['errors'] = $val->error_message();
     }
     return $this->response($this->data);
 }
Example #9
0
 public static function formatDate($date, $format_type)
 {
     $date = strtotime($date);
     $date_formated = '';
     if ($date != '' && $date > strtotime(SYSTEM_DEFAULT_DATE)) {
         if ($format_type == YEAR_MONTH_DAY_DIGITAL) {
             $date_formated = date("Y-m-d", $date);
         } else {
             if ($format_type == NEWSFEED_FORMAT) {
                 if (date("Ymd") == date('Ymd', $date)) {
                     $date_formated = \Fuel\Core\Lang::get('today') . ' | ' . date("g:iA", $date);
                 } else {
                     $date_formated = date("d.m.Y", $date) . ' | ' . date("g:iA", $date);
                 }
             }
         }
     }
     return $date_formated;
 }
Example #10
0
 public static function switch_language($other_lang)
 {
     $url = \Fuel\Core\Router::get('home_en') . '/';
     $switch_page = '';
     $params = array();
     $current_lang = \Fuel\Core\Lang::get_lang();
     // Loop through routes
     foreach (\Fuel\Core\Router::$routes as $key => $route) {
         // If there's segments in route (weird, but that tells us that it's the current route...!)
         if (count($route->segments) > 0) {
             if (strpos($key, '_' . $current_lang, strlen($key) - strlen('_' . $current_lang)) !== false) {
                 $switch_page = str_replace('_' . $current_lang, '_' . $other_lang, $key);
                 $params = $route->method_params;
             }
             $url = rtrim(\Fuel\Core\Router::get($switch_page, $route->named_params), "/") . "/";
             foreach ($params as $param) {
                 if ($param != $current_lang && $param != $other_lang) {
                     $url .= $param . '/';
                 }
             }
         }
     }
     return $url;
 }
Example #11
0
 public static function run($type = null, $options = array())
 {
     $data = array();
     $photo_name = array();
     try {
         Upload::process();
     } catch (Exception $e) {
         $data['error'] = Lang::get('notice.upload.no_file');
         return $data;
     }
     if (Upload::is_valid()) {
         Upload::save();
     }
     foreach (Upload::get_errors() as $file) {
         $data['error'] = $file['errors']['0']['message'];
         return $data;
     }
     foreach (Upload::get_files() as $file) {
         $resize = self::resize_photo($file['saved_to'], $file['saved_as'], $type);
         $photo_name[] = $file['saved_as'];
     }
     if ($resize) {
         switch ($type) {
             case 'icon':
                 if (Model_Base_User::update($options['user_id'], array('user_photo' => $photo_name[0]))) {
                     $old_photo = $file['saved_to'] . $type . '/' . $options['user_photo'];
                     if (File::exists($old_photo)) {
                         File::delete($old_photo);
                     }
                     $data['photo_name'] = _PATH_ICON_ . $photo_name[0];
                 } else {
                     $data['error'] = Lang::get('notice.upload.save_icon_error');
                 }
                 break;
             case 'category':
                 $old_photo = $options['type'] === 'new' ?: $file['saved_to'] . $type . '/' . Model_Category::find($options['category_id'])->category_photo;
                 if (Model_Base_Category::update($options['category_id'], array('category_photo' => $photo_name[0]))) {
                     if (File::exists($old_photo)) {
                         File::delete($old_photo);
                     }
                     $data['photo_name'] = _PATH_CATEGORY_ . $photo_name[0];
                 } else {
                     $data['error'] = Lang::get('notice.upload.save_category_error');
                 }
                 break;
             case 'product':
                 $old_photo = $file['saved_to'] . $type . '/' . Model_Product::find($options['product_id'])->product_photo;
                 if (Model_Base_Product::update($options['product_id'], array('product_photo' => $photo_name[0]))) {
                     if (File::exists($old_photo)) {
                         File::delete($old_photo);
                     }
                     $data['photo_name'] = _PATH_PRODUCT_ . $photo_name[0];
                 } else {
                     $data['error'] = Lang::get('notice.upload.save_product_error');
                 }
                 break;
             case 'photo':
                 if ($options['type'] === 'sub_product_photo') {
                     $photo_props = array('product_id' => $options['product_id'], 'photo_name' => $photo_name[0]);
                     if ($photo_id = Model_Base_Photo::insert($photo_props)) {
                         $data['photo_id'] = $photo_id;
                         $data['photo_name'] = _PATH_PHOTO_ . $photo_name[0];
                     } else {
                         $data['error'] = Lang::get('notice.upload.save_photo_error');
                     }
                 }
                 break;
             default:
                 $data['error'] = Lang::get('system_error');
                 break;
         }
     } else {
         $data['error'] = Lang::get('system_error');
     }
     return $data;
 }
Example #12
0
 public function post_sort_sub_photo()
 {
     $val = Validation::forge();
     $val->add_callable('MyRules');
     $val->add_field('photo', Lang::get('label.photo'), 'required');
     if ($val->run()) {
         $rank = 1;
         foreach ($val->validated('photo') as $value) {
             Model_Base_Photo::update($value, array('rank' => $rank++));
         }
         $this->data['success'] = true;
     } else {
         $this->data['errors'] = $val->error_message();
     }
     return $this->response($this->data);
 }
Example #13
0
 public function set_title()
 {
     if (is_object($this->template)) {
         $this->template->title = Lang::get($this->controller . '.' . $this->action . '.title');
     }
 }
Example #14
0
 public function post_update_icon()
 {
     $props = array('user_id' => $this->user_id, 'user_photo' => $this->user_info['user_photo']);
     $upload = Model_Service_Upload::run('icon', $props);
     if (empty($upload['error'])) {
         $this->data['success'] = true;
         $this->data['msg'] = Lang::get($this->controller . '.' . $this->action . '.success');
         $this->data['photo_name'] = $upload['photo_name'];
     } else {
         $this->data['error'] = $upload['error'];
     }
     return $this->response($this->data);
 }
Example #15
0
<?php

//Make sure orm is loaded first as we need this
\Fuel\Core\Package::load('orm');
//For fuel v1 add to the finder path
if (class_exists('\\Finder')) {
    \Fuel\Core\Finder::instance()->add_path(__DIR__ . DS . '..' . DS . '..');
}
\Fuel\Core\Config::load('ethanol', true);
\Fuel\Core\Config::load('ethanol_permissions', true);
\Fuel\Core\Lang::load('ethanol', 'ethanol');
Ethanol\Auth::instance()->register_driver(array('database', 'facebook'));
Example #16
0
 public static function _init()
 {
     static::$default_language = \Config::get('language');
     parent::_init();
 }