Ejemplo n.º 1
0
 function thumb($url = '', $source = '', $name = '', $type = -1, $width = 0, $height = 0)
 {
     //如何生成不成功,则返回原url
     global $cms_abs, $cmsurl, $ftp_url, $atm_smallsite;
     if (!$url || !$source || !$name || !$width || !$height) {
         return $url;
     }
     include_once M_ROOT . "./include/upload.cls.php";
     if ($ftp_url && preg_match(u_regcode($ftp_url), $url)) {
         //ftp上的文件
         include_once M_ROOT . "./include/http.cls.php";
         include_once M_ROOT . "./include/ftp.fun.php";
         //下载原图
         $tempfile = M_ROOT . './dynamic/imcache/' . basename($url);
         mmkdir($tempfile, 0, 1);
         $m_http = new http();
         $m_http->savetofile($url, $tempfile);
         unset($m_http);
         //生成缩略图
         $m_upload = new cls_upload();
         $m_upload->image_resize($tempfile, $width, $height, $tempfile . '.s.jpg');
         @unlink($tempfile);
         unset($m_upload);
         //上传缩略图
         $ftpfile = preg_replace(u_regcode($ftp_url), '', $url) . 's/' . $width . '_' . $height . '.jpg';
         //根据url得到缩略上传到的位置
         $tempfile .= '.s.jpg';
         if (ftp_upload($tempfile, $ftpfile)) {
             $this->refresh_record($source, $name, $type, $width, $height);
             //将缩略图规格写入数据库
             return $url . 's/' . $width . '_' . $height . '.jpg';
         } else {
             return $url;
         }
         @unlink($tempfile);
     } else {
         //本地服务器上的文件
         $m_upload = new cls_upload();
         $localfile = local_atm($url);
         $m_upload->image_resize($localfile, $width, $height, $localfile . 's/' . $width . '_' . $height . '.jpg');
         unset($m_upload);
         return $url . 's/' . $width . '_' . $height . '.jpg';
     }
 }
Ejemplo n.º 2
0
function upload_m($newvalue, $oldvalue = '', $mode = 'image', $rpid = 0)
{
    global $c_upload, $db, $tblprefix;
    if (!$newvalue) {
        return '';
    }
    $oldvalue = !$oldvalue ? array() : unserialize($oldvalue);
    $oldarr = array();
    foreach ($oldvalue as $k => $v) {
        $oldarr[basename($v['remote'])] = $v;
    }
    $temps = array_filter(explode("\n", $newvalue));
    if (!$temps) {
        return '';
    }
    $newarr = array();
    foreach ($temps as $v) {
        $v = str_replace(array("\n", "\r"), '', $v);
        $row = explode('|', $v);
        $row[0] = trim($row[0]);
        if (!$row[0]) {
            continue;
        }
        $filename = basename($row[0]);
        $atm = array();
        if (array_key_exists($filename, $oldarr)) {
            //旧数据
            $atm = $oldarr[$filename];
        } else {
            if (islocal($row[0], 1)) {
                //新的本地文件将附件id得到以便获取与文档的关联
                $atm['remote'] = save_atmurl($row[0]);
                if ($info = $db->fetch_one("SELECT ufid,size FROM {$tblprefix}userfiles WHERE filename='{$filename}' AND aid='0'")) {
                    $c_upload->ufids[] = $info['ufid'];
                    $atm['size'] = $info['size'];
                }
            } else {
                $atm = $c_upload->remote_upload($row[0], $rpid);
            }
        }
        $atm['title'] = empty($row[1]) ? '' : strip_tags($row[1]);
        if (!empty($row[2])) {
            $atm['player'] = intval($row[2]);
        }
        if ($mode == 'image' && empty($atm['width']) && ($info = @getimagesize(local_atm($row[0])))) {
            //某些情况下的图片尺寸补全
            $atm['width'] = $info[0];
            $atm['height'] = $info[1];
        }
        $atm && ($newarr[] = $atm);
    }
    unset($temps, $row, $atm, $info, $oldvalue, $oldarr);
    return $newarr;
}
Ejemplo n.º 3
0
 function deal_incell()
 {
     global $cotypes, $sid, $orelays, $acatalogs, $m_thumb;
     if (in_array($this->tclass, array('archives', 'alarchives', 'relates', 'searchs'))) {
         arc_parse($this->item, $this->temparr['m_thumbid']);
     } elseif (in_array($this->tclass, array('marchives', 'masearchs'))) {
         marc_parse($this->item, $this->temparr['m_thumbid']);
     } elseif ($this->tclass == 'catalogs') {
         //这是一个特例(含节点),在标识中会加入新元素,需要先处理midarr,
         //读取继承参数
         parse_str(cnstr($this->temparr), $midarr);
         if (isset($midarr['caid']) && @$this->tag['cainherit'] != 'active') {
             unset($midarr['caid']);
         }
         foreach ($cotypes as $k => $v) {
             if (isset($midarr['ccid' . $k]) && @$this->tag['coinherit' . $k] != 'active') {
                 unset($midarr['ccid' . $k]);
             }
         }
         $listby = $this->tag['listby'] == 'ca' ? 0 : intval(str_replace('co', '', $this->tag['listby']));
         if (!$listby) {
             //先处理非列表项目,因为列表项id要放在最后
             foreach ($cotypes as $k => $v) {
                 //读取手动指定的参数
                 if ($v['sortable'] && !empty($this->tag['coinherit' . $k]) && is_numeric($this->tag['coinherit' . $k])) {
                     $midarr['ccid' . $k] = $this->tag['coinherit' . $k];
                 }
             }
             unset($midarr['caid']);
             $midarr['caid'] = $this->item['caid'];
         } else {
             $coid = $listby;
             if (!empty($this->tag['cainherit']) && is_numeric($this->tag['cainherit'])) {
                 $midarr['caid'] = $this->tag['cainherit'];
             }
             foreach ($cotypes as $k => $v) {
                 $k != $coid && $v['sortable'] && !empty($this->tag['coinherit' . $k]) && is_numeric($this->tag['coinherit' . $k]) && ($midarr['ccid' . $k] = $this->tag['coinherit' . $k]);
             }
             unset($midarr['ccid' . $coid]);
             $midarr['ccid' . $coid] = $this->item['ccid'];
         }
         if (!empty($this->tag['urlmode']) && !empty($midarr[$this->tag['urlmode']])) {
             $midarr = array_merge(array($this->tag['urlmode'] => $midarr[$this->tag['urlmode']]), $midarr);
         }
         $nsid = empty($this->tag['nsid']) ? 0 : intval($this->tag['nsid']);
         if (!$nsid) {
             $nsid = isset($temparr['nsid']) ? $temparr['nsid'] : $sid;
             //当前子站需要分析是否有传下来的id,否则认为是全局id
         } elseif ($nsid == -1) {
             $nsid = 0;
         } elseif ($nsid == -2) {
             $nsid = $sid;
         }
         $cnstr = cnstr($midarr);
         $this->item = cn_parsearr($cnstr, $nsid, $listby, $this->temparr['m_thumbid']);
         $cnode = cnodearr($cnstr, $this->item['sid']);
         re_cnode($this->item, $cnstr, $cnode);
         unset($cnode, $midarr);
     } elseif ($this->tclass == 'farchives') {
         $m_thumb->config[$this->temparr['m_thumbid']] = array('id' => $this->item['aid'], 'mode' => 'fa', 'smode' => $this->item['chid']);
     } elseif ($this->tclass == 'commus') {
         $m_thumb->config[$this->temparr['m_thumbid']] = array('id' => $this->item['cid'], 'mode' => 'cu', 'smode' => @$this->tag['cuid']);
     } elseif ($this->tclass == 'mcommus') {
         $m_thumb->config[$this->temparr['m_thumbid']] = array('id' => $this->item['cid'], 'mode' => 'mcu', 'smode' => @$this->tag['cuid']);
     } elseif ($this->tclass == 'mcatalogs') {
         if ($this->tag['listby'] == 'ca') {
             $this->item['indexurl'] = mcn_url($this->item['mcaid']);
             $this->item['listurl'] = mcn_url($this->item['mcaid'], 0, 1);
         } elseif ($this->tag['listby'] == 'uc') {
             $this->item['indexurl'] = mcn_url($this->item['mcaid'], $this->item['ucid']);
             $this->item['listurl'] = mcn_url($this->item['mcaid'], $this->item['ucid'], 1);
         }
     } elseif ($this->tclass == 'images') {
         if ($this->tmode == 'p') {
             $m_thumb->config[$this->temparr['m_thumbid']] = $m_thumb->config['main'];
         }
         if (@$this->tag['thumb'] && @$this->tag['maxwidth'] && @$this->tag['maxheight'] && islocal($this->item['url'], 1)) {
             //生成缩略图或启用缩略图
             $true_local = islocal($this->item['url'], 2);
             if ($true_local && is_file(local_atm($this->item['url']) . 's/' . $this->tag['maxwidth'] . '_' . $this->tag['maxheight'] . '.jpg') || !$true_local && in_str($this->tag['maxwidth'] . '_' . $this->tag['maxheight'], @$this->item['thumbs'])) {
                 //已生成缩略图
                 $this->item['url_s'] = $this->item['url'] . 's/' . $this->tag['maxwidth'] . '_' . $this->tag['maxheight'] . '.jpg';
             } else {
                 $this->item['url_s'] = @$m_thumb->thumb($this->item['url'], $this->temparr['m_thumbid'], $this->tag['tname'], $this->item['fid'], @$this->tag['maxwidth'], @$this->tag['maxheight']);
             }
         } else {
             $this->item['url_s'] = $this->item['url'];
         }
         if ($this->item['url_s'] != $this->item['url']) {
             //真正启用了缩略图,直接使用设定的宽高
             $this->item['width'] = @$this->tag['maxwidth'];
             $this->item['height'] = @$this->tag['maxheight'];
         } else {
             //使用原图来重计宽高
             $wh = imagewh($this->item['url'], @$this->item['width'], @$this->item['height'], @$this->tag['maxwidth'], @$this->tag['maxheight']);
             $this->item['width'] = $wh['width'];
             $this->item['height'] = $wh['height'];
         }
     } elseif ($this->tclass == 'members') {
         global $grouptypes;
         foreach ($grouptypes as $k => $v) {
             $this->item['grouptype' . $k . 'name'] = '';
             if (!empty($this->item['grouptype' . $k])) {
                 $usergroups = read_cache('usergroups', $k);
                 $this->item['grouptype' . $k . 'name'] = $usergroups[$this->item['grouptype' . $k]]['cname'];
             }
         }
         $m_thumb->config = array('id' => $this->item['mid'], 'mode' => 'm', 'smode' => $this->item['mchid']);
         unset($usergroups, $v);
     }
     //从上级标识接受参数作为当前原始标识
     if (!empty($this->tag['rrelays'])) {
         $midarr = array();
         $relays = relays2arr($this->tag['rrelays']);
         foreach ($relays as $k => $v) {
             if (isset($this->temparr[$v])) {
                 $midarr[$k] = $this->temparr[$v];
             }
         }
         $this->item += $midarr;
         unset($midarr);
     }
     $this->item += $this->temparr;
     //从当前原始标识向下级标识传送参数
     $this->midarr = $this->temparr;
     $relays = $orelays;
     !empty($this->tag['relays']) && ($relays = relays2arr($this->tag['relays']) + $relays);
     foreach ($relays as $k => $v) {
         if (isset($this->item[$v])) {
             $this->midarr[$k] = $this->item[$v];
         }
     }
     unset($relays);
 }