Example #1
0
 function editSubmit($p)
 {
     $f = UserDataField::get($p['id']);
     $f->name = $p['name'];
     $f->label = $p['label'];
     $f->type = $p['type'];
     $f->id = $f->store();
     switch ($f->type) {
         case UserDataField::RADIO:
             for ($i = 1; $i < 6; $i++) {
                 if (!empty($p['opt_' . $i])) {
                     UserDataFieldOption::set($f->id, 'opt_' . $i, $p['opt_' . $i]);
                 }
             }
             break;
         case UserDataField::AVATAR:
             for ($i = 1; $i < 6; $i++) {
                 if (!empty($p['avatar_' . $i])) {
                     if ($p['avatar_' . $i]['error'] == UPLOAD_ERR_NO_FILE) {
                         continue;
                     }
                     $fileId = File::importImage(SITE, $p['avatar_' . $i]);
                     UserDataFieldOption::set($f->id, 'avatar_' . $i, $fileId);
                 }
             }
             break;
     }
     js_redirect('a/userdata/list');
 }
Example #2
0
 function handleEdit($p)
 {
     $session = SessionHandler::getInstance();
     foreach (UserDataField::getAll() as $f) {
         if (!empty($p['remove_' . $f->id])) {
             UserSetting::set($session->id, $f->name, 0);
             continue;
         }
         switch ($f->type) {
             case UserDataField::IMAGE:
                 if ($p[$f->name]['error'] == UPLOAD_ERR_NO_FILE) {
                     continue;
                 }
                 $album = PhotoAlbum::getProfileAlbumId();
                 $fileId = File::importImage(USER, $p[$f->name], $album);
                 UserSetting::set($session->id, $f->name, $fileId);
                 break;
             default:
                 UserSetting::set($session->id, $f->name, $p[$f->name]);
         }
     }
     js_redirect('u/profile');
 }
Example #3
0
 function handleUpload($p)
 {
     $session = SessionHandler::getInstance();
     //XXX SECURITY: verify that destination album is owned by current user
     $fileId = File::importImage(USER, $p['img'], $p['album']);
     if ($fileId) {
         js_redirect('u/album/show/' . $session->id . '/' . $p['album']);
     }
     return false;
 }
Example #4
0
    case 'album':
        // upload multiple images to photo album
        // child = album id
        // XXX verify im the owner of album
        //XXX SECURITY: verify that destination album is owned by current user
        // If the browser supports sendAsBinary () can use the array $_FILES
        if (count($_FILES) > 0) {
            $fileId = File::importImage(USER, $_FILES['upload'], $this->child);
            echo 'OK-1:' . $fileId;
            // XXX debug output
        } else {
            if (isset($_GET['up'])) {
                // If the browser does not support sendAsBinary ()
                if (isset($_GET['base64'])) {
                    $content = base64_decode(file_get_contents('php://input'));
                } else {
                    $content = file_get_contents('php://input');
                }
                $headers = getallheaders();
                $tmp_file = tempnam('/tmp', 'fileup-');
                file_put_contents($tmp_file, $content);
                $key = array('tmp_name' => $tmp_file, 'name' => $headers['UP-FILENAME'], 'type' => $headers['UP-TYPE'], 'size' => $headers['UP-SIZE']);
                $fileId = File::importImage(USER, $key, $this->child, true);
                echo 'OK-2:' . $fileId;
                // XXX debug output
            }
        }
        break;
    default:
        throw new \Exception('no such view: ' . $this->owner);
}
Example #5
0
/**
 * Generates image thumbnails from specified video file
 */
function generate_video_thumb($fileId, $where = '10%')
{
    if (!is_numeric($fileId)) {
        return false;
    }
    if (!file_exists(File::getUploadPath($fileId))) {
        throw new \Exception('file ' . File::getUploadPath($fileId) . ' dont exist!');
    }
    $c = 'avprobe ' . File::getUploadPath($fileId) . ' 2>&1 | /bin/grep Duration | cut -d, -f1';
    // returns: "Duration: 00:00:08.50"
    //echo "Executing: ".$c."\n";
    $x = exec($c);
    $xx = explode(': ', $x);
    $duration = in_seconds($xx[1]);
    // 00:00:08.50   => 8.5
    $pos_val = intval($where) / 10;
    $pos = $duration * $pos_val;
    $tmpimg = tempnam('/tmp', 'vid-thumb');
    $c = 'avconv -i ' . File::getUploadPath($fileId) . ' -ss ' . $pos . ' -vframes 1 -f image2 ' . $tmpimg . ' 2> /dev/null';
    //    echo "$ ".$c."\n";
    exec($c);
    $key = array('tmp_name' => $tmpimg, 'name' => 'thumbnail', 'type' => 'image/jpeg', 'size' => filesize($tmpimg));
    $thumbId = File::importImage(THUMB, $key, $fileId, true);
    return $thumbId;
}