function get_target_dir($type, $extid = '', $check_exists = true) { $subdir = $subdir1 = $subdir2 = ''; if ($type == 'album' || $type == 'forum' || $type == 'portal' || $type == 'category' || $type == 'profile') { $subdir1 = date('Ym'); $subdir2 = date('d'); $subdir = $subdir1 . '/' . $subdir2 . '/'; } elseif ($type == 'group' || $type == 'common') { $subdir = $subdir1 = substr(md5($extid), 0, 2) . '/'; } $check_exists && discuz_upload::check_dir_exists($type, $subdir1, $subdir2); return $subdir; }
function stringtopic($value, $key = '', $force = false, $rlength = 0) { if ($key === '') { $key = $value; } $basedir = !getglobal('setting/attachdir') ? './data/attachment' : getglobal('setting/attachdir'); $url = !getglobal('setting/attachurl') ? './data/attachment/' : getglobal('setting/attachurl'); $subdir1 = substr(md5($key), 0, 2); $subdir2 = substr(md5($key), 2, 2); $target = 'temp/' . $subdir1 . '/' . $subdir2 . '/'; $targetname = substr(md5($key), 8, 16) . '.png'; discuz_upload::check_dir_exists('temp', $subdir1, $subdir2); if (!$force && file_exists($basedir . '/' . $target . $targetname)) { return $url . $target . $targetname; } $value = str_replace("\n", '', $value); $fontfile = $fontname = ''; $ttfenabled = false; $size = 10; $w = 130; $rowh = 25; $value = explode("\r", $value); if ($rlength) { $temp = array(); foreach ($value as $str) { $strlen = dstrlen($str); if ($strlen > $rlength) { for ($i = 0; $i < $strlen; $i++) { $sub = cutstr($str, $rlength, ''); $temp[] = $sub; $str = substr($str, strlen($sub)); $strlen = $strlen - $rlength; } } else { $temp[] = $str; } } $value = $temp; unset($temp); } if (function_exists('imagettftext')) { $fontroot = DISCUZ_ROOT . './static/image/seccode/font/ch/'; $dirs = opendir($fontroot); while ($entry = readdir($dirs)) { if ($entry != '.' && $entry != '..' && in_array(strtolower(fileext($entry)), array('ttf', 'ttc'))) { $fontname = $entry; break; } } if (!empty($fontname)) { $fontfile = DISCUZ_ROOT . './static/image/seccode/font/ch/' . $fontname; } if ($fontfile) { if (strtoupper(CHARSET) != 'UTF-8') { include DISCUZ_ROOT . './source/class/class_chinese.php'; $cvt = new Chinese(CHARSET, 'utf8'); $value = $cvt->Convert(implode("\r", $value)); $value = explode("\r", $value); } $ttfenabled = true; } } foreach ($value as $str) { if ($ttfenabled) { $box = imagettfbbox($size, 0, $fontfile, $str); $height = max($box[1], $box[3]) - min($box[5], $box[7]); $len = max($box[2], $box[4]) - min($box[0], $box[6]); $rowh = max(array($height, $rowh)); } else { $len = strlen($str) * 12; } $w = max(array($len, $w)); } $h = $rowh * count($value) + count($value) * 2; $im = @imagecreate($w, $h); $background_color = imagecolorallocate($im, 255, 255, 255); $text_color = imagecolorallocate($im, 60, 60, 60); $h = $ttfenabled ? $rowh : 4; foreach ($value as $str) { if ($ttfenabled) { imagettftext($im, $size, 0, 0, $h, $text_color, $fontfile, $str); $h += 2; } else { imagestring($im, $size, 0, $h, $str, $text_color); } $h += $rowh; } imagepng($im, $basedir . '/' . $target . $targetname); imagedestroy($im); return $url . $target . $targetname; }
/** * 获取文件最终存储路径 * * @param string $type * @param int $extid * @param boolean $check_exists * @return string */ function get_target_dir($type, $extid = '', $check_exists = true) { $subdir1 = date('Ym'); $subdir2 = date('d'); $subdir = $subdir1 . '/' . $subdir2 . '/'; $check_exists && discuz_upload::check_dir_exists($type, $subdir1, $subdir2); return $subdir; }