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")); } }
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; }
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); }
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); }
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); }
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; }
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; }
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); }
public function set_title() { if (is_object($this->template)) { $this->template->title = Lang::get($this->controller . '.' . $this->action . '.title'); } }
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); }