Exemple #1
2
/**
 * utf8::str_pad
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _str_pad($str, $final_str_length, $pad_str = ' ', $pad_type = STR_PAD_RIGHT)
{
    if (utf8::is_ascii($str) and utf8::is_ascii($pad_str)) {
        return str_pad($str, $final_str_length, $pad_str, $pad_type);
    }
    $str_length = utf8::strlen($str);
    if ($final_str_length <= 0 or $final_str_length <= $str_length) {
        return $str;
    }
    $pad_str_length = utf8::strlen($pad_str);
    $pad_length = $final_str_length - $str_length;
    if ($pad_type == STR_PAD_RIGHT) {
        $repeat = ceil($pad_length / $pad_str_length);
        return utf8::substr($str . str_repeat($pad_str, $repeat), 0, $final_str_length);
    }
    if ($pad_type == STR_PAD_LEFT) {
        $repeat = ceil($pad_length / $pad_str_length);
        return utf8::substr(str_repeat($pad_str, $repeat), 0, floor($pad_length)) . $str;
    }
    if ($pad_type == STR_PAD_BOTH) {
        $pad_length /= 2;
        $pad_length_left = floor($pad_length);
        $pad_length_right = ceil($pad_length);
        $repeat_left = ceil($pad_length_left / $pad_str_length);
        $repeat_right = ceil($pad_length_right / $pad_str_length);
        $pad_left = utf8::substr(str_repeat($pad_str, $repeat_left), 0, $pad_length_left);
        $pad_right = utf8::substr(str_repeat($pad_str, $repeat_right), 0, $pad_length_left);
        return $pad_left . $str . $pad_right;
    }
    trigger_error('utf8::str_pad: Unknown padding type (' . $type . ')', E_USER_ERROR);
}
Exemple #2
0
function nc_utf2win($str)
{
    if (extension_loaded('mbstring')) {
        return mb_convert_encoding($str, "cp1251", "UTF-8");
    }
    if (extension_loaded('iconv')) {
        return iconv('UTF-8', 'cp1251', $str);
    }
    global $_UTFConverter;
    if (!$_UTFConverter) {
        require_once "utf8/utf8.class.php";
        $_UTFConverter = new utf8(CP1251);
    }
    return $_UTFConverter->utf8ToStr($str);
}
Exemple #3
0
 public function set($plugin, $keyword, $replace = array(), $pageTitle = true)
 {
     if (!($data = $this->cache->item('core_meta_tags_' . $plugin . '_' . session::item('language')))) {
         $data = array();
         $result = $this->db->query("SELECT * FROM `:prefix:core_meta_tags` WHERE `plugin`=?", array($plugin))->result();
         foreach ($result as $tags) {
             $data[$tags['keyword']]['title'] = $tags['meta_title_' . session::item('language')];
             $data[$tags['keyword']]['description'] = $tags['meta_description_' . session::item('language')];
             $data[$tags['keyword']]['keywords'] = $tags['meta_keywords_' . session::item('language')];
         }
         $this->cache->set('core_meta_tags_' . $plugin . '_' . session::item('language'), $data, 60 * 60 * 24 * 30);
     }
     foreach ($replace as $section => $array) {
         foreach ($array as $k => $v) {
             $k = '[' . $section . '.' . $k . ']';
             if (is_array($v)) {
                 $v = count($v) == 1 ? current($v) : implode(',', $v);
             }
             $data[$keyword]['title'] = utf8::str_replace($k, $v, $data[$keyword]['title']);
             $data[$keyword]['description'] = utf8::str_replace($k, $v, $data[$keyword]['description']);
             $data[$keyword]['keywords'] = utf8::str_replace($k, $v, $data[$keyword]['keywords']);
         }
     }
     if (isset($data[$keyword])) {
         if ($pageTitle) {
             view::setTitle($data[$keyword]['title']);
         } else {
             view::setMetaTitle($data[$keyword]['title']);
         }
         view::setMetaDescription($data[$keyword]['description']);
         view::setMetaKeywords($data[$keyword]['keywords']);
     }
 }
Exemple #4
0
 public function delete()
 {
     // Get URI vars
     $slugID = urldecode(utf8::trim(uri::segment(4)));
     // Do we have a slug ID?
     if ($slugID == '') {
         error::show404();
     }
     // Get user
     if (!($user = $this->users_model->getUser($slugID)) || !$user['active'] || !$user['verified']) {
         error::show404();
     } elseif ($user['user_id'] == session::item('user_id')) {
         router::redirect($user['slug']);
     }
     // Does user exist?
     if (!($blocked = $this->users_blocked_model->getUser($user['user_id'], true))) {
         view::setError(__('no_blocked_user', 'users_blocked'));
         router::redirect('users/blocked');
     }
     // Delete blocked user
     $this->users_blocked_model->deleteBlockedUser(session::item('user_id'), $user['user_id']);
     // Success
     view::setInfo(__('user_unblocked', 'users_blocked'));
     router::redirect(input::get('page') ? 'users/blocked' : $user['slug']);
 }
function zenphoto_sendmail($msg, $email_list, $subject, $message, $from_mail, $from_name, $cc_addresses, $replyTo, $html = false)
{
    $headers = sprintf('From: %1$s <%2$s>', $from_name, $from_mail) . "\n";
    if (count($cc_addresses) > 0) {
        $cclist = '';
        foreach ($cc_addresses as $cc_name => $cc_mail) {
            $cclist .= ',' . $cc_mail;
        }
        $headers .= 'Cc: ' . substr($cclist, 1) . "\n";
    }
    if ($replyTo) {
        $headers .= 'Reply-To: ' . array_shift($replyTo) . "\n";
    }
    $result = true;
    foreach ($email_list as $to_mail) {
        $result = $result && utf8::send_mail($to_mail, $subject, $message, $headers, '', $html);
    }
    if (!$result) {
        if (!empty($msg)) {
            $msg .= '<br />';
        }
        $msg .= sprintf(gettext('<code>zenphoto_sendmail</code> failed to send <em>%s</em> to one or more recipients.'), $subject);
    }
    return $msg;
}
Exemple #6
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;
 }
 public function testNumeric_to_utf8()
 {
     $ns = array(0x1403, 0x1403, 0x1403);
     $a = chr(0xe1) . chr(0x90) . chr(0x83) . chr(0xe1) . chr(0x90) . chr(0x83) . chr(0xe1) . chr(0x90) . chr(0x83);
     $r = utf8::numeric_to_utf8($ns);
     $this->assertEquals($a, $r);
 }
Exemple #8
0
/**
 * utf8::trim
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _trim($str, $charlist = NULL)
{
    if ($charlist === NULL) {
        return trim($str);
    }
    return utf8::ltrim(utf8::rtrim($str, $charlist), $charlist);
}
Exemple #9
0
/**
 * utf8::strlen
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007-2008 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strlen($str)
{
    if (utf8::is_ascii($str)) {
        return strlen($str);
    }
    return strlen(utf8_decode($str));
}
Exemple #10
0
 public function __construct()
 {
     parent::__construct();
     if (!config::item('news_blog', 'news') && uri::segment(1) != 'news') {
         router::redirect('news/' . utf8::substr(uri::getURI(), 5));
     }
 }
Exemple #11
0
 /**
  * Outputs the Captcha image.
  *
  * @param boolean $html HTML output
  * @return mixed
  */
 public function render($html = TRUE)
 {
     // Creates a black image to start from
     $this->image_create(Captcha::$config['background']);
     // Add random white/gray arcs, amount depends on complexity setting
     $count = (Captcha::$config['width'] + Captcha::$config['height']) / 2;
     $count = $count / 5 * min(10, Captcha::$config['complexity']);
     for ($i = 0; $i < $count; $i++) {
         imagesetthickness($this->image, mt_rand(1, 2));
         $color = imagecolorallocatealpha($this->image, 255, 255, 255, mt_rand(0, 120));
         imagearc($this->image, mt_rand(-Captcha::$config['width'], Captcha::$config['width']), mt_rand(-Captcha::$config['height'], Captcha::$config['height']), mt_rand(-Captcha::$config['width'], Captcha::$config['width']), mt_rand(-Captcha::$config['height'], Captcha::$config['height']), mt_rand(0, 360), mt_rand(0, 360), $color);
     }
     // Use different fonts if available
     $font = Captcha::$config['fontpath'] . Captcha::$config['fonts'][array_rand(Captcha::$config['fonts'])];
     // Draw the character's white shadows
     $size = (int) min(Captcha::$config['height'] / 2, Captcha::$config['width'] * 0.8 / utf8::strlen($this->response));
     $angle = mt_rand(-15 + utf8::strlen($this->response), 15 - utf8::strlen($this->response));
     $x = mt_rand(1, Captcha::$config['width'] * 0.9 - $size * utf8::strlen($this->response));
     $y = (Captcha::$config['height'] - $size) / 2 + $size;
     $color = imagecolorallocate($this->image, 255, 255, 255);
     imagefttext($this->image, $size, $angle, $x + 1, $y + 1, $color, $font, $this->response);
     // Add more shadows for lower complexities
     Captcha::$config['complexity'] < 10 and imagefttext($this->image, $size, $angle, $x - 1, $y - 1, $color, $font, $this->response);
     Captcha::$config['complexity'] < 8 and imagefttext($this->image, $size, $angle, $x - 2, $y + 2, $color, $font, $this->response);
     Captcha::$config['complexity'] < 6 and imagefttext($this->image, $size, $angle, $x + 2, $y - 2, $color, $font, $this->response);
     Captcha::$config['complexity'] < 4 and imagefttext($this->image, $size, $angle, $x + 3, $y + 3, $color, $font, $this->response);
     Captcha::$config['complexity'] < 2 and imagefttext($this->image, $size, $angle, $x - 3, $y - 3, $color, $font, $this->response);
     // Finally draw the foreground characters
     $color = imagecolorallocate($this->image, 0, 0, 0);
     imagefttext($this->image, $size, $angle, $x, $y, $color, $font, $this->response);
     // Output
     return $this->image_render($html);
 }
Exemple #12
0
 /**
  * Returns an array of the names of the days, using the current locale.
  *
  * @param   integer  left of day names
  * @return  array
  */
 public static function days($length = TRUE)
 {
     // strftime day format
     $format = $length > 3 ? '%A' : '%a';
     // Days of the week
     $days = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
     if (Calendar::$start_monday === TRUE) {
         // Push Sunday to the end of the days
         array_push($days, array_shift($days));
     }
     if (strpos(Kohana::config('locale.language.0'), 'en') !== 0) {
         // This is a bit awkward, but it works properly and is reliable
         foreach ($days as $i => $day) {
             // Convert the English names to i18n names
             $days[$i] = strftime($format, strtotime($day));
         }
     }
     if (is_int($length) or ctype_digit($length)) {
         foreach ($days as $i => $day) {
             // Shorten the days to the expected length
             $days[$i] = utf8::substr($day, 0, $length);
         }
     }
     return $days;
 }
Exemple #13
0
 public static function normalize($string, $encoding = 'utf-8')
 {
     $string = iconv($encoding, 'ascii//translit', $string);
     $string = utf8::str_ireplace(',', '', $string);
     $string = utf8::str_ireplace('\'', '', $string);
     $string = preg_replace('/[^a-z0-9-\\+\\/_ ]/iUD', '_', $string);
     return $string;
 }
/**
 * utf8::ucfirst
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _ucfirst($str)
{
    if (utf8::is_ascii($str)) {
        return ucfirst($str);
    }
    preg_match('/^(.?)(.*)$/us', $str, $matches);
    return utf8::strtoupper($matches[1]) . $matches[2];
}
Exemple #15
0
/**
 * utf8::strrev
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007-2008 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strrev($str)
{
    if (utf8::is_ascii($str)) {
        return strrev($str);
    }
    preg_match_all('/./us', $str, $matches);
    return implode('', array_reverse($matches[0]));
}
 /**
  * Method that allows sending any kind of HTTP request to remote url
  *
  * @param string $method
  * @param string $url
  * @param array $headers
  * @param array $data
  * @return HTTP_Response
  */
 public static function request($method, $url, $headers = array(), $data = array())
 {
     $valid_methods = array('POST', 'GET', 'PUT', 'DELETE');
     $method = utf8::strtoupper($method);
     if (!valid::url($url, 'http')) {
         return FALSE;
     }
     if (!in_array($method, $valid_methods)) {
         return FALSE;
     }
     // Get the hostname and path
     $url = parse_url($url);
     if (empty($url['path'])) {
         // Request the root document
         $url['path'] = '/';
     }
     // Open a remote connection
     $remote = fsockopen($url['host'], 80, $errno, $errstr, 5);
     if (!is_resource($remote)) {
         return FALSE;
     }
     // Set CRLF
     $CRLF = "\r\n";
     $path = $url['path'];
     if ($method == 'GET' and !empty($url['query'])) {
         $path .= '?' . $url['query'];
     }
     $headers_default = array('Host' => $url['host'], 'Connection' => 'close', 'User-Agent' => 'Ushahidi Scheduler (+http://ushahidi.com/)');
     $body_content = '';
     if ($method != 'GET') {
         $headers_default['Content-Type'] = 'application/x-www-form-urlencoded';
         if (count($data) > 0) {
             $body_content = http_build_query($data);
         }
         $headers_default['Content-Length'] = strlen($body_content);
     }
     $headers = array_merge($headers_default, $headers);
     // Send request
     $request = $method . ' ' . $path . ' HTTP/1.0' . $CRLF;
     foreach ($headers as $key => $value) {
         $request .= $key . ': ' . $value . $CRLF;
     }
     // Send one more CRLF to terminate the headers
     $request .= $CRLF;
     if ($body_content) {
         $request .= $body_content . $CRLF;
     }
     fwrite($remote, $request);
     $response = '';
     while (!feof($remote)) {
         // Get 1K from buffer
         $response .= fread($remote, 1024);
     }
     // Close the connection
     fclose($remote);
     return new HTTP_Response($response, $method);
 }
Exemple #17
0
/**
 * utf8::strcasecmp
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strcasecmp($str1, $str2)
{
    if (utf8::is_ascii($str1) and utf8::is_ascii($str2)) {
        return strcasecmp($str1, $str2);
    }
    $str1 = utf8::strtolower($str1);
    $str2 = utf8::strtolower($str2);
    return strcmp($str1, $str2);
}
Exemple #18
0
/**
 * utf8::ucwords
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007-2008 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _ucwords($str)
{
    if (utf8::is_ascii($str)) {
        return ucwords($str);
    }
    // [\x0c\x09\x0b\x0a\x0d\x20] matches form feeds, horizontal tabs, vertical tabs, linefeeds and carriage returns.
    // This corresponds to the definition of a 'word' defined at http://php.net/ucwords
    return preg_replace('/(?<=^|[\\x0c\\x09\\x0b\\x0a\\x0d\\x20])[^\\x0c\\x09\\x0b\\x0a\\x0d\\x20]/ue', 'utf8::strtoupper(\'$0\')', $str);
}
Exemple #19
0
 static function extract($item)
 {
     $keys = array();
     // Only try to extract EXIF from photos
     if ($item->is_photo() && $item->mime_type == "image/jpeg") {
         $data = array();
         require_once MODPATH . "exif/lib/exif.php";
         $exif_raw = read_exif_data_raw($item->file_path(), false);
         if (isset($exif_raw['ValidEXIFData'])) {
             foreach (self::_keys() as $field => $exifvar) {
                 if (isset($exif_raw[$exifvar[0]][$exifvar[1]])) {
                     $value = $exif_raw[$exifvar[0]][$exifvar[1]];
                     if (function_exists("mb_detect_encoding") && mb_detect_encoding($value) != "UTF-8") {
                         $value = utf8_encode($value);
                     }
                     $keys[$field] = utf8::clean($value);
                     if ($field == "DateTime") {
                         $time = strtotime($value);
                         if ($time > 0) {
                             $item->captured = $time;
                         }
                     } else {
                         if ($field == "Caption" && !$item->description) {
                             $item->description = $value;
                         }
                     }
                 }
             }
         }
         $size = getimagesize($item->file_path(), $info);
         if (is_array($info) && !empty($info["APP13"])) {
             $iptc = iptcparse($info["APP13"]);
             foreach (array("Keywords" => "2#025", "Caption" => "2#120") as $keyword => $iptc_key) {
                 if (!empty($iptc[$iptc_key])) {
                     $value = implode(" ", $iptc[$iptc_key]);
                     if (function_exists("mb_detect_encoding") && mb_detect_encoding($value) != "UTF-8") {
                         $value = utf8_encode($value);
                     }
                     $keys[$keyword] = utf8::clean($value);
                     if ($keyword == "Caption" && !$item->description) {
                         $item->description = $value;
                     }
                 }
             }
         }
     }
     $item->save();
     $record = ORM::factory("exif_record")->where("item_id", $item->id)->find();
     if (!$record->loaded) {
         $record->item_id = $item->id;
     }
     $record->data = serialize($keys);
     $record->key_count = count($keys);
     $record->dirty = 0;
     $record->save();
 }
 /**
  * Method to convert the content to UTF
  * @note Depricated on Ofuz 0.6 and will not be abailable on further version
  */
 function convert_to_utf($content)
 {
     include_once 'class/utf8.class.php';
     $do_utf8 = new utf8();
     $content = $do_utf8->convert($content, 'windows-1252', "UTF-8");
     $content = $do_utf8->convert($content, 'US-ASCII', "UTF-8");
     $content = $do_utf8->convert($content, 'ISO-8859-1', "UTF-8");
     $content = $do_utf8->convert($content, 'ISO-8859-2', "UTF-8");
     $content = $do_utf8->convert($content, 'ISO-8859-3', "UTF-8");
     $content = $do_utf8->convert($content, 'ISO-8859-4', "UTF-8");
     $content = $do_utf8->convert($content, 'ISO-8859-5', "UTF-8");
     $content = $do_utf8->convert($content, 'ISO-8859-6', "UTF-8");
     $content = $do_utf8->convert($content, 'ISO-8859-7', "UTF-8");
     $content = $do_utf8->convert($content, 'ISO-8859-8', "UTF-8");
     $content = $do_utf8->convert($content, 'ISO-8859-8-i', "UTF-8");
     $content = $do_utf8->convert($content, 'ISO-8859-9', "UTF-8");
     $content = $do_utf8->convert($content, 'ISO-8859-15', "UTF-8");
     return $content;
 }
 public function label($val = NULL)
 {
     if ($val === NULL) {
         // Do not display labels for checkboxes, labels wrap checkboxes
         return '';
     } else {
         $this->data['label'] = $val === TRUE ? utf8::ucwords(inflector::humanize($this->name)) : $val;
         return $this;
     }
 }
Exemple #22
0
/**
 * utf8::strlen
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strlen($str)
{
    // Try mb_strlen() first because it's faster than combination of is_ascii() and strlen()
    if (SERVER_UTF8) {
        return mb_strlen($str);
    }
    if (utf8::is_ascii($str)) {
        return strlen($str);
    }
    return strlen(utf8_decode($str));
}
Exemple #23
0
/**
 * utf8::substr
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _substr($str, $offset, $length = NULL)
{
    if (SERVER_UTF8) {
        return $length === NULL ? mb_substr($str, $offset) : mb_substr($str, $offset, $length);
    }
    if (utf8::is_ascii($str)) {
        return $length === NULL ? substr($str, $offset) : substr($str, $offset, $length);
    }
    // Normalize params
    $str = (string) $str;
    $strlen = utf8::strlen($str);
    $offset = (int) ($offset < 0) ? max(0, $strlen + $offset) : $offset;
    // Normalize to positive offset
    $length = $length === NULL ? NULL : (int) $length;
    // Impossible
    if ($length === 0 or $offset >= $strlen or $length < 0 and $length <= $offset - $strlen) {
        return '';
    }
    // Whole string
    if ($offset == 0 and ($length === NULL or $length >= $strlen)) {
        return $str;
    }
    // Build regex
    $regex = '^';
    // Create an offset expression
    if ($offset > 0) {
        // PCRE repeating quantifiers must be less than 65536, so repeat when necessary
        $x = (int) ($offset / 65535);
        $y = (int) ($offset % 65535);
        $regex .= $x == 0 ? '' : '(?:.{65535}){' . $x . '}';
        $regex .= $y == 0 ? '' : '.{' . $y . '}';
    }
    // Create a length expression
    if ($length === NULL) {
        $regex .= '(.*)';
        // No length set, grab it all
    } elseif ($length > 0) {
        // Reduce length so that it can't go beyond the end of the string
        $length = min($strlen - $offset, $length);
        $x = (int) ($length / 65535);
        $y = (int) ($length % 65535);
        $regex .= '(';
        $regex .= $x == 0 ? '' : '(?:.{65535}){' . $x . '}';
        $regex .= '.{' . $y . '})';
    } else {
        $x = (int) (-$length / 65535);
        $y = (int) (-$length % 65535);
        $regex .= '(.*)';
        $regex .= $x == 0 ? '' : '(?:.{65535}){' . $x . '}';
        $regex .= '.{' . $y . '}';
    }
    preg_match('/' . $regex . '/us', $str, $matches);
    return $matches[1];
}
Exemple #24
0
/**
 * utf8::rtrim
 *
 * @package    Kohana
 * @author     Kohana Team
 * @copyright  (c) 2007-2008 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _rtrim($str, $charlist = NULL)
{
    if ($charlist === NULL) {
        return rtrim($str);
    }
    if (utf8::is_ascii($charlist)) {
        return rtrim($str, $charlist);
    }
    $charlist = preg_replace('#[-\\[\\]:\\\\^/]#', '\\\\$0', $charlist);
    return preg_replace('/[' . $charlist . ']++$/uD', '', $str);
}
Exemple #25
0
/**
 * utf8::substr_replace
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _substr_replace($str, $replacement, $offset, $length = NULL)
{
    if (utf8::is_ascii($str)) {
        return $length === NULL ? substr_replace($str, $replacement, $offset) : substr_replace($str, $replacement, $offset, $length);
    }
    $length = $length === NULL ? utf8::strlen($str) : (int) $length;
    preg_match_all('/./us', $str, $str_array);
    preg_match_all('/./us', $replacement, $replacement_array);
    array_splice($str_array[0], $offset, $length, $replacement_array[0]);
    return implode('', $str_array[0]);
}
Exemple #26
0
 public static function __normalize_filename($filename)
 {
     $encoding = 'utf-8';
     $name = pathinfo($filename, PATHINFO_FILENAME);
     $ext = pathinfo($filename, PATHINFO_EXTENSION);
     $name = iconv($encoding, 'ascii//translit', $name);
     $name = utf8::str_ireplace(',', '', $name);
     $name = utf8::str_ireplace('\'', '', $name);
     $name = preg_replace('/[^a-z0-9\\-_\\$\\.\\+\\!\\(\\)]/i', '_', $name);
     return preg_replace('/_{2,}/i', '_', $name) . '.' . $ext;
 }
Exemple #27
0
 function __construct($filehandle)
 {
     $this->filehandle = $filehandle;
     // 1000 chars is max line length
     if (($fields = fgetcsv($filehandle, 1000)) !== FALSE) {
         $colnum = 0;
         foreach ($fields as $field) {
             $this->colnames[utf8::strtoupper($field)] = $colnum;
             $colnum++;
         }
     }
 }
 /**
  * Function: index
  *
  * Description: This is the function that renders and stores the settings for the enhanced map
  *
  * Params(POST)
  * - adminmap_height - CSS specification of the height of the map
  * - adminmap_width - CSS specification of the width of the map
  * - enable_bigmap - Is the front end big map enabled?
  * - enable_printmap - Is the print map enabled
  * - enable_iframemap - Is the iframe map enabled
  * - adminmap_height - The height of the admin map
  * - show_unapproved_backend - Should unapproved reports be shown on the back end map
  * - show_unapproved_frontend - Should unapproved reports be shown on the front end map
  * - show_hidden_categories_backend - Should hidden categories be shown on the back end map
  *
  * Views: enhancedmap/enhancedmap_settings
  *
  * Results: Enhanced map settings are updated.
  */
 public function index()
 {
     $this->template->content = new View('enhancedmap/enhancedmap_settings');
     $this->template->content->errors = array();
     $this->template->content->form_saved = false;
     $this->template->content->yesno_array = array('true' => utf8::strtoupper(Kohana::lang('ui_main.yes')), 'false' => utf8::strtoupper(Kohana::lang('ui_main.no')));
     $form = array();
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         //print_r($_POST);
         //echo "<br><br/>";
         $post = new Validation($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('adminmap_height', 'required', 'length[1,99]');
         $post->add_rules('adminmap_width', 'required', 'length[1,99]');
         /*
         $post->add_rules('enable_bigmap','required','in_array["true", "false"]');
         $post->add_rules('enable_printmap','required','in_array[\'true\', \'false\']');
         $post->add_rules('enable_iframemap','required','in_array[\'true\', \'false\']');
         $post->add_rules('adminmap_height','required','in_array[\'true\', \'false\']');
         $post->add_rules('show_unapproved_backend','required','in_array[\'true\', \'false\']');
         $post->add_rules('show_unapproved_frontend','required','in_array[\'true\', \'false\']');
         $post->add_rules('show_hidden_categories_backend','required','in_array[\'true\', \'false\']');
         */
         if ($post->validate()) {
             // Yes! everything is valid
             //load in the settings from the DB
             //load up all the settings
             $settings = ORM::factory('enhancedmap_settings')->find_all();
             foreach ($settings as $setting) {
                 $setting->value = $_POST[$setting->key];
                 $setting->save();
             }
             $form = $_POST;
             $this->template->content->form_saved = true;
         } else {
             // repopulate the form fields
             $form = $_POST;
             // populate the error fields, if any
             $this->template->content->errors = $post->errors('settings');
         }
     } else {
         //load up all the settings
         $settings = ORM::factory('enhancedmap_settings')->find_all();
         foreach ($settings as $setting) {
             $form[$setting->key] = $setting->value;
         }
     }
     $this->template->content->form = $form;
 }
Exemple #29
0
 public static function number_to_text($value, $separator = ' ')
 {
     $digits = (string) $value;
     if (utf8::strpos($digits, '.') !== FALSE) {
         $digits = explode('.', $digits);
         return static::number_to_text($digits[0]) . $separator . static::number_to_text($digits[1]);
     }
     $jednosci = array('zero', 'jeden', 'dwa', 'trzy', 'cztery', 'pięć', 'sześć', 'siedem', 'osiem', 'dziewięć');
     $dziesiatki = array('', 'dziesięć', 'dwadzieścia', 'trzydzieści', 'czterdzieści', 'piećdziesiąt', 'sześćdziesiąt', 'siedemdziesiąt', 'osiemdziesiąt', 'dziewiećdziesiąt');
     $setki = array('', 'sto', 'dwieście', 'trzysta', 'czterysta', 'piećset', 'sześćset', 'siedemset', 'osiemset', 'dziewiećset');
     $nastki = array('dziesieć', 'jedenaście', 'dwanaście', 'trzynaście', 'czternaście', 'piętnaście', 'szesnaście', 'siedemnaście', 'osiemnaście', 'dzięwietnaście');
     $tysiace = array('tysiąc', 'tysiące', 'tysięcy');
     $digits = (string) $value;
     $digits = utf8::strrev($digits);
     $i = utf8::strlen($digits);
     $string = '';
     if ($i > 5 && $digits[5] > 0) {
         $string .= $setki[$digits[5]] . ' ';
     }
     if ($i > 4 && $digits[4] > 1) {
         $string .= $dziesiatki[$digits[4]] . ' ';
     } elseif ($i > 3 && $digits[4] == 1) {
         $string .= $nastki[$digits[3]] . ' ';
     }
     if ($i > 3 && $digits[3] > 0 && $digits[4] != 1) {
         $string .= $jednosci[$digits[3]] . ' ';
     }
     $tmpStr = utf8::substr(utf8::strrev($digits), 0, -3);
     if (utf8::strlen($tmpStr) > 0) {
         $tmpInt = (int) $tmpStr;
         if ($tmpInt == 1) {
             $string .= $tysiace[0] . ' ';
         } elseif ($tmpInt % 10 > 1 && $tmpInt % 10 < 5 && ($tmpInt < 10 || $tmpInt > 20)) {
             $string .= $tysiace[1] . ' ';
         } else {
             $string .= $tysiace[2] . ' ';
         }
     }
     if ($i > 2 && $digits[2] > 0) {
         $string .= $setki[$digits[2]] . ' ';
     }
     if ($i > 1 && $digits[1] > 1) {
         $string .= $dziesiatki[$digits[1]] . ' ';
     } elseif ($i > 0 && $digits[1] == 1) {
         $string .= $nastki[$digits[0]] . ' ';
     }
     if ($digits[0] > 0 && $digits[1] != 1) {
         $string .= $jednosci[$digits[0]] . ' ';
     }
     return $string;
 }
Exemple #30
0
/**
 * utf8::strrpos
 *
 * @package    Kohana
 * @author     Kohana Team
 * @copyright  (c) 2007-2008 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strrpos($str, $search, $offset = 0)
{
    $offset = (int) $offset;
    if (utf8::is_ascii($str) and utf8::is_ascii($search)) {
        return strrpos($str, $search, $offset);
    }
    if ($offset == 0) {
        $array = explode($search, $str, -1);
        return isset($array[0]) ? utf8::strlen(implode($search, $array)) : FALSE;
    }
    $str = utf8::substr($str, $offset);
    $pos = utf8::strrpos($str, $search);
    return $pos === FALSE ? FALSE : $pos + $offset;
}