function import_tad_gallery($csn_menu = array(), $new_csn = "", $all = array(), $import = array()) { global $xoopsDB, $xoopsUser, $xoopsModuleConfig, $type_to_mime; krsort($csn_menu); foreach ($csn_menu as $cate_sn) { if (empty($cate_sn)) { continue; } else { $csn = $cate_sn; break; } } if (!empty($new_csn)) { $csn = add_tad_gallery_cate($csn, $new_csn); } $uid = $xoopsUser->getVar('uid'); if (!empty($csn)) { $_SESSION['tad_gallery_csn'] = $csn; } //處理上傳的檔案 $sort = 0; foreach ($all as $i => $source_file) { if ($import[$i]['upload'] != '1') { unlink($source_file); continue; } $orginal_file_name = strtolower(basename($import[$i]['filename'])); //get lowercase filename $file_ending = substr(strtolower($orginal_file_name), -3); //file extension $sql = "insert into " . $xoopsDB->prefix("tad_gallery") . " (\n `csn`, `title`, `description`, `filename`, `size`, `type`, `width`, `height`, `dir`, `uid`, `post_date`, `counter`, `exif`, `tag`, `good`, `photo_sort`) values('{$csn}','','','{$import[$i]['filename']}','{$import[$i]['size']}','{$import[$i]['type']}','{$import[$i]['width']}','{$import[$i]['height']}','{$import[$i]['dir']}','{$uid}','{$import[$i]['post_date']}','0','{$import[$i]['exif']}','','0',{$sort})"; $sort++; $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 10, mysql_error() . $sql); //取得最後新增資料的流水編號 $sn = $xoopsDB->getInsertId(); set_time_limit(0); mk_dir(_TADGAL_UP_FILE_DIR . $import[$i]['dir']); mk_dir(_TADGAL_UP_FILE_DIR . "small/" . $import[$i]['dir']); mk_dir(_TADGAL_UP_FILE_DIR . "medium/" . $import[$i]['dir']); $filename = photo_name($sn, "source", 1); if (rename($source_file, $filename)) { $m_thumb_name = photo_name($sn, "m", 1); $s_thumb_name = photo_name($sn, "s", 1); if (!empty($xoopsModuleConfig['thumbnail_b_width']) and ($import[$i]['width'] > $xoopsModuleConfig['thumbnail_b_width'] or $import[$i]['height'] > $xoopsModuleConfig['thumbnail_b_width'])) { thumbnail($filename, $filename, $type_to_mime[$file_ending], $xoopsModuleConfig['thumbnail_b_width']); } if ($import[$i]['width'] > $xoopsModuleConfig['thumbnail_m_width'] or $import[$i]['height'] > $xoopsModuleConfig['thumbnail_m_width']) { thumbnail($filename, $m_thumb_name, $type_to_mime[$file_ending], $xoopsModuleConfig['thumbnail_m_width']); } if ($import[$i]['width'] > $xoopsModuleConfig['thumbnail_s_width'] or $import[$i]['height'] > $xoopsModuleConfig['thumbnail_s_width']) { thumbnail($filename, $s_thumb_name, $type_to_mime[$file_ending], $xoopsModuleConfig['thumbnail_s_width']); } } else { $sql = "delete from " . $xoopsDB->prefix("tad_gallery") . " where sn='{$sn}'"; $xoopsDB->query($sql); redirect_header($_SERVER['PHP_SELF'], 5, sprintf(_MD_TADGAL_IMPORT_IMPORT_ERROR, $source_file, $filename)); } } rrmdir(_TADGAL_UP_IMPORT_DIR); return $csn; }
function paintr() { global $current_id; /* try {*/ load_current_id(STORE_DIR); $current_id++; //$filename_jpeg = WORK_DIR . $current_id . ".jpg"; $filename_svg = WORK_DIR . $current_id . ".svg"; $filename_svg_final = STORE_DIR . $current_id . ".svg"; $filename_html = STORE_DIR . $current_id . ".html"; echo "Begin.<br />"; echo "ID: " . $current_id . "<br />"; echo "Get palette.<br />"; $palette_source = get_palette(); $palette_name = palette_name($palette_source); $palette = palette_entries($palette_source); $palette = sort_palette_by_brightness($palette); $palette = light_to_dark_or_dark_to_light($palette); $palette_tags = palette_tags($palette_source); echo "Tags: " . implode(", ", $palette_tags) . "<br />\n"; //$wordnet_synonims = wordnet_tags_synonims ($palette_tags); //echo implode (", ", $wordnet_synonims) . "\n"; // At the moment flickr API access fails if we don't echo these. Huh? echo "Get photo.<br />"; $photo = photo_from_tags($palette_tags); //($wordnet_synonims); echo "Get photo user name.<br />"; $username = photo_user_name($photo); echo "Get photo name.<br/>"; $photo_name = photo_name($photo); $file_description = $photoname . ' by ' . $username . ', licensed under the Creative Commons Attribution-ShareAlike License' . '.jpg'; $filename_jpeg = WORK_DIR . urlencode($file_description); echo "Save JPEG.<br />"; photo_save_jpeg($photo, $filename_jpeg); echo "Autotrace.<br />"; autotrace(count($palette), $filename_jpeg, $filename_svg); echo "Delete old file.<br />"; @unlink($filename_jpeg); echo "Load svg.<br />"; $svg = load_svg($filename_svg); echo "Apply palette.<br />"; $svg = apply_palette_to_svg($palette, $svg); echo "Save SVG.<br />"; save_svg($svg, $filename_svg_final); echo "Save writeup.<br />"; save_writeup($filename_html, $palette_name, $palette, $palette_tags, $photo); echo "End.<br />"; /* } catch (Exception $e) { $error = "<h2>" . date ("l dS of F Y at h:i:s A") . "</h2>" . "<h2>An error occurred: " . get_class($e) . "</h2>\n" . "<h3>{$e->getMessage()} ({$e->getCode()})</h3>\n\n" . "file: {$e->getFile()}<br/>\n" . "line: {$e->getLine()}<br/>\n" . "<PRE>" . $e->getTraceAsString() . "</PRE><br />" ; file_put_contents ("./error.html", $error, FILE_APPEND); die (); }*/ // When finished, save the id for next time. If we failed, re-use same id. save_current_id(STORE_DIR); trim_older(); }
function upload_muti_file() { global $xoopsDB, $xoopsUser, $xoopsModule, $xoopsModuleConfig, $type_to_mime; krsort($_POST['csn_menu']); foreach ($_POST['csn_menu'] as $cate_sn) { if (empty($cate_sn)) { continue; } else { $csn = $cate_sn; break; } } if (!empty($_POST['new_csn'])) { $csn = add_tad_gallery_cate($csn, $_POST['new_csn'], $_POST['sort']); } $uid = $xoopsUser->getVar('uid'); if (!empty($_POST['csn'])) { $_SESSION['tad_gallery_csn'] = $_POST['csn']; } //取消上傳時間限制 set_time_limit(0); //設置上傳大小 ini_set('memory_limit', '100M'); $files = array(); foreach ($_FILES['upfile'] as $k => $l) { foreach ($l as $i => $v) { if (empty($v)) { continue; } if (!array_key_exists($i, $files)) { $files[$i] = array(); } $files[$i][$k] = $v; } } $sort = 0; foreach ($files as $i => $file) { if (empty($file['tmp_name'])) { continue; } $orginal_file_name = strtolower(basename($file["name"])); //get lowercase filename $file_ending = substr(strtolower($orginal_file_name), -3); //file extension $pic = getimagesize($file['tmp_name']); $width = $pic[0]; $height = $pic[1]; //讀取exif資訊 if (function_exists('exif_read_data')) { $result = exif_read_data($file['tmp_name'], 0, true); $creat_date = $result['IFD0']['DateTime']; } else { $creat_date = date("Y-m-d"); } $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); $now = date("Y-m-d H:i:s", xoops_getUserTimestamp(time())); $sql = "insert into " . $xoopsDB->prefix("tad_gallery") . "\n (`csn`, `title`, `description`, `filename`, `size`, `type`, `width`, `height`, `dir`, `uid`, `post_date`, `counter`, `exif`, `tag`, `good`, `photo_sort`)\n values('{$csn}','','','{$file['name']}','{$file['size']}','{$file['type']}','{$width}','{$height}','{$dir}','{$uid}','{$now}','0','{$exif}','','0',{$sort})"; $sort++; $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 10, mysql_error() . $sql); //取得最後新增資料的流水編號 $sn = $xoopsDB->getInsertId(); mk_dir(_TADGAL_UP_FILE_DIR . $dir); mk_dir(_TADGAL_UP_FILE_DIR . "small/" . $dir); mk_dir(_TADGAL_UP_FILE_DIR . "medium/" . $dir); $filename = photo_name($sn, "source", 1); if (move_uploaded_file($file['tmp_name'], $filename)) { $m_thumb_name = photo_name($sn, "m", 1); $s_thumb_name = photo_name($sn, "s", 1); if (!empty($xoopsModuleConfig['thumbnail_b_width']) and ($width > $xoopsModuleConfig['thumbnail_b_width'] or $height > $xoopsModuleConfig['thumbnail_b_width'])) { thumbnail($filename, $filename, $type_to_mime[$file_ending], $xoopsModuleConfig['thumbnail_b_width']); } if ($width > $xoopsModuleConfig['thumbnail_m_width'] or $height > $xoopsModuleConfig['thumbnail_m_width']) { thumbnail($filename, $m_thumb_name, $type_to_mime[$file_ending], $xoopsModuleConfig['thumbnail_m_width']); } if ($width > $xoopsModuleConfig['thumbnail_s_width'] or $height > $xoopsModuleConfig['thumbnail_s_width']) { thumbnail($filename, $s_thumb_name, $type_to_mime[$file_ending], $xoopsModuleConfig['thumbnail_s_width']); } } } return $csn; }
function re_thumb($csn = "", $kind = "") { global $xoopsDB, $xoopsModuleConfig, $type_to_mime; if (empty($csn)) { return 0; } //找出分類下所有相片 $sql = "select sn,title,filename,type,width,height,dir,post_date 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()); $n = 0; while (list($sn, $title, $filename, $type, $width, $height, $dir, $post_date) = $xoopsDB->fetchRow($result)) { $b_thumb_name = photo_name($sn, "b", 1, $filename, $dir); if (substr($type, 0, 5) !== "image") { $file_ending = substr(strtolower($filename), -3); //file extension $type = $type_to_mime[$file_ending]; } if ($kind == "m" or empty($kind)) { $m_thumb_name = photo_name($sn, "m", 1, $filename, $dir); if ($width > $xoopsModuleConfig['thumbnail_m_width'] or $height > $xoopsModuleConfig['thumbnail_m_width']) { thumbnail($b_thumb_name, $m_thumb_name, $type, $xoopsModuleConfig['thumbnail_m_width']); } } if ($kind == "s" or empty($kind)) { $m_thumb_name = photo_name($sn, "m", 1, $filename, $dir); $s_thumb_name = photo_name($sn, "s", 1, $filename, $dir); if ($width > $xoopsModuleConfig['thumbnail_s_width'] or $height > $xoopsModuleConfig['thumbnail_s_width']) { thumbnail($m_thumb_name, $s_thumb_name, $type, $xoopsModuleConfig['thumbnail_s_width']); } } $n++; } //exit; return $n; }