当前位置: 首页>>代码示例>>PHP>>正文


PHP attach_store函数代码示例

本文整理汇总了PHP中attach_store函数的典型用法代码示例。如果您正苦于以下问题:PHP attach_store函数的具体用法?PHP attach_store怎么用?PHP attach_store使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了attach_store函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: post

 function post()
 {
     $using_api = false;
     if (\App::$data['api_info'] && array_key_exists('media', $_FILES)) {
         $using_api = true;
         $user_info = \App::$data['api_info'];
         $nick = $user_info['screen_name'];
         $channel = get_channel_by_nick($user_info['screen_name']);
     } elseif (argc() > 1) {
         $channel = get_channel_by_nick(argv(1));
     }
     if (!$channel) {
         killme();
     }
     $observer = \App::get_observer();
     $def_album = get_pconfig($channel['channel_id'], 'system', 'photo_path');
     $def_attach = get_pconfig($channel['channel_id'], 'system', 'attach_path');
     $r = attach_store($channel, $observer ? $observer['xchan_hash'] : '', '', array('source' => 'editor', 'visible' => 0, 'album' => $def_album, 'directory' => $def_attach, 'allow_cid' => '<' . $channel['channel_hash'] . '>'));
     if (!$r['success']) {
         notice($r['message'] . EOL);
         killme();
     }
     if (intval($r['data']['is_photo'])) {
         $s = "\n\n" . $r['body'] . "\n\n";
     } else {
         $s = "\n\n" . '[attachment]' . $r['data']['hash'] . ',' . $r['data']['revision'] . '[/attachment]' . "\n";
     }
     if ($using_api) {
         return $s;
     }
     echo $s;
     killme();
 }
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:33,代码来源:Wall_attach.php

示例2: post

 function post()
 {
     // logger('file upload: ' . print_r($_REQUEST,true));
     $channel = $_REQUEST['channick'] ? get_channel_by_nick($_REQUEST['channick']) : null;
     if (!$channel) {
         logger('channel not found');
         killme();
     }
     $_REQUEST['source'] = 'file_upload';
     if ($channel['channel_id'] != local_channel()) {
         $_REQUEST['contact_allow'] = expand_acl($channel['channel_allow_cid']);
         $_REQUEST['group_allow'] = expand_acl($channel['channel_allow_gid']);
         $_REQUEST['contact_deny'] = expand_acl($channel['channel_deny_cid']);
         $_REQUEST['group_deny'] = expand_acl($channel['channel_deny_gid']);
     }
     if ($_REQUEST['filename']) {
         $_REQUEST['allow_cid'] = perms2str($_REQUEST['contact_allow']);
         $_REQUEST['allow_gid'] = perms2str($_REQUEST['group_allow']);
         $_REQUEST['deny_cid'] = perms2str($_REQUEST['contact_deny']);
         $_REQUEST['deny_gid'] = perms2str($_REQUEST['group_deny']);
         $r = attach_mkdir($channel, get_observer_hash(), $_REQUEST);
     } else {
         $r = attach_store($channel, get_observer_hash(), '', $_REQUEST);
     }
     goaway(z_root() . '/' . $_REQUEST['return_url']);
 }
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:26,代码来源:File_upload.php

示例3: wall_attach_post

function wall_attach_post(&$a)
{
    $using_api = false;
    if ($a->data['api_info'] && array_key_exists('media', $_FILES)) {
        $using_api = true;
        $user_info = $a->data['api_info'];
        $nick = $user_info['screen_name'];
        $channel = get_channel_by_nick($user_info['screen_name']);
    } elseif (argc() > 1) {
        $channel = get_channel_by_nick(argv(1));
    }
    if (!$channel) {
        killme();
    }
    $observer = $a->get_observer();
    //	if($_FILES['userfile']['tmp_name']) {
    //		$x = @getimagesize($_FILES['userfile']['tmp_name']);
    //		logger('getimagesize: ' . print_r($x,true), LOGGER_DATA);
    //		if(($x) && ($x[2] === IMAGETYPE_GIF || $x[2] === IMAGETYPE_JPEG || $x[2] === IMAGETYPE_PNG)) {
    //			$args = array( 'source' => 'editor', 'visible' => 0, 'contact_allow' => array($channel['channel_hash']));
    //			$ret = photo_upload($channel,$observer,$args);
    //			if($ret['success']) {
    //				echo  "\n\n" . $ret['body'] . "\n\n";
    //				killme();
    //			}
    //			if($using_api)
    //				return;
    //			notice($ret['message']);
    //			killme();
    //		}
    //	}
    $def_album = get_pconfig($channel['channel_id'], 'system', 'photo_path');
    $def_attach = get_pconfig($channel['channel_id'], 'system', 'attach_path');
    $r = attach_store($channel, $observer ? $observer['xchan_hash'] : '', '', array('source' => 'editor', 'visible' => 0, 'album' => $def_album, 'directory' => $def_attach, 'allow_cid' => '<' . $channel['channel_hash'] . '>'));
    if (!$r['success']) {
        notice($r['message'] . EOL);
        killme();
    }
    if (intval($r['data']['is_photo'])) {
        $s = "\n\n" . $r['body'] . "\n\n";
    } else {
        $s = "\n\n" . '[attachment]' . $r['data']['hash'] . ',' . $r['data']['revision'] . '[/attachment]' . "\n";
    }
    if ($using_api) {
        return $s;
    }
    echo $s;
    killme();
}
开发者ID:TamirAl,项目名称:hubzilla,代码行数:49,代码来源:wall_attach.php

示例4: wall_attach_post

function wall_attach_post(&$a)
{
    if (argc() > 1) {
        $channel = get_channel_by_nick(argv(1));
    } else {
        killme();
    }
    $r = attach_store($channel, get_observer_hash());
    if (!$r['success']) {
        notice($r['message'] . EOL);
        killme();
    }
    echo "\n\n" . '[attachment]' . $r['data']['hash'] . ',' . $r['data']['revision'] . '[/attachment]' . "\n";
    killme();
}
开发者ID:Mauru,项目名称:red,代码行数:15,代码来源:wall_attach.php

示例5: wall_attach_post

function wall_attach_post(&$a)
{
    if (argc() > 1) {
        $channel = get_channel_by_nick(argv(1));
    } elseif ($_FILES['media']) {
        require_once 'include/api.php';
        $user_info = api_get_user($a);
        $nick = $user_info['screen_name'];
        $channel = get_channel_by_nick($user_info['screen_name']);
    }
    if (!$channel) {
        killme();
    }
    $observer = $a->get_observer();
    if ($_FILES['userfile']['tmp_name']) {
        $x = @getimagesize($_FILES['userfile']['tmp_name']);
        logger('getimagesize: ' . print_r($x, true), LOGGER_DATA);
        if ($x && ($x[2] === IMAGETYPE_GIF || $x[2] === IMAGETYPE_JPEG || $x[2] === IMAGETYPE_PNG)) {
            $args = array('source' => 'editor', 'visible' => 0, 'contact_allow' => array($channel['channel_hash']));
            $ret = photo_upload($channel, $observer, $args);
            if ($ret['success']) {
                echo "\n\n" . $ret['body'] . "\n\n";
                killme();
            }
            if ($using_api) {
                return;
            }
            notice($ret['message']);
            killme();
        }
    }
    $r = attach_store($channel, $observer ? $observer['xchan_hash'] : '');
    if (!$r['success']) {
        notice($r['message'] . EOL);
        killme();
    }
    echo "\n\n" . '[attachment]' . $r['data']['hash'] . ',' . $r['data']['revision'] . '[/attachment]' . "\n";
    killme();
}
开发者ID:HaakonME,项目名称:redmatrix,代码行数:39,代码来源:wall_attach.php

示例6: profile_photo_post

function profile_photo_post(&$a)
{
    if (!local_channel()) {
        return;
    }
    check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo');
    if (x($_POST, 'cropfinal') && $_POST['cropfinal'] == 1) {
        // unless proven otherwise
        $is_default_profile = 1;
        if ($_REQUEST['profile']) {
            $r = q("select id, profile_guid, is_default, gender from profile where id = %d and uid = %d limit 1", intval($_REQUEST['profile']), intval(local_channel()));
            if ($r) {
                $profile = $r[0];
                if (!intval($profile['is_default'])) {
                    $is_default_profile = 0;
                }
            }
        }
        // phase 2 - we have finished cropping
        if (argc() != 2) {
            notice(t('Image uploaded but image cropping failed.') . EOL);
            return;
        }
        $image_id = 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 uid = %d AND scale = %d LIMIT 1", dbesc($image_id), dbesc(local_channel()), intval($scale));
        if ($r) {
            $base_image = $r[0];
            $base_image['data'] = $r[0]['os_storage'] ? @file_get_contents($base_image['data']) : dbunescbin($base_image['data']);
            $im = photo_factory($base_image['data'], $base_image['type']);
            if ($im->is_valid()) {
                $im->cropImage(300, $srcX, $srcY, $srcW, $srcH);
                $aid = get_account_id();
                $p = array('aid' => $aid, 'uid' => local_channel(), 'resource_id' => $base_image['resource_id'], 'filename' => $base_image['filename'], 'album' => t('Profile Photos'));
                $p['scale'] = 4;
                $p['photo_usage'] = $is_default_profile ? PHOTO_PROFILE : PHOTO_NORMAL;
                $r1 = $im->save($p);
                $im->scaleImage(80);
                $p['scale'] = 5;
                $r2 = $im->save($p);
                $im->scaleImage(48);
                $p['scale'] = 6;
                $r3 = $im->save($p);
                if ($r1 === false || $r2 === false || $r3 === false) {
                    // if one failed, delete them all so we can start over.
                    notice(t('Image resize failed.') . EOL);
                    $x = q("delete from photo where resource_id = '%s' and uid = %d and scale >= 4 ", dbesc($base_image['resource_id']), local_channel());
                    return;
                }
                $channel = App::get_channel();
                // If setting for the default profile, unset the profile photo flag from any other photos I own
                if ($is_default_profile) {
                    $r = q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d\n\t\t\t\t\t\tAND resource_id != '%s' AND `uid` = %d", intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), dbesc($base_image['resource_id']), intval(local_channel()));
                    send_profile_photo_activity($channel, $base_image, $profile);
                } else {
                    $r = q("update profile set photo = '%s', thumb = '%s' where id = %d and uid = %d", dbesc(z_root() . '/photo/' . $base_image['resource_id'] . '-4'), dbesc(z_root() . '/photo/' . $base_image['resource_id'] . '-5'), intval($_REQUEST['profile']), intval(local_channel()));
                }
                profiles_build_sync(local_channel());
                // We'll set the updated profile-photo timestamp even if it isn't the default profile,
                // so that browsers will do a cache update unconditionally
                $r = q("UPDATE xchan set xchan_photo_mimetype = '%s', xchan_photo_date = '%s' \n\t\t\t\t\twhere xchan_hash = '%s'", dbesc($im->getType()), dbesc(datetime_convert()), dbesc($channel['xchan_hash']));
                info(t('Shift-reload the page or clear browser cache if the new photo does not display immediately.') . EOL);
                // Update directory in background
                proc_run('php', "include/directory.php", $channel['channel_id']);
                // Now copy profile-permissions to pictures, to prevent privacyleaks by automatically created folder 'Profile Pictures'
                profile_photo_set_profile_perms($_REQUEST['profile']);
            } else {
                notice(t('Unable to process image') . EOL);
            }
        }
        goaway(z_root() . '/profiles');
        return;
        // NOTREACHED
    }
    $hash = photo_new_resource();
    $smallest = 0;
    require_once 'include/attach.php';
    $res = attach_store(App::get_channel(), get_observer_hash(), '', array('album' => t('Profile Photos'), 'hash' => $hash));
    logger('attach_store: ' . print_r($res, true));
    if ($res && intval($res['data']['is_photo'])) {
        $i = q("select * from photo where resource_id = '%s' and uid = %d order by scale", dbesc($hash), intval(local_channel()));
        if (!$i) {
            notice(t('Image upload failed.') . EOL);
            return;
        }
        $os_storage = false;
        foreach ($i as $ii) {
            if (intval($ii['scale']) < 2) {
                $smallest = intval($ii['scale']);
                $os_storage = intval($ii['os_storage']);
                $imagedata = $ii['data'];
                $filetype = $ii['type'];
            }
//.........这里部分代码省略.........
开发者ID:anmol26s,项目名称:hubzilla-yunohost,代码行数:101,代码来源:profile_photo.php

示例7: q

    $args['photo_usage'] = PHOTO_PROFILE;
}
if ($j['photo']['profile']) {
    $args['photo_usage'] = PHOTO_PROFILE;
}
if (array_key_exists('photo_usage', $args)) {
    $args['photo_usage'] = $j['photo']['photo_usage'];
}
$args['type'] = $j['photo']['type'];
$args['item'] = $j['item'] ? $j['item'] : false;
//		logger('redphotohelper: ' . print_r($j,true));
$r = q("select id from photo where resource_id = '%s' and uid = %d limit 1", dbesc($args['hash']), intval($channel['channel_id']));
if ($r) {
    killme();
}
$ret = attach_store($channel, $channel['channel_hash'], 'import', $args);
$r = q("select * from item where resource_id = '%s' and resource_type = 'photo' and uid = %d limit 1", dbesc($args['hash']), intval($channel['channel_id']));
if ($r) {
    $item = $r[0];
    item_url_replace($channel, $item, $fr_server, z_root(), $fr_username);
    dbesc_array($item);
    $item_id = $item['id'];
    unset($item['id']);
    $str = '';
    foreach ($item as $k => $v) {
        if ($str) {
            $str .= ",";
        }
        $str .= " `" . $k . "` = '" . $v . "' ";
    }
    $r = dbq("update `item` set " . $str . " where id = " . $item_id);
开发者ID:phellmes,项目名称:hubzilla-addons,代码行数:31,代码来源:redphotohelper.php

示例8: photos_post


//.........这里部分代码省略.........
                    $height = $ph->getHeight();
                    $x = q("update photo set data = '%s', height = %d, width = %d where `resource_id` = '%s' and uid = %d and scale = 2", dbescbin($ph->imageString()), intval($height), intval($width), dbesc($resource_id), intval($page_owner_uid));
                    if ($width > 320 || $height > 320) {
                        $ph->scaleImage(320);
                    }
                    $width = $ph->getWidth();
                    $height = $ph->getHeight();
                    $x = q("update photo set data = '%s', height = %d, width = %d where `resource_id` = '%s' and uid = %d and scale = 3", dbescbin($ph->imageString()), intval($height), intval($width), dbesc($resource_id), intval($page_owner_uid));
                }
            }
        }
        $p = q("SELECT type, is_nsfw, description, resource_id, scale, allow_cid, allow_gid, deny_cid, deny_gid FROM photo WHERE resource_id = '%s' AND uid = %d ORDER BY scale DESC", dbesc($resource_id), intval($page_owner_uid));
        if ($p) {
            $ext = $phototypes[$p[0]['type']];
            $r = q("UPDATE `photo` SET `description` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `resource_id` = '%s' AND `uid` = %d", dbesc($desc), dbesc($perm['allow_cid']), dbesc($perm['allow_gid']), dbesc($perm['deny_cid']), dbesc($perm['deny_gid']), dbesc($resource_id), intval($page_owner_uid));
        }
        $item_private = $str_contact_allow || $str_group_allow || $str_contact_deny || $str_group_deny ? true : false;
        $old_is_nsfw = $p[0]['is_nsfw'];
        if ($old_is_nsfw != $is_nsfw) {
            $r = q("update photo set is_nsfw = %d where resource_id = '%s' and uid = %d", intval($is_nsfw), dbesc($resource_id), intval($page_owner_uid));
        }
        /* Don't make the item visible if the only change was the album name */
        $visibility = 0;
        if ($p[0]['description'] !== $desc || strlen($rawtags)) {
            $visibility = 1;
        }
        if (!$item_id) {
            $item_id = photos_create_item($a->data['channel'], get_observer_hash(), $p[0], $visibility);
        }
        if ($item_id) {
            $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($item_id), intval($page_owner_uid));
            if ($r) {
                $old_tag = $r[0]['tag'];
                $old_inform = $r[0]['inform'];
            }
        }
        // make sure the linked item has the same permissions as the photo regardless of any other changes
        $x = q("update item set allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', item_private = %d\n\t\t\twhere id = %d", dbesc($perm['allow_cid']), dbesc($perm['allow_gid']), dbesc($perm['deny_cid']), dbesc($perm['deny_gid']), intval($acl->is_private()), intval($item_id));
        // make sure the attach has the same permissions as the photo regardless of any other changes
        $x = q("update attach set allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s' where hash = '%s' and uid = %d and is_photo = 1", dbesc($perm['allow_cid']), dbesc($perm['allow_gid']), dbesc($perm['deny_cid']), dbesc($perm['deny_gid']), dbesc($resource_id), intval($page_owner_uid));
        if (strlen($rawtags)) {
            $str_tags = '';
            $inform = '';
            // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a mention
            $x = substr($rawtags, 0, 1);
            if ($x !== '@' && $x !== '#') {
                $rawtags = '@' . $rawtags;
            }
            require_once 'include/text.php';
            $profile_uid = $a->profile['profile_uid'];
            $results = linkify_tags($a, $rawtags, local_channel() ? local_channel() : $profile_uid);
            $success = $results['success'];
            $post_tags = array();
            foreach ($results as $result) {
                $success = $result['success'];
                if ($success['replaced']) {
                    $post_tags[] = array('uid' => $profile_uid, 'type' => $success['termtype'], 'otype' => TERM_OBJ_POST, 'term' => $success['term'], 'url' => $success['url']);
                }
            }
            $r = q("select * from item where id = %d and uid = %d limit 1", intval($item_id), intval($page_owner_uid));
            if ($r) {
                $r = fetch_post_tags($r, true);
                $datarray = $r[0];
                if ($post_tags) {
                    if (!array_key_exists('term', $datarray) || !is_array($datarray['term'])) {
                        $datarray['term'] = $post_tags;
                    } else {
                        $datarray['term'] = array_merge($datarray['term'], $post_tags);
                    }
                }
                item_store_update($datarray, $execflag);
            }
        }
        goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
        return;
        // NOTREACHED
    }
    /**
     * default post action - upload a photo
     */
    $channel = $a->data['channel'];
    $observer = $a->data['observer'];
    $_REQUEST['source'] = 'photos';
    require_once 'include/attach.php';
    if (!local_channel()) {
        $_REQUEST['contact_allow'] = expand_acl($channel['channel_allow_cid']);
        $_REQUEST['group_allow'] = expand_acl($channel['channel_allow_gid']);
        $_REQUEST['contact_deny'] = expand_acl($channel['channel_deny_cid']);
        $_REQUEST['group_deny'] = expand_acl($channel['channel_deny_gid']);
    }
    $r = attach_store($a->channel, get_observer_hash(), '', $_REQUEST);
    if (!$r['success']) {
        notice($r['message'] . EOL);
    }
    if ($_REQUEST['newalbum']) {
        goaway($a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($_REQUEST['newalbum']));
    } else {
        goaway($a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex(datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y')));
    }
}
开发者ID:spthaolt,项目名称:hubzilla,代码行数:101,代码来源:photos.php

示例9: send_message


//.........这里部分代码省略.........
    if (!$retconv) {
        $r = q("select * from conv where guid = '%s' and uid = %d limit 1", dbesc($conv_guid), intval(local_channel()));
        if ($r) {
            $retconv = $r[0];
            $retconv['subject'] = base64url_decode(str_rot47($retconv['subject']));
        }
    }
    if (!$retconv) {
        $ret['message'] = 'conversation not found';
        return $ret;
    }
    // generate a unique message_id
    do {
        $dups = false;
        $hash = random_string();
        $mid = $hash . '@' . get_app()->get_hostname();
        $r = q("SELECT id FROM mail WHERE mid = '%s' LIMIT 1", dbesc($mid));
        if (count($r)) {
            $dups = true;
        }
    } while ($dups == true);
    if (!strlen($replyto)) {
        $replyto = $mid;
    }
    /**
     *
     * When a photo was uploaded into the message using the (profile wall) ajax 
     * uploader, The permissions are initially set to disallow anybody but the
     * owner from seeing it. This is because the permissions may not yet have been
     * set for the post. If it's private, the photo permissions should be set
     * appropriately. But we didn't know the final permissions on the post until
     * now. So now we'll look for links of uploaded messages that are in the
     * post and set them to the same permissions as the post itself.
     *
     */
    $match = null;
    $images = null;
    if (preg_match_all("/\\[zmg\\](.*?)\\[\\/zmg\\]/", strpos($body, '[/crypt]') ? $_POST['media_str'] : $body, $match)) {
        $images = $match[1];
    }
    $match = false;
    if (preg_match_all("/\\[attachment\\](.*?)\\[\\/attachment\\]/", strpos($body, '[/crypt]') ? $_POST['media_str'] : $body, $match)) {
        $attaches = $match[1];
    }
    $attachments = '';
    if (preg_match_all('/(\\[attachment\\](.*?)\\[\\/attachment\\])/', $body, $match)) {
        $attachments = array();
        foreach ($match[2] as $mtch) {
            $hash = substr($mtch, 0, strpos($mtch, ','));
            $rev = intval(substr($mtch, strpos($mtch, ',')));
            $r = attach_by_hash_nodata($hash, $rev);
            if ($r['success']) {
                $attachments[] = array('href' => $a->get_baseurl() . '/attach/' . $r['data']['hash'], 'length' => $r['data']['filesize'], 'type' => $r['data']['filetype'], 'title' => urlencode($r['data']['filename']), 'revision' => $r['data']['revision']);
            }
            $body = str_replace($match[1], '', $body);
        }
    }
    $jattach = $attachments ? json_encode($attachments) : '';
    if ($subject) {
        $subject = str_rot47(base64url_encode($subject));
    }
    if ($body) {
        $body = str_rot47(base64url_encode($body));
    }
    $r = q("INSERT INTO mail ( account_id, conv_guid, mail_obscured, channel_id, from_xchan, to_xchan, title, body, attach, mid, parent_mid, created, expires )\n\t\tVALUES ( %d, '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )", intval($channel['channel_account_id']), dbesc($conv_guid), intval(1), intval($channel['channel_id']), dbesc($channel['channel_hash']), dbesc($recipient), dbesc($subject), dbesc($body), dbesc($jattach), dbesc($mid), dbesc($replyto), dbesc(datetime_convert()), dbescdate($expires));
    // verify the save
    $r = q("SELECT * FROM mail WHERE mid = '%s' and channel_id = %d LIMIT 1", dbesc($mid), intval($channel['channel_id']));
    if ($r) {
        $post_id = $r[0]['id'];
        $retmail = $r[0];
        xchan_mail_query($retmail);
    } else {
        $ret['message'] = t('Stored post could not be verified.');
        return $ret;
    }
    if (count($images)) {
        foreach ($images as $image) {
            if (!stristr($image, $a->get_baseurl() . '/photo/')) {
                continue;
            }
            $image_uri = substr($image, strrpos($image, '/') + 1);
            $image_uri = substr($image_uri, 0, strpos($image_uri, '-'));
            $r = q("UPDATE photo SET allow_cid = '%s' WHERE resource_id = '%s' AND uid = %d and allow_cid = '%s'", dbesc('<' . $recipient . '>'), dbesc($image_uri), intval($channel['channel_id']), dbesc('<' . $channel['channel_hash'] . '>'));
            $r = q("UPDATE attach SET allow_cid = '%s' WHERE hash = '%s' AND is_photo = 1 and uid = %d and allow_cid = '%s'", dbesc('<' . $recipient . '>'), dbesc($image_uri), intval($channel['channel_id']), dbesc('<' . $channel['channel_hash'] . '>'));
        }
    }
    if ($attaches) {
        foreach ($attaches as $attach) {
            $hash = substr($attach, 0, strpos($attach, ','));
            $rev = intval(substr($attach, strpos($attach, ',')));
            attach_store($channel, $observer_hash, $options = 'update', array('hash' => $hash, 'revision' => $rev, 'allow_cid' => '<' . $recipient . '>'));
        }
    }
    proc_run('php', 'include/notifier.php', 'mail', $post_id);
    $ret['success'] = true;
    $ret['message_item'] = intval($post_id);
    $ret['conv'] = $retconv;
    $ret['mail'] = $retmail;
    return $ret;
}
开发者ID:23n,项目名称:hubzilla,代码行数:101,代码来源:message.php

示例10: fix_attached_file_permissions

function fix_attached_file_permissions($channel, $observer_hash, $body, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny)
{
    if (get_pconfig($channel['channel_id'], 'system', 'force_public_uploads')) {
        $str_contact_allow = $str_group_allow = $str_contact_deny = $str_group_deny = '';
    }
    $match = false;
    if (preg_match_all("/\\[attachment\\](.*?)\\[\\/attachment\\]/", $body, $match)) {
        $attaches = $match[1];
        if ($attaches) {
            foreach ($attaches as $attach) {
                $hash = substr($attach, 0, strpos($attach, ','));
                $rev = intval(substr($attach, strpos($attach, ',')));
                attach_store($channel, $observer_hash, $options = 'update', array('hash' => $hash, 'revision' => $rev, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow, 'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny));
            }
        }
    }
}
开发者ID:einervonvielen,项目名称:redmatrix,代码行数:17,代码来源:item.php

示例11: copy_folder_to_cloudfiles

function copy_folder_to_cloudfiles($channel, $observer_hash, $srcpath, $cloudpath)
{
    if (!is_dir($srcpath) || !is_readable($srcpath)) {
        logger('Error reading source path: ' . $srcpath, LOGGER_NORMAL);
        return false;
    }
    $nodes = array_diff(scandir($srcpath), array('.', '..'));
    foreach ($nodes as $node) {
        $clouddir = $cloudpath . '/' . $node;
        // Sub-folder in cloud files destination
        $nodepath = $srcpath . '/' . $node;
        // Sub-folder in source path
        if (is_dir($nodepath)) {
            $x = attach_mkdirp($channel, $observer_hash, array('pathname' => $clouddir));
            if (!$x['success']) {
                logger('Error creating cloud path: ' . $clouddir, LOGGER_NORMAL);
                return false;
            }
            // Recursively call this function where the source and destination are the subfolders
            $success = copy_folder_to_cloudfiles($channel, $observer_hash, $nodepath, $clouddir);
            if (!$success) {
                logger('Error copying contents of folder: ' . $nodepath, LOGGER_NORMAL);
                return false;
            }
        } elseif (is_file($nodepath) && is_readable($nodepath)) {
            $x = attach_store($channel, $observer_hash, 'import', array('directory' => $cloudpath, 'src' => $nodepath, 'filename' => $node, 'filesize' => @filesize($nodepath), 'preserve_original' => true));
            if (!$x['success']) {
                logger('Error copying file: ' . $nodepath, LOGGER_NORMAL);
                logger('Return value: ' . json_encode($x), LOGGER_NORMAL);
                return false;
            }
        } else {
            logger('Error scanning source path', LOGGER_NORMAL);
            return false;
        }
    }
    return true;
}
开发者ID:phellmes,项目名称:hubzilla,代码行数:38,代码来源:attach.php

示例12: cover_photo_post

function cover_photo_post(&$a)
{
    if (!local_channel()) {
        return;
    }
    $channel = App::get_channel();
    check_form_security_token_redirectOnErr('/cover_photo', 'cover_photo');
    if (x($_POST, 'cropfinal') && $_POST['cropfinal'] == 1) {
        // phase 2 - we have finished cropping
        if (argc() != 2) {
            notice(t('Image uploaded but image cropping failed.') . EOL);
            return;
        }
        $image_id = 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 gender from profile where uid = %d and is_default = 1 limit 1", intval(local_channel()));
        if ($r) {
            $profile = $r[0];
        }
        $r = q("SELECT * FROM photo WHERE resource_id = '%s' AND uid = %d AND scale = 0 LIMIT 1", dbesc($image_id), intval(local_channel()));
        if ($r) {
            $base_image = $r[0];
            $base_image['data'] = $r[0]['os_storage'] ? @file_get_contents($base_image['data']) : dbunescbin($base_image['data']);
            $im = photo_factory($base_image['data'], $base_image['type']);
            if ($im->is_valid()) {
                // We are scaling and cropping the relative pixel locations to the original photo instead of the
                // scaled photo we operated on.
                // First load the scaled photo to check its size. (Should probably pass this in the post form and save
                // a query.)
                $g = q("select width, height from photo where resource_id = '%s' and uid = %d and scale = 3", dbesc($image_id), intval(local_channel()));
                $scaled_width = $g[0]['width'];
                $scaled_height = $g[0]['height'];
                if (!$scaled_width || !$scaled_height) {
                    logger('potential divide by zero scaling cover photo');
                    return;
                }
                // unset all other cover photos
                q("update photo set photo_usage = %d where photo_usage = %d and uid = %d", intval(PHOTO_NORMAL), intval(PHOTO_COVER), intval(local_channel()));
                $orig_srcx = $r[0]['width'] / $scaled_width * $srcX;
                $orig_srcy = $r[0]['height'] / $scaled_height * $srcY;
                $orig_srcw = $srcW / $scaled_width * $r[0]['width'];
                $orig_srch = $srcH / $scaled_height * $r[0]['height'];
                $im->cropImageRect(1200, 435, $orig_srcx, $orig_srcy, $orig_srcw, $orig_srch);
                $aid = get_account_id();
                $p = array('aid' => $aid, 'uid' => local_channel(), 'resource_id' => $base_image['resource_id'], 'filename' => $base_image['filename'], 'album' => t('Cover Photos'));
                $p['scale'] = 7;
                $p['photo_usage'] = PHOTO_COVER;
                $r1 = $im->save($p);
                $im->doScaleImage(850, 310);
                $p['scale'] = 8;
                $r2 = $im->save($p);
                $im->doScaleImage(425, 160);
                $p['scale'] = 9;
                $r3 = $im->save($p);
                if ($r1 === false || $r2 === false || $r3 === false) {
                    // if one failed, delete them all so we can start over.
                    notice(t('Image resize failed.') . EOL);
                    $x = q("delete from photo where resource_id = '%s' and uid = %d and scale >= 7 ", dbesc($base_image['resource_id']), local_channel());
                    return;
                }
                $channel = App::get_channel();
                send_cover_photo_activity($channel, $base_image, $profile);
            } else {
                notice(t('Unable to process image') . EOL);
            }
        }
        goaway(z_root() . '/channel/' . $channel['channel_address']);
    }
    $hash = photo_new_resource();
    $smallest = 0;
    require_once 'include/attach.php';
    $res = attach_store(App::get_channel(), get_observer_hash(), '', array('album' => t('Cover Photos'), 'hash' => $hash));
    logger('attach_store: ' . print_r($res, true));
    if ($res && intval($res['data']['is_photo'])) {
        $i = q("select * from photo where resource_id = '%s' and uid = %d and scale = 0", dbesc($hash), intval(local_channel()));
        if (!$i) {
            notice(t('Image upload failed.') . EOL);
            return;
        }
        $os_storage = false;
        foreach ($i as $ii) {
            $smallest = intval($ii['scale']);
            $os_storage = intval($ii['os_storage']);
            $imagedata = $ii['data'];
            $filetype = $ii['type'];
        }
    }
    $imagedata = $os_storage ? @file_get_contents($imagedata) : $imagedata;
    $ph = photo_factory($imagedata, $filetype);
    if (!$ph->is_valid()) {
        notice(t('Unable to process image.') . EOL);
        return;
    }
//.........这里部分代码省略.........
开发者ID:anmol26s,项目名称:hubzilla-yunohost,代码行数:101,代码来源:cover_photo.php

示例13: post


//.........这里部分代码省略.........
                     }
                     $width = $ph->getWidth();
                     $height = $ph->getHeight();
                     $x = q("update photo set content = '%s', height = %d, width = %d where `resource_id` = '%s' and uid = %d and imgscale = 3", dbescbin($ph->imageString()), intval($height), intval($width), dbesc($resource_id), intval($page_owner_uid));
                 }
             }
         }
         $p = q("SELECT mimetype, is_nsfw, description, resource_id, imgscale, allow_cid, allow_gid, deny_cid, deny_gid FROM photo WHERE resource_id = '%s' AND uid = %d ORDER BY imgscale DESC", dbesc($resource_id), intval($page_owner_uid));
         if ($p) {
             $ext = $phototypes[$p[0]['mimetype']];
             $r = q("UPDATE `photo` SET `description` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `resource_id` = '%s' AND `uid` = %d", dbesc($desc), dbesc($perm['allow_cid']), dbesc($perm['allow_gid']), dbesc($perm['deny_cid']), dbesc($perm['deny_gid']), dbesc($resource_id), intval($page_owner_uid));
         }
         $item_private = $str_contact_allow || $str_group_allow || $str_contact_deny || $str_group_deny ? true : false;
         $old_is_nsfw = $p[0]['is_nsfw'];
         if ($old_is_nsfw != $is_nsfw) {
             $r = q("update photo set is_nsfw = %d where resource_id = '%s' and uid = %d", intval($is_nsfw), dbesc($resource_id), intval($page_owner_uid));
         }
         /* Don't make the item visible if the only change was the album name */
         $visibility = 0;
         if ($p[0]['description'] !== $desc || strlen($rawtags)) {
             $visibility = 1;
         }
         if (!$item_id) {
             $item_id = photos_create_item(\App::$data['channel'], get_observer_hash(), $p[0], $visibility);
         }
         if ($item_id) {
             $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($item_id), intval($page_owner_uid));
             if ($r) {
                 $old_tag = $r[0]['tag'];
                 $old_inform = $r[0]['inform'];
             }
         }
         // make sure the linked item has the same permissions as the photo regardless of any other changes
         $x = q("update item set allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', item_private = %d\n\t\t\t\twhere id = %d", dbesc($perm['allow_cid']), dbesc($perm['allow_gid']), dbesc($perm['deny_cid']), dbesc($perm['deny_gid']), intval($acl->is_private()), intval($item_id));
         // make sure the attach has the same permissions as the photo regardless of any other changes
         $x = q("update attach set allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s' where hash = '%s' and uid = %d and is_photo = 1", dbesc($perm['allow_cid']), dbesc($perm['allow_gid']), dbesc($perm['deny_cid']), dbesc($perm['deny_gid']), dbesc($resource_id), intval($page_owner_uid));
         if (strlen($rawtags)) {
             $str_tags = '';
             $inform = '';
             // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a mention
             $x = substr($rawtags, 0, 1);
             if ($x !== '@' && $x !== '#') {
                 $rawtags = '@' . $rawtags;
             }
             require_once 'include/text.php';
             $profile_uid = \App::$profile['profile_uid'];
             $results = linkify_tags($a, $rawtags, local_channel() ? local_channel() : $profile_uid);
             $success = $results['success'];
             $post_tags = array();
             foreach ($results as $result) {
                 $success = $result['success'];
                 if ($success['replaced']) {
                     $post_tags[] = array('uid' => $profile_uid, 'ttype' => $success['termtype'], 'otype' => TERM_OBJ_POST, 'term' => $success['term'], 'url' => $success['url']);
                 }
             }
             $r = q("select * from item where id = %d and uid = %d limit 1", intval($item_id), intval($page_owner_uid));
             if ($r) {
                 $r = fetch_post_tags($r, true);
                 $datarray = $r[0];
                 if ($post_tags) {
                     if (!array_key_exists('term', $datarray) || !is_array($datarray['term'])) {
                         $datarray['term'] = $post_tags;
                     } else {
                         $datarray['term'] = array_merge($datarray['term'], $post_tags);
                     }
                 }
                 item_store_update($datarray, $execflag);
             }
         }
         $sync = attach_export_data(\App::$data['channel'], $resource_id);
         if ($sync) {
             build_sync_packet($page_owner_uid, array('file' => array($sync)));
         }
         goaway(z_root() . '/' . $_SESSION['photo_return']);
         return;
         // NOTREACHED
     }
     /**
      * default post action - upload a photo
      */
     $channel = \App::$data['channel'];
     $observer = \App::$data['observer'];
     $_REQUEST['source'] = 'photos';
     require_once 'include/attach.php';
     if (!local_channel()) {
         $_REQUEST['contact_allow'] = expand_acl($channel['channel_allow_cid']);
         $_REQUEST['group_allow'] = expand_acl($channel['channel_allow_gid']);
         $_REQUEST['contact_deny'] = expand_acl($channel['channel_deny_cid']);
         $_REQUEST['group_deny'] = expand_acl($channel['channel_deny_gid']);
     }
     $r = attach_store($channel, get_observer_hash(), '', $_REQUEST);
     if (!$r['success']) {
         notice($r['message'] . EOL);
     }
     if ($_REQUEST['newalbum']) {
         goaway(z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/album/' . bin2hex($_REQUEST['newalbum']));
     } else {
         goaway(z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/album/' . bin2hex(datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y')));
     }
 }
开发者ID:phellmes,项目名称:hubzilla,代码行数:101,代码来源:Photos.php


注:本文中的attach_store函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。