예제 #1
0
파일: Message.php 프로젝트: ajaboa/crmpuan
 /**
  * Try to convert the encoding of the email to UTF-8
  * 
  * @param  stdClass $part
  */
 private function _convertEncoding(&$part)
 {
     $charset = 'UTF-8';
     if (isset($part->ctype_parameters['charset'])) {
         $charset = strtoupper($part->ctype_parameters['charset']);
     }
     if ($charset != 'UTF-8') {
         $part->body = \GO\Base\Util\String::to_utf8($part->body, $charset);
         $part->body = str_ireplace($charset, 'UTF-8', $part->body);
     }
 }
예제 #2
0
 protected function actionDescription($params)
 {
     $response = array();
     $response['title'] = '';
     $response['description'] = '';
     if (function_exists('curl_init')) {
         try {
             $c = new \GO\Base\Util\HttpClient();
             $c->setCurlOption(CURLOPT_CONNECTTIMEOUT, 2);
             $c->setCurlOption(CURLOPT_TIMEOUT, 5);
             $c->setCurlOption(CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
             $html = $c->request($params['url']);
             //go_debug($html);
             $html = str_replace("\r", '', $html);
             $html = str_replace("\n", ' ', $html);
             $html = preg_replace("'</[\\s]*([\\w]*)[\\s]*>'", "</\$1>", $html);
             preg_match('/<head>(.*)<\\/head>/i', $html, $match);
             if (isset($match[1])) {
                 $html = $match[1];
                 //go_debug($html);
                 preg_match('/charset=([^"\'>]*)/i', $c->getContentType(), $match);
                 if (isset($match[1])) {
                     $charset = strtolower(trim($match[1]));
                     if ($charset != 'utf-8') {
                         $html = \GO\Base\Util\String::to_utf8($html, $charset);
                     }
                 }
                 preg_match_all('/<meta[^>]*>/i', $html, $matches);
                 $description = '';
                 foreach ($matches[0] as $match) {
                     if (stripos($match, 'description')) {
                         $name_pos = stripos($match, 'content');
                         if ($name_pos) {
                             $description = substr($match, $name_pos + 7, -1);
                             $description = trim($description, '="\'/ ');
                             break;
                         }
                     }
                 }
                 //replace double spaces
                 $response['description'] = preg_replace('/\\s+/', ' ', $description);
                 preg_match('/<title>(.*)<\\/title>/i', $html, $match);
                 $response['title'] = $match ? preg_replace('/\\s+/', ' ', trim($match[1])) : '';
             }
         } catch (\Exception $e) {
         }
         try {
             $contents = $c->request($params['url'] . '/favicon.ico');
             if (!empty($contents) && $c->getHttpCode() != 404) {
                 $relpath = 'public/bookmarks/';
                 $path = \GO::config()->file_storage_path . $relpath;
                 if (!is_dir($path)) {
                     mkdir($path, 0755, true);
                 }
                 $filename = str_replace('.', '_', preg_replace('/^https?:\\/\\//', '', $_POST['url'])) . '.ico';
                 $filename = rtrim(str_replace('/', '_', $filename), '_ ');
                 //var_dump($filename);
                 file_put_contents($path . $filename, $contents);
                 $response['logo'] = $relpath . $filename;
             }
         } catch (\Exception $e) {
             $response['logo'] = '';
         }
     }
     $response['title'] = \GO\Base\Util\String::cut_string($response['title'], 64, true, "");
     $response['description'] = \GO\Base\Util\String::cut_string($response['description'], 255, true, "");
     return $response;
 }