Exemplo n.º 1
0
 public static function open(\Path $path)
 {
     $ext = $path->getExtension();
     switch ($ext) {
         case 'zip':
         case 'cbz':
             return new ZipArchive($path);
         case 'rar':
         case 'cbr':
             return new RarArchive($path);
         default:
             throw new \Exception('Invalid file type: ' . $ext);
     }
 }
Exemplo n.º 2
0
function api_addAttachment($blogid, $parent, $file)
{
    $pool = DBModel::getInstance();
    $attachment = array();
    $attachment['parent'] = $parent ? $parent : 0;
    $attachment['label'] = Path::getBaseName($file['name']);
    $label = Utils_Unicode::lessenAsEncoding($attachment['label'], 64);
    $attachment['size'] = $file['size'];
    $extension = Path::getExtension($attachment['label']);
    switch (strtolower($extension)) {
        case '.exe':
        case '.php':
        case '.sh':
        case '.com':
        case '.bat':
            $extension = '.xxx';
            break;
    }
    /* Create directory for owner */
    $path = __TEXTCUBE_ATTACH_DIR__ . "/{$blogid}";
    if (!is_dir($path)) {
        mkdir($path);
        if (!is_dir($path)) {
            return false;
        }
        @chmod($path, 0777);
    }
    $pool->reset('Attachments');
    $pool->setQualifier('blogid', 'eq', $blogid);
    $pool->setQualifier('parent', 'eq', $parent);
    $pool->setQualifier('label', 'eq', $label, true);
    $oldFile = $pool->getCell('name');
    if ($oldFile !== null) {
        $attachment['name'] = $oldFile;
    } else {
        $attachment['name'] = rand(1000000000, 9999999999) . $extension;
        while (Attachment::doesExist($attachment['name'])) {
            $attachment['name'] = rand(1000000000, 9999999999) . $extension;
        }
    }
    $attachment['path'] = "{$path}/{$attachment['name']}";
    deleteAttachment($blogid, -1, $attachment['name']);
    if ($file['content']) {
        $f = fopen($attachment['path'], "w");
        if (!$f) {
            return false;
        }
        $attachment['size'] = fwrite($f, $file['content']);
        fclose($f);
        $file['tmp_name'] = $attachment['path'];
    }
    if ($imageAttributes = @getimagesize($file['tmp_name'])) {
        $attachment['mime'] = $imageAttributes['mime'];
        $attachment['width'] = $imageAttributes[0];
        $attachment['height'] = $imageAttributes[1];
    } else {
        $attachment['mime'] = Utils_Misc::getMIMEType($extension);
        $attachment['width'] = 0;
        $attachment['height'] = 0;
    }
    $attachment['mime'] = Utils_Unicode::lessenAsEncoding($attachment['mime'], 32);
    @chmod($attachment['path'], 0666);
    $pool->reset('Attachments');
    $pool->setAttribute('blogid', $blogid);
    $pool->setAttribute('parent', $attachment['parent']);
    $pool->setAttribute('name', $attachment['name'], true);
    $pool->setAttribute('label', $label, true);
    $pool->setAttribute('mime', $attachment['mime'], true);
    $pool->setAttribute('size', $attachment['size'], true);
    $pool->setAttribute('width', $attachment['width']);
    $pool->setAttribute('height', $attachment['height']);
    $pool->setAttribute('attached', Timestamp::getUNIXtime());
    $pool->setAttribute('downloads', 0);
    $pool->setAttribute('enclosure', 0);
    $result = $pool->insert();
    if (!$result) {
        @unlink($attachment['path']);
        return false;
    }
    return $attachment;
}
Exemplo n.º 3
0
        array_push($errorText, _t('파비콘을 변경하지 못했습니다.'));
    } else {
        Attachment::confirmFolder();
        if (move_uploaded_file($_FILES['favicon']['tmp_name'], __TEXTCUBE_ATTACH_DIR__ . "/{$blogid}/favicon.ico")) {
            @chmod(__TEXTCUBE_ATTACH_DIR__ . "/{$blogid}/favicon.ico", 0666);
            array_push($errorText, _t('파비콘을 변경하였습니다.'));
        }
    }
}
// 블로그 아이콘 처리.
if ($_POST['deleteBlogIcon'] == "yes") {
    unlink(__TEXTCUBE_ATTACH_DIR__ . "/{$blogid}/index.gif");
    array_push($errorText, _t('블로그 아이콘을 초기화 하였습니다.'));
}
if (!empty($_FILES['blogIcon']['tmp_name'])) {
    $fileExt = Path::getExtension($_FILES['blogIcon']['name']);
    if (!in_array($fileExt, array('.gif', '.jpg', '.jpeg', '.png'))) {
        array_push($errorText, _t('블로그 아이콘을 변경하지 못했습니다.'));
    } else {
        Attachment::confirmFolder();
        if (move_uploaded_file($_FILES['blogIcon']['tmp_name'], __TEXTCUBE_ATTACH_DIR__ . "/{$blogid}/index.gif")) {
            @chmod(__TEXTCUBE_ATTACH_DIR__ . "/{$blogid}/index.gif", 0666);
            array_push($errorText, _t('블로그 아이콘을 변경하였습니다.'));
        } else {
        }
    }
}
Setting::setBlogSettingGlobal('useBlogIconAsIphoneShortcut', $_POST['useBlogIconAsIphoneShortcut']);
if (!empty($errorText)) {
    $errorText = urlencode(implode('<br />', $errorText));
} else {
Exemplo n.º 4
0
 public function getExtension()
 {
     return Path::getExtension($this->path);
 }
Exemplo n.º 5
0
function getImageFileUpload($target)
{
    global $database;
    if (doesHaveOwnership() && doesHaveMembership()) {
        $type = $_POST['type'];
        $file = $_FILES['teamImageFile'];
        $errcode = 0;
        if ($type == "upload") {
            $fileExt = Path::getExtension($file['name']);
            if ($fileExt != '.gif' && $fileExt != '.jpg' && $fileExt != '.png') {
                $errmsg = _t('잘못된 파일 형식입니다. 다시 시도하세요');
                $errcode = 1;
            } else {
                $result = getAddAttachment($file);
                $errmsg = _t('새로운 프로필 사진을 저장 했습니다.');
            }
        } else {
            if ($type == "delete") {
                $tmpImage = POD::queryCell("SELECT image FROM {$database['prefix']}TeamUserSettings WHERE blogid=" . getBlogId() . " and userid=" . getUserId());
                if ($tmpImage) {
                    $result = getDeleteAttachment();
                    $errmsg = _t('등록된 프로필 사진을 삭제 하였습니다.');
                } else {
                    $errmsg = _t('삭제할 파일이 없습니다. 다시 시도하세요');
                    $errcode = 1;
                }
            }
        }
    }
    $script = '<script type="text/javascript">//<![CDATA' . CRLF;
    if ($errcode != 1) {
        $script .= '	window.parent.top.document.getElementById("teamImage").src = "' . $result . '";';
    }
    $script .= '	window.parent.top.PM.showMessage("' . $errmsg . '", "center", "bottom");';
    $script .= '//]]></script>';
    echo $script;
    exit;
}
Exemplo n.º 6
0
 function splitSite($url)
 {
     $pos = strpos($url, '/', 8);
     if ($pos === false) {
         $ext = Path::getExtension($url);
         if (!in_array($ext, $this->extensions)) {
             return array($url, "");
         }
         die("{$url} not a valid url");
     }
     $site = substr($url, 0, $pos);
     $filename = substr($url, $pos + 1);
     return array($site, $filename);
 }
Exemplo n.º 7
0
 function resample($width, $height)
 {
     if (empty($width) && empty($height)) {
         return false;
     }
     if (empty($this->imageFile) || !file_exists($this->imageFile)) {
         return false;
     }
     // create an image device as image format.
     switch ($this->getImageType($this->imageFile)) {
         case "gif":
             if (imagetypes() & IMG_GIF) {
                 $originImageDevice = imagecreatefromgif($this->imageFile);
             } else {
                 return false;
             }
             break;
         case "jpg":
             if (imagetypes() & IMG_JPG) {
                 $originImageDevice = imagecreatefromjpeg($this->imageFile);
             } else {
                 return false;
             }
             break;
         case "png":
             if (imagetypes() & IMG_PNG && function_exists('imagecreatefrompng')) {
                 $originImageDevice = imagecreatefrompng($this->imageFile);
             } else {
                 return false;
             }
             break;
         case "wbmp":
             if (imagetypes() & IMG_WBMP) {
                 $originImageDevice = imagecreatefromwbmp($this->imageFile);
             } else {
                 return false;
             }
             break;
         case "xpm":
             if (imagetypes() & IMG_XPM) {
                 $originImageDevice = imagecreatefromxpm($this->imageFile);
             } else {
                 return false;
             }
             break;
         default:
             return false;
             break;
     }
     // 리샘플링은 최종단계에서 리샘플링만을 하는 기능임. 시스템을 예로 들면 OS의 기능에 해당함.
     // 이미지 프로세스는 어플리케이션의 기능으로 볼 수 있고, 따라서 이미지 리샘플링 중에는 이벤트가 끼어들면 안 됨.
     //$originImageDevice = fireEvent('BeforeResizeImage', $originImageDevice, $this);
     if (Path::getExtension($this->imageFile) == ".gif") {
         $this->resultImageDevice = imagecreate($width, $height);
     } else {
         $this->resultImageDevice = imagecreatetruecolor($width, $height);
     }
     $temp = imagecolorallocate($this->resultImageDevice, $this->bgColorBy16['R'], $this->bgColorBy16['G'], $this->bgColorBy16['B']);
     imagefilledrectangle($this->resultImageDevice, 0, 0, $width, $height, $temp);
     imagecopyresampled($this->resultImageDevice, $originImageDevice, 0, 0, 0, 0, $width, $height, imagesx($originImageDevice), imagesy($originImageDevice));
     imagedestroy($originImageDevice);
     //$this->resultImageDevice = fireEvent('AfterResizeImage', $this->resultImageDevice, $this);
     return true;
 }
Exemplo n.º 8
0
 function _generateName()
 {
     $blogid = getBlogId();
     if (isset($this->name)) {
         if (!Validator::filename($this->name)) {
             return $this->_error('name');
         }
         switch (Path::getExtension($this->name)) {
             case '.php':
             case '.exe':
             case '.com':
             case '.sh':
             case '.bat':
                 $ext = '.xxx';
                 $this->name = rand(1000000000, 9999999999.0) . $ext;
                 break;
             default:
                 $ext = Path::getExtension2($this->name);
                 break;
         }
     } else {
         $ext = '';
     }
     $this->confirmFolder();
     while (Attachment::doesExist($this->name)) {
         $this->name = rand(1000000000, 9999999999.0) . $ext;
     }
     return true;
 }
Exemplo n.º 9
0
function storeImage($image)
{
    echo "+----------------------------------------------------------------------------+<br>";
    include './sharedkeys.php';
    echo "Start Storing [{$image}]<br>";
    include_once './Path.php';
    $file_name = Path::getFileNameWithoutExtension($_FILES[$image]['name']);
    echo "The Sent File Name [{$file_name}]<br>";
    $name = $file_name;
    include_once './Path.php';
    $extension = Path::getExtension($_FILES[$image]['name']);
    echo "The File Extension [{$extension}]<br>";
    $index = 0;
    echo "Checking File Existance<br>";
    while (file_exists(IMAGES_LOCATION . $name . "." . $extension)) {
        $name = $file_name . "_" . $index;
        $index++;
    }
    $file_name = str_replace(' ', '_', $name . "." . $extension);
    echo "The Aproved File Name [{$file_name}]<br>";
    $picture = IMAGES_LOCATION . $file_name;
    echo "Move From Upload [" . $_FILES[$image]["tmp_name"] . "] To [{$picture}]<br>";
    move_uploaded_file($_FILES[$image]["tmp_name"], $picture);
    $thum = createThum(IMAGES_LOCATION, $file_name, 100, 100);
    echo "A Thum Created At [{$thum}]<br>";
    echo "Save The Info<br>";
    $result = array(IMAGES_LOCATION_R . $file_name, IMAGES_LOCATION_R . "thum_" . $file_name);
    echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><br>";
    return $result;
}
Exemplo n.º 10
0
function api_addAttachment($blogid, $parent, $file)
{
    global $database;
    $attachment = array();
    $attachment['parent'] = $parent ? $parent : 0;
    $attachment['label'] = Path::getBaseName($file['name']);
    $label = POD::escapeString(UTF8::lessenAsEncoding($attachment['label'], 64));
    $attachment['size'] = $file['size'];
    $extension = Path::getExtension($attachment['label']);
    switch (strtolower($extension)) {
        case '.exe':
        case '.php':
        case '.sh':
        case '.com':
        case '.bat':
            $extension = '.xxx';
            break;
    }
    /* Create directory for owner */
    $path = ROOT . "/attach/{$blogid}";
    if (!is_dir($path)) {
        mkdir($path);
        if (!is_dir($path)) {
            return false;
        }
        @chmod($path, 0777);
    }
    $oldFile = POD::queryCell("SELECT name FROM {$database['prefix']}Attachments WHERE blogid={$blogid} AND parent={$parent} AND label = '{$label}'");
    if ($oldFile !== null) {
        $attachment['name'] = $oldFile;
    } else {
        $attachment['name'] = rand(1000000000, 9999999999) . $extension;
        while (Attachment::doesExist($attachment['name'])) {
            $attachment['name'] = rand(1000000000, 9999999999) . $extension;
        }
    }
    $attachment['path'] = "{$path}/{$attachment['name']}";
    deleteAttachment($blogid, -1, $attachment['name']);
    if ($file['content']) {
        $f = fopen($attachment['path'], "w");
        if (!$f) {
            return false;
        }
        $attachment['size'] = fwrite($f, $file['content']);
        fclose($f);
        $file['tmp_name'] = $attachment['path'];
    }
    if ($imageAttributes = @getimagesize($file['tmp_name'])) {
        $attachment['mime'] = $imageAttributes['mime'];
        $attachment['width'] = $imageAttributes[0];
        $attachment['height'] = $imageAttributes[1];
    } else {
        $attachment['mime'] = Misc::getMIMEType($extension);
        $attachment['width'] = 0;
        $attachment['height'] = 0;
    }
    $attachment['mime'] = UTF8::lessenAsEncoding($attachment['mime'], 32);
    @chmod($attachment['path'], 0666);
    $result = POD::query("insert into {$database['prefix']}Attachments values ({$blogid}, {$attachment['parent']}, '{$attachment['name']}', '{$label}', '{$attachment['mime']}', {$attachment['size']}, {$attachment['width']}, {$attachment['height']}, UNIX_TIMESTAMP(), 0,0)");
    if (!$result) {
        @unlink($attachment['path']);
        return false;
    }
    return $attachment;
}