Exemplo n.º 1
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;
}
Exemplo n.º 2
0
 function thumb_pick($string, $datatype = 'htmltext', $rpid = 0)
 {
     //只处理已经stripslashes的文本。
     if (!$string) {
         return '';
     }
     $thumb = '';
     if (in_array($datatype, array('text', 'multitext', 'htmltext'))) {
         if (preg_match("/src\\s*=\\s*([\"']?)(.{1,100}?)(gif|jpg|jpeg|bmp|png)\\1/is", $string, $matches)) {
             $thumb = $matches[2] . $matches[3];
             $thumb = tag2atm($thumb);
             if (!islocal($thumb, 1) && $rpid) {
                 $filearr = $this->remote_upload($thumb, $rpid);
                 $thumb = $filearr['remote'];
             }
             if (isset($filearr['width'])) {
                 $thumb .= '#' . $filearr['width'] . '#' . $filearr['height'];
             } elseif ($infos = @getimagesize(local_file($thumb))) {
                 $thumb .= '#' . $infos[0] . '#' . $infos[1];
             }
         }
     } elseif ($datatype == 'images') {
         $images = @unserialize($string);
         if (is_array($images)) {
             $image = $images[min(array_keys($images))];
             $image['remote'] = tag2atm($image['remote']);
             if (!islocal($image['remote'], 1) && $rpid) {
                 $image = $this->remote_upload($image['remote'], $rpid);
             }
             $thumb = $image['remote'];
             isset($image['width']) && ($thumb .= '#' . $image['width'] . '#' . $image['height']);
         }
     } elseif ($datatype == 'image') {
         $image = array_filter(explode('#', $string));
         $image[0] = tag2atm($image[0]);
         if (!islocal($image[0], 1) && $rpid) {
             $filearr = $this->remote_upload($image[0], $rpid);
             $image[0] = $filearr['remote'];
             if (isset($filearr['width'])) {
                 $image[1] = $filearr['width'];
                 $image[2] = $filearr['height'];
             }
         }
         $thumb = $image[0];
         isset($image[1]) && ($thumb .= '#' . $image[1] . '#' . $image[2]);
     }
     return save_atmurl($thumb);
 }