Ejemplo n.º 1
0
 public function get_material_by_ids()
 {
     if (!$this->input['material_ids']) {
         $this->errorOutput(NO_IDS);
     }
     $material_ids = explode(',', $this->input['material_ids']);
     $material_ids = implode("','", $material_ids);
     $sql = "SELECT id,bundle_id,filepath, filename,type,mark,filesize,create_time \r\n                FROM " . DB_PREFIX . "material WHERE 1 AND id IN('" . $material_ids . "')";
     $q = $this->db->query($sql);
     $ret = array();
     while ($row = $this->db->fetch_array($q)) {
         $row['host'] = hg_getimg_host($row['bs']);
         $row['dir'] = app_to_dir($row['bundle_id'], $row['mark']);
         $ret[] = $row;
     }
     $this->addItem($ret);
     $this->output();
 }
Ejemplo n.º 2
0
 public function create_map_vote_question()
 {
     if (empty($this->input['app_bundle']) || empty($this->input['module_bundle']) || empty($this->input['name'])) {
         $this->errorOutput('参数不完整');
     }
     $app_bundle = urldecode($this->input['app_bundle']);
     $module_bundle = urldecode($this->input['module_bundle']);
     $srcFile = hg_getimg_dir() . app_to_dir($app_bundle) . urldecode($this->input['srcFile']);
     $dstPath = hg_getimg_dir() . "material/sketch_map/" . $app_bundle . "/" . $module_bundle . "/";
     hg_mkdir($dstPath);
     $name = urldecode($this->input['name']);
     $title = urldecode($this->input['title']);
     $url = hg_getimg_host() . "material/sketch_map/" . $app_bundle . "/" . $module_bundle . "/" . $name;
     $save_file_path = $dstPath . $name;
     if ($this->check_file($save_file_path)) {
         $this->addItem($url);
         $this->output();
     } else {
         //示意图拷贝到背景上
         $vote_map_bg = CUR_CONF_PATH . "font/vote_map_bg.png";
         $vote_map_bg_info = @getimagesize($vote_map_bg);
         switch ($vote_map_bg_info[2]) {
             case 3:
                 $map = imagecreatefrompng($vote_map_bg);
                 break;
             case 2:
                 $map = imagecreatefromjpeg($vote_map_bg);
                 break;
             case 1:
                 $map = imagecreatefromgif($vote_map_bg);
                 break;
             default:
                 return false;
         }
         imagesavealpha($map, true);
         //$size = array('width' => 355,'height' => 200);
         //$map = imagecreatetruecolor($size['width'], $size['height']);
         //$color =imagecolorallocate($map, 245, 245, 245);
         //imagefill($map, 0, 0, $color);
         $title = explode(',', $title);
         $tit = '投票:' . $title[0];
         unset($title[0]);
         $option = array();
         foreach ($title as $k => $v) {
             $arr = explode('_', $v);
             list($name, $single_total) = $arr;
             $option[] = array('title' => $name, 'single_total' => $single_total);
         }
         $black = imagecolorallocate($map, 0, 0, 0);
         imagettftext($map, 12, 0, 70, 30, $black, "../font/simhei.ttf", $tit);
         $total_num = 0;
         foreach ($option as $k => $v) {
             $total_num += $v['single_total'];
         }
         $num = 2;
         for ($i = 0; $i < $num; $i++) {
             imagettftext($map, 10, 0, 70, 75 + 40 * $i, $black, "../font/simhei.ttf", $option[$i]['title']);
             /*
             $bar_size = array('width' => 300,'height' => 30);
             $progress_size = array('width'=>150,'height'=>20);
             
             $bar = imagecreatetruecolor($bar_size['width'], $bar_size['height']);
             $bar_color = imagecolorallocate($bar, 245, 245, 245);
             imagefill($bar, 0, 0, $bar_color);
             
             $progress = imagecreatetruecolor($progress_size['width'], $progress_size['height']);
             $progress_color = imagecolorallocate($progress, 245, 245, 245);
             imagefill($progress, 0, 0, $progress_color);
             
             $black_color = imagecolorallocate($progress, 0, 0, 0);
             imagerectangle($progress, 0, 0, $progress_size['width']-1, $progress_size['height']-1, $black_color);
             
             		
             if($total_num !=0)
             {
             	$per = $option[$i]['single_total']/$total_num;
             }
             else 
             {
             	$per = 0;
             }
             
             $per_width = $per * ($progress_size['width']-2); 
             $per = round($per*100) . '%';
             
             $blue =imagecolorallocate($progress, 65, 122, 201);
             if($per_width != 0 )
             {
             	imagefilledrectangle($progress, 1, 1, $per_width, $progress_size['height']-2, $blue);
             }
             
             imagecopy($bar, $progress, 1, 5, 0, 0, $progress_size['width'], $progress_size['height']);
             
             $color = imagecolorallocate($bar, 0, 0, 0);
             $str = $option[$i]['single_total'] . '(' . $per . ')';
             
             imagettftext($bar, 10, 0, $progress_size['width']+10, 20, $color, '../font/simhei.ttf', $str);
             
             imagecopy($map, $bar, 70, 65+50*$i, 0, 0, $bar_size['width'], $bar_size['height']);
             */
         }
         $option_num = count($option);
         $gray = imagecolorallocate($map, 189, 189, 189);
         if ($option_num >= $num) {
             $option = "共" . $option_num . "个选项";
             imagettftext($map, 9, 0, 70, 68 + 40 * 2, $gray, "../font/simhei.ttf", $option);
         }
         imagealphablending($map, false);
         imagepng($map, $save_file_path);
         imagedestroy($map);
         $this->addItem($url);
         $this->output();
     }
 }
Ejemplo n.º 3
0
 /**
  * 将附件打包提供下载
  * 
  * @param material_path string 图片上传返回的路径信息(取出host)
  * @return string 包得地址 
  */
 function zip_material()
 {
     $material_path = $this->input['material_path'];
     if (empty($material_path)) {
         $this->errorOutput(NO_MATERIAL);
     }
     if (!is_array($material_path)) {
         $material_path = explode(',', $material_path);
     }
     foreach ((array) $material_path as $k => $v) {
         //$v = preg_replace('/(.*?)(\?.*)?/i', '\\1', $v);
         $pos = strpos($v, '?');
         if ($pos !== false) {
             $v = substr($v, 0, $pos);
         }
         if ($domain == $v) {
             $domain = '';
         }
         $material_path[$k] = hg_getimg_dir($domain, "host") . str_replace($domain, '', $v);
     }
     $material_path = implode(' ', $material_path);
     $path = 'ziptmp/' . date('Ym', TIMENOW) . '/';
     $zip_path = hg_getimg_dir() . $path;
     if (!hg_mkdir($zip_path) || !is_writeable($zip_path)) {
         $this->errorOutput('压缩文件存放临时目录不可写');
     }
     $zip_name = TIMENOW . hg_generate_user_salt() . '.zip';
     $zipcmd = ' zip -j ' . $zip_path . $zip_name . ' ' . $material_path;
     exec($zipcmd);
     $url = hg_getimg_host() . $path . $zip_name;
     $this->addItem($url);
     $this->output();
 }
Ejemplo n.º 4
0
 public function imgdata2pic($imgdata, $app_bundle, $type = 'png')
 {
     if (empty($imgdata)) {
         return false;
     }
     $info = array('host' => hg_getimg_host(), 'dir' => app_to_dir($app_bundle), 'filepath' => date('Y', TIMENOW) . '/' . date('m', TIMENOW) . '/', 'filename' => md5(hg_generate_salt(4) . TIMENOW) . '.' . $type);
     $img_dir = hg_getimg_dir() . $info['dir'] . $info['filepath'];
     if (!hg_mkdir($img_dir) || !is_writeable($img_dir)) {
         $this->errorOutput($img_dir . '目录不可写');
     }
     $imgdata = str_replace('data:image/png;base64,', '', $imgdata);
     $imgdata = strpos($imgdata, 'data:') !== false ? $imgdata : base64_decode($imgdata);
     hg_file_write($img_dir . $info['filename'], $imgdata);
     return $info;
 }
Ejemplo n.º 5
0
function hg_getimg_default_host()
{
    return hg_getimg_host("img1");
}
Ejemplo n.º 6
0
 public function upload_affix()
 {
     if ($_FILES['Filedata']) {
         if ($_FILES['Filedata']['error']) {
             return false;
         } else {
             $typetmp = explode('.', $_FILES['Filedata']['name']);
             $filetype = strtolower($typetmp[count($typetmp) - 1]);
             $filepath = date('Y') . '/' . date('m') . '/';
             $tmp_filename = date('YmdHis') . hg_generate_user_salt(4);
             $filename = $tmp_filename . '.' . $filetype;
             include_once CUR_CONF_PATH . 'lib/cache.class.php';
             $this->material_type = new cache();
             $gMaterialType = $this->material_type->check_cache('material_type.cache.php');
             $type = '';
             foreach ($gMaterialType as $k => $v) {
                 if ($k == 'img') {
                     if (in_array($filetype, array_keys($v))) {
                         $path = hg_getimg_dir() . MATERIAL_TMP_PATH . $filepath;
                         hg_mkdir($path);
                         if (!move_uploaded_file($_FILES["Filedata"]["tmp_name"], $path . $filename)) {
                             return false;
                         } else {
                             $ret = array('tmpurl' => hg_material_link(hg_getimg_host(), MATERIAL_TMP_PATH, $filepath, $filename), 'url' => hg_material_link(hg_getimg_host(), MATERIAL_TMP_PATH, $filepath, $filename, $this->settings['default_size']['label'] . '/'));
                         }
                     }
                 }
             }
             return $ret;
         }
     }
 }