Пример #1
0
function profile_photo_content(&$a)
{
    if (!local_channel()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $channel = App::get_channel();
    $newuser = false;
    if (argc() == 2 && argv(1) === 'new') {
        $newuser = true;
    }
    if (argv(1) === 'use') {
        if (argc() < 3) {
            notice(t('Permission denied.') . EOL);
            return;
        }
        //		check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo');
        $resource_id = argv(2);
        $r = q("SELECT id, album, scale FROM photo WHERE uid = %d AND resource_id = '%s' ORDER BY scale ASC", intval(local_channel()), dbesc($resource_id));
        if (!$r) {
            notice(t('Photo not available.') . EOL);
            return;
        }
        $havescale = false;
        foreach ($r as $rr) {
            if ($rr['scale'] == 5) {
                $havescale = true;
            }
        }
        // set an already loaded photo as profile photo
        if ($r[0]['album'] == t('Profile Photos') && $havescale) {
            // unset any existing profile photos
            $r = q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND uid = %d", intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval(local_channel()));
            $r = q("UPDATE photo SET photo_usage = %d WHERE uid = %d AND resource_id = '%s'", intval(PHOTO_PROFILE), intval(local_channel()), dbesc($resource_id));
            $r = q("UPDATE xchan set xchan_photo_date = '%s' \n\t\t\t\twhere xchan_hash = '%s'", dbesc(datetime_convert()), dbesc($channel['xchan_hash']));
            profile_photo_set_profile_perms();
            //Reset default photo permissions to public
            proc_run('php', 'include/directory.php', local_channel());
            goaway(z_root() . '/profiles');
        }
        $r = q("SELECT `data`, `type`, resource_id, os_storage FROM photo WHERE id = %d and uid = %d limit 1", intval($r[0]['id']), intval(local_channel()));
        if (!$r) {
            notice(t('Photo not available.') . EOL);
            return;
        }
        if (intval($r[0]['os_storage'])) {
            $data = @file_get_contents($r[0]['data']);
        } else {
            $data = dbunescbin($r[0]['data']);
        }
        $ph = photo_factory($data, $r[0]['type']);
        $smallest = 0;
        if ($ph->is_valid()) {
            // go ahead as if we have just uploaded a new photo to crop
            $i = q("select resource_id, scale from photo where resource_id = '%s' and uid = %d order by scale", dbesc($r[0]['resource_id']), intval(local_channel()));
            if ($i) {
                $hash = $i[0]['resource_id'];
                foreach ($i as $ii) {
                    if (intval($ii['scale']) < 2) {
                        $smallest = intval($ii['scale']);
                    }
                }
            }
        }
        profile_photo_crop_ui_head($a, $ph, $hash, $smallest);
    }
    $profiles = q("select id, profile_name as name, is_default from profile where uid = %d", intval(local_channel()));
    if (!x(App::$data, 'imagecrop')) {
        $tpl = get_markup_template('profile_photo.tpl');
        $o .= replace_macros($tpl, array('$user' => App::$channel['channel_address'], '$lbl_upfile' => t('Upload File:'), '$lbl_profiles' => t('Select a profile:'), '$title' => t('Upload Profile Photo'), '$submit' => t('Upload'), '$profiles' => $profiles, '$single' => count($profiles) == 1 ? true : false, '$profile0' => $profiles[0], '$form_security_token' => get_form_security_token("profile_photo"), '$select' => sprintf('%s %s', t('or'), $newuser ? '<a href="' . z_root() . '">' . t('skip this step') . '</a>' : '<a href="' . z_root() . '/photos/' . App::$channel['channel_address'] . '">' . t('select a photo from your photo albums') . '</a>')));
        call_hooks('profile_photo_content_end', $o);
        return $o;
    } else {
        $filename = App::$data['imagecrop'] . '-' . App::$data['imagecrop_resolution'];
        $resolution = App::$data['imagecrop_resolution'];
        $tpl = get_markup_template("cropbody.tpl");
        $o .= replace_macros($tpl, array('$filename' => $filename, '$profile' => intval($_REQUEST['profile']), '$resource' => App::$data['imagecrop'] . '-' . App::$data['imagecrop_resolution'], '$image_url' => z_root() . '/photo/' . $filename, '$title' => t('Crop Image'), '$desc' => t('Please adjust the image cropping for optimum viewing.'), '$form_security_token' => get_form_security_token("profile_photo"), '$done' => t('Done Editing')));
        return $o;
    }
    return;
    // NOTREACHED
}
function openclipatar_content(&$a)
{
    if (!local_channel()) {
        return;
    }
    $o = '';
    if (argc() == 3 && argv(1) == 'use') {
        $id = argv(2);
        $chan = $a->get_channel();
        $x = z_fetch_url('https://openclipart.org/image/250px/svg_to_png/' . $id . '/' . $id . '.png', true);
        if ($x['success']) {
            $imagedata = $x['body'];
        }
        $ph = photo_factory($imagedata, 'image/png');
        if (!$ph->is_valid()) {
            return t('Unknown error. Please try again later.');
        }
        // create a unique resource_id
        $hash = photo_new_resource();
        // save an original or "scale 0" image
        $p = array('aid' => get_account_id(), 'uid' => local_channel(), 'resource_id' => $hash, 'filename' => $id . '.png', 'album' => t('Profile Photos'), 'scale' => 0);
        $r = $ph->save($p);
        if ($r) {
            // scale 0 success, continue 4, 5, 6
            // we'll skip scales 1,2 (640, 320 rectangular formats as these images are all less than this)
            // ensure squareness at first, subsequent scales keep ratio
            $ph->scaleImageSquare(175);
            $p['scale'] = 4;
            $r = $ph->save($p);
            if ($r === false) {
                $photo_failure = true;
            }
            $ph->scaleImage(80);
            $p['scale'] = 5;
            $r = $ph->save($p);
            if ($r === false) {
                $photo_failure = true;
            }
            $ph->scaleImage(48);
            $p['scale'] = 6;
            $r = $ph->save($p);
            if ($r === false) {
                $photo_failure = true;
            }
        }
        $is_default_profile = 1;
        if ($_REQUEST['profile']) {
            $r = q("select id, is_default from profile where id = %d and uid = %d limit 1", intval($_REQUEST['profile']), intval(local_channel()));
            if ($r && !intval($r[0]['is_default'])) {
                $is_default_profile = 0;
            }
        }
        if ($is_default_profile) {
            // unset any existing profile photos
            $r = q("UPDATE photo SET profile = 0 WHERE profile = 1 AND uid = %d", intval(local_channel()));
            $r = q("UPDATE photo SET photo_flags = (photo_flags & ~%d ) WHERE (photo_flags & %d )>0 AND uid = %d", intval(PHOTO_PROFILE), intval(PHOTO_PROFILE), intval(local_channel()));
            // set all sizes of this one as profile photos
            $r = q("UPDATE photo SET profile = 1 WHERE uid = %d AND resource_id = '%s'", intval(local_channel()), dbesc($hash));
            $r = q("UPDATE photo SET photo_flags = ( photo_flags | %d ) WHERE uid = %d AND resource_id = '%s'", intval(PHOTO_PROFILE), intval(local_channel()), dbesc($hash));
            require_once 'mod/profile_photo.php';
            profile_photo_set_profile_perms();
            //Reset default profile photo permissions to public
            // only the default needs reload since it uses canonical url -- despite the slightly ambiguous message, left it so as to re-use translations
            info(t('Shift-reload the page or clear browser cache if the new photo does not display immediately.') . EOL);
        } else {
            // not the default profile, set the path in the correct entry in the profile DB
            $r = q("update profile set photo = '%s', thumb = '%s' where id = %d and uid = %d", dbesc(get_app()->get_baseurl() . '/photo/' . $hash . '-4'), dbesc(get_app()->get_baseurl() . '/photo/' . $hash . '-5'), intval($_REQUEST['profile']), intval(local_channel()));
            info(t('Profile photo updated successfully.') . EOL);
        }
        // set a new photo_date on our xchan so that we can tell everybody to update their cached copy
        $r = q("UPDATE xchan set xchan_photo_date = '%s' where xchan_hash = '%s'", dbesc(datetime_convert()), dbesc($chan['xchan_hash']));
        // tell everybody
        proc_run('php', 'include/directory.php', local_channel());
        $returnafter = get_config('openclipatar', 'returnafter');
        $returnafter_urls = array(0 => $a->get_baseurl() . '/profile/' . ($_REQUEST['profile'] ? $_REQUEST['profile'] . '/view' : $chan['channel_address']), 1 => $a->get_baseurl() . '/profiles/' . ($_REQUEST['profile'] ? $_REQUEST['profile'] : $a->profile_uid), 2 => $a->get_baseurl() . '/profiles');
        goaway($returnafter_urls[$returnafter]);
    } else {
        //invoked as module, we place in content pane the same as we would for the end of the profile photo page. Also handles json for endless scroll for either invokation.
        openclipatar_profile_photo_content_end($a, $o);
    }
    return $o;
}
Пример #3
0
 function get()
 {
     if (!local_channel()) {
         notice(t('Permission denied') . EOL);
         return;
     }
     if (argc() < 2) {
         notice(t('Invalid profile identifier.') . EOL);
         return;
     }
     // Switch to text mod interface if we have more than 'n' contacts or group members
     $switchtotext = get_pconfig(local_channel(), 'system', 'groupedit_image_limit');
     if ($switchtotext === false) {
         $switchtotext = get_config('system', 'groupedit_image_limit');
     }
     if ($switchtotext === false) {
         $switchtotext = 400;
     }
     if (argc() > 2 && intval(argv(1)) && intval(argv(2))) {
         $r = q("SELECT abook_id FROM abook WHERE abook_id = %d and abook_channel = %d limit 1", intval(argv(2)), intval(local_channel()));
         if ($r) {
             $change = intval(argv(2));
         }
     }
     if (argc() > 1 && intval(argv(1))) {
         $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is_default` = 0 LIMIT 1", intval(argv(1)), intval(local_channel()));
         if (!$r) {
             notice(t('Invalid profile identifier.') . EOL);
             return;
         }
         $profile = $r[0];
         $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d AND abook_profile = '%s'", intval(local_channel()), dbesc($profile['profile_guid']));
         $ingroup = array();
         if ($r) {
             foreach ($r as $member) {
                 $ingroup[] = $member['abook_id'];
             }
         }
         $members = $r;
         if ($change) {
             if (in_array($change, $ingroup)) {
                 q("UPDATE abook SET abook_profile = '' WHERE abook_id = %d AND abook_channel = %d", intval($change), intval(local_channel()));
             } else {
                 q("UPDATE abook SET abook_profile = '%s' WHERE abook_id = %d AND abook_channel = %d", dbesc($profile['profile_guid']), intval($change), intval(local_channel()));
             }
             //Time to update the permissions on the profile-pictures as well
             profile_photo_set_profile_perms($profile['id']);
             $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d AND abook_profile = '%s'", intval(local_channel()), dbesc($profile['profile_guid']));
             $members = $r;
             $ingroup = array();
             if (count($r)) {
                 foreach ($r as $member) {
                     $ingroup[] = $member['abook_id'];
                 }
             }
         }
         $o .= '<h2>' . t('Profile Visibility Editor') . '</h2>';
         $o .= '<h3>' . t('Profile') . ' \'' . $profile['profile_name'] . '\'</h3>';
         $o .= '<div id="prof-edit-desc">' . t('Click on a contact to add or remove.') . '</div>';
     }
     $o .= '<div id="prof-update-wrapper">';
     if ($change) {
         $o = '';
     }
     $o .= '<div id="prof-members-title">';
     $o .= '<h3>' . t('Visible To') . '</h3>';
     $o .= '</div>';
     $o .= '<div id="prof-members">';
     $textmode = $switchtotext && count($members) > $switchtotext ? true : false;
     foreach ($members as $member) {
         if ($member['xchan_url']) {
             $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['abook_id'] . '); return false;';
             $o .= micropro($member, true, 'mpprof', $textmode);
         }
     }
     $o .= '</div><div id="prof-members-end"></div>';
     $o .= '<hr id="prof-separator" />';
     $o .= '<div id="prof-all-contcts-title">';
     $o .= '<h3>' . t("All Connections") . '</h3>';
     $o .= '</div>';
     $o .= '<div id="prof-all-contacts">';
     $r = abook_connections(local_channel());
     if ($r) {
         $textmode = $switchtotext && count($r) > $switchtotext ? true : false;
         foreach ($r as $member) {
             if (!in_array($member['abook_id'], $ingroup)) {
                 $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['abook_id'] . '); return false;';
                 $o .= micropro($member, true, 'mpprof', $textmode);
             }
         }
     }
     $o .= '</div><div id="prof-all-contacts-end"></div>';
     if ($change) {
         echo $o;
         killme();
     }
     $o .= '</div>';
     return $o;
 }
Пример #4
0
function openclipatar_content(&$a)
{
    if (!local_channel()) {
        return;
    }
    $o = '';
    if (argc() == 3 && argv(1) == 'use') {
        $id = argv(2);
        $chan = App::get_channel();
        $x = z_fetch_url('https://openclipart.org/image/250px/svg_to_png/' . $id . '/' . $id . '.png', true);
        if ($x['success']) {
            $imagedata = $x['body'];
        }
        $ph = photo_factory($imagedata, 'image/png');
        if (!$ph->is_valid()) {
            return t('Unknown error. Please try again later.');
        }
        // create a unique resource_id
        $hash = photo_new_resource();
        $width = $ph->getWidth();
        $height = $ph->getHeight();
        // save an original or "scale 0" image
        $p = array('aid' => get_account_id(), 'uid' => local_channel(), 'resource_id' => $hash, 'filename' => $id . '.png', 'album' => t('Profile Photos'), 'imgscale' => 0);
        $r = $ph->save($p);
        if ($r) {
            if (($width > 1024 || $height > 1024) && !$errors) {
                $ph->scaleImage(1024);
            }
            $p['imgscale'] = 1;
            $r1 = $ph->save($p);
            if (($width > 640 || $height > 640) && !$errors) {
                $ph->scaleImage(640);
            }
            $p['imgscale'] = 2;
            $r2 = $ph->save($p);
            if (($width > 320 || $height > 320) && !$errors) {
                $ph->scaleImage(320);
            }
            $p['imgscale'] = 3;
            $r3 = $ph->save($p);
            // ensure squareness at first, subsequent scales keep ratio
            $ph->scaleImageSquare(175);
            $p['imgscale'] = 4;
            $r = $ph->save($p);
            if ($r === false) {
                $photo_failure = true;
            }
            $ph->scaleImage(80);
            $p['imgscale'] = 5;
            $r = $ph->save($p);
            if ($r === false) {
                $photo_failure = true;
            }
            $ph->scaleImage(48);
            $p['imgscale'] = 6;
            $r = $ph->save($p);
            if ($r === false) {
                $photo_failure = true;
            }
        }
        $is_default_profile = 1;
        if ($_REQUEST['profile']) {
            $r = q("select id, is_default from profile where id = %d and uid = %d limit 1", intval($_REQUEST['profile']), intval(local_channel()));
            if ($r && !intval($r[0]['is_default'])) {
                $is_default_profile = 0;
            }
        }
        if ($is_default_profile) {
            // unset any existing profile photos
            $r = q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND uid = %d", intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval(local_channel()));
            // set all sizes of this one as profile photos
            $r = q("UPDATE photo SET photo_usage = %d WHERE uid = %d AND resource_id = '%s'", intval(PHOTO_PROFILE), intval(local_channel()), dbesc($hash));
            require_once 'include/photos.php';
            profile_photo_set_profile_perms(local_channel());
            //Reset default profile photo permissions to public
            // only the default needs reload since it uses canonical url -- despite the slightly ambiguous message, left it so as to re-use translations
            info(t('Shift-reload the page or clear browser cache if the new photo does not display immediately.') . EOL);
        } else {
            // not the default profile, set the path in the correct entry in the profile DB
            $r = q("update profile set photo = '%s', thumb = '%s' where id = %d and uid = %d", dbesc(z_root() . '/photo/' . $hash . '-4'), dbesc(z_root() . '/photo/' . $hash . '-5'), intval($_REQUEST['profile']), intval(local_channel()));
            info(t('Profile photo updated successfully.') . EOL);
        }
        // set a new photo_date on our xchan so that we can tell everybody to update their cached copy
        $r = q("UPDATE xchan set xchan_photo_date = '%s' where xchan_hash = '%s'", dbesc(datetime_convert()), dbesc($chan['xchan_hash']));
        // Similarly, tell the nav bar to bypass the cache and update the avater image.
        $_SESSION['reload_avatar'] = true;
        // tell everybody
        Zotlabs\Daemon\Master::Summon(array('Directory', local_channel()));
        $returnafter = get_config('openclipatar', 'returnafter');
        $returnafter_urls = array(0 => z_root() . '/profile/' . ($_REQUEST['profile'] ? $_REQUEST['profile'] . '/view' : $chan['channel_address']), 1 => z_root() . '/profiles/' . ($_REQUEST['profile'] ? $_REQUEST['profile'] : App::$profile_uid), 2 => z_root() . '/profiles');
        goaway($returnafter_urls[$returnafter]);
    } else {
        //invoked as module, we place in content pane the same as we would for the end of the profile photo page. Also handles json for endless scroll for either invokation.
        openclipatar_profile_photo_content_end($a, $o);
    }
    return $o;
}
Пример #5
0
 function post()
 {
     if (!local_channel()) {
         return;
     }
     $contact_id = intval(argv(1));
     if (!$contact_id) {
         return;
     }
     $channel = \App::get_channel();
     // TODO if configured for hassle-free permissions, we'll post the form with ajax as soon as the
     // connection enable is toggled to a special autopost url and set permissions immediately, leaving
     // the other form elements alone pending a manual submit of the form. The downside is that there
     // will be a window of opportunity when the permissions have been set but before you've had a chance
     // to review and possibly restrict them. The upside is we won't have to warn you that your connection
     // can't do anything until you save the bloody form.
     $autopost = argc() > 2 && argv(2) === 'auto' ? true : false;
     $orig_record = q("SELECT * FROM abook WHERE abook_id = %d AND abook_channel = %d LIMIT 1", intval($contact_id), intval(local_channel()));
     if (!$orig_record) {
         notice(t('Could not access contact record.') . EOL);
         goaway(z_root() . '/connections');
         return;
         // NOTREACHED
     }
     call_hooks('contact_edit_post', $_POST);
     if (intval($orig_record[0]['abook_self'])) {
         $autoperms = intval($_POST['autoperms']);
         $is_self = true;
     } else {
         $autoperms = null;
         $is_self = false;
     }
     $profile_id = $_POST['profile_assign'];
     if ($profile_id) {
         $r = q("SELECT profile_guid FROM profile WHERE profile_guid = '%s' AND `uid` = %d LIMIT 1", dbesc($profile_id), intval(local_channel()));
         if (!count($r)) {
             notice(t('Could not locate selected profile.') . EOL);
             return;
         }
     }
     $abook_incl = escape_tags($_POST['abook_incl']);
     $abook_excl = escape_tags($_POST['abook_excl']);
     $hidden = intval($_POST['hidden']);
     $priority = intval($_POST['poll']);
     if ($priority > 5 || $priority < 0) {
         $priority = 0;
     }
     $closeness = intval($_POST['closeness']);
     if ($closeness < 0) {
         $closeness = 99;
     }
     $rating = intval($_POST['rating']);
     if ($rating < -10) {
         $rating = -10;
     }
     if ($rating > 10) {
         $rating = 10;
     }
     $rating_text = trim(escape_tags($_REQUEST['rating_text']));
     $abook_my_perms = 0;
     foreach ($_POST as $k => $v) {
         if (strpos($k, 'perms_') === 0) {
             $abook_my_perms += $v;
         }
     }
     $new_friend = false;
     if (!$is_self) {
         $signed = $orig_record[0]['abook_xchan'] . '.' . $rating . '.' . $rating_text;
         $sig = base64url_encode(rsa_sign($signed, $channel['channel_prvkey']));
         $z = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1 limit 1", dbesc($channel['channel_hash']), dbesc($orig_record[0]['abook_xchan']));
         if ($z) {
             $record = $z[0]['xlink_id'];
             $w = q("update xlink set xlink_rating = '%d', xlink_rating_text = '%s', xlink_sig = '%s', xlink_updated = '%s'\n\t\t\t\t\twhere xlink_id = %d", intval($rating), dbesc($rating_text), dbesc($sig), dbesc(datetime_convert()), intval($record));
         } else {
             $w = q("insert into xlink ( xlink_xchan, xlink_link, xlink_rating, xlink_rating_text, xlink_sig, xlink_updated, xlink_static ) values ( '%s', '%s', %d, '%s', '%s', '%s', 1 ) ", dbesc($channel['channel_hash']), dbesc($orig_record[0]['abook_xchan']), intval($rating), dbesc($rating_text), dbesc($sig), dbesc(datetime_convert()));
             $z = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1 limit 1", dbesc($channel['channel_hash']), dbesc($orig_record[0]['abook_xchan']));
             if ($z) {
                 $record = $z[0]['xlink_id'];
             }
         }
         if ($record) {
             proc_run('php', 'include/ratenotif.php', 'rating', $record);
         }
     }
     if ($_REQUEST['pending'] && intval($orig_record[0]['abook_pending'])) {
         $new_friend = true;
         // @fixme it won't be common, but when you accept a new connection request
         // the permissions will now be that of your permissions role and ignore
         // any you may have set manually on the form. We'll probably see a bug if somebody
         // tries to set the permissions *and* approve the connection in the same
         // request. The workaround is to approve the connection, then go back and
         // adjust permissions as desired.
         $abook_my_perms = get_channel_default_perms(local_channel());
         $role = get_pconfig(local_channel(), 'system', 'permissions_role');
         if ($role) {
             $x = get_role_perms($role);
             if ($x['perms_accept']) {
                 $abook_my_perms = $x['perms_accept'];
             }
         }
     }
     $abook_pending = $new_friend ? 0 : $orig_record[0]['abook_pending'];
     $r = q("UPDATE abook SET abook_profile = '%s', abook_my_perms = %d , abook_closeness = %d, abook_pending = %d,\n\t\t\tabook_incl = '%s', abook_excl = '%s'\n\t\t\twhere abook_id = %d AND abook_channel = %d", dbesc($profile_id), intval($abook_my_perms), intval($closeness), intval($abook_pending), dbesc($abook_incl), dbesc($abook_excl), intval($contact_id), intval(local_channel()));
     if ($orig_record[0]['abook_profile'] != $profile_id) {
         //Update profile photo permissions
         logger('A new profile was assigned - updating profile photos');
         profile_photo_set_profile_perms($profile_id);
     }
     if ($r) {
         info(t('Connection updated.') . EOL);
     } else {
         notice(t('Failed to update connection record.') . EOL);
     }
     if (\App::$poi && \App::$poi['abook_my_perms'] != $abook_my_perms && !intval(\App::$poi['abook_self'])) {
         proc_run('php', 'include/notifier.php', $new_friend ? 'permission_create' : 'permission_update', $contact_id);
     }
     if ($new_friend) {
         $default_group = $channel['channel_default_group'];
         if ($default_group) {
             require_once 'include/group.php';
             $g = group_rec_byhash(local_channel(), $default_group);
             if ($g) {
                 group_add_member(local_channel(), '', \App::$poi['abook_xchan'], $g['id']);
             }
         }
         // Check if settings permit ("post new friend activity" is allowed, and
         // friends in general or this friend in particular aren't hidden)
         // and send out a new friend activity
         $pr = q("select * from profile where uid = %d and is_default = 1 and hide_friends = 0", intval($channel['channel_id']));
         if ($pr && !intval($orig_record[0]['abook_hidden']) && intval(get_pconfig($channel['channel_id'], 'system', 'post_newfriend'))) {
             $xarr = array();
             $xarr['verb'] = ACTIVITY_FRIEND;
             $xarr['item_wall'] = 1;
             $xarr['item_origin'] = 1;
             $xarr['item_thread_top'] = 1;
             $xarr['owner_xchan'] = $xarr['author_xchan'] = $channel['channel_hash'];
             $xarr['allow_cid'] = $channel['channel_allow_cid'];
             $xarr['allow_gid'] = $channel['channel_allow_gid'];
             $xarr['deny_cid'] = $channel['channel_deny_cid'];
             $xarr['deny_gid'] = $channel['channel_deny_gid'];
             $xarr['item_private'] = $xarr['allow_cid'] || $xarr['allow_gid'] || $xarr['deny_cid'] || $xarr['deny_gid'] ? 1 : 0;
             $obj = array('type' => ACTIVITY_OBJ_PERSON, 'title' => \App::$poi['xchan_name'], 'id' => \App::$poi['xchan_hash'], 'link' => array(array('rel' => 'alternate', 'type' => 'text/html', 'href' => \App::$poi['xchan_url']), array('rel' => 'photo', 'type' => \App::$poi['xchan_photo_mimetype'], 'href' => \App::$poi['xchan_photo_l'])));
             $xarr['object'] = json_encode($obj);
             $xarr['obj_type'] = ACTIVITY_OBJ_PERSON;
             $xarr['body'] = '[zrl=' . $channel['xchan_url'] . ']' . $channel['xchan_name'] . '[/zrl]' . ' ' . t('is now connected to') . ' ' . '[zrl=' . \App::$poi['xchan_url'] . ']' . \App::$poi['xchan_name'] . '[/zrl]';
             $xarr['body'] .= "\n\n\n" . '[zrl=' . \App::$poi['xchan_url'] . '][zmg=80x80]' . \App::$poi['xchan_photo_m'] . '[/zmg][/zrl]';
             post_activity_item($xarr);
         }
         // pull in a bit of content if there is any to pull in
         proc_run('php', 'include/onepoll.php', $contact_id);
     }
     // Refresh the structure in memory with the new data
     $r = q("SELECT abook.*, xchan.*\n\t\t\tFROM abook left join xchan on abook_xchan = xchan_hash\n\t\t\tWHERE abook_channel = %d and abook_id = %d LIMIT 1", intval(local_channel()), intval($contact_id));
     if ($r) {
         \App::$poi = $r[0];
     }
     if ($new_friend) {
         $arr = array('channel_id' => local_channel(), 'abook' => \App::$poi);
         call_hooks('accept_follow', $arr);
     }
     if (!is_null($autoperms)) {
         set_pconfig(local_channel(), 'system', 'autoperms', $autoperms ? $abook_my_perms : 0);
     }
     $this->connedit_clone($a);
     if ($_REQUEST['pending'] && !$_REQUEST['done']) {
         goaway(z_root() . '/connections/ifpending');
     }
     return;
 }
Пример #6
0
 function get()
 {
     if (!local_channel()) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     $channel = \App::get_channel();
     $newuser = false;
     if (argc() == 2 && argv(1) === 'new') {
         $newuser = true;
     }
     if (argv(1) === 'use') {
         if (argc() < 3) {
             notice(t('Permission denied.') . EOL);
             return;
         }
         $resource_id = argv(2);
         // When using an existing photo, we don't have a dialogue to offer a choice of profiles,
         // so it gets attached to the default
         $p = q("select id from profile where is_default = 1 and uid = %d", intval(local_channel()));
         if ($p) {
             $_REQUEST['profile'] = $p[0]['id'];
         }
         $r = q("SELECT id, album, imgscale FROM photo WHERE uid = %d AND resource_id = '%s' ORDER BY imgscale ASC", intval(local_channel()), dbesc($resource_id));
         if (!$r) {
             notice(t('Photo not available.') . EOL);
             return;
         }
         $havescale = false;
         foreach ($r as $rr) {
             if ($rr['imgscale'] == PHOTO_RES_PROFILE_80) {
                 $havescale = true;
             }
         }
         // set an already loaded and cropped photo as profile photo
         if ($r[0]['album'] == t('Profile Photos') && $havescale) {
             // unset any existing profile photos
             $r = q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND uid = %d", intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval(local_channel()));
             $r = q("UPDATE photo SET photo_usage = %d WHERE uid = %d AND resource_id = '%s'", intval(PHOTO_PROFILE), intval(local_channel()), dbesc($resource_id));
             $r = q("UPDATE xchan set xchan_photo_date = '%s' \n\t\t\t\t\twhere xchan_hash = '%s'", dbesc(datetime_convert()), dbesc($channel['xchan_hash']));
             profile_photo_set_profile_perms(local_channel());
             // Reset default photo permissions to public
             \Zotlabs\Daemon\Master::Summon(array('Directory', local_channel()));
             goaway(z_root() . '/profiles');
         }
         $r = q("SELECT content, mimetype, resource_id, os_storage FROM photo WHERE id = %d and uid = %d limit 1", intval($r[0]['id']), intval(local_channel()));
         if (!$r) {
             notice(t('Photo not available.') . EOL);
             return;
         }
         if (intval($r[0]['os_storage'])) {
             $data = @file_get_contents($r[0]['content']);
         } else {
             $data = dbunescbin($r[0]['content']);
         }
         $ph = photo_factory($data, $r[0]['mimetype']);
         $smallest = 0;
         if ($ph->is_valid()) {
             // go ahead as if we have just uploaded a new photo to crop
             $i = q("select resource_id, imgscale from photo where resource_id = '%s' and uid = %d order by imgscale", dbesc($r[0]['resource_id']), intval(local_channel()));
             if ($i) {
                 $hash = $i[0]['resource_id'];
                 foreach ($i as $ii) {
                     if (intval($ii['imgscale']) < PHOTO_RES_640) {
                         $smallest = intval($ii['imgscale']);
                     }
                 }
             }
         }
         $this->profile_photo_crop_ui_head($a, $ph, $hash, $smallest);
         // falls through with App::$data['imagecrop'] set so we go straight to the cropping section
     }
     // present an upload form
     $profiles = q("select id, profile_name as name, is_default from profile where uid = %d order by id asc", intval(local_channel()));
     if (!x(\App::$data, 'imagecrop')) {
         $tpl = get_markup_template('profile_photo.tpl');
         $o .= replace_macros($tpl, array('$user' => \App::$channel['channel_address'], '$lbl_upfile' => t('Upload File:'), '$lbl_profiles' => t('Select a profile:'), '$title' => t('Upload Profile Photo'), '$submit' => t('Upload'), '$profiles' => $profiles, '$single' => count($profiles) == 1 ? true : false, '$profile0' => $profiles[0], '$form_security_token' => get_form_security_token("profile_photo"), '$select' => sprintf('%s %s', t('or'), $newuser ? '<a href="' . z_root() . '">' . t('skip this step') . '</a>' : '<a href="' . z_root() . '/photos/' . \App::$channel['channel_address'] . '">' . t('select a photo from your photo albums') . '</a>')));
         call_hooks('profile_photo_content_end', $o);
         return $o;
     } else {
         // present a cropping form
         $filename = \App::$data['imagecrop'] . '-' . \App::$data['imagecrop_resolution'];
         $resolution = \App::$data['imagecrop_resolution'];
         $tpl = get_markup_template("cropbody.tpl");
         $o .= replace_macros($tpl, array('$filename' => $filename, '$profile' => intval($_REQUEST['profile']), '$resource' => \App::$data['imagecrop'] . '-' . \App::$data['imagecrop_resolution'], '$image_url' => z_root() . '/photo/' . $filename, '$title' => t('Crop Image'), '$desc' => t('Please adjust the image cropping for optimum viewing.'), '$form_security_token' => get_form_security_token("profile_photo"), '$done' => t('Done Editing')));
         return $o;
     }
     return;
     // NOTREACHED
 }
Пример #7
0
function connedit_post(&$a)
{
    if (!local_user()) {
        return;
    }
    $contact_id = intval(argv(1));
    if (!$contact_id) {
        return;
    }
    $orig_record = q("SELECT * FROM abook WHERE abook_id = %d AND abook_channel = %d LIMIT 1", intval($contact_id), intval(local_user()));
    if (!$orig_record) {
        notice(t('Could not access contact record.') . EOL);
        goaway($a->get_baseurl(true) . '/connections');
        return;
        // NOTREACHED
    }
    call_hooks('contact_edit_post', $_POST);
    $profile_id = $_POST['profile_assign'];
    if ($profile_id) {
        $r = q("SELECT profile_guid FROM profile WHERE profile_guid = '%s' AND `uid` = %d LIMIT 1", dbesc($profile_id), intval(local_user()));
        if (!count($r)) {
            notice(t('Could not locate selected profile.') . EOL);
            return;
        }
    }
    $hidden = intval($_POST['hidden']);
    $priority = intval($_POST['poll']);
    if ($priority > 5 || $priority < 0) {
        $priority = 0;
    }
    $closeness = intval($_POST['closeness']);
    if ($closeness < 0) {
        $closeness = 99;
    }
    $abook_my_perms = 0;
    foreach ($_POST as $k => $v) {
        if (strpos($k, 'perms_') === 0) {
            $abook_my_perms += $v;
        }
    }
    $abook_flags = $orig_record[0]['abook_flags'];
    $new_friend = false;
    if ($_REQUEST['pending'] && $abook_flags & ABOOK_FLAG_PENDING) {
        $abook_flags = $abook_flags ^ ABOOK_FLAG_PENDING;
        $new_friend = true;
    }
    $r = q("UPDATE abook SET abook_profile = '%s', abook_my_perms = %d , abook_closeness = %d, abook_flags = %d\n\t\twhere abook_id = %d AND abook_channel = %d LIMIT 1", dbesc($profile_id), intval($abook_my_perms), intval($closeness), intval($abook_flags), intval($contact_id), intval(local_user()));
    if ($orig_record[0]['abook_profile'] != $profile_id) {
        //Update profile photo permissions
        logger('As a new profile was assigned updating profile photos');
        require_once 'mod/profile_photo.php';
        profile_photo_set_profile_perms($profile_id);
    }
    if ($r) {
        info(t('Connection updated.') . EOL);
    } else {
        notice(t('Failed to update connection record.') . EOL);
    }
    if ($a->poi && $a->poi['abook_my_perms'] != $abook_my_perms && !($a->poi['abook_flags'] & ABOOK_FLAG_SELF)) {
        proc_run('php', 'include/notifier.php', 'permission_update', $contact_id);
    }
    if ($new_friend) {
        $channel = $a->get_channel();
        $default_group = $channel['channel_default_group'];
        if ($default_group) {
            require_once 'include/group.php';
            $g = group_rec_byhash(local_user(), $default_group);
            if ($g) {
                group_add_member(local_user(), '', $a->poi['abook_xchan'], $g['id']);
            }
        }
        // Check if settings permit ("post new friend activity" is allowed, and
        // friends in general or this friend in particular aren't hidden)
        // and send out a new friend activity
        $pr = q("select * from profile where uid = %d and is_default = 1 and hide_friends = 0", intval($channel['channel_id']));
        if ($pr && !($abook_flags & ABOOK_FLAG_HIDDEN) && intval(get_pconfig($channel['channel_id'], 'system', 'post_newfriend'))) {
            $xarr = array();
            $xarr['verb'] = ACTIVITY_FRIEND;
            $xarr['item_flags'] = ITEM_WALL | ITEM_ORIGIN | ITEM_THREAD_TOP;
            $xarr['owner_xchan'] = $xarr['author_xchan'] = $channel['channel_hash'];
            $xarr['allow_cid'] = $channel['channel_allow_cid'];
            $xarr['allow_gid'] = $channel['channel_allow_gid'];
            $xarr['deny_cid'] = $channel['channel_deny_cid'];
            $xarr['deny_gid'] = $channel['channel_deny_gid'];
            $xarr['item_private'] = $xarr['allow_cid'] || $xarr['allow_gid'] || $xarr['deny_cid'] || $xarr['deny_gid'] ? 1 : 0;
            $obj = array('type' => ACTIVITY_OBJ_PERSON, 'title' => $a->poi['xchan_name'], 'id' => $a->poi['xchan_hash'], 'link' => array(array('rel' => 'alternate', 'type' => 'text/html', 'href' => $a->poi['xchan_url']), array('rel' => 'photo', 'type' => $a->poi['xchan_photo_mimetype'], 'href' => $a->poi['xchan_photo_l'])));
            $xarr['object'] = json_encode($obj);
            $xarr['obj_type'] = ACTIVITY_OBJ_PERSON;
            $xarr['body'] = '[zrl=' . $channel['xchan_url'] . ']' . $channel['xchan_name'] . '[/zrl]' . ' ' . t('is now connected to') . ' ' . '[zrl=' . $a->poi['xchan_url'] . ']' . $a->poi['xchan_name'] . '[/zrl]';
            $xarr['body'] .= "\n\n\n" . '[zrl=' . $a->poi['xchan_url'] . '][zmg=80x80]' . $a->poi['xchan_photo_m'] . '[/zmg][/zrl]';
            post_activity_item($xarr);
        }
        // pull in a bit of content if there is any to pull in
        proc_run('php', 'include/onepoll.php', $contact_id);
    }
    // Refresh the structure in memory with the new data
    $r = q("SELECT abook.*, xchan.* \n\t\tFROM abook left join xchan on abook_xchan = xchan_hash\n\t\tWHERE abook_channel = %d and abook_id = %d LIMIT 1", intval(local_user()), intval($contact_id));
    if ($r) {
        $a->poi = $r[0];
    }
    if ($new_friend) {
        $arr = array('channel_id' => local_user(), 'abook' => $a->poi);
        call_hooks('accept_follow', $arr);
    }
    connedit_clone($a);
    return;
}
Пример #8
0
 function profile_photo_content(&$a)
 {
     if (!local_user()) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     $channel = $a->get_channel();
     $newuser = false;
     if (argc() == 2 && argv(1) === 'new') {
         $newuser = true;
     }
     if (argv(1) === 'use') {
         if (argc() < 3) {
             notice(t('Permission denied.') . EOL);
             return;
         }
         //		check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo');
         $resource_id = argv(2);
         $r = q("SELECT id, album, scale FROM photo WHERE uid = %d AND resource_id = '%s' ORDER BY scale ASC", intval(local_user()), dbesc($resource_id));
         if (!$r) {
             notice(t('Photo not available.') . EOL);
             return;
         }
         $havescale = false;
         foreach ($r as $rr) {
             if ($rr['scale'] == 5) {
                 $havescale = true;
             }
         }
         // set an already loaded photo as profile photo
         if ($r[0]['album'] == t('Profile Photos') && $havescale) {
             // unset any existing profile photos
             $r = q("UPDATE photo SET profile = 0 WHERE profile = 1 AND uid = %d", intval(local_user()));
             $r = q("UPDATE photo SET photo_flags = (photo_flags ^ %d ) WHERE (photo_flags & %d ) AND uid = %d", intval(PHOTO_PROFILE), intval(PHOTO_PROFILE), intval(local_user()));
             // set all sizes of this one as profile photos
             $r = q("UPDATE photo SET profile = 1 WHERE uid = %d AND resource_id = '%s'", intval(local_user()), dbesc($resource_id));
             $r = q("UPDATE photo SET photo_flags = ( photo_flags | %d ) WHERE uid = %d AND resource_id = '%s'", intval(PHOTO_PROFILE), intval(local_user()), dbesc($resource_id));
             $r = q("UPDATE xchan set xchan_photo_date = '%s' \n\t\t\t\twhere xchan_hash = '%s' limit 1", dbesc(datetime_convert()), dbesc($channel['xchan_hash']));
             profile_photo_set_profile_perms();
             //Reset default photo permissions to public
             proc_run('php', 'include/directory.php', local_user());
             goaway($a->get_baseurl() . '/profiles');
         }
         $r = q("SELECT `data`, `type` FROM photo WHERE id = %d and uid = %d limit 1", intval($r[0]['id']), intval(local_user()));
         if (!$r) {
             notice(t('Photo not available.') . EOL);
             return;
         }
         $ph = photo_factory($r[0]['data'], $r[0]['type']);
         // go ahead as if we have just uploaded a new photo to crop
         profile_photo_crop_ui_head($a, $ph);
     }
     $profiles = q("select id, profile_name as name, is_default from profile where uid = %d", intval(local_user()));
     if (!x($a->data, 'imagecrop')) {
         $tpl = get_markup_template('profile_photo.tpl');
         $o .= replace_macros($tpl, array('$user' => $a->channel['channel_address'], '$lbl_upfile' => t('Upload File:'), '$lbl_profiles' => t('Select a profile:'), '$title' => t('Upload Profile Photo'), '$submit' => t('Upload'), '$profiles' => $profiles, '$form_security_token' => get_form_security_token("profile_photo"), '$select' => sprintf('%s %s', t('or'), $newuser ? '<a href="' . $a->get_baseurl() . '">' . t('skip this step') . '</a>' : '<a href="' . $a->get_baseurl() . '/photos/' . $a->channel['channel_address'] . '">' . t('select a photo from your photo albums') . '</a>')));
         return $o;
     } else {
         $filename = $a->data['imagecrop'] . '-' . $a->data['imagecrop_resolution'] . '.' . $a->data['imagecrop_ext'];
         $resolution = $a->data['imagecrop_resolution'];
         $tpl = get_markup_template("cropbody.tpl");
         $o .= replace_macros($tpl, array('$filename' => $filename, '$profile' => intval($_REQUEST['profile']), '$resource' => $a->data['imagecrop'] . '-' . $a->data['imagecrop_resolution'], '$image_url' => $a->get_baseurl() . '/photo/' . $filename, '$title' => t('Crop Image'), '$desc' => t('Please adjust the image cropping for optimum viewing.'), '$form_security_token' => get_form_security_token("profile_photo"), '$done' => t('Done Editing')));
         return $o;
     }
     return;
     // NOTREACHED
 }