Example #1
0
 function init($path, $field = 'upload', $image = false, $attach = false)
 {
     if (!is_dir($path)) {
         jmkdir($path);
     }
     $this->_path = $path;
     $this->_field = $field;
     $this->_max_size = 2048;
     $this->_image = $image;
     $this->_attach = $attach;
     $this->_ext = '';
     $this->_new_name = '';
     $this->_save_name = '';
     $this->_attach_types = explode('|', $GLOBALS['_J']['config']['attach_file_type']);
     $this->_ext_types = array('cgi', 'pl', 'js', 'asp', 'php', 'html', 'htm', 'jsp', 'jar', 'txt', 'rar', 'zip');
     $this->_image_types = array('gif', 'jpg', 'jpeg', 'png');
 }
Example #2
0
 function UploadHandler(&$file, $path, $field = 'upload', $image = false, $attach = false)
 {
     if (!is_dir($path)) {
         jmkdir($path);
     }
     $this->_file =& $file;
     $this->_path = $path;
     $this->_field = $field;
     $this->_max_size = 2048;
     $this->_image = $image;
     $this->_attach = $attach;
     $this->_ext = '';
     $this->_new_name = '';
     $this->_save_name = '';
     $this->_attach_types = array('rar', 'zip', 'txt', 'doc', 'xls', 'pdf', 'ppt');
     $this->_ext_types = array('cgi', 'pl', 'js', 'asp', 'php', 'html', 'htm', 'jsp', 'jar', 'txt', 'rar', 'zip');
     $this->_image_types = array('gif', 'jpg', 'jpeg', 'png');
 }
Example #3
0
 function MakeDir($dirname, $mode = 0777)
 {
     return jmkdir($dirname, $mode, 0);
 }
Example #4
0
 function init($method, $source, $target, $nosuffix = 0)
 {
     $this->errorcode = 0;
     if (empty($source)) {
         return -2;
     }
     $parse = parse_url($source);
     if (isset($parse['host'])) {
         return -2;
     }
     $targetpath = dirname($target);
     jmkdir($targetpath);
     clearstatcache();
     if (!is_readable($source) || !is_writable($targetpath)) {
         return -2;
     }
     $imginfo = @getimagesize($source);
     if ($imginfo === FALSE) {
         return -1;
     }
     $this->source = $source;
     $this->target = $target;
     $this->imginfo['width'] = $imginfo[0];
     $this->imginfo['height'] = $imginfo[1];
     $this->imginfo['mime'] = $imginfo['mime'];
     $this->imginfo['size'] = @filesize($source);
     $this->libmethod = $this->param['imagelib'] && $this->param['imageimpath'];
     if (!$this->libmethod) {
         switch ($this->imginfo['mime']) {
             case 'image/jpeg':
                 $this->imagecreatefromfunc = function_exists('imagecreatefromjpeg') ? 'imagecreatefromjpeg' : '';
                 $this->imagefunc = function_exists('imagejpeg') ? 'imagejpeg' : '';
                 break;
             case 'image/gif':
                 $this->imagecreatefromfunc = function_exists('imagecreatefromgif') ? 'imagecreatefromgif' : '';
                 $this->imagefunc = function_exists('imagegif') ? 'imagegif' : '';
                 break;
             case 'image/png':
                 $this->imagecreatefromfunc = function_exists('imagecreatefrompng') ? 'imagecreatefrompng' : '';
                 $this->imagefunc = function_exists('imagepng') ? 'imagepng' : '';
                 break;
         }
     } else {
         $this->imagecreatefromfunc = $this->imagefunc = TRUE;
     }
     if (!$this->libmethod && $this->imginfo['mime'] == 'image/gif') {
         if (!$this->imagecreatefromfunc) {
             return -4;
         }
         if (!($fp = @fopen($source, 'rb'))) {
             return -2;
         }
         $content = fread($fp, $this->imginfo['size']);
         fclose($fp);
         if ($this->param['ignored_animation'] === 0) {
             $this->imginfo['animated'] = strpos($content, 'NETSCAPE2.0') === FALSE ? 0 : 1;
         } else {
             $this->imginfo['animated'] = 0;
         }
     }
     return $this->imagecreatefromfunc ? 1 : 0;
 }
Example #5
0
 function face($p = array(), $modify = 1)
 {
     global $_J;
     $pic_file = $p['pic_file'] && is_image($p['pic_file']) ? $p['pic_file'] : '';
     $pic_url = $p['pic_url'] && false !== strpos($p['pic_url'], ':/' . '/') ? $p['pic_url'] : '';
     $p['pic_field'] = $p['pic_field'] ? $p['pic_field'] : 'face';
     $pic_field = $p['pic_field'] && $_FILES[$p['pic_field']] ? $p['pic_field'] : '';
     if (!$pic_file && !$pic_url && !$pic_field) {
         return jerror('pic is empty', 0);
     }
     $uid = $p['uid'] ? (int) $p['uid'] : MEMBER_ID;
     if ($uid < 1) {
         return jerror('请指定一个用户ID', -1);
     }
     $member = jsg_member_info($uid);
     if (!$member) {
         return jerror('用户已经不存在了', -2);
     }
     if (!$_J['config']['edit_face_enable'] && $member['__face__'] && 'admin' != MEMBER_ROLE_TYPE) {
         return jerror('不允许用户修改头像', -3);
     }
     $src_x = max(0, (int) $p['x']);
     $src_y = max(0, (int) $p['y']);
     $src_w = max(0, (int) $p['w']);
     $src_h = max(0, (int) $p['h']);
     $image_path = RELATIVE_ROOT_PATH . 'images/' . ($_J['config']['face_verify'] ? 'face_verify' : 'face') . '/' . face_path($uid);
     $image_name = $uid . '_b.jpg';
     $image_file = $image_path . $image_name;
     $image_file_small = $image_path . $uid . '_s.jpg';
     $image_file_temp = $image_path . $uid . '_t.jpg';
     if (!is_dir($image_path)) {
         jmkdir($image_path);
     }
     if (!$modify && is_image($image_file)) {
         return jerror('头像已经存在了', -4);
     }
     if ($pic_file) {
         $src_file = $pic_file;
     } elseif ($pic_url) {
         $image_data = dfopen($pic_url, 99999999, '', '', true, 3, $_SERVER['HTTP_USER_AGENT']);
         if ($image_data) {
             jio()->WriteFile($image_file, $image_data);
             if (is_image($image_file)) {
                 $src_file = $image_file;
             }
         }
     } elseif ($pic_field) {
         jupload()->init($image_path, $pic_field, true, false);
         jupload()->setNewName($image_name);
         $result = jupload()->doUpload();
         if ($result && is_image($image_file)) {
             $src_file = $image_file;
         }
     }
     if (!is_image($src_file)) {
         return jerror('源头像不存在了,请上传正确的图片文件', -5);
     }
     $w = max(50, min(128, $src_w > 50 ? $src_w : 200));
     $make_result = makethumb($src_file, $image_file, $w, $w, 0, 0, $src_x, $src_y, $src_w, $src_h);
     $make_result = makethumb($src_file, $image_file_small, 50, 50, 0, 0, $src_x, $src_y, $src_w, $src_h);
     $face_url = '';
     if ($_J['config']['ftp_on']) {
         $ftp_key = randgetftp();
         $get_ftps = jconf::get('ftp');
         $face_url = $get_ftps[$ftp_key]['attachurl'];
         $ftp_result = ftpcmd('upload', $image_file, '', $ftp_key);
         if ($ftp_result > 0) {
             ftpcmd('upload', $image_file_small, '', $ftp_key);
             jio()->DeleteFile($image_file);
             jio()->DeleteFile($image_file_small);
         }
     }
     if ($_J['config']['face_verify']) {
         $count = DB::result_first("SELECT COUNT(1) FROM " . DB::table('members_verify') . " WHERE `uid`='{$uid}'");
         if ($count) {
             $sql = "update `" . TABLE_PREFIX . "members_verify` set `face_url`='{$face_url}', `face`='{$image_file_small}' where `uid`='{$uid}'";
         } else {
             $sql = "insert into `" . TABLE_PREFIX . "members_verify` (`uid`,`nickname`,`face_url`,`face`) values('{$uid}','{$member['nickname']}','{$face_url}','{$image_file_small}')";
         }
         DB::query($sql);
         if ($_J['config']['notice_to_admin']) {
             $pm_post = array('message' => $member['nickname'] . " 修改了头像进入审核,<a href='admin.php?mod=verify&code=fs_verify' target='_blank'>点击</a>进入审核。", 'to_user' => str_replace('|', ',', $_J['config']['notice_to_admin']));
             $admin_info = jsg_member_info(1);
             jlogic('pm')->pmSend($pm_post, $admin_info['uid'], $admin_info['username'], $admin_info['nickname']);
         }
     } else {
         $sql = "update `" . TABLE_PREFIX . "members` set `face_url`='{$face_url}', `face`='{$image_file_small}' where `uid`='{$uid}'";
         DB::query($sql);
         if ($_J['config']['extcredits_enable'] && $uid > 0) {
             update_credits_by_action('face', $uid);
         }
     }
     return true;
 }
Example #6
0
 function _writeHtaccess($abs_path)
 {
     $un_writes = array();
     $is_local = preg_match("~^localhost|127\\.0\\.0\\.1|192\\.168\\.\\d+\\.\\d+\$~", $_SERVER['SERVER_ADDR']);
     $str = "# BEGIN JishiGou\r\n<IfModule mod_rewrite.c>\r\nRewriteEngine On\r\n" . ($is_local ? "Options FollowSymLinks" : "") . "\r\nRewriteBase {$abs_path}\r\nRewriteCond %{REQUEST_URI}\t!\\.(gif|jpeg|png|jpg|bmp)\$\r\nRewriteCond %{REQUEST_URI}  !^{$abs_path}(wap|mobile)\r\nRewriteCond %{REQUEST_FILENAME} !-f\r\nRewriteCond %{REQUEST_FILENAME} !-d\r\nRewriteRule . index.php [L]\r\n</IfModule>\r\n# END JishiGou";
     @($len = jio()->WriteFile(ROOT_PATH . ".htaccess", $str));
     if (!$len) {
         $un_writes[] = '.htaccess';
     }
     $_dirs = array('images/', 'templates/', 'theme/', 'wap/templates/');
     foreach ($_dirs as $_dir) {
         $_path = ROOT_PATH . $_dir;
         if (!is_dir($_path)) {
             jmkdir($_path);
         } else {
             if (!file_exists($_path . 'index.html')) {
                 @touch($_path . 'index.html');
             }
         }
         $str = "# BEGIN JishiGou dir safe protect for {$_dir}\r\n<IfModule mod_rewrite.c>\r\nRewriteEngine On\r\n" . ($is_local ? "Options FollowSymLinks" : "") . "\r\nRewriteBase {$abs_path}{$_dir}\r\nRewriteRule ^.*\\.(php|php3|php4|asp|aspx|jsp|cgi)\$ index.html [NC,L]\r\n</IfModule>\r\n# END JishiGou " . date("Y-m-d H:i:s");
         @($len = jio()->WriteFile($_path . '.htaccess', $str));
         if (!$len) {
             $un_writes[] = "{$_dir}.htaccess";
         }
     }
     $_dirs = array('api/pw_api/', 'api/pw_client/', 'include/', 'install/', 'modules/', 'setting/', 'wap/data/', 'wap/include/', 'wap/modules/');
     foreach ($_dirs as $_dir) {
         $_path = ROOT_PATH . $_dir;
         if (!is_dir($_path)) {
             jmkdir($_path);
         } else {
             if (!file_exists($_path . 'index.html')) {
                 @touch($_path . 'index.html');
             }
         }
         $str = "# BEGIN JishiGou dir safe protect for {$_dir}\r\n<IfModule mod_rewrite.c>\r\nRewriteEngine On\r\n" . ($is_local ? "Options FollowSymLinks" : "") . "\r\nRewriteBase {$abs_path}{$_dir}\r\nRewriteRule . index.html [L]\r\n</IfModule>\r\n# END JishiGou " . date("Y-m-d H:i:s");
         @($len = jio()->WriteFile($_path . '.htaccess', $str));
         if (!$len) {
             $un_writes[] = "{$_dir}.htaccess";
         }
     }
     if ($un_writes) {
         $this->Messager("以下文件无法写入,请检查相应的目录是否有可写权限。<br /><br />" . implode("<br />", $un_writes), null);
     }
 }
Example #7
0
function jmkdir($dir, $mode = 0777, $makeindex = TRUE)
{
    if (!is_dir($dir)) {
        clearstatcache();
        jmkdir(dirname($dir));
        @mkdir($dir, $mode);
        if (!empty($makeindex)) {
            $ret = @touch($dir . '/index.html');
            @chmod($dir . '/index.html', 0777);
            return $ret;
        }
    }
    return true;
}
Example #8
0
 public function cutProfile()
 {
     $w = (int) $this->Post['w'];
     $h = (int) $this->Post['h'];
     $x = (int) $this->Post['x'];
     $y = (int) $this->Post['y'];
     $image_path = RELATIVE_ROOT_PATH . 'images/temp/profile/' . face_path(MEMBER_ID);
     $image_name = MEMBER_ID . "_o.jpg";
     $image_file = $image_path . $image_name;
     if (!$image_file) {
         if ($this->Get['home']) {
             echo '<script>parent.show_message("剪切错误!请重新上传图片");parent.closeDialog("showuploadform");</script>';
             exit;
         } else {
             $this->Messager("剪切错误!请重新上传图片");
         }
     }
     $member = $this->_member();
     $image_thumb_file = RELATIVE_ROOT_PATH . 'images/profile/' . face_path($member['uid']) . "_o.jpg";
     if (!is_dir($image_thumb_dir = dirname($image_thumb_file))) {
         jmkdir($image_thumb_dir);
     }
     list($w_src, $h_src) = getimagesize($image_file);
     if (!$w_src) {
         if ($this->Get['home']) {
             echo '<script>parent.show_message("剪切图片已不存在!");parent.closeDialog("showuploadform");</script>';
             exit;
         } else {
             $this->Messager("剪切图片已不存在", jurl('index.php?mod=settings&code=profile'));
         }
     }
     if (!$w || !$h) {
         if ($w_src < 750) {
             $w = $w_src;
             $h = (int) ($w * (5 / 16));
         } else {
             $w = 750;
             $h = (int) ($w * (5 / 16));
         }
     }
     if ($w_src > 750) {
         $bili = $w_src / 750;
         round($w * $bili);
         $result = makethumb($image_file, $image_thumb_file, round($w * $bili), round($h * $bili), 0, 0, round($x * $bili), round($y * $bili), round($w * $bili), round($h * $bili));
         if ($result) {
             jio()->DeleteFile($image_file);
         }
     } else {
         $result = makethumb($image_file, $image_thumb_file, $w, $h, 0, 0, $x, $y, $w, $h);
         if ($result) {
             jio()->DeleteFile($image_file);
         }
     }
     if ($this->Config['ftp_on']) {
         $ftp_key = randgetftp();
         $get_ftps = jconf::get('ftp');
         $site_url = $get_ftps[$ftp_key]['attachurl'];
         $ftp_result = ftpcmd('upload', $image_thumb_file, '', $ftp_key);
         if ($ftp_result > 0) {
             jio()->DeleteFile($image_thumb_file);
             $image_thumb_file = $site_url . '/' . str_replace('./', '', $image_thumb_file);
         }
     }
     if ($result) {
         $sql = "update `" . TABLE_PREFIX . "members` set profile_image='" . $image_thumb_file . "' where `uid`='" . MEMBER_ID . "'";
         $this->DatabaseHandler->Query($sql);
         if ($this->Get['home']) {
             echo '<script>parent.show_message("已保存!");parent.location.replace(parent.location.href);parent.closeDialog("showuploadform");</script>';
             exit;
         } else {
             $this->Messager("已保存", jurl('index.php?mod=settings&code=profile'));
         }
     } else {
         if ($this->Get['home']) {
             echo '<script>parent.show_message("保存失败!");parent.closeDialog("showuploadform");</script>';
             exit;
         } else {
             $this->Messager("保存失败", jurl('index.php?mod=settings&code=profile'));
         }
     }
 }
Example #9
0
 function DoModify()
 {
     $ids = max(0, (int) $this->Post['ids']);
     if (!$ids) {
         $this->Messager("请指定一个ID", null);
     }
     $name = $this->Post['name'];
     $type = $this->Post['type'];
     $dateline = time();
     $style = $this->Post['share']['style'];
     $style = serialize($style);
     $show = $this->Post['share']['show'];
     $show = serialize($show);
     $module = $this->Post['share']['condition'];
     $condition = serialize($module);
     $nickname = $type == 'topic' ? trim($this->Post['share']['nickname']) : '';
     $tag = $type == 'tag' ? trim($this->Post['share']['tag']) : '';
     $sql = "update `" . TABLE_PREFIX . "share`\r\n    \t\t\tset `name`='{$name}',\r\n    \t\t\t\t`type`='{$type}' ,\r\n    \t\t\t\t`topic_style`='{$style}' ,\r\n    \t\t\t\t`show_style`='{$show}' ,\r\n    \t\t\t\t`condition`='{$condition}' ,\r\n    \t\t\t\t`nickname`='{$nickname}',\r\n    \t\t\t\t`tag`='{$tag}',\r\n    \t\t\t\t`dateline`={$dateline}\r\n    \t\t\twhere `id` = '{$ids}'";
     $this->DatabaseHandler->Query($sql);
     $set = $this->Post['sharetemp'];
     $set = jstripslashes($set);
     $file = ROOT_PATH . 'templates/default/share/sharetemp_' . $ids . '.html';
     if (!is_dir(dirname($file))) {
         jmkdir(dirname($file));
     }
     $len = jio()->WriteFile($file, $set);
     if (!$len) {
         die($file . " 文件无法写入,请检查是否有可写权限。");
     }
     $sets['sharetemp'] = $set;
     jconf::set('sharetemp_' . $ids, $sets);
     $this->Messager("编辑成功", "admin.php?mod=share&code=modify&ids={$ids}");
 }
Example #10
0
 static function backup($type = null)
 {
     if (null === $type) {
         $config = ConfigHandler::core_settings();
     } else {
         $config = ConfigHandler::get($type);
     }
     if ($config) {
         $dir = ROOT_PATH . 'data/backup/setting/';
         if (!is_dir($dir)) {
             jmkdir($dir);
         }
         return jio()->WriteFile($dir . (null === $type ? 'settings' : $type) . '.php', '<?php $config' . (null === $type ? '' : "['{$type}']") . ' = ' . var_export($config, true) . '; ?>');
     }
 }
 /**
  * 同步头像到指定的DZ uid(同步到DZ)。
  * 适用于没有安装UC的DZ。普通站长一般是DZ6.0.0
  *
  * @param integer $uid DZ uid
  * @return integer 同步结果。正常为0,否则:
  *  -1到-10:此错误码预留给_getFaceAndCreateTemp方法,请自行参阅该方法的注释
  *
  * 	-20:要复制的中等头像不存在
  * 	-21:论坛设置不允许该用户所在用户组上传头像
  * 	-22:复制头像到指定论坛头像目录失败
  */
 function syncToNoUC($uid)
 {
     $step1result = $this->_getFaceAndCreateTemp($uid);
     if ($step1result < 0) {
         return $step1result;
     }
     $db = XWB_plugin::getDB();
     //由于中等头像经大头像创建,而大头像已经经过安全检测,因此在这里只需要检测中等头像是否存在即可。
     if (!file_exists($this->faceTempPath[3])) {
         $this->_delTempFace();
         return -20;
     }
     $_destPrefix = './images/face/' . jsg_face_path($this->uid) . $this->uid;
     $image_file_small = $destPath = $_destPrefix . '_s.jpg';
     $image_file = $_destPrefix . '_b.jpg';
     $destRealPath = XWB_S_ROOT . $destPath;
     if (!is_dir(dirname($destPath))) {
         jmkdir(dirname($destPath));
     }
     copy($this->faceTempPath[2], XWB_S_ROOT . $image_file);
     $copyresult = copy($this->faceTempPath[3], $destRealPath);
     $this->_delTempFace();
     if (false == $copyresult) {
         return -22;
     } else {
         $face_url = '';
         if ($GLOBALS['_J']['config']['ftp_enable']) {
             $ftp_key = randgetftp();
             $get_ftps = jconf::get('ftp');
             $face_url = $get_ftps[$ftp_key]['attachurl'];
             $ftp_result = ftpcmd('upload', $image_file, '', $ftp_key);
             if ($ftp_result > 0) {
                 ftpcmd('upload', $image_file_small, '', $ftp_key);
                 @unlink($image_file);
                 @unlink($image_file_small);
             }
         }
         $destPath = mysql_real_escape_string($destPath);
         $db->result_first("UPDATE " . XWB_S_TBPRE . "members SET `face_url`='{$face_url}', `face`= '" . $destPath . "' WHERE uid = '" . $this->uid . "' LIMIT 1");
         return 0;
     }
 }