ZBLOG PHP调用随机文章、热门文章、热评文章程序

 更新时间:2016年11月25日 17:17  点击:1259
本文章来为各位介绍一篇关于ZBLOG PHP调用随机文章、热门文章、热评文章的例子,希望这篇教程能够为各位同学带来帮助的哦.
使用方法:

 

第一、在我们的主题目录中需要创建include.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;

}

 

然后就是在我们需要的界面模板中调用。

 

A - 随机文章

 

 代码如下 复制代码

{$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>

 

随机10篇文章

 

B - 热门文章

 

 代码如下 复制代码

{$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>

 

调用10篇热门文章

 

C - 热评文章

 

 代码如下 复制代码

{$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>

 

调用10篇热评文章。

 

具体的根据我们实际使用调用就可以。
复制文件夹是相当的复杂的一个过程了,我们需要先判断类型是文件还是目录,然后查找目录中是否还有目录了,下面我们来看一个关于PHP递归复制文件夹的类,希望例子能够帮助到各位.

<?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');
?>

PHP提交MYSQL数据库中文内容乱码问题其实与查询乱码是一样的我们只需要把它进行一个简单的调整即可了,在数据库连接处填写mysql_query("set names 'utf8'");即可解决了.
无论是ASP还是PHP程序语言,甚至有其他WEB语言,基础的应用无非就是数据库添加、读取、编辑、删除等需求,再复杂的功能项目都围绕这些进行的。在录入MYSQL数据库的时候提交的中文数据出现乱码问题,这个问题对于新手学习PHP肯定是有遇到过的。

 

其实问题还是比较简单的,肯定是编码不对应导致的。比如页面的编码,数据库字段的编码,以及数据库链接编码问题,这里老蒋全部采用UTF-8编码,那需要寻找这几个地方的问题,就解决乱码问题。

 

第一、页面编码问题

 

我们在WEB页面中,需要全部保持是UTF-8编码。

 

第二、创建数据库的时候编码问题

 

在"PHP创建MYSQL数据库与数据表常用命令和数据类型设定"文章中,老蒋采用的是SQL直接导入的方式,我们在添加数据库字段的时候,如果我们是需要全部保持UTF-8编码的时候,我们需要在最后"CHARSET=utf8",这里保持数据库字段的UTF8。

 

第三、数据库链接的编码问题

 

在数据库链接文件处,我们需要设置:

 

mysql_query("set names 'utf8'");

 

同样的是UTF8编码设置。

 

这样,通过3处的统一编码,我们在提交数据之后,乱码问题肯定是可以解决的。

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新浪云平台给图片添加水印方法的例子,希望这篇教程能够帮助到各位使用新浪云平台的朋友.

<?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);
}
?>

[!--infotagslink--]

相关文章

  • C#开发Windows窗体应用程序的简单操作步骤

    这篇文章主要介绍了C#开发Windows窗体应用程序的简单操作步骤,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-04-12
  • C++调用C#的DLL程序实现方法

    本文通过例子,讲述了C++调用C#的DLL程序的方法,作出了以下总结,下面就让我们一起来学习吧。...2020-06-25
  • C#使用Process类调用外部exe程序

    本文通过两个示例讲解了一下Process类调用外部应用程序的基本用法,并简单讲解了StartInfo属性,有需要的朋友可以参考一下。...2020-06-25
  • 微信小程序 页面传值详解

    这篇文章主要介绍了微信小程序 页面传值详解的相关资料,需要的朋友可以参考下...2017-03-13
  • 使用GruntJS构建Web程序之构建篇

    大概有如下步骤 新建项目Bejs 新建文件package.json 新建文件Gruntfile.js 命令行执行grunt任务 一、新建项目Bejs源码放在src下,该目录有两个js文件,selector.js和ajax.js。编译后代码放在dest,这个grunt会...2014-06-07
  • uniapp微信小程序:key失效的解决方法

    这篇文章主要介绍了uniapp微信小程序:key失效的解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-01-20
  • PHP常用的小程序代码段

    本文实例讲述了PHP常用的小程序代码段。分享给大家供大家参考,具体如下:1.计算两个时间的相差几天$startdate=strtotime("2009-12-09");$enddate=strtotime("2009-12-05");上面的php时间日期函数strtotime已经把字符串...2015-11-24
  • 将c#编写的程序打包成应用程序的实现步骤分享(安装,卸载) 图文

    时常会写用c#一些程序,但如何将他们和photoshop一样的大型软件打成一个压缩包,以便于发布....2020-06-25
  • 微信小程序 网络请求(GET请求)详解

    这篇文章主要介绍了微信小程序 网络请求(GET请求)详解的相关资料,需要的朋友可以参考下...2016-11-22
  • 微信小程序如何获取图片宽度与高度

    这篇文章主要给大家介绍了关于微信小程序如何获取图片宽度与高度的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-10
  • 微信小程序自定义tabbar组件

    这篇文章主要为大家详细介绍了微信小程序自定义tabbar组件,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-03-14
  • 微信小程序二维码生成工具 weapp-qrcode详解

    这篇文章主要介绍了微信小程序 二维码生成工具 weapp-qrcode详解,教大家如何在项目中引入weapp-qrcode.js文件,通过实例代码给大家介绍的非常详细,需要的朋友可以参考下...2021-10-23
  • Python爬取微信小程序通用方法代码实例详解

    这篇文章主要介绍了Python爬取微信小程序通用方法代码实例详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-09-29
  • 微信小程序(应用号)开发新闻客户端实例

    这篇文章主要介绍了微信小程序(应用号)开发新闻客户端实例的相关资料,需要的朋友可以参考下...2016-10-25
  • 微信小程序手势操作之单触摸点与多触摸点

    这篇文章主要介绍了微信小程序手势操作之单触摸点与多触摸点的相关资料,需要的朋友可以参考下...2017-03-13
  • 微信小程序 页面跳转传递值几种方法详解

    这篇文章主要介绍了微信小程序 页面跳转传递值几种方法详解的相关资料,需要的朋友可以参考下...2017-01-16
  • 手把手教你uniapp和小程序分包(图文)

    本文主要介绍了手把手教你uniapp和小程序分包,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-09-02
  • 微信小程序实现点击导航条切换页面

    这篇文章主要为大家详细介绍了微信小程序实现点击导航条切换页面,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-11-19
  • 微信小程序实现canvas分享朋友圈海报

    这篇文章主要为大家详细介绍了微信小程序实现canvas分享朋友圈海报,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-06-21
  • PHP调用MySQL存储过程并返回值实现程序

    本文章来给大家详细介绍在php中如何来调用执行mysql存储过程然后返回由存储过程返回的值了,有需要了解的同学可进入参考。 。调用存储过程的方法。 a。如果存储过...2016-11-25