Beispiel #1
0
function kfm_editCaption($imgID, $caption)
{
    $img = kfmImage::getInstance($imgID);
    $img->setCaption($caption);
    $data['id'] = $imgID;
    $data['caption'] = $caption;
    echo json_encode($data);
}
Beispiel #2
0
function _cropToNew($fid, $x1, $y1, $width, $height, $newname)
{
    $cwd_id = $GLOBALS['kfm_session']->get('cwd_id');
    $im = kfmImage::getInstance($fid);
    $im->crop($x1, $y1, $width, $height, $newname);
    if ($im->hasErrors()) {
        return $im->getErrors();
    }
    return kfm_loadFiles($cwd_id);
}
Beispiel #3
0
 /**
  * Returns the file instance. This is preferred above new kfmFile($id)
  * @param int $file_id
  * @return Object file or image
  */
 function getInstance($id = 0)
 {
     if (is_object($id)) {
         $id = $id->id;
     }
     $id = (int) $id;
     if ($id < 1) {
         return;
     }
     if (!@array_key_exists($id, self::$instances)) {
         self::$instances[$id] = new kfmFile($id);
     }
     if (self::$instances[$id]->isImage()) {
         return kfmImage::getInstance($id);
     }
     return self::$instances[$id];
 }
Beispiel #4
0
 /**
  * Returns the file instance. This is preferred above new kfmFile($id)
  * @param int $file_id
  * @return Object file or image
  */
 function getInstance($id = 0)
 {
     global $fileInstances;
     if (!$id) {
         return false;
     }
     if (is_object($id)) {
         $id = $id->id;
     }
     if (!isset($fileInstances[$id])) {
         $fileInstances[$id] = new kfmFile($id);
     }
     if ($fileInstances[$id]->isImage()) {
         return kfmImage::getInstance($id);
     }
     return $fileInstances[$id];
 }
Beispiel #5
0
 function getFiles()
 {
     $filesdb = db_fetch_all("select * from " . KFM_DB_PREFIX . "files where directory=" . $this->id);
     $fileshash = array();
     if (is_array($filesdb)) {
         foreach ($filesdb as $r) {
             $fileshash[$r['name']] = $r['id'];
         }
     }
     // { get files from directoryIterator, then sort them
     $tmp = array();
     foreach (new directoryIterator($this->path()) as $f) {
         if ($f->isDot()) {
             continue;
         }
         if (is_file($this->path() . $f) && kfmFile::checkName($f)) {
             $tmp[] = $f . '';
         }
     }
     natsort($tmp);
     // }
     // { load file details from database
     $files = array();
     foreach ($tmp as $filename) {
         if (!isset($fileshash[$filename])) {
             $fileshash[$filename] = kfmFile::addToDb($filename, $this->id);
         }
         $file = kfmFile::getInstance($fileshash[$filename]);
         if (!$file) {
             continue;
         }
         if ($file->isImage()) {
             $file = kfmImage::getInstance($fileshash[$filename]);
             if ($this->maxWidth > 0 && $this->maxHeight > 0 && ($file->width > $this->maxWidth || $file->height > $this->maxHeight)) {
                 $file->resize($this->maxWidth, $this->maxHeight);
             }
         }
         $files[] = $file;
         unset($fileshash[$filename]);
     }
     // }
     return $files;
 }
Beispiel #6
0
 if (!count($errors)) {
     move_uploaded_file($tmpname, $to);
     if (!file_exists($to)) {
         $errors[] = kfm_lang('failedToSaveTmpFile', $tmpname, $to);
     } else {
         if ($kfm_only_allow_image_upload && !getimagesize($to)) {
             $errors[] = 'only images may be uploaded';
             unlink($to);
         } else {
             chmod($to, octdec('0' . $kfm_default_upload_permission));
             $fid = kfmFile::addToDb($filename, $kfm_session->get('cwd_id'));
             $file = kfmFile::getInstance($fid);
             if (function_exists('exif_imagetype')) {
                 $imgtype = @exif_imagetype($to);
                 if ($imgtype) {
                     $file = kfmImage::getInstance($file);
                     $comment = '';
                     if ($imgtype == 1) {
                         // gif
                         $fc = file_get_contents($to);
                         $arr = explode('!', $fc);
                         $found = 0;
                         for ($i = 0; $i < count($arr) && !$found; ++$i) {
                             $block = $arr[$i];
                             if (substr($block, 0, 2) == chr(254) . chr(21)) {
                                 $found = 1;
                                 $comment = substr($block, 2, strpos($block, 0) - 1);
                             }
                         }
                     } else {
                         $data = @exif_read_data($to, 0, true);
Beispiel #7
0
    }
}
$id = @$_GET['id'];
if (!is_numeric($id)) {
    echo kfm_lang('errorInvalidID');
    exit;
}
$extension = 'unknown';
if (isset($_GET['type']) && $_GET['type'] == 'thumb') {
    $path = WORKPATH . 'thumbs/' . $id;
    $name = $id;
} else {
    if (isset($_GET['width']) && isset($_GET['height'])) {
        $width = (int) $_GET['width'];
        $height = (int) $_GET['height'];
        $image = kfmImage::getInstance($id);
        if (!$image) {
            echo kfm_lang('errorFileIDNotFound', $id);
            exit;
        }
        if ($width > $image->width) {
            $width = $image->width;
        }
        if ($height > $image->height) {
            $height = $image->height;
        }
        $h = 0;
        $s = 0;
        $l = 0;
        if (isset($_GET['hsl'])) {
            list($h, $s, $l) = explode(':', $_GET['hsl']);
Beispiel #8
0
 function addFile($file)
 {
     if (!$GLOBALS['kfm_allow_file_create']) {
         return $this->error(kfm_lang('permissionDeniedCreateFile'));
     }
     if (is_numeric($file)) {
         $file = kfmFile::getInstance($file);
     }
     if (!$this->isWritable()) {
         return $this->error(kfm_lang('fileNotCreatedDirUnwritable', $file->name));
     }
     copy($file->path, $this->path . '/' . $file->name);
     $id = $file->addToDb($file->name, $this->id);
     if ($file->isImage()) {
         $file = kfmImage::getInstance($file->id);
         $newFile = kfmImage::getInstance($id);
         $newFile->setCaption($file->caption);
     } else {
         $newFile = kfmFile::getInstance($id);
     }
     $newFile->setTags($file->getTags());
     return true;
 }