Skip to content

Instantly share code, notes, and snippets.

@geek01
Last active April 2, 2018 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geek01/4cbfccbdd9e2cfa7af344340b7170f8d to your computer and use it in GitHub Desktop.
Save geek01/4cbfccbdd9e2cfa7af344340b7170f8d to your computer and use it in GitHub Desktop.
tadgallery加入相片分頁
<?php
//列出所有照片
function list_photos($csn = "", $uid = "")
{
global $xoopsModuleConfig, $xoopsTpl, $tadgallery, $xoopsDB;
if (!file_exists(XOOPS_ROOT_PATH . "/modules/tadtools/fancybox.php")) {
redirect_header("index.php", 3, _MA_NEED_TADTOOLS);
}
include_once XOOPS_ROOT_PATH . "/modules/tadtools/fancybox.php";
if ($csn) {
$tadgallery->set_orderby("photo_sort");
$tadgallery->set_view_csn($csn);
$tadgallery->set_only_thumb($xoopsModuleConfig['only_thumb']);
$tadgallery->set_limit($xoopsModuleConfig['thumbnail_number']);//限制相片數
$cate = $tadgallery->get_tad_gallery_cate($csn);
$xoopsTpl->assign("cate", $cate);
$upload_powers = $tadgallery->chk_cate_power("upload");
if ($upload_powers) {
include_once XOOPS_ROOT_PATH . "/modules/tadtools/jeditable.php";
$file = "save.php";
$jeditable = new jeditable();
$jeditable->setTextAreaCol("#content", $file, '90%', '100px', "{'csn':$csn,'op' : 'save'}", _MD_TADGAL_EDIT_CATE_CONTENT);
$jeditable_set = $jeditable->render();
$xoopsTpl->assign("jeditable_set", $jeditable_set);
}
} else {
$nowuid = "";
if ($xoopsUser) {
$nowuid = $xoopsUser->uid();
}
$tadgallery->set_orderby("rand");
$tadgallery->set_limit($xoopsModuleConfig['thumbnail_number']);
}
if ($xoopsModuleConfig['random_photo'] != 0 or !empty($csn)) {
$photo = $tadgallery->get_photos();
}
$xoopsTpl->assign("random_photo", $xoopsModuleConfig['random_photo']);
// die(var_export($photo));
$xoopsTpl->assign("photo", $photo);
$tadgallery->get_albums();
$cate_fancybox = new fancybox('.editbtn');
$cate_fancybox_code = $cate_fancybox->render(false);
$xoopsTpl->assign('cate_fancybox_code', $cate_fancybox_code);
if (!file_exists(XOOPS_ROOT_PATH . "/modules/tadtools/colorbox.php")) {
redirect_header("index.php", 3, _MA_NEED_TADTOOLS);
}
include_once XOOPS_ROOT_PATH . "/modules/tadtools/colorbox.php";
$colorbox = new colorbox('.Photo');
$colorbox_code = $colorbox->render(false);
$xoopsTpl->assign('colorbox_code', $colorbox_code);
$xoopsTpl->assign('only_thumb', $xoopsModuleConfig['only_thumb']);
$xoopsTpl->assign("csn", $csn);
}
<?php
//取得相片
public function get_photos($include_sub = 0)
{
global $xoopsTpl, $xoopsDB, $xoopsModuleConfig, $isAdmin, $xoopsUser;
$nowuid = "";
if ($xoopsUser) {
$nowuid = $xoopsUser->uid();
}
//密碼檢查
$this->chk_passwd();
//相簿人氣值
$tg_count = $this->get_tad_gallery_cate_count();
$photo = $show_csn = array();
if (is_null($this->view_csn)) {
$cates = $this->chk_cate_power();
//找最新的10個相簿,避免分類太多無法執行
$csn_arr = array();
$sql = "select `csn`,`passwd` from " . $xoopsDB->prefix("tad_gallery_cate") . " where `enable`='1' order by `csn` desc limit 0,10";
$result = $xoopsDB->queryF($sql) or web_error($sql);
while (list($csn, $passwd) = $xoopsDB->fetchRow($result)) {
$csn_arr[] = $csn;
$the_passwd[$csn] = $passwd;
}
if (is_array($cates)) {
foreach ($cates as $the_csn) {
if (!empty($csn_arr) and is_array($csn_arr)) {
if (!in_array($the_csn, $csn_arr)) {
continue;
}
}
// $the_cate = $this->get_tad_gallery_cate($the_csn);
$save_passwd = isset($_SESSION['tadgallery'][$the_csn]) ? $_SESSION['tadgallery'][$the_csn] : "";
if (!empty($the_passwd[$the_csn]) and $save_passwd = $the_passwd[$the_csn]) {
$show_csn[] = $the_csn;
} elseif (empty($the_passwd[$the_csn])) {
$show_csn[] = $the_csn;
}
}
}
$show_csn_all = is_array($show_csn) ? implode(",", $show_csn) : "";
$and_csn = empty($show_csn_all) ? "" : "and a.`csn` in($show_csn_all)";
} elseif ($include_sub == 1) {
$show_csn = $this->get_tad_gallery_sub_cate_array($this->view_csn);
$show_csn_all = is_array($show_csn) ? implode(",", $show_csn) : "";
$and_csn = empty($show_csn_all) ? "" : "and a.`csn` in($show_csn_all)";
} else {
$and_csn = "and a.`csn`='{$this->view_csn}'";
}
$and_good = $this->view_good ? "and a.`good`='1'" : '';
//$limit = !empty($this->limit) ? "limit 0 , " . $this->limit : "";
$orderby = ($this->orderby == "rand") ? "rand()" : "a.{$this->orderby}";
$and_uid = empty($this->show_uid) ? "" : "and a.uid='{$this->show_uid}'";
//找出分類下所有相片
$sql = "select a.* , b.title as album_title from " . $xoopsDB->prefix("tad_gallery") . " as a left join " . $xoopsDB->prefix("tad_gallery_cate") . " as b on a.csn=b.csn where 1 $and_csn $and_good $and_uid order by {$orderby} {$this->order_desc}";
//die($sql);
//getPageBar($原sql語法, 每頁顯示幾筆資料, 最多顯示幾個頁數選項);
$PageBar = getPageBar($sql, $this->limit);
$bar = $PageBar['bar'];
$sql = $PageBar['sql'];
$result = $xoopsDB->queryF($sql) or web_error($sql);
$pp = $types = array();
if ($this->display2fancybox) {
if (!file_exists(XOOPS_ROOT_PATH . "/modules/tadtools/colorbox.php")) {
redirect_header("index.php", 3, _MA_NEED_TADTOOLS);
}
include_once XOOPS_ROOT_PATH . "/modules/tadtools/colorbox.php";
$colorbox = new colorbox('.' . $this->display2fancybox);
$colorbox->render(false);
// if (!file_exists(XOOPS_ROOT_PATH . "/modules/tadtools/fancybox.php")) {
// redirect_header("index.php", 3, _MA_NEED_TADTOOLS);
// }
// include_once XOOPS_ROOT_PATH . "/modules/tadtools/fancybox.php";
// $fancybox = new fancybox('.' . $this->display2fancybox);
// $fancybox->render();
}
$i = 0;
//$photo="";
while ($all = $xoopsDB->fetchArray($result)) {
foreach ($all as $k => $v) {
$$k = $v;
}
if (!isset($db_csn)) {
$db_csn = '';
}
if (!isset($album_title)) {
$album_title = '';
}
$photo[$i]['sn'] = $sn;
$photo[$i]['db_csn'] = $db_csn;
$photo[$i]['title'] = $title;
$photo[$i]['description'] = nl2br($description);
$photo[$i]['filename'] = $filename;
$photo[$i]['size'] = $size;
$photo[$i]['type'] = $type;
$photo[$i]['width'] = $width;
$photo[$i]['height'] = $height;
$photo[$i]['dir'] = $dir;
$photo[$i]['uid'] = $uid;
//以uid取得使用者名稱
$uid_name = XoopsUser::getUnameFromId($uid, 1);
if (empty($uid_name)) {
$uid_name = XoopsUser::getUnameFromId($uid, 0);
}
$photo[$i]['author'] = $uid_name;
$photo[$i]['post_date'] = $post_date;
$photo[$i]['counter'] = $counter;
$photo[$i]['exif'] = $exif;
$photo[$i]['tag'] = $tag;
$photo[$i]['good'] = $good;
$photo[$i]['photo_sort'] = $photo_sort;
$photo[$i]['photo_l'] = $this->get_pic_url($dir, $sn, $filename);
$photo[$i]['photo_l_url'] = urlencode($this->get_pic_url($dir, $sn, $filename));
$photo[$i]['photo_m'] = $this->get_pic_url($dir, $sn, $filename, "m");
$photo[$i]['photo_s'] = $this->get_pic_url($dir, $sn, $filename, "s");
$photo[$i]['photo_del'] = ($uid == $nowuid or $isAdmin) ? true : false;
$photo[$i]['photo_edit'] = ($uid == $nowuid or $isAdmin) ? true : false;
$photo[$i]['album_title'] = $album_title;
$photo[$i]['is360'] = $is360;
$photo[$i]['fancy_class'] = $this->display2fancybox ? 'class="' . $this->display2fancybox . '" rel="group"' : "";
preg_match("/\[DateTime\]=(.*)\|\|\[IFD0\]/", $exif, $matches);
$photo[$i]['DateTime'] = $matches[1];
if (isset($types[$type])) {
$types[$type]++;
} else {
$types[$type] = 1;
}
// preg_match("/\[Model\]=(.*)\|\|\[IFD0\]\[DateTime\]/", $exif, $matches);
// $Model360 = get360_arr();
// $photo[$i]['is360'] = in_array($matches[1], $Model360) ? true : false;
$i++;
}
arsort($types);
foreach ($types as $extension => $value) {
if ($extension == "image/png") {
$extension = "png";
} elseif ($extension == "image/gif") {
$extension = "gif";
} else {
$extension = "jpg";
}
$xoopsTpl->assign("extension", $extension);
break;
}
$xoopsTpl->assign("bar", $bar);
return $photo;
}
<{includeq file="db:tadgallery_list_header.tpl"}>
<link rel="stylesheet" type="text/css" media="screen" href="<{$xoops_url}>/modules/tadgallery/module.css" />
<!--相片-->
<{if $photo}>
<div class="row">
<div class="col-sm-12" id="tg_container">
<{foreach item=photo from=$photo}>
<div class='PhotoCate' id="PhotoCate_<{$photo.sn}>">
<{if $photo.is360}>
<a class='Photo360' href="360.php?sn=<{$photo.sn}>&file=<{$photo.photo_l}>" id="item_photo_<{$photo.sn}>" title="<{$photo.sn}>" data-author="<{$photo.author}>">
<div style="width:125px; height:100px; background: white url('<{$photo.photo_m}>') no-repeat center center; cursor: pointer; margin: 0px auto; background-size: contain;" class="show_photo">
<span class="fa-stack">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-street-view fa-stack-1x fa-inverse"></i>
</span>
</div>
<{else}>
<a class="Photo" id="item_photo_<{$photo.sn}>" title="<{$photo.sn}>" data-photo="<{$photo.photo_l}>" data-author="<{$photo.author}>" alt="<{$photo.author}>" href="<{$photo.photo_l}>">
<div style="width:125px; height:100px; background: white url('<{$photo.photo_s}>') no-repeat center center; cursor: pointer; margin: 0px auto; background-size: contain;" class="show_photo">
</div>
<{/if}>
<div class="pic_title2"><{$photo.title}></div>
</a>
<{if $photo.photo_del}>
<button onclick="javascript:delete_tad_gallery_func(<{$photo.sn}>)" class="btn btn-xs btn-danger" style="position:absolute;bottom:2px;left:2px;display:none;"><{$smarty.const._TAD_DEL}></button>
<{/if}>
<{if $photo.photo_edit}>
<button href="ajax.php?op=edit_photo&sn=<{$photo.sn}>" class="btn btn-xs btn-warning fancybox.ajax editbtn" style="position:absolute;bottom:2px;right:2px;display:none;"><{$smarty.const._TAD_EDIT}></button>
<{/if}>
</div>
<{/foreach}>
</div>
</div>
<{$bar}>
<script type="text/javascript" src="<{$xoops_url}>/modules/tadgallery/class/jquery.animate-shadow.js"></script>
<script>
$(function(){
$('.Photo').colorbox({rel:'group', photo:true, maxWidth:'100%', maxHeight:'100%', title: function(){
var author= $(this).data('author');
var sn = $(this).attr('title');
return '<a href="view.php?sn=' + sn + '#photo' + sn + '" target="_blank"><{$smarty.const._MD_TADGAL_VIEW_PHOTO}></a> post by '+ author;
}});
$('.Photo360').colorbox({rel:'group', iframe:true, width:"90%", height:"90%", maxWidth:'100%', maxHeight:'100%', title: function(){
var author= $(this).data('author');
var sn = $(this).attr('title');
return '<a href="view.php?sn=' + sn + '#photo' + sn + '" target="_blank"><{$smarty.const._MD_TADGAL_VIEW_PHOTO}></a> post by '+ author;
}});
});
function delete_tad_gallery_func(sn){
var sure = window.confirm('<{$smarty.const._TAD_DEL_CONFIRM}>');
if (!sure) return;
//location.href="ajax.php?op=delete_tad_gallery&sn=" + sn;
$.post("ajax.php", { op: "delete_tad_gallery", sn: sn },
function(data) {
$('#PhotoCate_'+sn).remove();
});
}
</script>
<{elseif $csn}>
<div class="alert alert-danger">
<{$smarty.const._MD_TADGAL_EMPTY}>
</div>
<{/if}>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment