ZBLOG PHP调用随机文章、热门文章、热评文章程序
代码如下 | 复制代码 |
/**
* 获取文章列表 * @param int $count 数量 * @param null $cate 分类ID * @param null $auth 用户ID * @param null $date 日期 * @param null $tags 标签 * @param null $search 搜索关键词 * @param null $order 排序 * @param null $option * @return array|mixed */ function TcgetList($count = 10, $cate = null, $auth = null, $date = null, $tags = null, $search = null, $option = null,$order=null) { global $zbp; if (!is_array($option)) {
$option = array(); } if (!isset($option['only_ontop']))
$option['only_ontop'] = false; if (!isset($option['only_not_ontop'])) $option['only_not_ontop'] = false; if (!isset($option['has_subcate'])) $option['has_subcate'] = false; if (!isset($option['is_related'])) $option['is_related'] = false; if ($option['is_related']) {
$at = $zbp->GetPostByID($option['is_related']); $tags = $at->Tags; if (!$tags) return array(); $count = $count + 1; } if ($option['only_ontop'] == true) {
$w[] = array('=', 'log_IsTop', 0); } elseif ($option['only_not_ontop'] == true) { $w[] = array('=', 'log_IsTop', 1); } $w = array();
$w[] = array('=', 'log_Status', 0); $articles = array();
if (!is_null($cate)) {
$category = new Category; $category = $zbp->GetCategoryByID($cate); if ($category->ID > 0) {
if (!$option['has_subcate']) {
$w[] = array('=', 'log_CateID', $category->ID); } else { $arysubcate = array(); $arysubcate[] = array('log_CateID', $category->ID); foreach ($zbp->categorys[$category->ID]->SubCategorys as $subcate) { $arysubcate[] = array('log_CateID', $subcate->ID); } $w[] = array('array', $arysubcate); }
}
} if (!is_null($auth)) {
$author = new Member; $author = $zbp->GetMemberByID($auth); if ($author->ID > 0) {
$w[] = array('=', 'log_AuthorID', $author->ID); } } if (!is_null($date)) {
$datetime = strtotime($date); if ($datetime) { $datetitle = str_replace(array('%y%', '%m%'), array(date('Y', $datetime), date('n', $datetime)), $zbp->lang['msg']['year_month']); $w[] = array('BETWEEN', 'log_PostTime', $datetime, strtotime('+1 month', $datetime)); } } if (!is_null($tags)) {
$tag = new Tag; if (is_array($tags)) { $ta = array(); foreach ($tags as $t) { $ta[] = array('log_Tag', '%{' . $t->ID . '}%'); } $w[] = array('array_like', $ta); unset($ta); } else { if (is_int($tags)) { $tag = $zbp->GetTagByID($tags); } else { $tag = $zbp->GetTagByAliasOrName($tags); } if ($tag->ID > 0) { $w[] = array('LIKE', 'log_Tag', '%{' . $tag->ID . '}%'); } } } if (is_string($search)) {
$search=trim($search); if ($search!=='') { $w[] = array('search', 'log_Content', 'log_Intro', 'log_Title', $search); } } if(!empty($order)){
if($order=='new'){ $order = array('log_PostTime'=>'DESC'); } if($order=='hot'){ $order = array('log_ViewNums'=>'DESC'); } if($order=='comm'){ $order = array('log_CommNums'=>'DESC'); } if($order=='rand'){ $order = array('rand()'=>' '); } } $articles = $zbp->GetArticleList('*', $w, $order, $count, null, false);
if ($option['is_related']) {
foreach ($articles as $k => $a) { if ($a->ID == $option['is_related']) unset($articles[$k]); } if (count($articles) == $count){ array_pop($articles); } } return $articles;
}
|
代码如下 | 复制代码 |
{$array=TcgetList(10,null,null,null,null,null,null,'rand');}
<ul id="related"> {foreach $array as $related} <li><span class="time">{$related.Time('m-d')}</span><span class="title"><a href="{$related.Url}" title="{$related.Title}">{$related.Title}</a></span></li> {/foreach} </ul> |
代码如下 | 复制代码 |
{$array=TcgetList(10,null,null,null,null,null,null,'hot');}
<ul id="related"> {foreach $array as $related} <li><span class="time">{$related.Time('m-d')}</span><span class="title"><a href="{$related.Url}" title="{$related.Title}">{$related.Title}</a></span></li> {/foreach} </ul> |
代码如下 | 复制代码 |
{$array=TcgetList(10,null,null,null,null,null,null,'comm';}
<ul id="related"> {foreach $array as $related} <li><span class="time">{$related.Time('m-d')}</span><span class="title"><a href="{$related.Url}" title="{$related.Title}">{$related.Title}</a></span></li> {/foreach} </ul> |
<?php
/*
* 文件夹复制类,
* 吴钧泽 2015年11月2日16点29分
*/
class CopyFile
{
public $fromFile;
public $toFile;
/*
* $fromFile 要复制谁
* $toFile 复制到那
*/
function copyFile($fromFile,$toFile){
$this->CreateFolder($toFile);
$folder1=opendir($fromFile);
while($f1=readdir($folder1)){
if($f1!="." && $f1!=".."){
$path2="{$fromFile}/{$f1}";
if(is_file($path2)){
$file = $path2;
$newfile = "{$toFile}/{$f1}";
copy($file, $newfile);
}elseif(is_dir($path2)){
$toFiles = $toFile.'/'.$f1;
$this->copyFile($path2,$toFiles);
}
}
}
}
/*
* 递归创建文件夹
*/
function CreateFolder($dir, $mode = 0777){
if (is_dir($dir) || @mkdir($dir,$mode)){
return true;
}
if (!$this->CreateFolder(dirname($dir),$mode)){
return false;
}
return @mkdir($dir, $mode);
}
}
//使用方法
//引入本类,直接new copyFile('要复制谁','复制到那');
//$file = new CopyFile('./10010','./10010copy');
?>
s
图片添加水印我相信各位朋友都知道的,今天我们来看一段php的图片添加水印例子,希望文章能够帮助到各位朋友.<?php
/**
* 图片添加水印
* $target 源文件路径
* $wtrmrk_file 水印图片路径
* $newcopy 添加水印后的图片路径
*
*/
public function watermark_image($target, $wtrmrk_file, $newcopy) {
$watermark = imagecreatefrompng($wtrmrk_file);
imagealphablending($watermark, false);
imagesavealpha($watermark, true);
$img = imagecreatefromjpeg($target);
$img_w = imagesx($img);
$img_h = imagesy($img);
$wtrmrk_w = imagesx($watermark);
$wtrmrk_h = imagesy($watermark);
$dst_x = ($img_w ) – ($wtrmrk_w); // For centering the watermark on any image
$dst_y = ($img_h) – ($wtrmrk_h ); // For centering the watermark on any image
imagecopy($img, $watermark, $dst_x, $dst_y, 0, 0, $wtrmrk_w, $wtrmrk_h);
imagejpeg($img, $newcopy, 100);
imagedestroy($img);
imagedestroy($watermark);
//return $img;
}
?>
<?php
//原文件名
$file_name = $_FILES['imgFile']['name'];
//服务器上临时文件名
$tmp_name = $_FILES['imgFile']['tmp_name'];
//获得文件扩展名
$temp_arr = explode(".", $file_name);
$file_ext = array_pop($temp_arr);
$file_ext = trim($file_ext);
$file_ext = strtolower($file_ext);
//新文件名
$new_file_name = date("YmdHis") . '_' . rand(10000, 99999) . '.' . $file_ext;
$water=true;
if(isset($_SERVER['HTTP_APPNAME'])){//sae环境
$s=new SaeStorage();
//水印
if($water){
$waterpath='./watermark.png';
//新浪云只有SAE_TMP_PATH这个临时目录具有io操作的权限
$tmp_url = SAE_TMP_PATH.$new_file_name;//保存到sae临时目录
file_put_contents($tmp_url,file_get_contents($tmp_name));
watermark_image($tmp_url,$waterpath,$tmp_url);
if(!$s->upload('pic', $new_file_name, $tmp_url)){
echo '上传文件失败';exit;
}
}else{
if(!$s->upload('pic', $new_file_name, $tmp_name)){
echo '上传文件失败';exit;
}
}
//添加过水印的图片路径
$file_url = $s->getUrl('pic', $new_file_name);
}
?>
相关文章
- 这篇文章主要介绍了C#开发Windows窗体应用程序的简单操作步骤,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-04-12
- 本文通过例子,讲述了C++调用C#的DLL程序的方法,作出了以下总结,下面就让我们一起来学习吧。...2020-06-25
- 本文通过两个示例讲解了一下Process类调用外部应用程序的基本用法,并简单讲解了StartInfo属性,有需要的朋友可以参考一下。...2020-06-25
- 这篇文章主要介绍了微信小程序 页面传值详解的相关资料,需要的朋友可以参考下...2017-03-13
- 大概有如下步骤 新建项目Bejs 新建文件package.json 新建文件Gruntfile.js 命令行执行grunt任务 一、新建项目Bejs源码放在src下,该目录有两个js文件,selector.js和ajax.js。编译后代码放在dest,这个grunt会...2014-06-07
- 这篇文章主要介绍了uniapp微信小程序:key失效的解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-01-20
- 本文实例讲述了PHP常用的小程序代码段。分享给大家供大家参考,具体如下:1.计算两个时间的相差几天$startdate=strtotime("2009-12-09");$enddate=strtotime("2009-12-05");上面的php时间日期函数strtotime已经把字符串...2015-11-24
将c#编写的程序打包成应用程序的实现步骤分享(安装,卸载) 图文
时常会写用c#一些程序,但如何将他们和photoshop一样的大型软件打成一个压缩包,以便于发布....2020-06-25- 这篇文章主要介绍了微信小程序 网络请求(GET请求)详解的相关资料,需要的朋友可以参考下...2016-11-22
- 这篇文章主要给大家介绍了关于微信小程序如何获取图片宽度与高度的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-10
- 这篇文章主要为大家详细介绍了微信小程序自定义tabbar组件,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-03-14
- 这篇文章主要介绍了微信小程序 二维码生成工具 weapp-qrcode详解,教大家如何在项目中引入weapp-qrcode.js文件,通过实例代码给大家介绍的非常详细,需要的朋友可以参考下...2021-10-23
- 这篇文章主要介绍了Python爬取微信小程序通用方法代码实例详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-09-29
- 这篇文章主要介绍了微信小程序(应用号)开发新闻客户端实例的相关资料,需要的朋友可以参考下...2016-10-25
- 这篇文章主要介绍了微信小程序手势操作之单触摸点与多触摸点的相关资料,需要的朋友可以参考下...2017-03-13
- 这篇文章主要介绍了微信小程序 页面跳转传递值几种方法详解的相关资料,需要的朋友可以参考下...2017-01-16
- 本文主要介绍了手把手教你uniapp和小程序分包,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-09-02
- 这篇文章主要为大家详细介绍了微信小程序实现点击导航条切换页面,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-11-19
- 这篇文章主要为大家详细介绍了微信小程序实现canvas分享朋友圈海报,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-06-21
- 本文章来给大家详细介绍在php中如何来调用执行mysql存储过程然后返回由存储过程返回的值了,有需要了解的同学可进入参考。 。调用存储过程的方法。 a。如果存储过...2016-11-25