Ejemplo n.º 1
0
/**
 * 会员头像
 *
 * @param	intval	$uid
 * @param	string	$size
 * @return	string
 */
function dr_avatar($uid, $size = '45')
{
    if (!$uid) {
        return $size == 45 ? SITE_URL . 'omooo/statics/images/avatar_45.png' : SITE_URL . 'omooo/statics/images/avatar_90.png';
    }
    $ci =& get_instance();
    $member = $ci->get_cache('member');
    if ($member['setting']['ucenter']) {
        $data = $ci->db->select('username')->where('uid', $uid)->limit(1)->get('member')->row_array();
        list($ucenter) = uc_get_user($data['username']);
        return UC_API . '/avatar.php?uid=' . $ucenter . '&size=' . ($size == 45 ? 'small' : 'big');
    }
    if (is_file(FCPATH . 'member/uploadfile/member/' . $uid . '/' . $size . 'x' . $size . '.jpg')) {
        return SITE_URL . 'member/uploadfile/member/' . $uid . '/' . $size . 'x' . $size . '.jpg';
    }
    $data = $ci->db->select('avatar')->where('uid', $uid)->limit(1)->get('member')->row_array();
    return isset($data['avatar']) && $data['avatar'] ? dr_get_file($data['avatar']) : ($size == 45 ? SITE_URL . 'omooo/statics/images/avatar_45.png' : SITE_URL . 'omooo/statics/images/avatar_90.png');
}
 /**
  * 远程图片下载
  *
  * @param	array	$data
  * @return  Bool|String
  */
 public function _execute_down_file($data)
 {
     $data = dr_string2array($data);
     if (!$data) {
         return '执行值不存在';
     }
     $path = SYS_UPLOAD_PATH . '/' . date('Ym', SYS_TIME) . '/';
     if (!is_dir($path)) {
         dr_mkdirs($path);
     }
     $file = dr_catcher_data($data['url']);
     if (!$file) {
         return '获取远程数据失败';
     }
     $fileext = strtolower(trim(substr(strrchr($data['url'], '.'), 1, 10)));
     //扩展名
     $filename = substr(md5(time()), 0, 7) . rand(100, 999);
     if (@file_put_contents($path . $filename . '.' . $fileext, $file)) {
         $info = array('file_ext' => '.' . $fileext, 'full_path' => $path . $filename . '.' . $fileext, 'file_size' => filesize($path . $filename . '.' . $fileext) / 1024, 'client_name' => $data['url']);
         $this->load->model('attachment_model');
         $result = $this->attachment_model->upload($data['uid'], $info, $data['id']);
         if (is_array($result)) {
             list($table, $tid, $eid) = explode('-', $result['related']);
             $this->ci->load->model('system_model');
             $tableinfo = $this->ci->system_model->cache();
             // 表结构缓存
             $this->ci->clear_cache('attachment-' . $data['id']);
             // 数据源判断
             if (strpos($table, $this->db->dbprefix($result['siteid'])) === 0) {
                 $db = isset($this->site[$result['siteid']]) ? $this->site[$result['siteid']] : $this->db;
             } else {
                 $db = $this->db;
             }
             $url = dr_get_file($data['id']);
             // 完整地址忽略水印
             $field = $data['field']['fieldname'];
             // 字段名称
             if ($data['field']['relatedname'] == 'module') {
                 // 模块表部分
                 if (strpos($table, '_draft') || strpos($table, '_verify')) {
                     // 草稿和审核表
                     $row = $db->where('id', $tid)->get($table)->row_array();
                     $content = dr_string2array($row['content']);
                     if (isset($content[$field]) && $content[$field]) {
                         $content[$field] = str_replace($data['url'] . '?s=finecms', $url, $content[$field]);
                         $db->where('id', $tid)->update($table, array('content' => dr_array2string($content)));
                     }
                     return TRUE;
                 } else {
                     // 模块表
                     if (!$data['field']['ismain']) {
                         // 附表
                         $index = $db->where('id', $tid)->get($table . '_index')->row_array();
                         $table = $table . '_data_' . intval($index['tableid']);
                     }
                 }
             } elseif ($data['field']['relatedname'] == 'extend') {
                 // 模块扩展表部分
                 if (strpos($table, '_draft') || strpos($table, '_verify')) {
                     // 草稿和审核表
                     $row = $db->where('id', $tid)->get($table)->row_array();
                     $content = dr_string2array($row['content']);
                     if (isset($content[$field]) && $content[$field]) {
                         $content[$field] = str_replace($data['url'] . '?s=finecms', $url, $content[$field]);
                         $db->where('id', $tid)->update($table, array('content' => dr_array2string($content)));
                     }
                     return TRUE;
                 } else {
                     // 内容表
                     if (!$data['field']['ismain']) {
                         // 附表
                         $index = $db->where('id', $tid)->get($table . '_extend_index')->row_array();
                         $table = $table . '_extend_data_' . intval($index['tableid']);
                     }
                 }
             } else {
                 list($dir, $catid) = explode('-', $data['field']['relatedname']);
                 if (is_dir(FCPATH . $dir)) {
                     // 栏目附加字段
                     if (!$data['field']['ismain']) {
                         // 附表
                         $index = $db->where('id', $tid)->get($table . '_index')->row_array();
                         $table = $table . '_category_data_' . intval($index['tableid']);
                     } else {
                         // 主表
                         $table = $table . '_category_data';
                     }
                 }
             }
             // 表结构不存在
             if (!isset($tableinfo[$table]['field'])) {
                 @unlink($info['full_path']);
                 return '表结构不存在:' . $table;
             }
             // 替换操作
             if (isset($tableinfo[$table]['field'][$field])) {
                 $db->query('UPDATE `' . $table . '` SET `' . $field . '` = replace (`' . $field . '`, "' . $data['url'] . '?s=finecms", "' . $url . '")');
             } else {
                 @unlink($info['full_path']);
                 return '表' . $table . '没有字段:' . $field;
             }
             return TRUE;
         } else {
             return $result;
         }
     } else {
         return '文件移动失败,目录无权限(' . $path . ')';
     }
 }
Ejemplo n.º 3
0
 /**
  * 文件信息
  */
 public function fileinfo()
 {
     $this->load->helper('system');
     $key = $this->input->get('name');
     $info = dr_file_info($key);
     $file = count($info) > 2 ? dr_get_file($info['attachment']) : $key;
     if (in_array(strtolower(trim(substr(strrchr($file, '.'), 1, 10))), array('jpg', 'jpeg', 'gif', 'png'))) {
         echo '<img src="' . $file . '" onload="if(this.width>$(window).width()/2)this.width=$(window).width()/2;">';
     } else {
         echo '<a href="' . $file . '" target=_blank>' . ($info['filename'] ? $info['filename'] : $file) . '</a><br>&nbsp;';
     }
 }
 private function _show($id, $file, $cfg)
 {
     $code = '';
     $file = $file ? dr_get_file($file) : SITE_URL . 'dayrui/statics/images/poster.png';
     $file_ext = strtolower(substr(strrchr($file, '.'), 1));
     if (in_array($file_ext, array('gif', 'png', 'jpg'))) {
         $code = '<a href="' . $this->get_url($id) . '" target="_blank"><img src="' . $file . '"  width="' . $cfg['width'] . '" height="' . $cfg['height'] . '" /></a>';
     } elseif ($file_ext == 'swf') {
         $code = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' . $cfg['width'] . '" height="' . $cfg['height'] . '" id="swf_poster_' . $id . '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">';
         $code .= '<param name="movie" value="' . $file . '" />';
         $code .= '<param name="quality" value="autohigh" />';
         $code .= '<param name="wmode" value="opaque" />';
         $code .= '<embed wmode="opaque" src="' . $file . '" quality="autohigh" name="flashad" swliveconnect="TRUE" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' . $cfg['width'] . '" height="' . $cfg['height'] . '"></embed>';
         $code .= '</object>';
     } else {
         $code = '无效文件(' . $file . '),必须是图片或者swf动画。';
     }
     return $code;
 }