function text2etc($text, $CP, $mode = "png", $trans = 1) { global $TTF_LOCATION, $FONT_SIZE; //$outputtext = implode('',file($f)); $outputtext = $text; $outputtext = Conv2UTF8($outputtext, 1, $CP); $outputtext = str_replace("\r\n", "\n", $outputtext); $outputtext = str_replace("\r", "\n", $outputtext); $outputtext = str_replace("\n", "\r\n", $outputtext); $outputtext = str_replace("<br />", "\r\n", $outputtext); $outputtext = str_replace(" ", " ", $outputtext); $outputtext = unhtmlentities($outputtext); if ($mode == "png") { $dim = imageftbbox($FONT_SIZE, 0, $TTF_LOCATION, $outputtext, array("linespacing" => 1.0)); # $dim= imagettfbbox($FONT_SIZE, 0, $TTF_LOCATION, $outputtext); $min_x = min($dim[0], $dim[2], $dim[4], $dim[6]); $max_x = max($dim[0], $dim[2], $dim[4], $dim[6]); $width = $max_x - $min_x + 1; $min_y = min($dim[1], $dim[3], $dim[5], $dim[7]); $max_y = max($dim[1], $dim[3], $dim[5], $dim[7]); $height = $max_y - $min_y + 1; $img = imagecreate($width + 1, $height + 1); $white = ImageColorAllocate($img, 255, 255, 255); if ($trans) { $twhite = imagecolortransparent($img, $white); } $black = ImageColorAllocate($img, 0, 0, 0); # ImageTTFText($img, $FONT_SIZE, 0, -$min_x+$dim[0],-$min_y, $black, $TTF_LOCATION, $outputtext); ImageFTText($img, $FONT_SIZE, 0, -$min_x + $dim[0], -$min_y, $black, $TTF_LOCATION, $outputtext, array("linespacing" => 1.0)); Header("Content-type: image/png"); ImagePng($img); ImageDestroy($img); } else { if ($mode == "pre") { echo "<pre>\n{$outputtext}\n</pre>"; } else { if ($mode == "text") { Header("Content-type: text/plain"); echo utf8Encode($outputtext); } } } }
/** * RFC1738 compliant replacement to PHP's rawurldecode - which actually works with unicode (using utf-8 encoding) * @author Ronen Botzer * @param $source [STRING] * @return unicode safe rawurldecoded string [STRING] * @access public */ function utf8RawUrlDecode($source) { $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 .= utf8Encode($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++; } } return $decodedStr; }
function utf8Encode($res) { if (is_array($res)) { foreach ($res as $key => $element) { $out[$key] = utf8Encode($element); } return $out; } else { if (is_string($res)) { return iconv("cp1251", "UTF-8", $res); } else { return $res; } } }
function utf8Encode($array) { $utf8EncodedArray = array(); foreach ($array as $key => $value) { $key = utf8_encode($key); if (is_array($value)) { $utf8EncodedArray[$key] = utf8Encode($value); continue; } if (is_string($value) && mb_detect_encoding($value, 'UTF-8') != "UTF-8") { $utf8EncodedArray[$key] = utf8_encode($value); } else { $utf8EncodedArray[$key] = $value; } } return $utf8EncodedArray; }
/** * Make an SEO title for use in the URL * * @access public * @param string Raw SEO title or text * @return string Cleaned up SEO title */ function makeAlias($text) { if (!$text) { return ''; } $text = str_replace(array('`', ' ', '+', '.', '?', '_', '%'), '-', $text); /* Strip all HTML tags first */ $text = strip_tags($text); /* Preserve %data */ $text = preg_replace('#%([a-fA-F0-9][a-fA-F0-9])#', '-xx-$1-xx-', $text); $text = str_replace(array('%', '`'), '', $text); $text = preg_replace('#-xx-([a-fA-F0-9][a-fA-F0-9])-xx-#', '%$1', $text); /* Convert accented chars */ $text = convertAccents($text); /* Convert it */ if (isUTF8($text)) { if (function_exists('mb_strtolower')) { $text = mb_strtolower($text, 'UTF-8'); } $text = utf8Encode($text, 500); } /* Finish off */ $text = strtolower($text); if (strtolower(Yii::app()->charset) == 'utf-8') { $text = preg_replace('#&.+?;#', '', $text); $text = preg_replace('#[^%a-z0-9 _-]#', '', $text); } else { /* Remove &#xx; and &#xxx; but keep &#xxxx; */ $text = preg_replace('/&#(\\d){2,3};/', '', $text); $text = preg_replace('#[^%&\\#;a-z0-9 _-]#', '', $text); $text = str_replace(array('"', '&'), '', $text); } $text = str_replace(array('`', ' ', '+', '.', '?', '_'), '-', $text); $text = preg_replace("#-{2,}#", '-', $text); $text = trim($text, '-'); return $text ? $text : '-'; }
/** * send the SOAP message * * Note: if the operation has multiple return values * the return value of this method will be an array * of those values. * * @param string $msg a SOAPx4 soapmsg object * @param string $soapaction SOAPAction value * @param integer $timeout set connection timeout in seconds * @param integer $response_timeout set response timeout in seconds * @return mixed native PHP types. * @access private */ function send($msg, $soapaction = '', $timeout = 0, $response_timeout = 30) { $this->checkCookies(); // detect transport switch (true) { // http(s) case ereg('^http', $this->endpoint): $this->debug('transporting via HTTP'); if ($this->persistentConnection == true && is_object($this->persistentConnection)) { $http =& $this->persistentConnection; } else { $http = new soap_transport_http($this->endpoint); if ($this->persistentConnection) { $http->usePersistentConnection(); } } $http->setContentType($this->getHTTPContentType(), $this->getHTTPContentTypeCharset()); $http->setSOAPAction($soapaction); if ($this->proxyhost && $this->proxyport) { $http->setProxy($this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword); } if ($this->authtype != '') { $http->setCredentials($this->username, $this->password, $this->authtype, array(), $this->certRequest); } if ($this->http_encoding != '') { $http->setEncoding($this->http_encoding); } $this->debug('sending message, length=' . strlen($msg)); if (ereg('^http:', $this->endpoint)) { //if(strpos($this->endpoint,'http:')){ $this->responseData = $http->send($msg, $timeout, $response_timeout, $this->cookies); } elseif (ereg('^https', $this->endpoint)) { //} elseif(strpos($this->endpoint,'https:')){ //if(phpversion() == '4.3.0-dev'){ //$response = $http->send($msg,$timeout,$response_timeout); //$this->request = $http->outgoing_payload; //$this->response = $http->incoming_payload; //} else $this->responseData = $http->sendHTTPS($msg, $timeout, $response_timeout, $this->cookies); } else { $this->setError('no http/s in endpoint url'); } $this->request = $http->outgoing_payload; // APIlity modification: decode hex encoded entities in pure utf-8 $this->response = utf8Encode($http->incoming_payload, true, true); $this->appendDebug($http->getDebug()); $this->UpdateCookies($http->incoming_cookies); // save transport object if using persistent connections if ($this->persistentConnection) { $http->clearDebug(); if (!is_object($this->persistentConnection)) { $this->persistentConnection = $http; } } if ($err = $http->getError()) { $this->setError('HTTP Error: ' . $err); return false; } elseif ($this->getError()) { return false; } else { $this->debug('got response, length=' . strlen($this->responseData) . ' type=' . $http->incoming_headers['content-type']); return $this->parseResponse($http->incoming_headers, $this->responseData); } break; default: $this->setError('no transport found, or selected transport is not yet supported!'); return false; break; } }