function api_force_utf8($v, $src_encoding)
{
    if (utf8_compliant($v)) {
        $ret = $v;
    } else {
        // assume iso-8859-1
        $ret = utf8_encode($v);
    }
    return $ret;
}
Beispiel #2
0
 /**
  * Tests whether a string complies as UTF-8; faster and less strict than utf8_is_valid
  * see lib/phputf8/utils/validation.php for more details
  * @param $str string input string
  * @return boolean
  */
 static function utf8_compliant($str)
 {
     require_once './lib/pkp/lib/phputf8/utils/validation.php';
     return utf8_compliant($str);
 }
Beispiel #3
0
function get_cue_info($cue, $length_s)
{
    $cue_data = file($cue);
    $out = array('artist' => '', 'album' => '', 'year' => '', 'total' => '', 'genre' => '', 'disc' => '', 'discid' => '', 'comment' => '', 'tracks' => array());
    $mod = 'album';
    $track_n = 0;
    foreach ($cue_data as $line) {
        $line = trim($line);
        if (!utf8_compliant($line)) {
            $line = iconv(cue_encoding, 'UTF-8', $line);
        }
        if (false !== strpos($line, 'TRACK ')) {
            $mod = 'track';
            $track = array('track' => ++$track_n, 'title' => '', 'length' => '', 'artist' => '');
        }
        if ($mod == 'album') {
            if (false !== strpos($line, 'REM ')) {
                if (false !== ($pos = strpos($line, 'GENRE '))) {
                    $out['genre'] = trim(substr($line, $pos + strlen('GENRE ')));
                    if (0 === strpos($out['genre'], '"')) {
                        $out['genre'] = substr($out['genre'], 1, -1);
                    }
                } elseif (false !== ($pos = strpos($line, 'DATE '))) {
                    $out['year'] = trim(substr($line, $pos + strlen('DATE ')));
                } elseif (false !== ($pos = strpos($line, 'DISCID '))) {
                    $out['discid'] = trim(substr($line, $pos + strlen('DISCID ')));
                } elseif (false !== ($pos = strpos($line, 'DISC '))) {
                    $out['disc'] = trim(substr($line, $pos + strlen('DISC ')));
                } elseif (false !== ($pos = strpos($line, 'COMMENT "'))) {
                    $out['comment'] = trim(substr($line, $pos + strlen('COMMENT "'), -1));
                }
            } elseif (false !== ($pos = strpos($line, 'PERFORMER "'))) {
                $out['artist'] = trim(substr($line, $pos + strlen('PERFORMER "'), -1));
            } elseif (false !== ($pos = strpos($line, 'TITLE "'))) {
                $out['album'] = trim(substr($line, $pos + strlen('TITLE "'), -1));
            }
        } elseif ($mod == 'track') {
            if (false !== ($pos = strpos($line, 'PERFORMER "'))) {
                $track['artist'] = trim(substr($line, $pos + strlen('PERFORMER "'), -1));
            } elseif (false !== ($pos = strpos($line, 'TITLE "'))) {
                $track['title'] = trim(substr($line, $pos + strlen('TITLE "'), -1));
            } elseif (false !== ($pos = strpos($line, 'INDEX ')) && !$track['length']) {
                $track['length'] = mmss2s(end(explode(' ', trim(substr($line, $pos + strlen('INDEX '))))));
            }
            $out['tracks'][$track_n - 1] = $track;
        }
    }
    $rev_tracks = array_reverse($out['tracks']);
    $prev_index_s = $length_s;
    foreach ($rev_tracks as $track) {
        $out['tracks'][$track['track'] - 1]['length'] = $prev_index_s - $track['length'];
        $prev_index_s = $track['length'];
    }
    $out['total'] = count($out['tracks']);
    return $out;
}
 /**
  * Tests whether a string complies as UTF-8. This will be much
  * faster than utf8_is_valid but will pass five and six octet
  * UTF-8 sequences, which are not supported by Unicode and
  * so cannot be displayed correctly in a browser. In other words
  * it is not as strict as utf8_is_valid but it's faster. If you use
  * it to validate user input, you place yourself at the risk that
  * attackers will be able to inject 5 and 6 byte sequences (which
  * may or may not be a significant risk, depending on what you are
  * are doing)
  *
  * @param   string  $str  UTF-8 string to check
  *
  * @return  boolean  TRUE if string is valid UTF-8
  *
  * @see     valid
  * @see     http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php#54805
  * @since   2.0
  */
 public static function compliant($str)
 {
     require_once __DIR__ . '/phputf8/utils/validation.php';
     return utf8_compliant($str);
 }
Beispiel #5
0
 /**
  * Tests whether a string complies as UTF-8; faster and less strict than utf8_is_valid
  * see lib/phputf8/utils/validation.php for more details
  * @param $str string input string
  * @return boolean
  */
 function utf8_compliant($str)
 {
     require_once 'utils/validation.php';
     return utf8_compliant($str);
 }
Beispiel #6
0
function getHometown($artist)
{
    $id = requestStarted(__METHOD__, "{$artist}");
    $country = $state = $hometown = "";
    $artist = rawurldecode($artist);
    // Figure out if this is debug mode.
    $debug = false;
    $debugSuffix = "_debug";
    if (strlen($artist) >= strlen($debugSuffix) && substr($artist, 0 - strlen($debugSuffix)) == $debugSuffix) {
        $artist = substr($artist, 0, strlen($artist) - strlen($debugSuffix));
        print "ARTIST: {$artist}\n";
        $debug = true;
    }
    $artist = trim(html_entity_decode($artist));
    $isUTF = utf8_compliant("{$artist}");
    global $SHUT_DOWN_API;
    if (!$SHUT_DOWN_API) {
        print !$debug ? "" : "Formatting \"{$artist}\"\n";
        print !$debug ? "" : "utf8_compliant: " . utf8_compliant("{$artist}") . "\n";
        $title = lw_getTitle($artist, "", !$isUTF);
        // if isUTF, skips the utf8 encoding (that is only for the values from the db... from the URL they should be fine already).
        print !$debug ? "" : "utf8_compliant: " . utf8_compliant("{$title}") . " - {$title}\n";
        print !$debug ? "" : "Looking for \"{$title}\"\n";
        $finalName = "";
        if (lw_pageExists($title)) {
            $page = lw_getPage($title, $finalName, $debug);
            $matches = array();
            if (0 < preg_match("/\\{\\{Hometown[\\s*\\|]+country\\s*=\\s*([a-z _]*)[\\s*\\|]+state\\s*=\\s*([a-z _]*)[\\s*\\|]+hometown\\s*=\\s*([a-z _]*)/is", $page, $matches)) {
                $country = $matches[1];
                $state = $matches[2];
                $hometown = $matches[3];
            } else {
                if (0 < preg_match("/\\|\\s*country\\s*=\\s*([a-z _]*)[\\s*\\|]+state\\s*=\\s*([a-z _]*)[\\s*\\|]+hometown\\s*=\\s*([a-z _]*)/is", $page, $matches)) {
                    $country = $matches[1];
                    $state = $matches[2];
                    $hometown = $matches[3];
                }
            }
        }
    }
    $retVal = array('country' => $country, 'state' => $state, 'hometown' => $hometown);
    requestFinished($id);
    return $retVal;
}
 /**
  * Tests whether a string complies as UTF-8.
  *
  * This will be much faster than StringHelper::valid() but will pass five and six octet UTF-8 sequences, which are not supported by Unicode and
  * so cannot be displayed correctly in a browser. In other words it is not as strict as StringHelper::valid() but it's faster. If you use it to
  * validate user input, you place yourself at the risk that attackers will be able to inject 5 and 6 byte sequences (which may or may not be a
  * significant risk, depending on what you are are doing).
  *
  * @param   string  $str  UTF-8 string to check
  *
  * @return  boolean  TRUE if string is valid UTF-8
  *
  * @see     StringHelper::valid
  * @see     http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php#54805
  * @since   1.3.0
  */
 public static function compliant($str)
 {
     return utf8_compliant($str);
 }
Beispiel #8
0
 /**
  * Tests whether a string complies as UTF-8. This will be much
  * faster than utf8_is_valid but will pass five and six octet
  * UTF-8 sequences, which are not supported by Unicode and
  * so cannot be displayed correctly in a browser. In other words
  * it is not as strict as utf8_is_valid but it's faster. If you use
  * it to validate user input, you place yourself at the risk that
  * attackers will be able to inject 5 and 6 byte sequences (which
  * may or may not be a significant risk, depending on what you are
  * are doing)
  *
  * @param   string  $str  UTF-8 string to check
  *
  * @return  boolean  TRUE if string is valid UTF-8
  *
  * @see     valid
  * @see     http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php#54805
  * @since   1.3.0
  */
 public static function compliant($str)
 {
     if (!function_exists('utf8_compliant')) {
         require_once __DIR__ . '/phputf8/utils/validation.php';
     }
     return utf8_compliant($str);
 }