', $searchIndex);
if (!$searchIndex) {
break;
}
$searchIndex += 7;
} elseif ($tagName == "', $searchIndex);
if (!$searchIndex) {
break;
}
$searchIndex += 6;
} elseif ($tagName == "', $searchIndex);
if (!$searchIndex) {
break;
}
$searchIndex += 6;
} elseif ($tagName == "', $searchIndex);
if (!$searchIndex) {
break;
}
$searchIndex += 9;
} elseif ($tagName == "', $searchIndex);
if (!$searchIndex) {
break;
}
$searchIndex += 8;
} else {
break;
}
if (!$searchIndex) {
break;
}
$replaceIndex = $searchIndex;
$searchCloseTag = false;
continue;
} else {
$searchCodeIndex = strpos($content, 'cdn_add == ""){
return $imageSrc;
}
if($imageSrc!=null && strpos($imageSrc,$options->rootUrl) === false){//不是本地服务器图片
$isLocal = false;
}else{//替换图片的域名地址为云存储空间地址
$cdnArray = explode("|",$options->cdn_add);
$imageSrc = str_ireplace($options->rootUrl,trim($cdnArray[0]),$imageSrc);
$cdnType = trim($cdnArray[1]);
}
return $imageSrc . self::getImageAddOn($options,$isLocal,$cdnType,$width,$height);
}
/**
* 云存储选项
* @param array $options 后台选项设置
* @param bool $isLocal 是否是本地服务器图片
* @param String $cdnType 云服务商类型
* @param int $width 目标图片的宽度
* @param int $height 目标图片的高度
* @return string
*/
public static function getImageAddOn($options,$isLocal = false,$cdnType = null, $width = 0, $height = 0){
$addOn = "";//图片后缀
if (!$isLocal){//不是本地服务器图片
return $addOn;
}
if ($options->cdn_add!="" && (@in_array('1',$options->cloudOptions) || @in_array('0',$options->cloudOptions))){//开启了镜像存储的功能
if ($cdnType == null){//如果参数中没有cdnType,这里会进行获取cdn类型
$cdnArray = explode("|",$options->cdn_add);
$cdnType = trim($cdnArray[1]);
}
if (@in_array('1',$options->cloudOptions)){//启用了webp格式
if ($cdnType == "ALIOSS" || $cdnType == "UPYUN"){//阿里云和又拍云
$addOn .= "!";//分隔符
}else{//七牛云
$addOn .= "?";//分隔符
}
if ($cdnType == "ALIOSS"){//阿里云
$format = "/format,webp";
}else{//又拍云和七牛云
$format = "/format/webp";
}
$addOn .= $format;
}
if (!($width == 0 && $height == 0) && @in_array('0',$options->cloudOptions)){//启用了图片缩放 TODO:优化这个缩放
if (trim($addOn) == ""){
if ($cdnType == "ALIOSS" || $cdnType == "UPYUN"){//阿里云和又拍云
$addOn .= "!";//分隔符
}else{//七牛云
$addOn .= "?";//分隔符
}
}
if ($height == 0){//根据宽度尺寸进行缩放
if ($cdnType == "UPYUN"){
$addOn .= "/fw/$width";
}else if ($cdnType == "ALIOSS"){
$addOn .= "/x-oss-process=image/resize,w_$width";
}else{//七牛云
$addOn .= "/imageView2/2/w/$width";
}
}else if ($width === 0){//根据高度尺寸进行缩放
if ($cdnType == "UPYUN"){
$addOn .= "/fh/$height";
}else if ($cdnType == "ALIOSS"){
$addOn .= "/x-oss-process=image/resize,h_$height";
}else{//七牛云
$addOn .= "/imageView2/2/h/$height";
}
}else{
if ($cdnType == "UPYUN"){
$addOn .= "/fwfh/".$width."x".$height;
}else if ($cdnType == "ALIOSS"){
$addOn .= "/x-oss-process=image/resize,m_lfit,h_".$height.",w_".$width;
}else{//七牛云
$addOn .= "/imageView2/2/w/".$width."/h/".$height;
}
}
}
}
return $addOn;
}
public static function returnDivLazyLoadHtml($originalSrc,$width,$height){
$options = mget();
$placeholder = Utils::choosePlaceholder($options);
$lazyLoadHtml = "";
$originalSrc = self::returnImageSrcWithSuffix($originalSrc,null,$width,$height);
if (in_array('lazyload',$options->featuresetup)){
$imageSrc = $placeholder;
$lazyLoadHtml = 'data-original="'.$originalSrc.'"';
}else{
$imageSrc = $originalSrc;
}
return $lazyLoadHtml. ' style="background-image: url('.$imageSrc.')"';
}
public static function returnImageLazyLoadHtml($originalSrc,$width,$height){
$options = mget();
$placeholder = Utils::choosePlaceholder($options);
$originalSrc .= self::getImageAddOn($options,$originalSrc,null,$width,$height);
if (in_array('lazyload',$options->featuresetup)){
$imageSrc = $placeholder;
$lazyLoadHtml = 'data-original="'.$originalSrc.'"';
}else{
$lazyLoadHtml = "";
$imageSrc = $originalSrc;
}
return $lazyLoadHtml. ' src="'.$imageSrc.'"';
}
public static function choosePlaceholder($options){
if (@in_array("opacityMode",$options->indexsetup)){//透明模式
return Handsome_Config::OPACITY_PLACEHOLDER;
}else{//普通占位符
return Handsome_Config::NORMAL_PLACEHOLDER;
}
}
public static function getSj1ImageNum(){
try{
$basedir = dirname(dirname(__FILE__))."/usr/img/sj";
$arr = scandir($basedir);
$image = count(preg_grep("/\.jpg$/", $arr));
return $image;
}catch (Exception $e){
print_r($e);
return 5;
}
}
/**
* 获取右侧边栏的图片数目
* @return int
*/
public static function getSj2ImageNum(){
try{
$basedir = dirname(dirname(__FILE__))."/usr/img/sj2";
$arr = scandir($basedir);
$image = count(preg_grep("/\.jpg$/", $arr));
return $image;
}catch (Exception $e){
print_r($e);
return 5;
}
}
/**
* 返回运行时间
*/
public static function getOpenDays(){
$options = mget();
$oldtime = $options->startTime;
try{
$catime = strtotime($oldtime);
$now = time();
$difference = $now - $catime;
$year = floor($difference/31536000);
if ($year >=1){
$difference = $difference - $year * 31536000;
$day = floor($difference/86400);
return sprintf(_mt("%d年%d天"),$year,$day);
}else{//小于一年
$day = floor($difference/86400);
return sprintf(_mt("%d天"),$day);
}
}catch (Exception $exception){
return "null";
}
}
/**
* 返回最后更新时间
*/
public static function getLatestTime($obj){
$recent = $obj->widget('Widget_Contents_Post_Recent','pageSize=1');
if($recent->have()){
while($recent->next()){
return Utils::naturalDate($recent->modified,"short");
}
}
}
public static function hEcho($text){
if (strtoupper(Handsome_Config::HANDSOME_DEBUG_DISPLAY) == 'ON'){
echo $text;
}
}
public static function print_r($text){
if (strtoupper(Handsome_Config::HANDSOME_DEBUG_DISPLAY) == 'ON'){
print_r ($text);
}
}
public static function var_dump($text){
if (strtoupper(Handsome_Config::HANDSOME_DEBUG_DISPLAY) == 'ON'){
var_dump ($text);
}
}
public static function returnDefaultIfEmpty($target, $default){
if (trim($target) == ""){
return $default;
}else{
return $target;
}
}
public static function getWordsOfContentPost($content){
return mb_strlen(trim($content));
}
/**
* @param $blogUrl
* @param $name
* @param $pic
* @param $type string,表示pic内容是网络地址,local表示内容是本地图片
* @param string $suffix 图片后缀
* @return string
*/
public static function uploadPic($blogUrl, $name, $pic,$type,$suffix){
$childDir = DIRECTORY_SEPARATOR.'usr'.DIRECTORY_SEPARATOR.'uploads' . DIRECTORY_SEPARATOR .'time' .DIRECTORY_SEPARATOR;
$dir = __TYPECHO_ROOT_DIR__ . $childDir;
if (!file_exists($dir)){
mkdir($dir, 0777, true);
}
$fileName = $name. $suffix;
$file = $dir .$fileName;
if ($type == "web"){
//开始捕捉
ob_start();
readfile($pic);
$img = ob_get_contents();
ob_end_clean();
}else{
$img = $pic;//本地图片直接就是二进制数据
}
$fp2 = fopen($file , "a");
fwrite($fp2, $img);
fclose($fp2);
return $blogUrl.$childDir.$fileName;
}
}