Beispiel #1
0
function read_dir_pic($main_dir = "")
{
    global $xoopsDB;
    $pics = "";
    $post_max_size = ini_get('post_max_size');
    //$size_limit=intval($post_max_size) * 0.5  * 1024 * 1024;
    if (substr($main_dir, -1) != '/') {
        $main_dir = $main_dir . "/";
    }
    if ($dh = opendir($main_dir)) {
        $total_size = 0;
        $i = 1;
        while (($file = readdir($dh)) !== false) {
            if (substr($file, 0, 1) == ".") {
                continue;
            }
            if (is_dir($main_dir . $file)) {
                $pic = read_dir_pic($main_dir . $file);
                $pics .= $pic['pics'];
                $total_size += $pic['total_size'];
            } else {
                //讀取exif資訊
                $result = exif_read_data($main_dir . $file, 0, true);
                $creat_date = $result['IFD0']['DateTime'];
                $dir = (empty($creat_date) or substr($creat_date, 0, 1) != "2") ? date("Y_m_d") : str_replace(":", "_", substr($result['IFD0']['DateTime'], 0, 10));
                $exif = mk_exif($result);
                $size = filesize($main_dir . $file);
                $total_size += intval($size);
                $size_txt = sizef($size);
                $pic = getimagesize($main_dir . $file);
                $width = $pic[0];
                $height = $pic[1];
                $subname = strtolower(substr($file, -3));
                if ($subname == "jpg" or $subname == "peg") {
                    $type = "image/jpeg";
                } elseif ($subname == "png") {
                    $type = "image/png";
                } elseif ($subname == "gif") {
                    $type = "image/gif";
                } else {
                    $type = $subname;
                    continue;
                }
                $sql = "select width,height from " . $xoopsDB->prefix("tad_gallery") . " where filename='{$file}' and size='{$size}'";
                $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, mysql_error());
                list($db_width, $db_height) = $xoopsDB->fetchRow($result);
                if ($db_width == $width and $db_height == $height) {
                    $checked = "disabled='disabled'";
                    $upload = "0";
                    $status = _MD_TADGAL_IMPORT_EXIST;
                    //}elseif($total_size >= $size_limit){
                    // $checked="disabled='disabled'";
                    // $upload="1";
                    // $status=sprintf(_MD_TADGAL_IMPORT_OVER_SIZE,sizef($total_size),$post_max_size);
                } else {
                    $checked = "checked='checked'";
                    $upload = "1";
                    $status = $type;
                }
                if (_CHARSET == "UTF-8") {
                    $file = to_utf8($file);
                }
                $pics .= "\n                <tr>\n                  <td style='font-size:11px'>{$i}</td>\n                  <td style='font-size:11px'>\n                    <input type='hidden' name='all[{$i}]' value='" . $main_dir . $file . "'>\n                    <input type='checkbox' name='import[{$i}][upload]' value='1' {$checked}>\n                    {$file}\n                    <input type='hidden' name='import[{$i}][filename]' value='{$file}'></td>\n                  <td style='font-size:11px'>{$dir}<input type='hidden' name='import[{$i}][dir]' value='{$dir}'></td>\n                  <td style='font-size:11px'>{$width} x {$height}\n                    <input type='hidden' name='import[{$i}][post_date]' value='{$creat_date}'>\n                    <input type='hidden' name='import[{$i}][width]' value='{$width}'>\n                    <input type='hidden' name='import[{$i}][height]' value='{$height}'></td>\n                  <td style='font-size:11px'>{$size_txt}<input type='hidden' name='import[{$i}][size]' value='{$size}'></td>\n                  <td style='font-size:11px'>{$status}\n                    <input type='hidden' name='import[{$i}][exif]' value='{$exif}'>\n                    <input type='hidden' name='import[{$i}][type]' value='{$type}'></td>\n                </tr>";
                $i++;
            }
        }
        closedir($dh);
    }
    $main['pics'] = $pics;
    $main['total_size'] = $total_size;
    return $main;
}
Beispiel #2
0
function view_pic($sn = "")
{
    global $xoopsDB, $xoopsUser, $xoopsModule, $xoopsModuleConfig, $xoopsTpl, $xoTheme;
    $tadgallery = new tadgallery();
    //判斷是否對該模組有管理權限,  若空白
    if ($xoopsUser) {
        $nowuid = $xoopsUser->getVar('uid');
        $module_id = $xoopsModule->getVar('mid');
        $isAdmin = $xoopsUser->isAdmin($module_id);
    } else {
        $isAdmin = false;
        $nowuid = "";
    }
    $sql = "select * from " . $xoopsDB->prefix("tad_gallery") . " where sn='{$sn}'";
    $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, mysql_error());
    $all = $xoopsDB->fetchArray($result);
    //$csn,$title,$description,$filename,$size,$type,$width,$height,$dir,$uid,$post_date,$counter,$exif,$good,$tag,$photo_sort
    foreach ($all as $k => $v) {
        ${$k} = $v;
        $xoopsTpl->assign($k, $v);
    }
    $photo_s = $tadgallery->get_pic_url($dir, $sn, $filename, "s");
    $photo_m = $tadgallery->get_pic_url($dir, $sn, $filename, "m");
    $photo_l = $tadgallery->get_pic_url($dir, $sn, $filename);
    $xoopsTpl->assign("photo_s", $photo_s);
    $xoopsTpl->assign("photo_m", $photo_m);
    $xoopsTpl->assign("photo_l", $photo_l);
    if (!empty($csn)) {
        $ok_cat = $tadgallery->chk_cate_power();
        $cate = $tadgallery->get_tad_gallery_cate($csn);
        if (!in_array($csn, $ok_cat)) {
            redirect_header("index.php?csn={$csn}&op=passwd_form", 3, sprintf(_TADGAL_NO_PASSWD_CONTENT, $cate['title']));
            exit;
        }
        $sql = "select * from " . $xoopsDB->prefix("tad_gallery") . " where csn='{$csn}' order by photo_sort , post_date";
        $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, mysql_error());
        $slides1 = $slides2 = "";
        $i = 0;
        $start = false;
        while ($all = $xoopsDB->fetchArray($result)) {
            if ($sn == $all['sn']) {
                $start = true;
                $i = 0;
            }
            if ($start) {
                $slides1[$i]['sn'] = $all['sn'];
                $slides1[$i]['photo'] = $tadgallery->get_pic_url($all['dir'], $all['sn'], $all['filename']);
                $slides1[$i]['description'] = strip_tags($all['description']);
                $slides1[$i]['thumb'] = $tadgallery->get_pic_url($all['dir'], $all['sn'], $all['filename'], 's');
            } else {
                $slides2[$i]['sn'] = $all['sn'];
                $slides2[$i]['photo'] = $tadgallery->get_pic_url($all['dir'], $all['sn'], $all['filename']);
                $slides2[$i]['description'] = strip_tags($all['description']);
                $slides2[$i]['thumb'] = $tadgallery->get_pic_url($all['dir'], $all['sn'], $all['filename'], 's');
            }
            $i++;
        }
    }
    $xoopsTpl->assign("slides1", $slides1);
    $xoopsTpl->assign("slides2", $slides2);
    //找出上一張或下一張
    $pnp = get_pre_next($csn, $sn);
    $xoopsTpl->assign("next", $pnp['next']);
    $xoopsTpl->assign("back", $pnp['pre']);
    $arr = get_tadgallery_cate_path($csn);
    $jBreadCrumbPath = breadcrumb($csn, $arr);
    $xoopsTpl->assign("path", $jBreadCrumbPath);
    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('.fancybox');
    $fancybox_code = $fancybox->render(false);
    $xoopsTpl->assign('fancybox_code', $fancybox_code);
    $title = empty($title) ? $filename : $title;
    $div_width = $xoopsModuleConfig['thumbnail_m_width'] + 30;
    $size_txt = sizef($size);
    if ($uid == $nowuid or $isAdmin) {
        $xoopsTpl->assign('show_del', 1);
        //$del_btn="<a src='javascript:delete_tad_gallery_func($sn)' title='"._TADGAL_DEL_PIC."' class='btn btn-danger'>"._TAD_DEL."</a>";
        $xoopsTpl->assign('good', $good);
        $del_js = "\n    <script>\n    function delete_tad_gallery_func(sn){\n      var sure = window.confirm('" . _TAD_DEL_CONFIRM . "');\n      if (!sure)  return;\n      location.href=\"{$_SERVER['PHP_SELF']}?op=delete_tad_gallery&sn=\" + sn;\n    }\n    </script>";
    } else {
        $del_btn = $admin_tool = $del_js = "";
    }
    $xoopsTpl->assign('del_btn', $del_btn);
    //秀出各種尺寸圖示
    if ($xoopsModuleConfig['show_copy_pic']) {
        $xoopsTpl->assign("photo_s", $photo_s);
        $xoopsTpl->assign("photo_m", $photo_m);
        $xoopsTpl->assign("photo_l", $photo_l);
        $xoopsTpl->assign("description", $description);
        $xoopsTpl->assign("sel_size", 1);
    } else {
        $xoopsTpl->assign("sel_size", 0);
    }
    //推文工具
    $push = push_url($xoopsModuleConfig['use_social_tools']);
    $xoopsTpl->assign("push", $push);
    $xoopsTpl->assign("pic_toolbar", $xoopsModuleConfig['pic_toolbar']);
    $xoopsTpl->assign("thumb_slider", $xoopsModuleConfig['thumb_slider']);
    //計數器
    add_tad_gallery_counter($sn);
    //地圖部份
    $info = explode("||", $exif);
    foreach ($info as $v) {
        $exif_arr = explode("=", $v);
        $exif_arr[1] = str_replace("&#65533;", "", $exif_arr[1]);
        $bb = "\$photoexif{$exif_arr[0]}=\"{$exif_arr[1]}\";";
        if (empty($exif_arr[0])) {
            continue;
        }
        @eval($bb);
    }
    $latitude = $photoexif['GPS']['latitude'];
    $longitude = $photoexif['GPS']['longitude'];
    $xoopsTpl->assign("latitude", $latitude);
    $xoopsTpl->assign("longitude", $longitude);
    $jquery_path = get_jquery(true);
    $xoopsTpl->assign("jquery", $jquery_path);
    $xoopsTpl->assign("path", $jBreadCrumbPath);
    $xoopsTpl->assign("del_js", $del_js);
    $xoopsTpl->assign("div_width", $div_width);
    $facebook_comments = facebook_comments($xoopsModuleConfig['facebook_comments_width'], 'tadgallery', 'view.php', 'sn', $sn);
    $xoopsTpl->assign("facebook_comments", $facebook_comments);
    $fb_tag = "\n      <meta property=\"og:title\" content=\"{$title}\" />\n      <meta property=\"og:description\" content=\"{$description}\" />\n      <meta property=\"og:image\" content=\"" . $tadgallery->get_pic_url($dir, $sn, $filename, "m") . "\" />\n      ";
    $xoopsTpl->assign("xoops_module_header", $fb_tag);
    $xoopsTpl->assign("xoops_pagetitle", $title);
    if (is_object($xoTheme)) {
        $xoTheme->addMeta('meta', 'keywords', $title);
        $xoTheme->addMeta('meta', 'description', $description);
    } else {
        $xoopsTpl->assign('xoops_meta_keywords', 'keywords', $title);
        $xoopsTpl->assign('xoops_meta_description', $description);
    }
}