function getCleanSubString($cutString = '', $maxLength, $moreChar = '', $cutMode = 'char', $sanitize = NULL) { // used to cut a string by words or chars if (empty($maxLength) || $maxLength < 0) { return $cutString; } if ($cutMode == 'word') { $words = preg_split("/[\\s]+/", $cutString, -1, PREG_SPLIT_NO_EMPTY); $cutString = ''; for ($i = 0; $i < $maxLength; $i++) { if (!empty($words[$i])) { $cutString .= $words[$i] . ' '; } } $cutString = trim($cutString); if (count($words) > $maxLength && $moreChar) { $cutString .= $moreChar; } } else { $curString = trim($cutString); if ($curString == '') { return ''; } elseif ($sanitize === NULL && $maxLength >= mb_strlen($curString)) { return $curString; } preg_match_all('/&[^;]+;|./', $curString, $match); if (is_array($match[0]) && count($match[0]) > $maxLength) { $match[0] = array_slice($match[0], 0, $maxLength); $cutString = trim(implode('', $match[0])); $cutString .= $moreChar; } } if ($sanitize !== NULL) { $cutString = htmlfilter_sanitize($cutString, array(), array(), array('img', 'br', 'hr', 'input'), true); } return $cutString; }
function include_url($url) { // include given URL but only take content between <body></body> global $include_urlparts; if (is_string($url)) { $url = array(1 => $url); } elseif (!isset($url[1])) { return ''; } $k = ''; $url = trim($url[1]); $url = explode(' ', $url); $cache = isset($url[1]) ? intval(str_replace('CACHE=', '', strtoupper($url[1]))) : 0; $url = $url[0]; $cache_status = 'MISSING'; if ($url && $cache) { $cache_filename = md5($url) . '-url'; // set cache file name $cache_file = PHPWCMS_CONTENT . 'tmp/' . $cache_filename; // set caching file $cache_status = check_cache($cache_file, $cache); // ceck existence if ($cache_status == 'VALID') { // read cache $k = read_textfile($cache_file); $k = trim($k); if (empty($k)) { $cache_status == 'EXPIRED'; // check if cache content is available } } } if ($cache_status != 'VALID' && $url) { // cache file is missing or outdated $include_urlparts = parse_url($url); if (!empty($include_urlparts['path'])) { $include_urlparts['path'] = dirname($include_urlparts['path']); $include_urlparts['path'] = str_replace('\\', '/', $include_urlparts['path']); } $k = @file_get_contents($url); if ($k) { // now check against charset if (preg_match('/charset=(.*?)"/i', $k, $match)) { $charset = $match[1]; $charset = str_replace(array('"', "'", '/'), '', $charset); $charset = strtolower(trim($charset)); } elseif (preg_match('/http-equiv="{0,1}Content-Type"{0,1}\\s{1,}(content="{0,1}.*?"{0,1}.{0,3}>)/i', $k, $match)) { $charset = ''; if (!empty($match[1])) { $charset = strtolower($match[1]); $charset = trim(str_replace(array('"', "'", '/', 'content=', ' ', '>'), '', $charset)); } } else { $charset = false; } if (preg_match('/<body[^>]*?' . '>(.*)<\\/body>/is', $k, $match)) { $k = $match[1]; } $k = str_replace(array('<?', '?>', '<%', '%>'), array('<?', '?>', '<%', '%>'), $k); $k = preg_replace_callback('/(href|src|action)=[\'|"]{0,1}(.*?)[\'|"]{0,1}( .*?){0,1}>/i', 'make_absoluteURL', $k); $k = htmlfilter_sanitize(trim($k), array(false, 'link', 'meta'), array(), array('img', 'br', 'hr', 'input'), true); if ($charset != false) { $k = makeCharsetConversion($k, $charset, PHPWCMS_CHARSET, 1); } // now write or update cache file in case there is timeout or content if ($cache && $k) { @write_textfile($cache_file, $k); } } $include_urlparts = ''; } return $k; }