示例#1
1
function VietCoding_sanitize_title_with_dashes($title)
{
    $title = vi2en($title);
    $title = strip_tags($title);
    // Preserve escaped octets.
    $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
    // Remove percent signs that are not part of an octet.
    $title = str_replace('%', '', $title);
    // Restore octets.
    $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);
    $title = remove_accents($title);
    if (seems_utf8($title)) {
        if (function_exists('mb_strtolower')) {
            $title = mb_strtolower($title, 'UTF-8');
        }
        $title = utf8_uri_encode($title, 200);
    }
    $title = strtolower($title);
    $title = preg_replace('/&.+?;/', '', $title);
    // kill entities
    $title = str_replace('.', '-', $title);
    $title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
    $title = preg_replace('/\\s+/', '-', $title);
    $title = preg_replace('|-+|', '-', $title);
    $title = trim($title, '-');
    $title = vi2en($title);
    return $title;
}
 public function cdata($text)
 {
     if (!seems_utf8($text)) {
         $text = utf8_encode($text);
     }
     return parent::cdata($text);
 }
示例#3
0
 /**
  * Format URI
  * 
  * Formats a category uri.
  * 
  * @param	string $cat_uri The uri name
  * @uses 	check_uri
  * @uses		remove_accents
  * @uses		seems_utf8
  * @uses		utf8_uri_encode
  * @uses		format_uri
  * @return	string A cleaned uri
  */
 function format_uri($cat_uri, $i = 0, $cat_id = false)
 {
     $cat_uri = strip_tags($cat_uri);
     // Preserve escaped octets.
     $cat_uri = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $cat_uri);
     // Remove percent signs that are not part of an octet.
     $cat_uri = str_replace('%', '', $cat_uri);
     // Restore octets.
     $cat_uri = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $cat_uri);
     $cat_uri = remove_accents($cat_uri);
     if (seems_utf8($cat_uri)) {
         if (function_exists('mb_strtolower')) {
             $cat_uri = mb_strtolower($cat_uri, 'UTF-8');
         }
         $cat_uri = utf8_uri_encode($cat_uri, 200);
     }
     $cat_uri = strtolower($cat_uri);
     $cat_uri = preg_replace('/&.+?;/', '', $cat_uri);
     // kill entities
     $cat_uri = preg_replace('/[^%a-z0-9 _-]/', '', $cat_uri);
     $cat_uri = preg_replace('/\\s+/', '-', $cat_uri);
     $cat_uri = preg_replace('|-+|', '-', $cat_uri);
     $cat_uri = trim($cat_uri, '-');
     if ($i > 0) {
         $cat_uri = $cat_uri . "-" . $i;
     }
     if (!$this->check_uri($cat_uri, $cat_id)) {
         $i++;
         $cat_uri = $this->format_uri($cat_uri, $i);
     }
     return $cat_uri;
 }
示例#4
0
/**
 * Convert from dotclear charset to utf8 if required
 *
 * @package WordPress
 * @subpackage Dotclear_Import
 *
 * @param string $s
 * @return string
 */
function csc($s)
{
    if (seems_utf8($s)) {
        return $s;
    } else {
        return iconv(get_option("dccharset"), "UTF-8", $s);
    }
}
示例#5
0
/**
 * Wrap given string in XML CDATA tag.
 *
 * @since 2.1.0
 *
 * @param string $str String to wrap in XML CDATA tag.
 */
function wxr_cdata($str)
{
    if (seems_utf8($str) == false) {
        $str = utf8_encode($str);
    }
    // $str = ent2ncr(esc_html($str));
    $str = "<![CDATA[{$str}" . (substr($str, -1) == ']' ? ' ' : '') . ']]>';
    return $str;
}
/**
 * Wrap given string in XML CDATA tag.
 *
 * @since 2.1.0
 *
 * @param string $str String to wrap in XML CDATA tag.
 * @return string
 */
function wxr_cdata($str)
{
    if (seems_utf8($str) == false) {
        $str = utf8_encode($str);
    }
    // $str = ent2ncr(esc_html($str));
    $str = '<![CDATA[' . str_replace(']]>', ']]]]><![CDATA[>', $str) . ']]>';
    return $str;
}
示例#7
0
 function wxr_cdata($str)
 {
     if (seems_utf8($str) == false) {
         $str = utf8_encode($str);
     }
     // $str = ent2ncr(wp_specialchars($str));
     $str = "<![CDATA[{$str}" . (substr($str, -1) == ']' ? ' ' : '') . "]]>";
     return $str;
 }
示例#8
0
function rutranslit($title)
{
    global $chars;
    if (seems_utf8($title)) {
        $title = urldecode($title);
    }
    $title = preg_replace('/\\.+/', '.', $title);
    $r = strtr($title, $chars);
    return $r;
}
示例#9
0
 public function guess_encoding($string, $encoding = '')
 {
     $blog_encoding = $this->blog_encoding;
     if (!$encoding && seems_utf8($string)) {
         return 'UTF-8';
     } elseif (!$encoding) {
         return $blog_encoding;
     } else {
         return $encoding;
     }
 }
示例#10
0
function o42_cu_permalinks($title)
{
    global $o42_cu_chars;
    if (seems_utf8($title)) {
        $invalid_latin_chars = array(chr(197) . chr(146) => 'OE', chr(197) . chr(147) => 'oe', chr(197) . chr(160) => 'S', chr(197) . chr(189) => 'Z', chr(197) . chr(161) => 's', chr(197) . chr(190) => 'z', chr(226) . chr(130) . chr(172) => 'E');
        $title = utf8_decode(strtr($title, $invalid_latin_chars));
    }
    $title = str_replace($o42_cu_chars['ecto'], $o42_cu_chars['perma'], $title);
    $title = str_replace($o42_cu_chars['in'], $o42_cu_chars['perma'], $title);
    $title = sanitize_title_with_dashes($title);
    return $title;
}
function woo_ce_is_xml_cdata( $string = '', $export_type = '', $field = '' ) {

	if( !empty( $string ) && seems_utf8( trim( $string ) ) == false || preg_match( '!.!u', trim( $string ) ) == false )
		return true;
	if( !empty( $export_type ) && !empty( $export_type ) ) {
		// Force these fields to export as CDATA
		if(
			$export_type == 'product' && $field == 'category'
		)
			return true;
	}

}
示例#12
0
function remove_accents($string)
{
    if (seems_utf8($string)) {
        $chars = array(chr(195) . chr(128) => 'A', chr(195) . chr(129) => 'A', chr(195) . chr(130) => 'A', chr(195) . chr(131) => 'A', chr(195) . chr(132) => 'A', chr(195) . chr(133) => 'A', chr(195) . chr(135) => 'C', chr(195) . chr(136) => 'E', chr(195) . chr(137) => 'E', chr(195) . chr(138) => 'E', chr(195) . chr(139) => 'E', chr(195) . chr(140) => 'I', chr(195) . chr(141) => 'I', chr(195) . chr(142) => 'I', chr(195) . chr(143) => 'I', chr(195) . chr(145) => 'N', chr(195) . chr(146) => 'O', chr(195) . chr(147) => 'O', chr(195) . chr(148) => 'O', chr(195) . chr(149) => 'O', chr(195) . chr(150) => 'O', chr(195) . chr(153) => 'U', chr(195) . chr(154) => 'U', chr(195) . chr(155) => 'U', chr(195) . chr(156) => 'U', chr(195) . chr(157) => 'Y', chr(195) . chr(159) => 's', chr(195) . chr(160) => 'a', chr(195) . chr(161) => 'a', chr(195) . chr(162) => 'a', chr(195) . chr(163) => 'a', chr(195) . chr(164) => 'a', chr(195) . chr(165) => 'a', chr(195) . chr(167) => 'c', chr(195) . chr(168) => 'e', chr(195) . chr(169) => 'e', chr(195) . chr(170) => 'e', chr(195) . chr(171) => 'e', chr(195) . chr(172) => 'i', chr(195) . chr(173) => 'i', chr(195) . chr(174) => 'i', chr(195) . chr(175) => 'i', chr(195) . chr(177) => 'n', chr(195) . chr(178) => 'o', chr(195) . chr(179) => 'o', chr(195) . chr(180) => 'o', chr(195) . chr(181) => 'o', chr(195) . chr(182) => 'o', chr(195) . chr(182) => 'o', chr(195) . chr(185) => 'u', chr(195) . chr(186) => 'u', chr(195) . chr(187) => 'u', chr(195) . chr(188) => 'u', chr(195) . chr(189) => 'y', chr(195) . chr(191) => 'y', chr(196) . chr(128) => 'A', chr(196) . chr(129) => 'a', chr(196) . chr(130) => 'A', chr(196) . chr(131) => 'a', chr(196) . chr(132) => 'A', chr(196) . chr(133) => 'a', chr(196) . chr(134) => 'C', chr(196) . chr(135) => 'c', chr(196) . chr(136) => 'C', chr(196) . chr(137) => 'c', chr(196) . chr(138) => 'C', chr(196) . chr(139) => 'c', chr(196) . chr(140) => 'C', chr(196) . chr(141) => 'c', chr(196) . chr(142) => 'D', chr(196) . chr(143) => 'd', chr(196) . chr(144) => 'D', chr(196) . chr(145) => 'd', chr(196) . chr(146) => 'E', chr(196) . chr(147) => 'e', chr(196) . chr(148) => 'E', chr(196) . chr(149) => 'e', chr(196) . chr(150) => 'E', chr(196) . chr(151) => 'e', chr(196) . chr(152) => 'E', chr(196) . chr(153) => 'e', chr(196) . chr(154) => 'E', chr(196) . chr(155) => 'e', chr(196) . chr(156) => 'G', chr(196) . chr(157) => 'g', chr(196) . chr(158) => 'G', chr(196) . chr(159) => 'g', chr(196) . chr(160) => 'G', chr(196) . chr(161) => 'g', chr(196) . chr(162) => 'G', chr(196) . chr(163) => 'g', chr(196) . chr(164) => 'H', chr(196) . chr(165) => 'h', chr(196) . chr(166) => 'H', chr(196) . chr(167) => 'h', chr(196) . chr(168) => 'I', chr(196) . chr(169) => 'i', chr(196) . chr(170) => 'I', chr(196) . chr(171) => 'i', chr(196) . chr(172) => 'I', chr(196) . chr(173) => 'i', chr(196) . chr(174) => 'I', chr(196) . chr(175) => 'i', chr(196) . chr(176) => 'I', chr(196) . chr(177) => 'i', chr(196) . chr(178) => 'IJ', chr(196) . chr(179) => 'ij', chr(196) . chr(180) => 'J', chr(196) . chr(181) => 'j', chr(196) . chr(182) => 'K', chr(196) . chr(183) => 'k', chr(196) . chr(184) => 'k', chr(196) . chr(185) => 'L', chr(196) . chr(186) => 'l', chr(196) . chr(187) => 'L', chr(196) . chr(188) => 'l', chr(196) . chr(189) => 'L', chr(196) . chr(190) => 'l', chr(196) . chr(191) => 'L', chr(197) . chr(128) => 'l', chr(197) . chr(129) => 'L', chr(197) . chr(130) => 'l', chr(197) . chr(131) => 'N', chr(197) . chr(132) => 'n', chr(197) . chr(133) => 'N', chr(197) . chr(134) => 'n', chr(197) . chr(135) => 'N', chr(197) . chr(136) => 'n', chr(197) . chr(137) => 'N', chr(197) . chr(138) => 'n', chr(197) . chr(139) => 'N', chr(197) . chr(140) => 'O', chr(197) . chr(141) => 'o', chr(197) . chr(142) => 'O', chr(197) . chr(143) => 'o', chr(197) . chr(144) => 'O', chr(197) . chr(145) => 'o', chr(197) . chr(146) => 'OE', chr(197) . chr(147) => 'oe', chr(197) . chr(148) => 'R', chr(197) . chr(149) => 'r', chr(197) . chr(150) => 'R', chr(197) . chr(151) => 'r', chr(197) . chr(152) => 'R', chr(197) . chr(153) => 'r', chr(197) . chr(154) => 'S', chr(197) . chr(155) => 's', chr(197) . chr(156) => 'S', chr(197) . chr(157) => 's', chr(197) . chr(158) => 'S', chr(197) . chr(159) => 's', chr(197) . chr(160) => 'S', chr(197) . chr(161) => 's', chr(197) . chr(162) => 'T', chr(197) . chr(163) => 't', chr(197) . chr(164) => 'T', chr(197) . chr(165) => 't', chr(197) . chr(166) => 'T', chr(197) . chr(167) => 't', chr(197) . chr(168) => 'U', chr(197) . chr(169) => 'u', chr(197) . chr(170) => 'U', chr(197) . chr(171) => 'u', chr(197) . chr(172) => 'U', chr(197) . chr(173) => 'u', chr(197) . chr(174) => 'U', chr(197) . chr(175) => 'u', chr(197) . chr(176) => 'U', chr(197) . chr(177) => 'u', chr(197) . chr(178) => 'U', chr(197) . chr(179) => 'u', chr(197) . chr(180) => 'W', chr(197) . chr(181) => 'w', chr(197) . chr(182) => 'Y', chr(197) . chr(183) => 'y', chr(197) . chr(184) => 'Y', chr(197) . chr(185) => 'Z', chr(197) . chr(186) => 'z', chr(197) . chr(187) => 'Z', chr(197) . chr(188) => 'z', chr(197) . chr(189) => 'Z', chr(197) . chr(190) => 'z', chr(197) . chr(191) => 's', chr(226) . chr(130) . chr(172) => 'E');
        $string = strtr($string, $chars);
    } else {
        // Assume ISO-8859-1 if not UTF-8
        $chars['in'] = chr(128) . chr(131) . chr(138) . chr(142) . chr(154) . chr(158) . chr(159) . chr(162) . chr(165) . chr(181) . chr(192) . chr(193) . chr(194) . chr(195) . chr(196) . chr(197) . chr(199) . chr(200) . chr(201) . chr(202) . chr(203) . chr(204) . chr(205) . chr(206) . chr(207) . chr(209) . chr(210) . chr(211) . chr(212) . chr(213) . chr(214) . chr(216) . chr(217) . chr(218) . chr(219) . chr(220) . chr(221) . chr(224) . chr(225) . chr(226) . chr(227) . chr(228) . chr(229) . chr(231) . chr(232) . chr(233) . chr(234) . chr(235) . chr(236) . chr(237) . chr(238) . chr(239) . chr(241) . chr(242) . chr(243) . chr(244) . chr(245) . chr(246) . chr(248) . chr(249) . chr(250) . chr(251) . chr(252) . chr(253) . chr(255);
        $chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy";
        $string = strtr($string, $chars['in'], $chars['out']);
        $double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254));
        $double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th');
        $string = str_replace($double_chars['in'], $double_chars['out'], $string);
    }
    return $string;
}
/**
 * Remove non-Latin accents
 */
function remove_nonlatin_accents($string)
{
    if (!preg_match('/[\\x80-\\xff]/', $string)) {
        return $string;
    }
    // FIXME convert: AltGr + (0..Ó, Ő, Ű) -> ''
    /*
    §
    ˇ
    ˘
    ˛
    ˙
    ´
    ˝
    ¨
    ¸
    ÷
    ¤
    */
    if (seems_utf8($string)) {
        $chars = array(chr(226) . chr(130) . chr(172) => 'E', chr(194) . chr(163) => '', chr(198) . chr(160) => 'O', chr(198) . chr(161) => 'o', chr(198) . chr(175) => 'U', chr(198) . chr(176) => 'u', chr(225) . chr(186) . chr(166) => 'A', chr(225) . chr(186) . chr(167) => 'a', chr(225) . chr(186) . chr(176) => 'A', chr(225) . chr(186) . chr(177) => 'a', chr(225) . chr(187) . chr(128) => 'E', chr(225) . chr(187) . chr(129) => 'e', chr(225) . chr(187) . chr(146) => 'O', chr(225) . chr(187) . chr(147) => 'o', chr(225) . chr(187) . chr(156) => 'O', chr(225) . chr(187) . chr(157) => 'o', chr(225) . chr(187) . chr(170) => 'U', chr(225) . chr(187) . chr(171) => 'u', chr(225) . chr(187) . chr(178) => 'Y', chr(225) . chr(187) . chr(179) => 'y', chr(225) . chr(186) . chr(162) => 'A', chr(225) . chr(186) . chr(163) => 'a', chr(225) . chr(186) . chr(168) => 'A', chr(225) . chr(186) . chr(169) => 'a', chr(225) . chr(186) . chr(178) => 'A', chr(225) . chr(186) . chr(179) => 'a', chr(225) . chr(186) . chr(186) => 'E', chr(225) . chr(186) . chr(187) => 'e', chr(225) . chr(187) . chr(130) => 'E', chr(225) . chr(187) . chr(131) => 'e', chr(225) . chr(187) . chr(136) => 'I', chr(225) . chr(187) . chr(137) => 'i', chr(225) . chr(187) . chr(142) => 'O', chr(225) . chr(187) . chr(143) => 'o', chr(225) . chr(187) . chr(148) => 'O', chr(225) . chr(187) . chr(149) => 'o', chr(225) . chr(187) . chr(158) => 'O', chr(225) . chr(187) . chr(159) => 'o', chr(225) . chr(187) . chr(166) => 'U', chr(225) . chr(187) . chr(167) => 'u', chr(225) . chr(187) . chr(172) => 'U', chr(225) . chr(187) . chr(173) => 'u', chr(225) . chr(187) . chr(182) => 'Y', chr(225) . chr(187) . chr(183) => 'y', chr(225) . chr(186) . chr(170) => 'A', chr(225) . chr(186) . chr(171) => 'a', chr(225) . chr(186) . chr(180) => 'A', chr(225) . chr(186) . chr(181) => 'a', chr(225) . chr(186) . chr(188) => 'E', chr(225) . chr(186) . chr(189) => 'e', chr(225) . chr(187) . chr(132) => 'E', chr(225) . chr(187) . chr(133) => 'e', chr(225) . chr(187) . chr(150) => 'O', chr(225) . chr(187) . chr(151) => 'o', chr(225) . chr(187) . chr(160) => 'O', chr(225) . chr(187) . chr(161) => 'o', chr(225) . chr(187) . chr(174) => 'U', chr(225) . chr(187) . chr(175) => 'u', chr(225) . chr(187) . chr(184) => 'Y', chr(225) . chr(187) . chr(185) => 'y', chr(225) . chr(186) . chr(164) => 'A', chr(225) . chr(186) . chr(165) => 'a', chr(225) . chr(186) . chr(174) => 'A', chr(225) . chr(186) . chr(175) => 'a', chr(225) . chr(186) . chr(190) => 'E', chr(225) . chr(186) . chr(191) => 'e', chr(225) . chr(187) . chr(144) => 'O', chr(225) . chr(187) . chr(145) => 'o', chr(225) . chr(187) . chr(154) => 'O', chr(225) . chr(187) . chr(155) => 'o', chr(225) . chr(187) . chr(168) => 'U', chr(225) . chr(187) . chr(169) => 'u', chr(225) . chr(186) . chr(160) => 'A', chr(225) . chr(186) . chr(161) => 'a', chr(225) . chr(186) . chr(172) => 'A', chr(225) . chr(186) . chr(173) => 'a', chr(225) . chr(186) . chr(182) => 'A', chr(225) . chr(186) . chr(183) => 'a', chr(225) . chr(186) . chr(184) => 'E', chr(225) . chr(186) . chr(185) => 'e', chr(225) . chr(187) . chr(134) => 'E', chr(225) . chr(187) . chr(135) => 'e', chr(225) . chr(187) . chr(138) => 'I', chr(225) . chr(187) . chr(139) => 'i', chr(225) . chr(187) . chr(140) => 'O', chr(225) . chr(187) . chr(141) => 'o', chr(225) . chr(187) . chr(152) => 'O', chr(225) . chr(187) . chr(153) => 'o', chr(225) . chr(187) . chr(162) => 'O', chr(225) . chr(187) . chr(163) => 'o', chr(225) . chr(187) . chr(164) => 'U', chr(225) . chr(187) . chr(165) => 'u', chr(225) . chr(187) . chr(176) => 'U', chr(225) . chr(187) . chr(177) => 'u', chr(225) . chr(187) . chr(180) => 'Y', chr(225) . chr(187) . chr(181) => 'y', chr(201) . chr(145) => 'a', chr(199) . chr(149) => 'U', chr(199) . chr(150) => 'u', chr(199) . chr(151) => 'U', chr(199) . chr(152) => 'u', chr(199) . chr(141) => 'A', chr(199) . chr(142) => 'a', chr(199) . chr(143) => 'I', chr(199) . chr(144) => 'i', chr(199) . chr(145) => 'O', chr(199) . chr(146) => 'o', chr(199) . chr(147) => 'U', chr(199) . chr(148) => 'u', chr(199) . chr(153) => 'U', chr(199) . chr(154) => 'u', chr(199) . chr(155) => 'U', chr(199) . chr(156) => 'u');
        // Used for locale-specific rules
        $locale = get_locale();
        if ('de_DE' == $locale) {
            $chars[chr(195) . chr(132)] = 'Ae';
            $chars[chr(195) . chr(164)] = 'ae';
            $chars[chr(195) . chr(150)] = 'Oe';
            $chars[chr(195) . chr(182)] = 'oe';
            $chars[chr(195) . chr(156)] = 'Ue';
            $chars[chr(195) . chr(188)] = 'ue';
            $chars[chr(195) . chr(159)] = 'ss';
        }
        $string = strtr($string, $chars);
    } else {
        // Assume ISO-8859-1 if not UTF-8
        $chars['in'] = chr(128) . chr(131) . chr(138) . chr(142) . chr(154) . chr(158) . chr(159) . chr(162) . chr(165) . chr(181) . chr(192) . chr(193) . chr(194) . chr(195) . chr(196) . chr(197) . chr(199) . chr(200) . chr(201) . chr(202) . chr(203) . chr(204) . chr(205) . chr(206) . chr(207) . chr(209) . chr(210) . chr(211) . chr(212) . chr(213) . chr(214) . chr(216) . chr(217) . chr(218) . chr(219) . chr(220) . chr(221) . chr(224) . chr(225) . chr(226) . chr(227) . chr(228) . chr(229) . chr(231) . chr(232) . chr(233) . chr(234) . chr(235) . chr(236) . chr(237) . chr(238) . chr(239) . chr(241) . chr(242) . chr(243) . chr(244) . chr(245) . chr(246) . chr(248) . chr(249) . chr(250) . chr(251) . chr(252) . chr(253) . chr(255);
        $chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy";
        $string = strtr($string, $chars['in'], $chars['out']);
        $double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254));
        $double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th');
        $string = str_replace($double_chars['in'], $double_chars['out'], $string);
    }
    return $string;
}
示例#14
0
文件: lib_aux.php 项目: nvvetal/water
function cf_sanitize_ids($t)
{
    $t = strip_tags($t);
    $t = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $t);
    $t = str_replace('%', '', $t);
    $t = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $t);
    $t = remove_accents($t);
    if (seems_utf8($t)) {
        $t = utf8_uri_encode($t, 200);
    }
    $t = preg_replace('/&.+?;/', '', $t);
    // kill entities
    $t = preg_replace('/\\s+/', '-', $t);
    $t = preg_replace('|-+|', '-', $t);
    $t = preg_replace("|'|", '-', $t);
    $t = trim($t, '-');
    $t = str_replace('[', '', $t);
    $t = str_replace(']', '', $t);
    return $t;
}
/**
 * Slugify title, replacing whitespace and a few other characters with dashes.
 *
 * Limits the output to alphanumeric characters, underscore (_) and dash (-).
 * Whitespace becomes a dash.
 *
 *
 * @param string $title The title to be sanitized.
 * @param string $raw_title Optional. Not used.
 * @param string $context Optional. The operation for which the string is sanitized.
 * @return string The sanitized title.
 */
function slugify($title, $raw_title = '', $context = 'display')
{
    $title = strip_tags($title);
    // Preserve escaped octets.
    $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
    // Remove percent signs that are not part of an octet.
    $title = str_replace('%', '', $title);
    // Restore octets.
    $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);
    if (seems_utf8($title)) {
        if (function_exists('mb_strtolower')) {
            $title = mb_strtolower($title, 'UTF-8');
        }
        $title = utf8_uri_encode($title, 200);
    }
    $title = strtolower($title);
    $title = preg_replace('/&.+?;/', '', $title);
    // kill entities
    $title = str_replace('.', '-', $title);
    if ('save' == $context) {
        // nbsp, ndash and mdash
        $title = str_replace(array('%c2%a0', '%e2%80%93', '%e2%80%94'), '-', $title);
        // iexcl and iquest
        $title = str_replace(array('%c2%a1', '%c2%bf'), '', $title);
        // angle quotes
        $title = str_replace(array('%c2%ab', '%c2%bb', '%e2%80%b9', '%e2%80%ba'), '', $title);
        // curly quotes
        $title = str_replace(array('%e2%80%98', '%e2%80%99', '%e2%80%9c', '%e2%80%9d'), '', $title);
        // copy, reg, deg, hellip and trade
        $title = str_replace(array('%c2%a9', '%c2%ae', '%c2%b0', '%e2%80%a6', '%e2%84%a2'), '', $title);
    }
    $title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
    $title = preg_replace('/\\s+/', '-', $title);
    $title = preg_replace('|-+|', '-', $title);
    $title = trim($title, '-');
    return $title;
}
示例#16
0
function convert_to_utf8(&$str, $old_charset)
{
    if (is_null($str) || $str == '') {
        return false;
    }
    $save = $str;
    // Replace literal entities (for non-UTF-8 compliant html_entity_encode)
    if (version_compare(PHP_VERSION, '5.0.0', '<') && $old_charset == 'ISO-8859-1' || $old_charset == 'ISO-8859-15') {
        $str = html_entity_decode($str, ENT_QUOTES, $old_charset);
    }
    if ($old_charset != 'UTF-8' && !seems_utf8($str)) {
        if (function_exists('iconv')) {
            $str = iconv(!empty($old_charset) ? $old_charset : 'ISO-8859-1', 'UTF-8', $str);
        } else {
            if (function_exists('mb_convert_encoding')) {
                $str = mb_convert_encoding($str, 'UTF-8', !empty($old_charset) ? $old_charset : 'ISO-8859-1');
            } else {
                if ($old_charset == 'ISO-8859-1') {
                    $str = utf8_encode($str);
                }
            }
        }
    }
    // Replace literal entities (for UTF-8 compliant html_entity_encode)
    if (version_compare(PHP_VERSION, '5.0.0', '>=')) {
        $str = html_entity_decode($str, ENT_QUOTES, 'UTF-8');
    }
    // Replace numeric entities
    $str = preg_replace_callback('%&#([0-9]+);%', 'utf8_callback_1', $str);
    $str = preg_replace_callback('%&#x([a-f0-9]+);%i', 'utf8_callback_2', $str);
    // Remove "bad" characters
    $str = remove_bad_characters($str);
    return $save != $str;
}
示例#17
0
 public static function start_export($form)
 {
     $form_id = $form['id'];
     $fields = $_POST['export_field'];
     $start_date = empty($_POST['export_date_start']) ? '' : self::get_gmt_date($_POST['export_date_start'] . ' 00:00:00');
     $end_date = empty($_POST['export_date_end']) ? '' : self::get_gmt_date($_POST['export_date_end'] . ' 23:59:59');
     $search_criteria['status'] = 'active';
     $search_criteria['field_filters'] = GFCommon::get_field_filters_from_post($form);
     if (!empty($start_date)) {
         $search_criteria['start_date'] = $start_date;
     }
     if (!empty($end_date)) {
         $search_criteria['end_date'] = $end_date;
     }
     $sorting = array('key' => 'date_created', 'direction' => 'DESC', 'type' => 'info');
     GFCommon::log_debug("GFExport::start_export(): Start date: {$start_date}");
     GFCommon::log_debug("GFExport::start_export(): End date: {$end_date}");
     $form = self::add_default_export_fields($form);
     $entry_count = GFAPI::count_entries($form_id, $search_criteria);
     $page_size = 100;
     $offset = 0;
     //Adding BOM marker for UTF-8
     $lines = chr(239) . chr(187) . chr(191);
     // set the separater
     $separator = gf_apply_filters('gform_export_separator', $form_id, ',', $form_id);
     $field_rows = self::get_field_row_count($form, $fields, $entry_count);
     //writing header
     $headers = array();
     foreach ($fields as $field_id) {
         $field = RGFormsModel::get_field($form, $field_id);
         $label = gf_apply_filters('gform_entries_field_header_pre_export', array($form_id, $field_id), GFCommon::get_label($field, $field_id), $form, $field);
         $value = str_replace('"', '""', $label);
         GFCommon::log_debug("GFExport::start_export(): Header for field ID {$field_id}: {$value}");
         $headers[$field_id] = $value;
         $subrow_count = isset($field_rows[$field_id]) ? intval($field_rows[$field_id]) : 0;
         if ($subrow_count == 0) {
             $lines .= '"' . $value . '"' . $separator;
         } else {
             for ($i = 1; $i <= $subrow_count; $i++) {
                 $lines .= '"' . $value . ' ' . $i . '"' . $separator;
             }
         }
         GFCommon::log_debug("GFExport::start_export(): Lines: {$lines}");
     }
     $lines = substr($lines, 0, strlen($lines) - 1) . "\n";
     //paging through results for memory issues
     while ($entry_count > 0) {
         $paging = array('offset' => $offset, 'page_size' => $page_size);
         $leads = GFAPI::get_entries($form_id, $search_criteria, $sorting, $paging);
         $leads = gf_apply_filters('gform_leads_before_export', $form_id, $leads, $form, $paging);
         foreach ($leads as $lead) {
             foreach ($fields as $field_id) {
                 switch ($field_id) {
                     case 'date_created':
                         $lead_gmt_time = mysql2date('G', $lead['date_created']);
                         $lead_local_time = GFCommon::get_local_timestamp($lead_gmt_time);
                         $value = date_i18n('Y-m-d H:i:s', $lead_local_time, true);
                         break;
                     default:
                         $field = RGFormsModel::get_field($form, $field_id);
                         $value = is_object($field) ? $field->get_value_export($lead, $field_id, false, true) : rgar($lead, $field_id);
                         $value = apply_filters('gform_export_field_value', $value, $form_id, $field_id, $lead);
                         GFCommon::log_debug("GFExport::start_export(): Value for field ID {$field_id}: {$value}");
                         break;
                 }
                 if (isset($field_rows[$field_id])) {
                     $list = empty($value) ? array() : unserialize($value);
                     foreach ($list as $row) {
                         $row_values = array_values($row);
                         $row_str = implode('|', $row_values);
                         $lines .= '"' . str_replace('"', '""', $row_str) . '"' . $separator;
                     }
                     //filling missing subrow columns (if any)
                     $missing_count = intval($field_rows[$field_id]) - count($list);
                     for ($i = 0; $i < $missing_count; $i++) {
                         $lines .= '""' . $separator;
                     }
                 } else {
                     $value = maybe_unserialize($value);
                     if (is_array($value)) {
                         $value = implode('|', $value);
                     }
                     $lines .= '"' . str_replace('"', '""', $value) . '"' . $separator;
                 }
             }
             $lines = substr($lines, 0, strlen($lines) - 1);
             GFCommon::log_debug("GFExport::start_export(): Lines: {$lines}");
             $lines .= "\n";
         }
         $offset += $page_size;
         $entry_count -= $page_size;
         if (!seems_utf8($lines)) {
             $lines = utf8_encode($lines);
         }
         $lines = apply_filters('gform_export_lines', $lines);
         echo $lines;
         $lines = '';
     }
     /**
      * Fires after exporting all the entries in form
      *
      * @param array $form The Form object to get the entries from
      * @param string $start_date The start date for when the export of entries should take place
      * @param string $end_date The end date for when the export of entries should stop
      * @param array $fields The specified fields where the entries should be exported from
      */
     do_action('gform_post_export_entries', $form, $start_date, $end_date, $fields);
 }
示例#18
0
 /**
  * Replace SQL incorrect characters (0x80 - 0xFF) with their UTF-8 equivalents
  * 
  * @since 1.41
  *
  * @param	string	unencoded string
  *
  * @return	string	UTF-8 encoded string
  */
 private static function _bin_to_utf8($string)
 {
     if (seems_utf8($string)) {
         return $string;
     }
     if (function_exists('utf8_encode')) {
         return utf8_encode($string);
     }
     $output = '';
     for ($index = 0; $index < strlen($string); $index++) {
         $value = ord($string[$index]);
         if ($value < 0x80) {
             $output .= chr($value);
         } else {
             $output .= self::$utf8_chars[$value - 0x80];
         }
     }
     return $output;
 }
示例#19
0
/**
 * @fileoverview 用于截断包含中文(或其他多字节的?)utf8编码的字符串
 */
function utf8_cut_string($str, $len = 30, $truncation = '…')
{
    if (utf8_strlen($str) > $len) {
        if (seems_utf8($str[$len - 1])) {
            // 判断截断字符串的最后一个字符是否是utf8编码的
            $str = utf8_substr($str, 0, $len);
            // 如果是utf8编码的,直接截断输出
        } else {
            // 如果不是utf8编码的,因为utf8编码的中文是三个字节进行保存的,则判断该字符和周围字符组成的字符串是否符合utf8编码
            if (seems_utf8($str[$len - 3] . $str[$len - 2] . $str[$len - 1])) {
                $str = utf8_substr($str, 0, $len - 3);
            } elseif (seems_utf8($str[$len - 2] . $str[$len - 1] . $str[$len])) {
                $str = utf8_substr($str, 0, $len - 2);
            } elseif (seems_utf8($str[$len - 1] . $str[$len] . $str[$len + 1])) {
                $str = utf8_substr($str, 0, $len - 1);
            } else {
                // 这个else应该不用也是可以的
                $str = utf8_substr($str, 0, $len);
            }
        }
        $str .= $truncation;
    }
    return $str;
}
示例#20
0
/**
 * Return the author display_name of the topic
 *
 * @since 2.0.0 bbPress (r2485)
 *
 * @param int $topic_id Optional. Topic id
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_is_topic_anonymous() To check if the topic is by an
 *                                 anonymous user
 * @uses bbp_get_topic_author_id() To get the topic author id
 * @uses get_the_author_meta() To get the author meta
 * @uses get_post_meta() To get the anonymous user name
 * @uses apply_filters() Calls 'bbp_get_topic_author_id' with the
 *                        display name and topic id
 * @return string Topic's author's display name
 */
function bbp_get_topic_author_display_name($topic_id = 0)
{
    $topic_id = bbp_get_topic_id($topic_id);
    // Check for anonymous user
    if (!bbp_is_topic_anonymous($topic_id)) {
        // Get the author ID
        $author_id = bbp_get_topic_author_id($topic_id);
        // Try to get a display name
        $author_name = get_the_author_meta('display_name', $author_id);
        // Fall back to user login
        if (empty($author_name)) {
            $author_name = get_the_author_meta('user_login', $author_id);
        }
        // User does not have an account
    } else {
        $author_name = get_post_meta($topic_id, '_bbp_anonymous_name', true);
    }
    // If nothing could be found anywhere, use Anonymous
    if (empty($author_name)) {
        $author_name = __('Anonymous', 'bbpress');
    }
    // Encode possible UTF8 display names
    if (seems_utf8($author_name) === false) {
        $author_name = utf8_encode($author_name);
    }
    return apply_filters('bbp_get_topic_author_display_name', $author_name, $topic_id);
}
示例#21
0
文件: image.php 项目: skinnard/FTL-2
/**
 * Get extended image metadata, exif or iptc as available.
 *
 * Retrieves the EXIF metadata aperture, credit, camera, caption, copyright, iso
 * created_timestamp, focal_length, shutter_speed, and title.
 *
 * The IPTC metadata that is retrieved is APP13, credit, byline, created date
 * and time, caption, copyright, and title. Also includes FNumber, Model,
 * DateTimeDigitized, FocalLength, ISOSpeedRatings, and ExposureTime.
 *
 * @todo Try other exif libraries if available.
 * @since 2.5.0
 *
 * @param string $file
 * @return bool|array False on failure. Image metadata array on success.
 */
function wp_read_image_metadata($file)
{
    if (!file_exists($file)) {
        return false;
    }
    list(, , $sourceImageType) = getimagesize($file);
    /*
     * EXIF contains a bunch of data we'll probably never need formatted in ways
     * that are difficult to use. We'll normalize it and just extract the fields
     * that are likely to be useful. Fractions and numbers are converted to
     * floats, dates to unix timestamps, and everything else to strings.
     */
    $meta = array('aperture' => 0, 'credit' => '', 'camera' => '', 'caption' => '', 'created_timestamp' => 0, 'copyright' => '', 'focal_length' => 0, 'iso' => 0, 'shutter_speed' => 0, 'title' => '', 'orientation' => 0, 'keywords' => array());
    $iptc = array();
    /*
     * Read IPTC first, since it might contain data not available in exif such
     * as caption, description etc.
     */
    if (is_callable('iptcparse')) {
        getimagesize($file, $info);
        if (!empty($info['APP13'])) {
            $iptc = iptcparse($info['APP13']);
            // Headline, "A brief synopsis of the caption."
            if (!empty($iptc['2#105'][0])) {
                $meta['title'] = trim($iptc['2#105'][0]);
                /*
                 * Title, "Many use the Title field to store the filename of the image,
                 * though the field may be used in many ways."
                 */
            } elseif (!empty($iptc['2#005'][0])) {
                $meta['title'] = trim($iptc['2#005'][0]);
            }
            if (!empty($iptc['2#120'][0])) {
                // description / legacy caption
                $caption = trim($iptc['2#120'][0]);
                mbstring_binary_safe_encoding();
                $caption_length = strlen($caption);
                reset_mbstring_encoding();
                if (empty($meta['title']) && $caption_length < 80) {
                    // Assume the title is stored in 2:120 if it's short.
                    $meta['title'] = $caption;
                }
                $meta['caption'] = $caption;
            }
            if (!empty($iptc['2#110'][0])) {
                // credit
                $meta['credit'] = trim($iptc['2#110'][0]);
            } elseif (!empty($iptc['2#080'][0])) {
                // creator / legacy byline
                $meta['credit'] = trim($iptc['2#080'][0]);
            }
            if (!empty($iptc['2#055'][0]) && !empty($iptc['2#060'][0])) {
                // created date and time
                $meta['created_timestamp'] = strtotime($iptc['2#055'][0] . ' ' . $iptc['2#060'][0]);
            }
            if (!empty($iptc['2#116'][0])) {
                // copyright
                $meta['copyright'] = trim($iptc['2#116'][0]);
            }
            if (!empty($iptc['2#025'][0])) {
                // keywords array
                $meta['keywords'] = array_values($iptc['2#025']);
            }
        }
    }
    /**
     * Filter the image types to check for exif data.
     *
     * @since 2.5.0
     *
     * @param array $image_types Image types to check for exif data.
     */
    if (is_callable('exif_read_data') && in_array($sourceImageType, apply_filters('wp_read_image_metadata_types', array(IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM)))) {
        $exif = @exif_read_data($file);
        if (!empty($exif['ImageDescription'])) {
            mbstring_binary_safe_encoding();
            $description_length = strlen($exif['ImageDescription']);
            reset_mbstring_encoding();
            if (empty($meta['title']) && $description_length < 80) {
                // Assume the title is stored in ImageDescription
                $meta['title'] = trim($exif['ImageDescription']);
            }
            if (empty($meta['caption']) && !empty($exif['COMPUTED']['UserComment'])) {
                $meta['caption'] = trim($exif['COMPUTED']['UserComment']);
            }
            if (empty($meta['caption'])) {
                $meta['caption'] = trim($exif['ImageDescription']);
            }
        } elseif (empty($meta['caption']) && !empty($exif['Comments'])) {
            $meta['caption'] = trim($exif['Comments']);
        }
        if (empty($meta['credit'])) {
            if (!empty($exif['Artist'])) {
                $meta['credit'] = trim($exif['Artist']);
            } elseif (!empty($exif['Author'])) {
                $meta['credit'] = trim($exif['Author']);
            }
        }
        if (empty($meta['copyright']) && !empty($exif['Copyright'])) {
            $meta['copyright'] = trim($exif['Copyright']);
        }
        if (!empty($exif['FNumber'])) {
            $meta['aperture'] = round(wp_exif_frac2dec($exif['FNumber']), 2);
        }
        if (!empty($exif['Model'])) {
            $meta['camera'] = trim($exif['Model']);
        }
        if (empty($meta['created_timestamp']) && !empty($exif['DateTimeDigitized'])) {
            $meta['created_timestamp'] = wp_exif_date2ts($exif['DateTimeDigitized']);
        }
        if (!empty($exif['FocalLength'])) {
            $meta['focal_length'] = (string) wp_exif_frac2dec($exif['FocalLength']);
        }
        if (!empty($exif['ISOSpeedRatings'])) {
            $meta['iso'] = is_array($exif['ISOSpeedRatings']) ? reset($exif['ISOSpeedRatings']) : $exif['ISOSpeedRatings'];
            $meta['iso'] = trim($meta['iso']);
        }
        if (!empty($exif['ExposureTime'])) {
            $meta['shutter_speed'] = (string) wp_exif_frac2dec($exif['ExposureTime']);
        }
        if (!empty($exif['Orientation'])) {
            $meta['orientation'] = $exif['Orientation'];
        }
    }
    foreach (array('title', 'caption', 'credit', 'copyright', 'camera', 'iso') as $key) {
        if ($meta[$key] && !seems_utf8($meta[$key])) {
            $meta[$key] = utf8_encode($meta[$key]);
        }
    }
    foreach ($meta['keywords'] as $key => $keyword) {
        if (!seems_utf8($keyword)) {
            $meta['keywords'][$key] = utf8_encode($keyword);
        }
    }
    $meta = wp_kses_post_deep($meta);
    /**
     * Filter the array of meta data read from an image's exif data.
     *
     * @since 2.5.0
     * @since 4.4.0 The `$iptc` parameter was added.
     *
     * @param array  $meta            Image meta data.
     * @param string $file            Path to image file.
     * @param int    $sourceImageType Type of image.
     * @param array  $iptc            IPTC data.
     */
    return apply_filters('wp_read_image_metadata', $meta, $file, $sourceImageType, $iptc);
}
示例#22
0
/**
 * Sanitizes title, replacing whitespace and a few other characters with dashes.
 *
 * Limits the output to alphanumeric characters, underscore (_) and dash (-).
 * Whitespace becomes a dash.
 *
 * @since 1.2.0
 *
 * @param string $title The title to be sanitized.
 * @param string $raw_title Optional. Not used.
 * @param string $context Optional. The operation for which the string is sanitized.
 * @return string The sanitized title.
 */
function sanitize_title_with_dashes($title, $raw_title = '', $context = 'display')
{
    $title = strip_tags($title);
    // Preserve escaped octets.
    $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
    // Remove percent signs that are not part of an octet.
    $title = str_replace('%', '', $title);
    // Restore octets.
    $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);
    if (seems_utf8($title)) {
        if (function_exists('mb_strtolower')) {
            $title = mb_strtolower($title, 'UTF-8');
        }
        $title = utf8_uri_encode($title, 200);
    }
    $title = strtolower($title);
    $title = preg_replace('/&.+?;/', '', $title);
    // kill entities
    $title = str_replace('.', '-', $title);
    if ('save' == $context) {
        // Convert nbsp, ndash and mdash to hyphens
        $title = str_replace(array('%c2%a0', '%e2%80%93', '%e2%80%94'), '-', $title);
        // Strip these characters entirely
        $title = str_replace(array('%c2%a1', '%c2%bf', '%c2%ab', '%c2%bb', '%e2%80%b9', '%e2%80%ba', '%e2%80%98', '%e2%80%99', '%e2%80%9c', '%e2%80%9d', '%e2%80%9a', '%e2%80%9b', '%e2%80%9e', '%e2%80%9f', '%c2%a9', '%c2%ae', '%c2%b0', '%e2%80%a6', '%e2%84%a2', '%cc%80', '%cc%81', '%cc%84', '%cc%8c'), '', $title);
        // Convert times to x
        $title = str_replace('%c3%97', 'x', $title);
    }
    $title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
    $title = preg_replace('/\\s+/', '-', $title);
    $title = preg_replace('|-+|', '-', $title);
    $title = trim($title, '-');
    return $title;
}
示例#23
0
 public static function start_export($form)
 {
     $form_id = $form["id"];
     $fields = $_POST["export_field"];
     $start_date = $_POST["export_date_start"];
     $end_date = $_POST["export_date_end"];
     //adding default fields
     array_push($form["fields"], array("id" => "id", "label" => __("Entry Id", "gravityforms")));
     array_push($form["fields"], array("id" => "date_created", "label" => __("Entry Date", "gravityforms")));
     array_push($form["fields"], array("id" => "ip", "label" => __("User IP", "gravityforms")));
     array_push($form["fields"], array("id" => "source_url", "label" => __("Source Url", "gravityforms")));
     array_push($form["fields"], array("id" => "payment_status", "label" => __("Payment Status", "gravityforms")));
     array_push($form["fields"], array("id" => "payment_date", "label" => __("Payment Date", "gravityforms")));
     array_push($form["fields"], array("id" => "transaction_id", "label" => __("Transaction Id", "gravityforms")));
     $entry_count = RGFormsModel::get_lead_count($form_id, "", null, null, $start_date, $end_date);
     $page_size = 200;
     $offset = 0;
     //Adding BOM marker for UTF-8
     $lines = chr(239) . chr(187) . chr(191);
     //writing header
     foreach ($fields as $field_id) {
         $field = RGFormsModel::get_field($form, $field_id);
         $value = '"' . str_replace('"', '""', GFCommon::get_label($field, $field_id)) . '"';
         $lines .= "{$value},";
     }
     $lines = substr($lines, 0, strlen($lines) - 1) . "\n";
     //paging through results for memory issues
     while ($entry_count > 0) {
         $leads = RGFormsModel::get_leads($form_id, "date_created", "DESC", "", $offset, $page_size, null, null, false, $start_date, $end_date);
         foreach ($leads as $lead) {
             foreach ($fields as $field_id) {
                 $long_text = "";
                 if (strlen($lead[$field_id]) >= GFORMS_MAX_FIELD_LENGTH) {
                     $long_text = RGFormsModel::get_field_value_long($lead["id"], $field_id);
                 }
                 $value = !empty($long_text) ? $long_text : $lead[$field_id];
                 $lines .= '"' . str_replace('"', '""', $value) . '",';
             }
             $lines = substr($lines, 0, strlen($lines) - 1);
             $lines .= "\n";
         }
         $offset += $page_size;
         $entry_count -= $page_size;
         if (!seems_utf8($lines)) {
             $lines = utf8_encode($lines);
         }
         echo $lines;
         $lines = "";
     }
 }
示例#24
0
 private function bwg_wp_read_image_metadata($file)
 {
     if (!file_exists($file)) {
         return false;
     }
     list(, , $sourceImageType) = getimagesize($file);
     $meta = array('aperture' => 0, 'credit' => '', 'camera' => '', 'caption' => '', 'created_timestamp' => 0, 'copyright' => '', 'focal_length' => 0, 'iso' => 0, 'shutter_speed' => 0, 'title' => '', 'orientation' => 0);
     if (is_callable('iptcparse')) {
         getimagesize($file, $info);
         if (!empty($info['APP13'])) {
             $iptc = iptcparse($info['APP13']);
             if (!empty($iptc['2#105'][0])) {
                 $meta['title'] = trim($iptc['2#105'][0]);
             } elseif (!empty($iptc['2#005'][0])) {
                 $meta['title'] = trim($iptc['2#005'][0]);
             }
             if (!empty($iptc['2#120'][0])) {
                 $caption = trim($iptc['2#120'][0]);
                 if (empty($meta['title'])) {
                     mbstring_binary_safe_encoding();
                     $caption_length = strlen($caption);
                     reset_mbstring_encoding();
                     if ($caption_length < 80) {
                         $meta['title'] = $caption;
                     } else {
                         $meta['caption'] = $caption;
                     }
                 } elseif ($caption != $meta['title']) {
                     $meta['caption'] = $caption;
                 }
             }
             if (!empty($iptc['2#110'][0])) {
                 $meta['credit'] = trim($iptc['2#110'][0]);
             } elseif (!empty($iptc['2#080'][0])) {
                 $meta['credit'] = trim($iptc['2#080'][0]);
             }
             if (!empty($iptc['2#055'][0]) and !empty($iptc['2#060'][0])) {
                 $meta['created_timestamp'] = strtotime($iptc['2#055'][0] . ' ' . $iptc['2#060'][0]);
             }
             if (!empty($iptc['2#116'][0])) {
                 $meta['copyright'] = trim($iptc['2#116'][0]);
             }
         }
     }
     if (is_callable('exif_read_data') && in_array($sourceImageType, apply_filters('wp_read_image_metadata_types', array(IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM)))) {
         $exif = @exif_read_data($file);
         if (empty($meta['title']) && !empty($exif['Title'])) {
             $meta['title'] = trim($exif['Title']);
         }
         if (!empty($exif['ImageDescription'])) {
             mbstring_binary_safe_encoding();
             $description_length = strlen($exif['ImageDescription']);
             reset_mbstring_encoding();
             if (empty($meta['title']) && $description_length < 80) {
                 $meta['title'] = trim($exif['ImageDescription']);
                 if (empty($meta['caption']) && !empty($exif['COMPUTED']['UserComment']) && trim($exif['COMPUTED']['UserComment']) != $meta['title']) {
                     $meta['caption'] = trim($exif['COMPUTED']['UserComment']);
                 }
             } elseif (empty($meta['caption']) && trim($exif['ImageDescription']) != $meta['title']) {
                 $meta['caption'] = trim($exif['ImageDescription']);
             }
         } elseif (empty($meta['caption']) && !empty($exif['Comments']) && trim($exif['Comments']) != $meta['title']) {
             $meta['caption'] = trim($exif['Comments']);
         }
         if (empty($meta['credit'])) {
             if (!empty($exif['Artist'])) {
                 $meta['credit'] = trim($exif['Artist']);
             } elseif (!empty($exif['Author'])) {
                 $meta['credit'] = trim($exif['Author']);
             }
         }
         if (empty($meta['copyright']) && !empty($exif['Copyright'])) {
             $meta['copyright'] = trim($exif['Copyright']);
         }
         if (!empty($exif['FNumber'])) {
             $meta['aperture'] = round(wp_exif_frac2dec($exif['FNumber']), 2);
         }
         if (!empty($exif['Model'])) {
             $meta['camera'] = trim($exif['Model']);
         }
         if (empty($meta['created_timestamp']) && !empty($exif['DateTimeDigitized'])) {
             $meta['created_timestamp'] = wp_exif_date2ts($exif['DateTimeDigitized']);
         }
         if (!empty($exif['FocalLength'])) {
             $meta['focal_length'] = (string) wp_exif_frac2dec($exif['FocalLength']);
         }
         if (!empty($exif['ISOSpeedRatings'])) {
             $meta['iso'] = is_array($exif['ISOSpeedRatings']) ? reset($exif['ISOSpeedRatings']) : $exif['ISOSpeedRatings'];
             $meta['iso'] = trim($meta['iso']);
         }
         if (!empty($exif['ExposureTime'])) {
             $meta['shutter_speed'] = (string) wp_exif_frac2dec($exif['ExposureTime']);
         }
         if (!empty($exif['Orientation'])) {
             $meta['orientation'] = $exif['Orientation'];
         }
     }
     foreach (array('title', 'caption', 'credit', 'copyright', 'camera', 'iso') as $key) {
         if ($meta[$key] && !seems_utf8($meta[$key])) {
             $meta[$key] = utf8_encode($meta[$key]);
         }
     }
     foreach ($meta as &$value) {
         if (is_string($value)) {
             $value = wp_kses_post($value);
         }
     }
     return $meta;
 }
 /**
  * Wrap given string in XML CDATA tag.
  *
  * @since 1.7
  *
  * @param string $str String to wrap in XML CDATA tag.
  * @return string
  */
 function cdata($str)
 {
     if (seems_utf8($str) == false) {
         $str = utf8_encode($str);
     }
     $str = '<![CDATA[' . str_replace(']]>', ']]]]><![CDATA[>', $str) . ']]>';
     return $str;
 }
示例#26
0
 public static function cdata($str)
 {
     $str = maybe_unserialize($str);
     if (is_array($str)) {
         $str = json_encode($str);
     } else {
         if (seems_utf8($str) == false) {
             $str = utf8_encode($str);
         }
     }
     if (is_numeric($str)) {
         return $str;
     }
     // $str = ent2ncr(esc_html($str));
     $str = '<![CDATA[' . str_replace(']]>', ']]]]><![CDATA[>', $str) . ']]>';
     return $str;
 }
示例#27
0
/**
 *
 */
function utf8_decode_if_is_utf8($str)
{
    return seems_utf8($str) ? utf8_decode($str) : $str;
}
 public static function start_export($form)
 {
     $form_id = $form['id'];
     $fields = $_POST['export_field'];
     $start_date = empty($_POST['export_date_start']) ? '' : self::get_gmt_date($_POST['export_date_start'] . ' 00:00:00');
     $end_date = empty($_POST['export_date_end']) ? '' : self::get_gmt_date($_POST['export_date_end'] . ' 23:59:59');
     $search_criteria['status'] = 'active';
     $search_criteria['field_filters'] = GFCommon::get_field_filters_from_post($form);
     if (!empty($start_date)) {
         $search_criteria['start_date'] = $start_date;
     }
     if (!empty($end_date)) {
         $search_criteria['end_date'] = $end_date;
     }
     $sorting = array('key' => 'date_created', 'direction' => 'DESC', 'type' => 'info');
     GFCommon::log_debug("GFExport::start_export(): Start date: {$start_date}");
     GFCommon::log_debug("GFExport::start_export(): End date: {$end_date}");
     $form = self::add_default_export_fields($form);
     $entry_count = GFAPI::count_entries($form_id, $search_criteria);
     $page_size = 100;
     $offset = 0;
     //Adding BOM marker for UTF-8
     $lines = chr(239) . chr(187) . chr(191);
     // set the separater
     $separator = apply_filters('gform_export_separator_' . $form_id, apply_filters('gform_export_separator', ',', $form_id), $form_id);
     $field_rows = self::get_field_row_count($form, $fields, $entry_count);
     //writing header
     $headers = array();
     foreach ($fields as $field_id) {
         $field = RGFormsModel::get_field($form, $field_id);
         $value = str_replace('"', '""', GFCommon::get_label($field, $field_id));
         GFCommon::log_debug("GFExport::start_export(): Header for field ID {$field_id}: {$value}");
         $headers[$field_id] = $str = preg_replace('/[^a-z\\d ]/i', '', $value);
         $subrow_count = isset($field_rows[$field_id]) ? intval($field_rows[$field_id]) : 0;
         if ($subrow_count == 0) {
             $lines .= '"' . $value . '"' . $separator;
         } else {
             for ($i = 1; $i <= $subrow_count; $i++) {
                 $lines .= '"' . $value . ' ' . $i . '"' . $separator;
             }
         }
         GFCommon::log_debug("GFExport::start_export(): Lines: {$lines}");
     }
     $lines = substr($lines, 0, strlen($lines) - 1) . "\n";
     //paging through results for memory issues
     while ($entry_count > 0) {
         $paging = array('offset' => $offset, 'page_size' => $page_size);
         $leads = GFAPI::get_entries($form_id, $search_criteria, $sorting, $paging);
         $leads = apply_filters("gform_leads_before_export_{$form_id}", apply_filters('gform_leads_before_export', $leads, $form, $paging), $form, $paging);
         foreach ($leads as $lead) {
             foreach ($fields as $field_id) {
                 switch ($field_id) {
                     case 'date_created':
                         $lead_gmt_time = mysql2date('G', $lead['date_created']);
                         $lead_local_time = GFCommon::get_local_timestamp($lead_gmt_time);
                         $value = date_i18n('Y-m-d H:i:s', $lead_local_time, true);
                         break;
                     default:
                         $long_text = '';
                         if (strlen(rgar($lead, $field_id)) >= GFORMS_MAX_FIELD_LENGTH - 10) {
                             $long_text = RGFormsModel::get_field_value_long($lead, $field_id, $form);
                         }
                         $value = !empty($long_text) ? $long_text : rgar($lead, $field_id);
                         $field = RGFormsModel::get_field($form, $field_id);
                         $input_type = RGFormsModel::get_input_type($field);
                         if ($input_type == 'checkbox') {
                             //pass in label value that has not had quotes escaped so the is_checkbox_checked function compares the unchanged label value with the lead value
                             $header_label_not_escaped = GFCommon::get_label($field, $field_id);
                             $value = GFFormsModel::is_checkbox_checked($field_id, $header_label_not_escaped, $lead, $form);
                             if ($value === false) {
                                 $value = '';
                             }
                         } else {
                             if ($input_type == 'fileupload' && $field->multipleFiles) {
                                 $value = !empty($value) ? implode(' , ', json_decode($value, true)) : '';
                             }
                         }
                         $value = preg_replace('/[^a-z\\d ]/i', '', $value);
                         $value = apply_filters('gform_export_field_value', $value, $form_id, $field_id, $lead);
                         GFCommon::log_debug("GFExport::start_export(): Value for field ID {$field_id}: {$value}");
                         break;
                 }
                 if (isset($field_rows[$field_id])) {
                     $list = empty($value) ? array() : unserialize($value);
                     foreach ($list as $row) {
                         $row_values = array_values($row);
                         $row_str = implode('|', $row_values);
                         $lines .= '"' . str_replace('"', '""', $row_str) . '"' . $separator;
                     }
                     //filling missing subrow columns (if any)
                     $missing_count = intval($field_rows[$field_id]) - count($list);
                     for ($i = 0; $i < $missing_count; $i++) {
                         $lines .= '""' . $separator;
                     }
                 } else {
                     $value = maybe_unserialize($value);
                     if (is_array($value)) {
                         $value = implode('|', $value);
                     }
                     $lines .= '"' . str_replace('"', '""', $value) . '"' . $separator;
                 }
             }
             $lines = substr($lines, 0, strlen($lines) - 1);
             GFCommon::log_debug("GFExport::start_export(): Lines: {$lines}");
             $lines .= "\n";
         }
         $offset += $page_size;
         $entry_count -= $page_size;
         if (!seems_utf8($lines)) {
             $lines = utf8_encode($lines);
         }
         if (function_exists('mb_convert_encoding')) {
             // Convert the contents to UTF-16LE which has wider support than UTF-8.
             // This fixes an issue with special characters in Excel for Mac.
             $lines = mb_convert_encoding($lines, 'UTF-16LE', 'UTF-8');
         }
         echo $lines;
         $lines = '';
     }
 }
/**
 * Sanitizes a title, replacing whitespace and a few other characters with dashes.
 *
 * Limits the output to alphanumeric characters, underscore (_) and dash (-).
 * Whitespace becomes a dash.
 *
 * @since 1.2.0
 *
 * @param string $title     The title to be sanitized.
 * @param string $raw_title Optional. Not used.
 * @param string $context   Optional. The operation for which the string is sanitized.
 * @return string The sanitized title.
 */
function sanitize_title_with_dashes( $title, $raw_title = '', $context = 'display' ) {
	$title = strip_tags($title);
	// Preserve escaped octets.
	$title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
	// Remove percent signs that are not part of an octet.
	$title = str_replace('%', '', $title);
	// Restore octets.
	$title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);

	if (seems_utf8($title)) {
		if (function_exists('mb_strtolower')) {
			$title = mb_strtolower($title, 'UTF-8');
		}
		$title = utf8_uri_encode($title, 200);
	}

	$title = strtolower($title);

	if ( 'save' == $context ) {
		// Convert nbsp, ndash and mdash to hyphens
		$title = str_replace( array( '%c2%a0', '%e2%80%93', '%e2%80%94' ), '-', $title );
		// Convert nbsp, ndash and mdash HTML entities to hyphens
		$title = str_replace( array( '&nbsp;', '&#160;', '&ndash;', '&#8211;', '&mdash;', '&#8212;' ), '-', $title );

		// Strip these characters entirely
		$title = str_replace( array(
			// iexcl and iquest
			'%c2%a1', '%c2%bf',
			// angle quotes
			'%c2%ab', '%c2%bb', '%e2%80%b9', '%e2%80%ba',
			// curly quotes
			'%e2%80%98', '%e2%80%99', '%e2%80%9c', '%e2%80%9d',
			'%e2%80%9a', '%e2%80%9b', '%e2%80%9e', '%e2%80%9f',
			// copy, reg, deg, hellip and trade
			'%c2%a9', '%c2%ae', '%c2%b0', '%e2%80%a6', '%e2%84%a2',
			// acute accents
			'%c2%b4', '%cb%8a', '%cc%81', '%cd%81',
			// grave accent, macron, caron
			'%cc%80', '%cc%84', '%cc%8c',
		), '', $title );

		// Convert times to x
		$title = str_replace( '%c3%97', 'x', $title );
	}

	$title = preg_replace('/&.+?;/', '', $title); // kill entities
	$title = str_replace('.', '-', $title);

	$title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
	$title = preg_replace('/\s+/', '-', $title);
	$title = preg_replace('|-+|', '-', $title);
	$title = trim($title, '-');

	return $title;
}
示例#30
0
/**
 * Get extended image metadata, exif or iptc as available.
 *
 * Retrieves the EXIF metadata aperture, credit, camera, caption, copyright, iso
 * created_timestamp, focal_length, shutter_speed, and title.
 *
 * The IPTC metadata that is retrieved is APP13, credit, byline, created date
 * and time, caption, copyright, and title. Also includes FNumber, Model,
 * DateTimeDigitized, FocalLength, ISOSpeedRatings, and ExposureTime.
 *
 * @todo Try other exif libraries if available.
 * @since 2.5.0
 *
 * @param string $file
 * @return bool|array False on failure. Image metadata array on success.
 */
function wp_read_image_metadata($file)
{
    if (!file_exists($file)) {
        return false;
    }
    list(, , $sourceImageType) = getimagesize($file);
    // exif contains a bunch of data we'll probably never need formatted in ways
    // that are difficult to use. We'll normalize it and just extract the fields
    // that are likely to be useful. Fractions and numbers are converted to
    // floats, dates to unix timestamps, and everything else to strings.
    $meta = array('aperture' => 0, 'credit' => '', 'camera' => '', 'caption' => '', 'created_timestamp' => 0, 'copyright' => '', 'focal_length' => 0, 'iso' => 0, 'shutter_speed' => 0, 'title' => '');
    // read iptc first, since it might contain data not available in exif such
    // as caption, description etc
    if (is_callable('iptcparse')) {
        getimagesize($file, $info);
        if (!empty($info['APP13'])) {
            $iptc = iptcparse($info['APP13']);
            // headline, "A brief synopsis of the caption."
            if (!empty($iptc['2#105'][0])) {
                $meta['title'] = trim($iptc['2#105'][0]);
            } elseif (!empty($iptc['2#005'][0])) {
                $meta['title'] = trim($iptc['2#005'][0]);
            }
            if (!empty($iptc['2#120'][0])) {
                // description / legacy caption
                $caption = trim($iptc['2#120'][0]);
                if (empty($meta['title'])) {
                    // Assume the title is stored in 2:120 if it's short.
                    if (strlen($caption) < 80) {
                        $meta['title'] = $caption;
                    } else {
                        $meta['caption'] = $caption;
                    }
                } elseif ($caption != $meta['title']) {
                    $meta['caption'] = $caption;
                }
            }
            if (!empty($iptc['2#110'][0])) {
                // credit
                $meta['credit'] = trim($iptc['2#110'][0]);
            } elseif (!empty($iptc['2#080'][0])) {
                // creator / legacy byline
                $meta['credit'] = trim($iptc['2#080'][0]);
            }
            if (!empty($iptc['2#055'][0]) and !empty($iptc['2#060'][0])) {
                // created date and time
                $meta['created_timestamp'] = strtotime($iptc['2#055'][0] . ' ' . $iptc['2#060'][0]);
            }
            if (!empty($iptc['2#116'][0])) {
                // copyright
                $meta['copyright'] = trim($iptc['2#116'][0]);
            }
        }
    }
    // fetch additional info from exif if available
    if (is_callable('exif_read_data') && in_array($sourceImageType, apply_filters('wp_read_image_metadata_types', array(IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM)))) {
        $exif = @exif_read_data($file);
        if (!empty($exif['Title'])) {
            $meta['title'] = trim($exif['Title']);
        }
        if (!empty($exif['ImageDescription'])) {
            if (empty($meta['title']) && strlen($exif['ImageDescription']) < 80) {
                // Assume the title is stored in ImageDescription
                $meta['title'] = trim($exif['ImageDescription']);
                if (!empty($exif['COMPUTED']['UserComment']) && trim($exif['COMPUTED']['UserComment']) != $meta['title']) {
                    $meta['caption'] = trim($exif['COMPUTED']['UserComment']);
                }
            } elseif (trim($exif['ImageDescription']) != $meta['title']) {
                $meta['caption'] = trim($exif['ImageDescription']);
            }
        } elseif (!empty($exif['Comments']) && trim($exif['Comments']) != $meta['title']) {
            $meta['caption'] = trim($exif['Comments']);
        }
        if (!empty($exif['Artist'])) {
            $meta['credit'] = trim($exif['Artist']);
        } elseif (!empty($exif['Author'])) {
            $meta['credit'] = trim($exif['Author']);
        }
        if (!empty($exif['Copyright'])) {
            $meta['copyright'] = trim($exif['Copyright']);
        }
        if (!empty($exif['FNumber'])) {
            $meta['aperture'] = round(wp_exif_frac2dec($exif['FNumber']), 2);
        }
        if (!empty($exif['Model'])) {
            $meta['camera'] = trim($exif['Model']);
        }
        if (!empty($exif['DateTimeDigitized'])) {
            $meta['created_timestamp'] = wp_exif_date2ts($exif['DateTimeDigitized']);
        }
        if (!empty($exif['FocalLength'])) {
            $meta['focal_length'] = (string) wp_exif_frac2dec($exif['FocalLength']);
        }
        if (!empty($exif['ISOSpeedRatings'])) {
            $meta['iso'] = is_array($exif['ISOSpeedRatings']) ? reset($exif['ISOSpeedRatings']) : $exif['ISOSpeedRatings'];
            $meta['iso'] = trim($meta['iso']);
        }
        if (!empty($exif['ExposureTime'])) {
            $meta['shutter_speed'] = (string) wp_exif_frac2dec($exif['ExposureTime']);
        }
    }
    foreach (array('title', 'caption', 'credit', 'copyright', 'camera', 'iso') as $key) {
        if ($meta[$key] && !seems_utf8($meta[$key])) {
            $meta[$key] = utf8_encode($meta[$key]);
        }
    }
    return apply_filters('wp_read_image_metadata', $meta, $file, $sourceImageType);
}