Beispiel #1
0
function wall_upload_post(&$a)
{
    if (!local_user()) {
        echo t('Permission denied.') . EOL;
        killme();
    }
    if (!x($_FILES, 'userfile')) {
        killme();
    }
    $src = $_FILES['userfile']['tmp_name'];
    $filename = basename($_FILES['userfile']['name']);
    $filesize = intval($_FILES['userfile']['size']);
    $imagedata = @file_get_contents($src);
    $ph = new Photo($imagedata);
    if (!($image = $ph->getImage())) {
        echo t('Unable to process image.') . EOL;
        @unlink($src);
        killme();
    }
    @unlink($src);
    $width = $ph->getWidth();
    $height = $ph->getHeight();
    $hash = hash('md5', uniqid(mt_rand(), true));
    $smallest = 0;
    $r = $ph->store(0, $hash, $filename, t('Wall Photos'), 0);
    if (!$r) {
        echo t('Image upload failed.') . EOL;
        killme();
    }
    if ($width > 640 || $height > 640) {
        $ph->scaleImage(640);
        $r = $ph->store(0, $hash, $filename, t('Wall Photos'), 1);
        if ($r) {
            $smallest = 1;
        }
    }
    if ($width > 320 || $height > 320) {
        $ph->scaleImage(320);
        $r = $ph->store(0, $hash, $filename, t('Wall Photos'), 2);
        if ($r) {
            $smallest = 2;
        }
    }
    $basename = basename($filename);
    echo "<br /><br /><img src=\"" . $a->get_baseurl() . "/photo/{$hash}-{$smallest}.jpg\" alt=\"{$basename}\" /><br /><br />";
    killme();
    return;
    // NOTREACHED
}
Beispiel #2
0
function photos_post(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        killme();
    }
    $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = 1  WHERE `self` = 1 LIMIT 1");
    $contact_record = $r[0];
    if ($a->argc > 2 && $a->argv[1] == 'album') {
        $album = hex2bin($a->argv[2]);
        if ($album == t('Profile Photos') || $album == t('Contact Photos')) {
            goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
            return;
            // NOTREACHED
        }
        $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' ", dbesc($album));
        if (!count($r)) {
            notice(t('Album not found.') . EOL);
            goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
            return;
            // NOTREACHED
        }
        $newalbum = notags(trim($_POST['albumname']));
        if ($newalbum != $album) {
            q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' ", dbesc($newalbum), dbesc($album));
            $newurl = str_replace(bin2hex($album), bin2hex($newalbum), $_SESSION['photo_return']);
            goaway($a->get_baseurl() . '/' . $newurl);
            return;
            // NOTREACHED
        }
        if ($_POST['dropalbum'] == t('Delete Album')) {
            $res = array();
            $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `album` = '%s'", dbesc($album));
            if (count($r)) {
                foreach ($r as $rr) {
                    $res[] = "'" . dbesc($rr['rid']) . "'";
                }
            } else {
                goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
                return;
                // NOTREACHED
            }
            $str_res = implode(',', $res);
            q("DELETE FROM `photo` WHERE `resource-id` IN ( {$str_res} ) ");
            $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( {$str_res} ) ");
            if (count($r)) {
                foreach ($r as $rr) {
                    q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' ", dbesc(datetime_convert()), dbesc($rr['parent-uri']));
                    $drop_id = intval($rr['id']);
                    $php_path = strlen($a->config['php_path']) ? $a->config['php_path'] : 'php';
                    // send the notification upstream/downstream as the case may be
                    if ($rr['visible']) {
                        proc_close(proc_open("\"{$php_path}\" \"include/notifier.php\" \"drop\" \"{$drop_id}\" & ", array(), $foo));
                    }
                }
            }
        }
        goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
        return;
        // NOTREACHED
    }
    if ($a->argc > 1 && x($_POST, 'delete') && $_POST['delete'] == t('Delete Photo')) {
        $r = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' LIMIT 1", dbesc($a->argv[1]));
        if (count($r)) {
            q("DELETE FROM `photo` WHERE `resource-id` = '%s'", dbesc($r[0]['resource-id']));
            $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' LIMIT 1", dbesc($r[0]['resource-id']));
            if (count($i)) {
                q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s'  WHERE `parent-uri` = '%s' ", dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc($i[0]['uri']));
                $drop_id = intval($i[0]['id']);
                $php_path = strlen($a->config['php_path']) ? $a->config['php_path'] : 'php';
                // send the notification upstream/downstream as the case may be
                if ($i[0]['visible']) {
                    proc_close(proc_open("\"{$php_path}\" \"include/notifier.php\" \"drop\" \"{$drop_id}\" & ", array(), $foo));
                }
            }
        }
        goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
        return;
        // NOTREACHED
    }
    if ($a->argc > 1 && x($_POST, 'desc') !== false) {
        $desc = notags(trim($_POST['desc']));
        $tags = notags(trim($_POST['tags']));
        $item_id = intval($_POST['item_id']);
        $resource_id = $a->argv[1];
        $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' ORDER BY `scale` DESC", dbesc($resource_id));
        if (count($r)) {
            $r = q("UPDATE `photo` SET `desc` = '%s' WHERE `resource-id` = '%s' ", dbesc($desc), dbesc($resource_id));
        }
        if (!$item_id) {
            $title = '';
            $basename = basename($filename);
            // Create item container
            $body = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]' . '[/url]';
            $uri = item_new_uri($a->get_hostname(), get_uid());
            $r = q("INSERT INTO `item` (`type`, `wall`, `resource-id`, `contact-id`,\n\t\t\t\t`owner-name`,`owner-link`,`owner-avatar`, `created`,\n\t\t\t\t`edited`, `changed`, `uri`, `parent-uri`, `title`, `body`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`)\n\t\t\t\tVALUES( '%s', %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )", dbesc('photo'), intval(1), dbesc($p[0]['resource-id']), intval($contact_record['id']), dbesc($contact_record['name']), dbesc($contact_record['url']), dbesc($contact_record['thumb']), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc($uri), dbesc($uri), dbesc($title), dbesc($body), dbesc($p[0]['allow_cid']), dbesc($p[0]['allow_gid']), dbesc($p[0]['deny_cid']), dbesc($p[0]['deny_gid']));
            if ($r) {
                $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($uri));
                if (count($r)) {
                    $item_id = $r[0]['id'];
                }
                q("UPDATE `item` SET `parent` = %d, `last-child` = 1 WHERE `id` = %d LIMIT 1", intval($r[0]['id']), intval($r[0]['id']));
            }
        }
        $r = q("UPDATE `item` SET `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1", dbesc($tags), dbesc(datetime_convert()), dbesc(datetime_convert()), intval($item_id));
        goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
        return;
        // NOTREACHED
    }
    if (!x($_FILES, 'userfile')) {
        killme();
    }
    if ($_POST['partitionCount']) {
        $java_upload = true;
    } else {
        $java_upload = false;
    }
    $album = notags(trim($_POST['album']));
    $newalbum = notags(trim($_POST['newalbum']));
    if (!strlen($album)) {
        if (strlen($newalbum)) {
            $album = $newalbum;
        } else {
            $album = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
        }
    }
    $r = q("SELECT * FROM `photo` WHERE `album` = '%s' ", dbesc($album));
    if (!count($r) || $album == t('Profile Photos')) {
        $visible = 1;
    } else {
        $visibile = 0;
    }
    $str_group_allow = perms2str($_POST['group_allow']);
    $str_contact_allow = perms2str($_POST['contact_allow']);
    $str_group_deny = perms2str($_POST['group_deny']);
    $str_contact_deny = perms2str($_POST['contact_deny']);
    $src = $_FILES['userfile']['tmp_name'];
    $filename = basename($_FILES['userfile']['name']);
    $filesize = intval($_FILES['userfile']['size']);
    $imagedata = @file_get_contents($src);
    $ph = new Photo($imagedata);
    if (!($image = $ph->getImage())) {
        notice(t('Unable to process image.') . EOL);
        @unlink($src);
        killme();
    }
    @unlink($src);
    $width = $ph->getWidth();
    $height = $ph->getHeight();
    $smallest = 0;
    $photo_hash = hash('md5', uniqid(mt_rand(), true));
    $r = $ph->store(0, $photo_hash, $filename, $album, 0, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
    if (!$r) {
        notice(t('Image upload failed.') . EOL);
        killme();
    }
    if ($width > 640 || $height > 640) {
        $ph->scaleImage(640);
        $ph->store(0, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
        $smallest = 1;
    }
    if ($width > 320 || $height > 320) {
        $ph->scaleImage(320);
        $ph->store(0, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
        $smallest = 2;
    }
    $basename = basename($filename);
    // Create item container
    $body = '[url=' . $a->get_baseurl() . '/photos/' . $contact_record['nickname'] . '/image/' . $photo_hash . ']' . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]' . '[/url]';
    $uri = item_new_uri($a->get_hostname(), get_uid());
    $r = q("INSERT INTO `item` (`type`, `wall`, `resource-id`, `contact-id`,`owner-name`,`owner-link`,`owner-avatar`, `created`,\n\t\t`edited`, `changed`, `uri`, `parent-uri`, `title`, `body`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `visible`)\n\t\tVALUES( '%s', %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d )", dbesc('photo'), intval(1), dbesc($photo_hash), intval($contact_record['id']), dbesc($contact_record['name']), dbesc($contact_record['url']), dbesc($contact_record['thumb']), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc($uri), dbesc($uri), dbesc($title), dbesc($body), dbesc($str_contact_allow), dbesc($str_group_allow), dbesc($str_contact_deny), dbesc($str_group_deny), intval($visible));
    if ($r) {
        $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($uri));
        if (count($r)) {
            q("UPDATE `item` SET `parent` = %d, `last-child` = 1 WHERE `id` = %d LIMIT 1", intval($r[0]['id']), intval($r[0]['id']));
        }
    }
    if (!$java_upload) {
        goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
        return;
        // NOTREACHED
    }
    killme();
    return;
    // NOTREACHED
}
function profile_photo_post(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    if (x($_POST, 'cropfinal') && $_POST['cropfinal'] == 1) {
        // phase 2 - we have finished cropping
        if ($a->argc != 2) {
            notice(t('Image uploaded but image cropping failed.') . EOL);
            return;
        }
        $image_id = $a->argv[1];
        if (substr($image_id, -2, 1) == '-') {
            $scale = substr($image_id, -1, 1);
            $image_id = substr($image_id, 0, -2);
        }
        $srcX = $_POST['xstart'];
        $srcY = $_POST['ystart'];
        $srcW = $_POST['xfinal'] - $srcX;
        $srcH = $_POST['yfinal'] - $srcY;
        $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d LIMIT 1", dbesc($image_id), intval($scale));
        if (count($r)) {
            $base_image = $r[0];
            $im = new Photo($base_image['data']);
            $im->cropImage(175, $srcX, $srcY, $srcW, $srcH);
            $r = $im->store(0, $base_image['resource-id'], $base_image['filename'], t('Profile Photos'), 4, 1);
            if ($r === false) {
                notice(t('Image size reduction (175) failed.') . EOL);
            }
            $im->scaleImage(80);
            $r = $im->store(0, $base_image['resource-id'], $base_image['filename'], t('Profile Photos'), 5, 1);
            if ($r === false) {
                notice(t('Image size reduction (80) failed.') . EOL);
            }
            // Unset the profile photo flag from any other photos I own
            $r = q("UPDATE `photo` SET `profile` = 0 WHERE `profile` = 1 AND `resource-id` != '%s' ", dbesc($base_image['resource-id']));
            $r = q("UPDATE `contact` SET `avatar-date` = '%s' WHERE `self` = 1 LIMIT 1", dbesc(datetime_convert()));
            // Update global directory in background
            $php_path = strlen($a->config['php_path']) ? $a->config['php_path'] : 'php';
            $url = $_SESSION['my_url'];
            if ($url && strlen(get_config('system', 'directory_submit_url'))) {
                proc_close(proc_open("\"{$php_path}\" \"include/directory.php\" \"{$url}\" &", array(), $foo));
            }
        }
        goaway($a->get_baseurl() . '/profiles');
        return;
        // NOTREACHED
    }
    $src = $_FILES['userfile']['tmp_name'];
    $filename = basename($_FILES['userfile']['name']);
    $filesize = intval($_FILES['userfile']['size']);
    $imagedata = @file_get_contents($src);
    $ph = new Photo($imagedata);
    if (!($image = $ph->getImage())) {
        notice(t('Unable to process image.') . EOL);
        @unlink($src);
        return;
    }
    @unlink($src);
    $width = $ph->getWidth();
    $height = $ph->getHeight();
    if ($width < 175 || $height < 175) {
        $ph->scaleImageUp(200);
        $width = $ph->getWidth();
        $height = $ph->getHeight();
    }
    $hash = hash('md5', uniqid(mt_rand(), true));
    $smallest = 0;
    $r = $ph->store(0, $hash, $filename, t('Profile Photos'), 0);
    if ($r) {
        notice(t('Image uploaded successfully.') . EOL);
    } else {
        notice(t('Image upload failed.') . EOL);
    }
    if ($width > 640 || $height > 640) {
        $ph->scaleImage(640);
        $r = $ph->store(0, $hash, $filename, t('Profile Photos'), 1);
        if ($r === false) {
            notice(t('Image size reduction (640) failed.') . EOL);
        } else {
            $smallest = 1;
        }
    }
    $a->config['imagecrop'] = $hash;
    $a->config['imagecrop_resolution'] = $smallest;
    $a->page['htmlhead'] .= file_get_contents("view/crophead.tpl");
    return;
}