/**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $data = array('title' => \Input::get('title'), 'slug' => \Unicode::make(\Input::get('title')), 'show' => \Input::get('show'), 'sort' => \Input::get('sort'));
     $this->album->update($id, $data);
     \Notification::success('UPDATED !');
     return \Redirect::route('admin.album.index');
 }
 /**
  * Filters HTML to prevent cross-site-scripting (XSS) vulnerabilities.
  *
  * Based on kses by Ulf Harnhammar, see http://sourceforge.net/projects/kses.
  * For examples of various XSS attacks, see: http://ha.ckers.org/xss.html.
  *
  * This code does five things:
  * - Removes characters and constructs that can trick browsers.
  * - Makes sure all HTML entities are well-formed.
  * - Makes sure all HTML tags and attributes are well-formed.
  * - Makes sure no HTML tags contain URLs with a disallowed protocol (e.g.
  *   javascript:).
  * - Marks the sanitized, XSS-safe version of $string as safe markup for
  *   rendering.
  *
  * @param $string
  *   The string with raw HTML in it. It will be stripped of everything that
  *   can cause an XSS attack.
  * @param array $html_tags
  *   An array of HTML tags.
  * @param bool $mode
  *   (optional) Defaults to FILTER_MODE_WHITELIST ($html_tags is used as a
  *   whitelist of allowed tags), but can also be set to FILTER_MODE_BLACKLIST
  *   ($html_tags is used as a blacklist of disallowed tags).
  *
  * @return string
  *   An XSS safe version of $string, or an empty string if $string is not
  *   valid UTF-8.
  *
  * @see \Drupal\Component\Utility\Unicode::validateUtf8()
  * @see \Drupal\Component\Utility\SafeMarkup
  *
  * @ingroup sanitization
  */
 public static function filter($string, $html_tags = array('a', 'em', 'strong', 'cite', 'blockquote', 'code', 'ul', 'ol', 'li', 'dl', 'dt', 'dd'), $mode = Xss::FILTER_MODE_WHITELIST)
 {
     // Only operate on valid UTF-8 strings. This is necessary to prevent cross
     // site scripting issues on Internet Explorer 6.
     if (!Unicode::validateUtf8($string)) {
         return '';
     }
     // Remove NULL characters (ignored by some browsers).
     $string = str_replace(chr(0), '', $string);
     // Remove Netscape 4 JS entities.
     $string = preg_replace('%&\\s*\\{[^}]*(\\}\\s*;?|$)%', '', $string);
     // Defuse all HTML entities.
     $string = str_replace('&', '&', $string);
     // Change back only well-formed entities in our whitelist:
     // Decimal numeric entities.
     $string = preg_replace('/&#([0-9]+;)/', '&#\\1', $string);
     // Hexadecimal numeric entities.
     $string = preg_replace('/&#[Xx]0*((?:[0-9A-Fa-f]{2})+;)/', '&#x\\1', $string);
     // Named entities.
     $string = preg_replace('/&([A-Za-z][A-Za-z0-9]*;)/', '&\\1', $string);
     $html_tags = array_flip($html_tags);
     $splitter = function ($matches) use($html_tags, $mode) {
         return static::split($matches[1], $html_tags, $mode);
     };
     return SafeMarkup::set(preg_replace_callback('%
   (
   <(?=[^a-zA-Z!/])  # a lone <
   |                 # or
   <!--.*?-->        # a comment
   |                 # or
   <[^>]*(>|$)       # a string that starts with a <, up until the > or the end of the string
   |                 # or
   >                 # just a >
   )%x', $splitter, $string));
 }
Exemple #3
0
 /**
  * Validates whether a hexadecimal color value is syntactically correct.
  *
  * @param $hex
  *   The hexadecimal string to validate. May contain a leading '#'. May use
  *   the shorthand notation (e.g., '123' for '112233').
  *
  * @return bool
  *   TRUE if $hex is valid or FALSE if it is not.
  */
 public static function validateHex($hex)
 {
     // Must be a string.
     $valid = is_string($hex);
     // Hash prefix is optional.
     $hex = ltrim($hex, '#');
     // Must be either RGB or RRGGBB.
     $length = Unicode::strlen($hex);
     $valid = $valid && ($length === 3 || $length === 6);
     // Must be a valid hex value.
     $valid = $valid && ctype_xdigit($hex);
     return $valid;
 }
Exemple #4
0
 /**
  * Filters HTML to prevent cross-site-scripting (XSS) vulnerabilities.
  *
  * Based on kses by Ulf Harnhammar, see http://sourceforge.net/projects/kses.
  * For examples of various XSS attacks, see: http://ha.ckers.org/xss.html.
  *
  * This code does four things:
  * - Removes characters and constructs that can trick browsers.
  * - Makes sure all HTML entities are well-formed.
  * - Makes sure all HTML tags and attributes are well-formed.
  * - Makes sure no HTML tags contain URLs with a disallowed protocol (e.g.
  *   javascript:).
  *
  * @param $string
  *   The string with raw HTML in it. It will be stripped of everything that
  *   can cause an XSS attack.
  * @param array $html_tags
  *   An array of HTML tags.
  *
  * @return string
  *   An XSS safe version of $string, or an empty string if $string is not
  *   valid UTF-8.
  *
  * @see \Drupal\Component\Utility\Unicode::validateUtf8()
  *
  * @ingroup sanitization
  */
 public static function filter($string, array $html_tags = NULL)
 {
     if (is_null($html_tags)) {
         $html_tags = static::$htmlTags;
     }
     // Only operate on valid UTF-8 strings. This is necessary to prevent cross
     // site scripting issues on Internet Explorer 6.
     if (!Unicode::validateUtf8($string)) {
         return '';
     }
     // Remove NULL characters (ignored by some browsers).
     $string = str_replace(chr(0), '', $string);
     // Remove Netscape 4 JS entities.
     $string = preg_replace('%&\\s*\\{[^}]*(\\}\\s*;?|$)%', '', $string);
     // Defuse all HTML entities.
     $string = str_replace('&', '&amp;', $string);
     // Change back only well-formed entities in our whitelist:
     // Decimal numeric entities.
     $string = preg_replace('/&amp;#([0-9]+;)/', '&#\\1', $string);
     // Hexadecimal numeric entities.
     $string = preg_replace('/&amp;#[Xx]0*((?:[0-9A-Fa-f]{2})+;)/', '&#x\\1', $string);
     // Named entities.
     $string = preg_replace('/&amp;([A-Za-z][A-Za-z0-9]*;)/', '&\\1', $string);
     $html_tags = array_flip($html_tags);
     // Late static binding does not work inside anonymous functions.
     $class = get_called_class();
     $splitter = function ($matches) use($html_tags, $class) {
         return $class::split($matches[1], $html_tags, $class);
     };
     // Strip any tags that are not in the whitelist, then mark the text as safe
     // for output. All other known XSS vectors have been filtered out by this
     // point and any HTML tags remaining will have been deliberately allowed, so
     // it is acceptable to call SafeMarkup::set() on the resultant string.
     return preg_replace_callback('%
   (
   <(?=[^a-zA-Z!/])  # a lone <
   |                 # or
   <!--.*?-->        # a comment
   |                 # or
   <[^>]*(>|$)       # a string that starts with a <, up until the > or the end of the string
   |                 # or
   >                 # just a >
   )%x', $splitter, $string);
 }
 public function addmoreAddition($post_id)
 {
     $array_modal_attr = \Input::get('modal_attr');
     $array_modal_attr_value = \Input::get('modal_attr_value');
     $data_arr = array();
     if (\Input::has('modal_attr') || \Input::has('modal_attr_value')) {
         foreach ($array_modal_attr as $k => $v) {
             $data_arr[] = new \Addition(array('key' => $v, 'slug' => \Unicode::make($v), 'value' => $array_modal_attr_value[$k]));
         }
     }
     $currentPost = $this->post->find($post_id);
     $currentPost->addition()->saveMany($data_arr);
     \Notification::success('Done !');
     return \Redirect::back();
 }
 public static function shorten($string, $max_len)
 {
     $str = strlen($string) > $max_len ? Unicode::substr($string, 0, $max_len) : $string;
     return $str;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     if (!\Input::has('file')) {
         $img_path = \Input::get('img-bk');
         if (empty($img_path)) {
             $img_path = '/public/backend/img/image_thumbnail.gif';
         }
         $img_name = \GetNameImage::make('/', $img_path);
     } else {
         $ha = \Input::get('file');
         $img_path = str_replace($this->name_project, '', $ha);
         $img_name = \GetNameImage::make('/', $img_path);
     }
     $danhmuc = $this->danhmuc->find($id);
     $danhmuc->title = \Input::get('title');
     $danhmuc->slug = \Unicode::make(\Input::get('title'));
     $danhmuc->mota = \Input::get('mota');
     $danhmuc->image_path = $img_path;
     $danhmuc->image_name = $img_path;
     $danhmuc->image_name = $img_path;
     $danhmuc->status = \Input::get('status');
     $danhmuc->order = \Input::get('order');
     $danhmuc->save();
     \Notification::success('UPDATED !');
     return \Redirect::route('admin.danhmuc.index');
 }
 public function getAutocompleteSuggestions(QueryInterface $query, SearchApiAutocompleteSearch $search, $incomplete_key, $user_input)
 {
     $suggestions = array();
     // Reset request handler
     $this->request_handler = NULL;
     // Turn inputs to lower case, otherwise we get case sensivity problems.
     $incomp = Unicode::strtolower($incomplete_key);
     $index = $query->getIndex();
     $field_names = $this->getFieldNames($index);
     $complete = $query->getOriginalKeys();
     // Extract keys
     $keys = $query->getKeys();
     if (is_array($keys)) {
         $keys_array = array();
         while ($keys) {
             reset($keys);
             if (!element_child(key($keys))) {
                 array_shift($keys);
                 continue;
             }
             $key = array_shift($keys);
             if (is_array($key)) {
                 $keys = array_merge($keys, $key);
             } else {
                 $keys_array[$key] = $key;
             }
         }
         $keys = $this->getSolrHelper()->flattenKeys($query->getKeys());
     } else {
         $keys_array = preg_split('/[-\\s():{}\\[\\]\\\\"]+/', $keys, -1, PREG_SPLIT_NO_EMPTY);
         $keys_array = array_combine($keys_array, $keys_array);
     }
     if (!$keys) {
         $keys = NULL;
     }
     // Set searched fields
     $options = $query->getOptions();
     $search_fields = $query->getFulltextFields();
     $qf = array();
     foreach ($search_fields as $f) {
         $qf[] = $field_names[$f];
     }
     // Extract filters
     $fq = $this->createFilterQueries($query->getFilter(), $field_names, $index->getOption('fields', array()));
     $index_id = $this->getIndexId($index->id());
     $fq[] = 'index_id:' . $this->getQueryHelper()->escapePhrase($index_id);
     if ($this->configuration['site_hash']) {
         $site_hash = $this->getQueryHelper()->escapePhrase(SearchApiSolrUtility::getSiteHash());
         $fq[] = 'hash:' . $site_hash;
     }
     // Autocomplete magic
     $facet_fields = array();
     foreach ($search_fields as $f) {
         $facet_fields[] = $field_names[$f];
     }
     $limit = $query->getOption('limit', 10);
     $params = array('qf' => $qf, 'fq' => $fq, 'rows' => 0, 'facet' => 'true', 'facet.field' => $facet_fields, 'facet.prefix' => $incomp, 'facet.limit' => $limit * 5, 'facet.mincount' => 1, 'spellcheck' => !isset($this->configuration['autocorrect_spell']) || $this->configuration['autocorrect_spell'] ? 'true' : 'false', 'spellcheck.count' => 1);
     // Retrieve http method from server options.
     $http_method = !empty($this->configuration['http_method']) ? $this->configuration['http_method'] : 'AUTO';
     $call_args = array('query' => &$keys, 'params' => &$params, 'http_method' => &$http_method);
     if ($this->request_handler) {
         $this->setRequestHandler($this->request_handler, $call_args);
     }
     $second_pass = !isset($this->configuration['autocorrect_suggest_words']) || $this->configuration['autocorrect_suggest_words'];
     for ($i = 0; $i < ($second_pass ? 2 : 1); ++$i) {
         try {
             // Send search request
             $this->connect();
             $this->moduleHandler->alter('search_api_solr_query', $call_args, $query);
             $this->preQuery($call_args, $query);
             $response = $this->solr->search($keys, $params, $http_method);
             if (!empty($response->spellcheck->suggestions)) {
                 $replace = array();
                 foreach ($response->spellcheck->suggestions as $word => $data) {
                     $replace[$word] = $data->suggestion[0];
                 }
                 $corrected = str_ireplace(array_keys($replace), array_values($replace), $user_input);
                 if ($corrected != $user_input) {
                     array_unshift($suggestions, array('prefix' => $this->t('Did you mean') . ':', 'user_input' => $corrected));
                 }
             }
             $matches = array();
             if (isset($response->facet_counts->facet_fields)) {
                 foreach ($response->facet_counts->facet_fields as $terms) {
                     foreach ($terms as $term => $count) {
                         if (isset($matches[$term])) {
                             // If we just add the result counts, we can easily get over the
                             // total number of results if terms appear in multiple fields.
                             // Therefore, we just take the highest value from any field.
                             $matches[$term] = max($matches[$term], $count);
                         } else {
                             $matches[$term] = $count;
                         }
                     }
                 }
                 if ($matches) {
                     // Eliminate suggestions that are too short or already in the query.
                     foreach ($matches as $term => $count) {
                         if (strlen($term) < 3 || isset($keys_array[$term])) {
                             unset($matches[$term]);
                         }
                     }
                     // Don't suggest terms that are too frequent (by default in more
                     // than 90% of results).
                     $result_count = $response->response->numFound;
                     $max_occurrences = $result_count * $this->searchApiSolrSettings->get('autocomplete_max_occurrences');
                     if (($max_occurrences >= 1 || $i > 0) && $max_occurrences < $result_count) {
                         foreach ($matches as $match => $count) {
                             if ($count > $max_occurrences) {
                                 unset($matches[$match]);
                             }
                         }
                     }
                     // The $count in this array is actually a score. We want the
                     // highest ones first.
                     arsort($matches);
                     // Shorten the array to the right ones.
                     $additional_matches = array_slice($matches, $limit - count($suggestions), NULL, TRUE);
                     $matches = array_slice($matches, 0, $limit, TRUE);
                     // Build suggestions using returned facets
                     $incomp_length = strlen($incomp);
                     foreach ($matches as $term => $count) {
                         if (Unicode::strtolower(substr($term, 0, $incomp_length)) == $incomp) {
                             $suggestions[] = array('suggestion_suffix' => substr($term, $incomp_length), 'term' => $term, 'results' => $count);
                         } else {
                             $suggestions[] = array('suggestion_suffix' => ' ' . $term, 'term' => $term, 'results' => $count);
                         }
                     }
                 }
             }
         } catch (SearchApiException $e) {
             watchdog_exception('search_api_solr', $e, "%type during autocomplete Solr query: !message in %function (line %line of %file).", array(), WATCHDOG_WARNING);
         }
         if (count($suggestions) >= $limit) {
             break;
         }
         // Change parameters for second query.
         unset($params['facet.prefix']);
         $keys = trim($keys . ' ' . $incomplete_key);
     }
     return $suggestions;
 }
 /**
  * Returns the string length.
  *
  * @return int
  *   The length of the string.
  */
 public function count()
 {
     return Unicode::strlen($this->string);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function updatesanpham($sp_id)
 {
     if (!\Input::has('file')) {
         $img_path = \Input::get('img-bk');
         if (empty($img_path)) {
             $img_path = '/public/backend/img/image_thumbnail.gif';
         }
         $img_name = \GetNameImage::make('/', $img_path);
     } else {
         $ha = \Input::get('file');
         $img_path = str_replace($this->name_project, '', $ha);
         $img_name = \GetNameImage::make('/', $img_path);
     }
     $sanpham = $this->sanpham->find($sp_id);
     $sanpham->name = \Input::get('name');
     $sanpham->slug = \Unicode::make(\Input::get('name'));
     $sanpham->chatlieu = \Input::get('chatlieu');
     $sanpham->mausac = \Input::get('mausac');
     $sanpham->size = \Input::get('size');
     $sanpham->style = \Input::get('style');
     $sanpham->mota = \Input::get('mota');
     $sanpham->image_path = $img_path;
     $sanpham->image_name = $img_name;
     $sanpham->status = \Input::get('status');
     $sanpham->order = \Input::get('order');
     $sanpham->danhmuc_id = \Input::get('danhmuc_id');
     $sanpham->khuyenmai = \Input::get('khuyenmai');
     $sanpham->save();
     \Notification::success('UPDATED !');
     return \Redirect::route('admin.sanpham.index', \Input::get('danhmuc_id'));
 }
 public function docreateRole()
 {
     $pers = \Input::get('name_per');
     try {
         $this->validator->validate(\Input::all());
     } catch (FormValidationException $e) {
         return \Redirect::back()->withErrors($e->getErrors());
     }
     $data = array('name' => \Input::get('name_role'));
     $role = $this->role->createGet($data);
     $id_role = $role->id;
     $role_att = $this->role->find($id_role);
     // print_r($role_att);
     foreach ($pers as $k => $per) {
         $check_per = $this->pers->whereFirst('name', \Str::lower($per), array());
         if ($check_per == null) {
             $data = array('name' => \Str::lower($per), 'display_name' => \Unicode::make($per));
             $news[$k] = $this->pers->createGet($data);
         } else {
             $news[$k] = $check_per;
         }
         $role_att->attachPermission($news[$k]);
     }
     \Notification::success('Create Role with Permission');
     return \Redirect::back();
 }
Exemple #12
0
 /**
  * Prepares a string for use as a valid HTML ID.
  *
  * Only use this function when you want to intentionally skip the uniqueness
  * guarantee of self::getUniqueId().
  *
  * @param string $id
  *   The ID to clean.
  *
  * @return string
  *   The cleaned ID.
  *
  * @see self::getUniqueId()
  */
 public static function getId($id)
 {
     $id = str_replace([' ', '_', '[', ']'], ['-', '-', '-', ''], Unicode::strtolower($id));
     // As defined in http://www.w3.org/TR/html4/types.html#type-name, HTML IDs can
     // only contain letters, digits ([0-9]), hyphens ("-"), underscores ("_"),
     // colons (":"), and periods ("."). We strip out any character not in that
     // list. Note that the CSS spec doesn't allow colons or periods in identifiers
     // (http://www.w3.org/TR/CSS21/syndata.html#characters), so we strip those two
     // characters as well.
     $id = preg_replace('/[^A-Za-z0-9\\-_]/', '', $id);
     // Removing multiple consecutive hyphens.
     $id = preg_replace('/\\-+/', '-', $id);
     return $id;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     if (!\Input::hasFile('img')) {
         $img = \Input::get('img_bk');
         $path_img = $img;
     } else {
         try {
             $this->valid->validate(\Input::all());
         } catch (FormValidationException $e) {
             \Notification::error('Please choose Image type: jpg, png, jpeg');
             return \Redirect::back()->withInput();
         }
         $img = \Input::file('img');
         $name = $img->getClientOriginalName();
         $path = 'public/upload/images/';
         $img->move($path, $name);
         $path_img = $path . $name;
     }
     $data = array('alt_text' => \Input::get('alt_text'), 'slug' => \Unicode::make(\Input::get('alt_text')), 'show' => \Input::get('show'), 'sort' => \Input::get('sort'), 'path_img' => $path_img);
     $this->image->update($id, $data);
     \Notification::success('UPDATED !');
     return \Redirect::back();
 }
Exemple #14
0
 public function testEndsWith()
 {
     $this->assertTrue(Unicode::endsWith('', ''));
     $this->assertTrue(Unicode::endsWith('foo', ''));
     $this->assertTrue(Unicode::endsWith('foo', 'o'));
     $this->assertTrue(Unicode::endsWith('foo', 'oo'));
     $this->assertTrue(Unicode::endsWith('foo', 'foo'));
     $this->assertFalse(Unicode::endsWith('foo', 'f'));
     $this->assertFalse(Unicode::endsWith('foo', 'ffoo'));
     $this->assertFalse(Unicode::endsWith('foo', 'bar'));
     $this->assertFalse(Unicode::endsWith('foo', 'phoo'));
     $this->assertTrue(Unicode::endsWith('☢☣☯♥☺', ''));
     $this->assertTrue(Unicode::endsWith('☢☣☯♥☺', '☺'));
     $this->assertTrue(Unicode::endsWith('☢☣☯♥☺', '☢☣☯♥☺'));
     $this->assertFalse(Unicode::endsWith('☢☣☯♥☺', 'foo☢☣☯♥☺'));
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     if (!\Input::has('file')) {
         $img_path = \Input::get('img-bk');
         if (empty($img_path)) {
             $img_path = '/public/backend/img/image_thumbnail.gif';
         }
         $img_name = \GetNameImage::make('/', $img_path);
     } else {
         $ha = \Input::get('file');
         $img_path = str_replace($this->name_project, '', $ha);
         $img_name = \GetNameImage::make('/', $img_path);
     }
     $data = array('title' => \Input::get('title'), 'slug' => \Unicode::make(\Input::get('title')), 'content' => \Input::get('content'), 'image_path' => $img_path, 'image_name' => $img_name, 'status' => \Input::get('status'), 'order' => \Input::get('order'));
     $news = $this->news->find($id);
     $news->title = \Input::get('title');
     $news->slug = \Unicode::make(\Input::get('title'));
     $news->content = \Input::get('content');
     $news->image_path = $img_path;
     $news->image_name = $img_name;
     $news->status = \Input::get('status');
     $news->order = \Input::get('order');
     $news->save();
     \Notification::success('UPDATED !');
     return \Redirect::route('admin.tintuc.index');
 }
 /**
  * Capitalizes the first character of each word in a UTF-8 string.
  *
  * @param string $text
  *   The text that will be converted.
  *
  * @return string
  *   The input $text with each word capitalized.
  *
  * @ingroup php_wrappers
  */
 public static function ucwords($text)
 {
     $regex = '/(^|[' . static::PREG_CLASS_WORD_BOUNDARY . '])([^' . static::PREG_CLASS_WORD_BOUNDARY . '])/u';
     return preg_replace_callback($regex, function (array $matches) {
         return $matches[1] . Unicode::strtoupper($matches[2]);
     }, $text);
 }
 /**
  * Formats the address for display based on the country's address format.
  *
  * @return
  *   A formatted string containing the address.
  */
 public function __toString()
 {
     $variables = array('!company' => $this->company, '!first_name' => $this->first_name, '!last_name' => $this->last_name, '!street1' => $this->street1, '!street2' => $this->street2, '!city' => $this->city, '!postal_code' => $this->postal_code);
     $country = \Drupal::service('country_manager')->getCountry($this->country);
     if ($country) {
         $variables += array('!zone_code' => $this->zone ?: t('N/A'), '!zone_name' => isset($country->getZones()[$this->zone]) ? $country->getZones()[$this->zone] : t('Unknown'), '!country_name' => t($country->getName()), '!country_code2' => $country->id(), '!country_code3' => $country->getAlpha3());
         $format = implode("\r\n", $country->getAddressFormat());
     } else {
         $variables += array('!zone_code' => t('N/A'), '!zone_name' => t('Unknown'), '!country_name' => t('Unknown'), '!country_code2' => t('N/A'), '!country_code3' => t('N/A'));
         $format = "!company\r\n!first_name !last_name\r\n!street1\r\n!street2\r\n!city, !zone_code !postal_code\r\n!country_name_if";
     }
     if (uc_store_default_country() != $this->country) {
         $variables['!country_name_if'] = $variables['!country_name'];
         $variables['!country_code2_if'] = $variables['!country_code2'];
         $variables['!country_code3_if'] = $variables['!country_code3'];
     } else {
         $variables['!country_name_if'] = '';
         $variables['!country_code2_if'] = '';
         $variables['!country_code3_if'] = '';
     }
     $address = SafeMarkup::checkPlain(strtr($format, $variables));
     $address = preg_replace("/\r/", '', $address);
     $address = preg_replace("/\n +\n/", "\n", $address);
     $address = trim($address, "\n");
     if (\Drupal::config('uc_store.settings')->get('capitalize_address')) {
         $address = Unicode::strtoupper($address);
     }
     // <br> instead of <br />, because Twig will change it to <br> anyway and it's nice
     // to be able to test the Raw output.
     return nl2br($address, FALSE);
 }
        if (self::$has_mb) {
            $firstChar = mb_substr($string, 0, 1, $encoding);
            $then = mb_substr($string, 1, null, $encoding);
            return mb_strtoupper($firstChar, $encoding) . $then;
        } else {
            return ucfirst($string);
        }
    }
    public static function strtoupper($string, $encoding = 'UTF8')
    {
        return self::$has_mb ? mb_strtoupper($string, $encoding) : strtoupper($string);
    }
    public static function strtolower($string, $encoding = 'UTF8')
    {
        return self::$has_mb ? mb_strtolower($string, $encoding) : strtolower($string);
    }
    public static function substr($str, $start, $length = null, $encoding = 'UTF8')
    {
        return self::$has_mb ? mb_substr($str, $start, $length, $encoding) : substr($str, $start, $length);
    }
    public static function strpos($haystack, $needle, $offset = null, $encoding = 'UTF8')
    {
        return self::$has_mb ? mb_strpos($haystack, $needle, $offset, $encoding) : strripos($haystack, $needle, $offset);
    }
    public static function strripos($haystack, $needle, $offset = null, $encoding = 'UTF8')
    {
        return self::$has_mb ? mb_strripos($haystack, $needle, $offset, $encoding) : strripos($haystack, $needle, $offset);
    }
}
Unicode::$has_mb = function_exists('mb_strtolower');
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $input = \Input::all();
     try {
         $this->validation->validate($input);
     } catch (FormValidationException $e) {
         return \Redirect::back()->withInput()->withErrors($e->getErrors());
     }
     $data = array('title' => \Input::get('title'), 'slug' => \Unicode::make(\Input::get('title')), 'parent_id' => \Input::get('parent_id'), 'show' => \Input::get('show'), 'sort' => \Input::get('sort'));
     $this->cate->update($id, $data);
     \Notification::success('UPDATED !');
     return \Redirect::route('admin.category.index');
 }
Exemple #20
0
 /**
  * buildHashFile
  *
  * This constructs a file, usually named something.mo.php, which will
  * contain a PHP hash array literal. The literal can be included later
  * and used by this class to provide a translation via functions
  * declared below such as __()
  */
 static function buildHashFile($mofile, $outfile = false, $return = false)
 {
     if (!$outfile) {
         $stream = fopen('php://stdout', 'w');
     } elseif (is_string($outfile)) {
         $stream = fopen($outfile, 'w');
     } elseif (is_resource($outfile)) {
         $stream = $outfile;
     }
     if (!$stream) {
         throw new InvalidArgumentException('Expected a filename or valid resource');
     }
     if (!$mofile instanceof FileReader) {
         $mofile = new FileReader($mofile);
     }
     $reader = new parent($mofile, true);
     if ($reader->short_circuit || $reader->error) {
         throw new Exception('Unable to initialize MO input file');
     }
     $reader->load_tables();
     // Get basic table
     if (!($table = $reader->cache_translations)) {
         throw new Exception('Unable to read translations from file');
     }
     // Transcode the table to UTF-8
     $header = $table[""];
     $info = array();
     preg_match('/^content-type: (.*)$/im', $header, $info);
     $charset = false;
     if ($content_type = $info[1]) {
         // Find the charset property
         $settings = explode(';', $content_type);
         foreach ($settings as $v) {
             @(list($prop, $value) = explode('=', trim($v), 2));
             if (strtolower($prop) == 'charset') {
                 $charset = trim($value);
                 break;
             }
         }
     }
     if ($charset && strcasecmp($charset, 'utf-8') !== 0) {
         foreach ($table as $orig => $trans) {
             // Format::encode defaults to UTF-8 output
             $source = new Unicode($orig, $charset);
             $trans = new Unicode($trans, $charset);
             $table[(string) $source->encode('utf-8')] = (string) $trans->encode('utf-8');
             unset($table[$orig]);
         }
     }
     // Add in some meta-data
     $table[self::META_HEADER] = array('Revision' => $reader->revision, 'Total-Strings' => $reader->total, 'Table-Size' => count($table), 'Build-Timestamp' => gmdate(DATE_RFC822), 'Format-Version' => 'A', 'Encoding' => 'UTF-8');
     // Serialize the PHP array and write to output
     $contents = sprintf('<?php return %s;', var_export($table, true));
     if ($return) {
         return $contents;
     } else {
         fwrite($stream, $contents);
     }
 }