Example #1
0
File: utils.php Project: yunter/crm
/**
* the function is like unescape in javascript
* added by dingjianting on 2006-10-1 for picklist editor
*/
function utf8RawUrlDecode($source)
{
    global $default_charset;
    $decodedStr = "";
    $pos = 0;
    $len = strlen($source);
    while ($pos < $len) {
        $charAt = substr($source, $pos, 1);
        if ($charAt == '%') {
            $pos++;
            $charAt = substr($source, $pos, 1);
            if ($charAt == 'u') {
                // we got a unicode character
                $pos++;
                $unicodeHexVal = substr($source, $pos, 4);
                $unicode = hexdec($unicodeHexVal);
                $entity = "&#" . $unicode . ';';
                $decodedStr .= utf8_encode($entity);
                $pos += 4;
            } else {
                // we have an escaped ascii character
                $hexVal = substr($source, $pos, 2);
                $decodedStr .= chr(hexdec($hexVal));
                $pos += 2;
            }
        } else {
            $decodedStr .= $charAt;
            $pos++;
        }
    }
    if (strtolower($default_charset) == 'utf-8') {
        return html_to_utf8($decodedStr);
    } else {
        return $decodedStr;
    }
    //return html_to_utf8($decodedStr);
}
/**
* Function to convert html values to its original character available in a database
* This function can called at any time after the migration
* It get all the tables and its VARCHAR/TEXT/LONGTEXT fields from the DB
* Converts the html-values to its original character and restore it. 
**/
function convert_html2utf8_db()
{
    global $adb, $log;
    //Getting all the tables from the current database.
    $alltables = $adb->get_tables();
    $log->debug("Started HTML to UTF-8 Conversion");
    $values = array();
    //Tables for which conversion to utf8 not required.
    $skip_tables = array('vtiger_sharedcalendar', 'vtiger_potcompetitorrel', 'vtiger_users2group', 'vtiger_group2grouprel', 'vtiger_group2role', 'vtiger_group2rs', 'vtiger_campaigncontrel', 'vtiger_campaignleadrel', 'vtiger_cntactivityrel', 'vtiger_crmentitynotesrel', 'vtiger_salesmanactivityrel', 'vtiger_vendorcontactrel', 'vtiger_salesmanticketrel', 'vtiger_seactivityrel', 'vtiger_seticketsrel', 'vtiger_senotesrel', 'vtiger_profile2globalpermissions', 'vtiger_profile2standardpermissions', 'vtiger_profile2field', 'vtiger_role2profile', 'vtiger_profile2utility', 'vtiger_activityproductrel', 'vtiger_pricebookproductrel', 'vtiger_activity_reminder', 'vtiger_actionmapping', 'vtiger_org_share_action2tab', 'vtiger_datashare_relatedmodule_permission', 'vtiger_tmp_read_user_sharing_per', 'vtiger_tmp_read_group_sharing_per', 'vtiger_tmp_write_user_sharing_per', 'vtiger_tmp_write_group_sharing_per', 'vtiger_tmp_read_user_rel_sharing_per', 'vtiger_tmp_read_group_rel_sharing_per', 'vtiger_tmp_write_user_rel_sharing_per', 'vtiger_tmp_write_group_rel_sharing_per', 'vtiger_role2picklist', 'vtiger_freetagged_objects', 'vtiger_tab', 'vtiger_blocks', 'vtiger_group2role', 'vtiger_group2rs');
    //echo '<table width="98%" border="1px" cellpadding="3" cellspacing="0" height="100%">';
    //echo '<tr width="100%"> <th colspan="3">Started converting data from HTML to UTF-8</th></tr>';
    for ($i = 0; $i < count($alltables); $i++) {
        $table = $alltables[$i];
        if (!in_array($table, $skip_tables)) {
            //Here selecting all the colums from the table
            $result = $adb->query("SHOW COLUMNS FROM {$table}");
            while ($row = $adb->fetch_array($result)) {
                //Getting the primary key column of the table.
                if ($row['key'] == 'PRI') {
                    $values[$table]['key'][] = $row['field'];
                }
                //And Getting columns of type varchar, text and longtext.
                if (stristr($row['type'], 'varchar') != '' || stristr($row['type'], 'text') != '' || stristr($row['type'], 'longtext') != '') {
                    $values[$table]['columns'][] = $row['field'];
                }
            }
        }
    }
    $final_array = $values;
    foreach ($final_array as $tablename => $value) {
        //Going to update values in the table.
        $key = $value['key'];
        $cols = $value['columns'];
        if ($cols != "" && $key != "") {
            if (count($key) > 1) {
                $key_list = implode(", ", $key);
            } else {
                $key_list = $key[0];
            }
            if (count($cols) > 1) {
                $col_list = implode(", ", $cols);
            } else {
                $col_list = $cols[0];
            }
            //Getting the records available in the table.
            $query = "SELECT {$key_list}, {$col_list} FROM {$tablename}";
            $res1 = $adb->query($query);
            $val = array();
            $id = array();
            //	echo '
            //			<tr width="100%">
            //			<td width="80%">Updating the values in the table <b>'.$tablename.'</b></td>';
            $log->debug("Converting values in the table :" . $tablename);
            //Sending the current status to the browser
            for ($k = 0; $k < $adb->num_rows($res1); $k++) {
                $whereStr = "";
                for ($l = 0; $l < count($key); $l++) {
                    $id[$l] = $adb->query_result($res1, $k, $key[$l]);
                    if ($l != 0) {
                        $whereStr .= " and ";
                    }
                    $whereStr .= $key[$l] . "=?";
                }
                $updateStr = "";
                for ($j = 0; $j < count($cols); $j++) {
                    //Converting the html values to utf8 chars
                    //echo "<br>Updating the value of ".$cols[$j]." column with utf8 value";
                    $val[$j] = html_to_utf8(decode_html($adb->query_result($res1, $k, $cols[$j])));
                    if ($j != 0) {
                        $updateStr .= ", ";
                    }
                    $updateStr .= $cols[$j] . "=?";
                }
                $updateQ = "UPDATE {$tablename} SET {$updateStr} where {$whereStr}";
                $params = array($val, $id);
                $adb->pquery($updateQ, $params);
            }
            //	echo '
            //			<td width="20%">Completed</td>
            //			</tr>';
            //Sending the current status to the browser
        }
    }
    //	echo '</table>';
    //	echo '<div align = "center"><br><br><b> Conversion completed.</b></div>';
    $log->debug("HTML to UTF-8 Conversion has been completed");
}
Example #3
0
function fix1($in)
{
    $s = html_to_utf8($in);
    $s = urlencode($s);
    $s = str_replace("+", " ", $s);
    $s = str_replace("%2B", "+", $s);
    $s = str_replace("%28", "(", $s);
    $s = str_replace("%29", ")", $s);
    $s = str_replace("%26", "&", $s);
    $s = str_replace("%3B", ";", $s);
    $s = str_replace("%2F", "/", $s);
    $s = str_replace("%23", "#", $s);
    $s = str_replace("%5B", "[", $s);
    $s = str_replace("%5D", "]", $s);
    return $s;
}
Example #4
0
//$html=file_get_contents("H:/BB Skin V2/new/channels.xml");
$baseurl = "http://127.0.0.1/cgi-bin/scripts/util/translate.cgi?stream,";
$videos = explode("<stream>", $html);
//$videos=explode("<item>",$html);
unset($videos[0]);
$videos = array_values($videos);
$n = 0;
foreach ($videos as $video) {
    $video = str_replace("<![CDATA[", "", $video);
    $video = str_replace("]]>", "", $video);
    $opt = "";
    $title = str_between($video, "<title>", "</title>");
    $title = trim(str_replace("'", "", $title));
    //$title = str_replace("&amp;","&",$title);
    //$title=html_entity_decode($title,ENT_QUOTES, "UTF-8");
    $title = html_to_utf8($title);
    //$title=html_entity_decode($title,ENT_QUOTES, "UTF-8");
    //$title=htmlentities($title, ENT_QUOTES, "UTF-8");
    //$title=htmlspecialchars_decode($title, ENT_NOQUOTES);
    $swf = trim(str_between($video, '<swfUrl>', '</swfUrl>'));
    $link = trim(str_between($video, "<link>", "</link>"));
    $page = trim(str_between($video, "<pageUrl>", "</pageUrl>"));
    $playpath = trim(str_between($video, "<playpath>", "</playpath>"));
    $adv = trim(str_between($video, "<advanced>", "</advanced>"));
    if ($swf != "" || $page != "" || $playpath != "" || $adv != "") {
        $opt = "Rtmp-options:";
        if ($swf != "") {
            $opt = $opt . "-W%20" . $swf . "%20";
        }
        if ($playpath != "") {
            $opt = $opt . "-y%20" . $playpath . "%20";