Example #1
0
function bookmarks_content(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    require_once 'include/menu.php';
    require_once 'include/conversation.php';
    $channel = $a->get_channel();
    $o = profile_tabs($a, true, $channel['channel_address']);
    $o .= '<h3>' . t('My Bookmarks') . '</h3>';
    $x = menu_list(local_user(), '', MENU_BOOKMARK);
    if ($x) {
        foreach ($x as $xx) {
            $y = menu_fetch($xx['menu_name'], local_user(), get_observer_hash());
            $o .= menu_render($y, '', true);
        }
    }
    $o .= '<h3>' . t('My Connections Bookmarks') . '</h3>';
    $x = menu_list(local_user(), '', MENU_SYSTEM | MENU_BOOKMARK);
    if ($x) {
        foreach ($x as $xx) {
            $y = menu_fetch($xx['menu_name'], local_user(), get_observer_hash());
            $o .= menu_render($y, '', true);
        }
    }
    return $o;
}
 function get()
 {
     if (!local_channel()) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     $channel = \App::get_channel();
     $is_owner = local_channel() && local_channel() == $channel['channel_id'];
     //check for updated items and remove them
     require_once 'include/sharedwithme.php';
     apply_updates();
     //drop single file - localuser
     if (argc() > 2 && argv(2) === 'drop') {
         $id = intval(argv(1));
         q("DELETE FROM item WHERE id = %d AND uid = %d", intval($id), intval(local_channel()));
         goaway(z_root() . '/sharedwithme');
     }
     //drop all files - localuser
     if (argc() > 1 && argv(1) === 'dropall') {
         q("DELETE FROM item WHERE verb = '%s' AND obj_type = '%s' AND uid = %d", dbesc(ACTIVITY_POST), dbesc(ACTIVITY_OBJ_FILE), intval(local_channel()));
         goaway(z_root() . '/sharedwithme');
     }
     //list files
     $r = q("SELECT id, uid, object, item_unseen FROM item WHERE verb = '%s' AND obj_type = '%s' AND uid = %d AND owner_xchan != '%s'", dbesc(ACTIVITY_POST), dbesc(ACTIVITY_OBJ_FILE), intval(local_channel()), dbesc($channel['channel_hash']));
     $items = array();
     $ids = '';
     if ($r) {
         foreach ($r as $rr) {
             $object = json_decode($rr['object'], true);
             $item = array();
             $item['id'] = $rr['id'];
             $item['objfiletype'] = $object['filetype'];
             $item['objfiletypeclass'] = getIconFromType($object['filetype']);
             $item['objurl'] = rawurldecode(get_rel_link($object['link'], 'alternate')) . '?f=&zid=' . $channel['xchan_addr'];
             $item['objfilename'] = $object['filename'];
             $item['objfilesize'] = userReadableSize($object['filesize']);
             $item['objedited'] = $object['edited'];
             $item['unseen'] = $rr['item_unseen'];
             $items[] = $item;
             if ($item['unseen'] > 0) {
                 $ids .= " '" . $rr['id'] . "',";
             }
         }
     }
     if ($ids) {
         //remove trailing ,
         $ids = rtrim($ids, ",");
         q("UPDATE item SET item_unseen = 0 WHERE id IN ( {$ids} ) AND uid = %d", intval(local_channel()));
     }
     $o = profile_tabs($a, $is_owner, $channel['channel_address']);
     $o .= replace_macros(get_markup_template('sharedwithme.tpl'), array('$header' => t('Files: shared with me'), '$name' => t('Name'), '$label_new' => t('NEW'), '$size' => t('Size'), '$lastmod' => t('Last Modified'), '$dropall' => t('Remove all files'), '$drop' => t('Remove this file'), '$items' => $items));
     return $o;
 }
Example #3
0
function notes_content(&$a, $update = false)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    require_once "include/bbcode.php";
    require_once 'include/security.php';
    require_once 'include/conversation.php';
    require_once 'include/acl_selectors.php';
    $groups = array();
    $o = '';
    $remote_contact = false;
    $contact_id = $_SESSION['cid'];
    $contact = $a->contact;
    $is_owner = true;
    $o = "";
    $o .= profile_tabs($a, True);
    if (!$update) {
        $o .= '<h3>' . t('Personal Notes') . '</h3>';
        $commpage = false;
        $commvisitor = false;
        $celeb = false;
        $x = array('is_owner' => $is_owner, 'allow_location' => $a->user['allow_location'] ? true : false, 'default_location' => $a->user['default-location'], 'nickname' => $a->user['nickname'], 'lockstate' => 'lock', 'acl' => '', 'bang' => '', 'visitor' => 'block', 'profile_uid' => local_user(), 'button' => t('Save'), 'acl_data' => '');
        $o .= status_editor($a, $x, $a->contact['id']);
    }
    // Construct permissions
    // default permissions - anonymous user
    $sql_extra = " AND `allow_cid` = '<" . $a->contact['id'] . ">' ";
    $r = q("SELECT COUNT(*) AS `total`\n\t\tFROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\tWHERE `item`.`uid` = %d AND `item`.`visible` = 1 and `item`.`moderated` = 0 \n\t\tAND `item`.`deleted` = 0 AND `item`.`type` = 'note'\n\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`self` = 1\n\t\tAND `item`.`id` = `item`.`parent` AND `item`.`wall` = 0\n\t\t{$sql_extra} ", intval(local_user()));
    if (count($r)) {
        $a->set_pager_total($r[0]['total']);
        $a->set_pager_itemspage(40);
    }
    $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact-uid`\n\t\tFROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\tWHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 \n\t\tand `item`.`moderated` = 0 AND `item`.`type` = 'note'\n\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`self` = 1\n\t\tAND `item`.`id` = `item`.`parent` AND `item`.`wall` = 0\n\t\t{$sql_extra}\n\t\tORDER BY `item`.`created` DESC LIMIT %d ,%d ", intval(local_user()), intval($a->pager['start']), intval($a->pager['itemspage']));
    $parents_arr = array();
    $parents_str = '';
    if (count($r)) {
        foreach ($r as $rr) {
            $parents_arr[] = $rr['item_id'];
        }
        $parents_str = implode(', ', $parents_arr);
        $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, \n\t\t\t`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`network`, `contact`.`rel`, \n\t\t\t`contact`.`thumb`, `contact`.`self`, `contact`.`writable`, \n\t\t\t`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`\n\t\t\tFROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\t\tWHERE `item`.`uid` = %d AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0\n\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\tAND `item`.`parent` IN ( %s )\n\t\t\t{$sql_extra}\n\t\t\tORDER BY `parent` DESC, `gravity` ASC, `item`.`id` ASC ", intval(local_user()), dbesc($parents_str));
        if (count($r)) {
            $items = conv_sort($r, "`commented`");
            $o .= conversation($a, $items, 'notes', $update);
        }
    }
    $o .= paginate($a);
    return $o;
}
Example #4
0
function viewcontacts_content(&$a)
{
    require_once "mod/proxy.php";
    if (get_config('system', 'block_public') && !local_user() && !remote_user()) {
        notice(t('Public access denied.') . EOL);
        return;
    }
    if (!count($a->profile) || $a->profile['hide-friends']) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $o = "";
    // tabs
    $o .= profile_tabs($a, $is_owner, $a->data['user']['nickname']);
    $r = q("SELECT COUNT(*) AS `total` FROM `contact`\n\t\tWHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0\n\t\t\tAND `network` IN ('%s', '%s', '%s')", intval($a->profile['uid']), dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
    if (count($r)) {
        $a->set_pager_total($r[0]['total']);
    }
    $r = q("SELECT * FROM `contact`\n\t\tWHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0\n\t\t\tAND `network` IN ('%s', '%s', '%s')\n\t\tORDER BY `name` ASC LIMIT %d, %d", intval($a->profile['uid']), dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS), intval($a->pager['start']), intval($a->pager['itemspage']));
    if (!count($r)) {
        info(t('No contacts.') . EOL);
        return $o;
    }
    $contacts = array();
    foreach ($r as $rr) {
        if ($rr['self']) {
            continue;
        }
        $url = $rr['url'];
        // route DFRN profiles through the redirect
        $is_owner = local_user() && $a->profile['profile_uid'] == local_user() ? true : false;
        if ($is_owner && $rr['network'] === NETWORK_DFRN && $rr['rel']) {
            $url = 'redir/' . $rr['id'];
        } else {
            $url = zrl($url);
        }
        $contact_details = get_contact_details_by_url($rr['url'], $a->profile['uid']);
        $contacts[] = array('id' => $rr['id'], 'img_hover' => sprintf(t('Visit %s\'s profile [%s]'), $rr['name'], $rr['url']), 'photo_menu' => contact_photo_menu($rr), 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB), 'name' => htmlentities(substr($rr['name'], 0, 20)), 'username' => htmlentities($rr['name']), 'details' => $contact_details['location'], 'tags' => $contact_details['keywords'], 'about' => $contact_details['about'], 'account_type' => $contact_details['community'] ? t('Forum') : '', 'url' => $url, 'sparkle' => '', 'itemurl' => $contact_details['addr'] != "" ? $contact_details['addr'] : $rr['url'], 'network' => network_to_name($rr['network'], $rr['url']));
    }
    $tpl = get_markup_template("viewcontact_template.tpl");
    $o .= replace_macros($tpl, array('$title' => t('Contacts'), '$contacts' => $contacts, '$paginate' => paginate($a)));
    return $o;
}
Example #5
0
function profile_content(&$a, $update = 0)
{
    if (get_config('system', 'block_public') && !get_account_id() && !remote_channel()) {
        return login();
    }
    $groups = array();
    $tab = 'profile';
    $o = '';
    if (!perm_is_allowed($a->profile['profile_uid'], get_observer_hash(), 'view_profile')) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $is_owner = local_channel() && local_channel() == $a->profile['profile_uid'] ? true : false;
    if ($a->profile['hidewall'] && !$is_owner && !remote_channel()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $o .= profile_tabs($a, $is_owner, $a->profile['channel_address']);
    $o .= advanced_profile($a);
    call_hooks('profile_advanced', $o);
    return $o;
}
Example #6
0
function profile_content(&$a, $update = 0)
{
    if (get_config('system', 'block_public') && !get_account_id() && !remote_channel()) {
        return login();
    }
    $groups = array();
    $tab = 'profile';
    $o = '';
    if (!perm_is_allowed($a->profile['profile_uid'], get_observer_hash(), 'view_profile')) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $is_owner = local_channel() && local_channel() == $a->profile['profile_uid'] ? true : false;
    if ($a->profile['hidewall'] && !$is_owner && !remote_channel()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $o .= profile_tabs($a, $is_owner, $a->profile['channel_address']);
    $a->page['htmlhead'] .= "\r\n" . '<link rel="alternate" type="application/json+oembed" href="' . z_root() . '/oep?f=&url=' . urlencode(z_root() . '/' . $a->query_string) . '" title="oembed" />' . "\r\n";
    $o .= advanced_profile($a);
    call_hooks('profile_advanced', $o);
    return $o;
}
Example #7
0
 function get()
 {
     if (observer_prohibited(true)) {
         return login();
     }
     $groups = array();
     $tab = 'profile';
     $o = '';
     if (!perm_is_allowed(\App::$profile['profile_uid'], get_observer_hash(), 'view_profile')) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     $is_owner = local_channel() && local_channel() == \App::$profile['profile_uid'] ? true : false;
     if (\App::$profile['hidewall'] && !$is_owner && !remote_channel()) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     $o .= profile_tabs($a, $is_owner, \App::$profile['channel_address']);
     \App::$page['htmlhead'] .= "\r\n" . '<link rel="alternate" type="application/json+oembed" href="' . z_root() . '/oep?f=&url=' . urlencode(z_root() . '/' . \App::$query_string) . '" title="oembed" />' . "\r\n";
     $o .= advanced_profile($a);
     call_hooks('profile_advanced', $o);
     return $o;
 }
Example #8
0
function photos_content(&$a)
{
    // URLs:
    // photos/name
    // photos/name/upload
    // photos/name/upload/xxxxx (xxxxx is album name)
    // photos/name/album/xxxxx
    // photos/name/album/xxxxx/edit
    // photos/name/image/xxxxx
    // photos/name/image/xxxxx/edit
    if (get_config('system', 'block_public') && !local_user() && !remote_user()) {
        notice(t('Public access denied.') . EOL);
        return;
    }
    require_once 'include/bbcode.php';
    require_once 'include/security.php';
    require_once 'include/conversation.php';
    if (!x($a->data, 'user')) {
        notice(t('No photos selected') . EOL);
        return;
    }
    $phototypes = Photo::supportedTypes();
    $_SESSION['photo_return'] = $a->cmd;
    //
    // Parse arguments
    //
    if ($a->argc > 3) {
        $datatype = $a->argv[2];
        $datum = $a->argv[3];
    } elseif ($a->argc > 2 && $a->argv[2] === 'upload') {
        $datatype = 'upload';
    } else {
        $datatype = 'summary';
    }
    if ($a->argc > 4) {
        $cmd = $a->argv[4];
    } else {
        $cmd = 'view';
    }
    //
    // Setup permissions structures
    //
    $can_post = false;
    $visitor = 0;
    $contact = null;
    $remote_contact = false;
    $contact_id = 0;
    $owner_uid = $a->data['user']['uid'];
    $community_page = $a->data['user']['page-flags'] == PAGE_COMMUNITY ? true : false;
    if (local_user() && local_user() == $owner_uid) {
        $can_post = true;
    } else {
        if ($community_page && remote_user()) {
            if (is_array($_SESSION['remote'])) {
                foreach ($_SESSION['remote'] as $v) {
                    if ($v['uid'] == $owner_uid) {
                        $contact_id = $v['cid'];
                        break;
                    }
                }
            }
            if ($contact_id) {
                $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), intval($owner_uid));
                if (count($r)) {
                    $can_post = true;
                    $contact = $r[0];
                    $remote_contact = true;
                    $visitor = $cid;
                }
            }
        }
    }
    // perhaps they're visiting - but not a community page, so they wouldn't have write access
    if (remote_user() && !$visitor) {
        $contact_id = 0;
        if (is_array($_SESSION['remote'])) {
            foreach ($_SESSION['remote'] as $v) {
                if ($v['uid'] == $owner_uid) {
                    $contact_id = $v['cid'];
                    break;
                }
            }
        }
        if ($contact_id) {
            $groups = init_groups_visitor($contact_id);
            $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), intval($owner_uid));
            if (count($r)) {
                $contact = $r[0];
                $remote_contact = true;
            }
        }
    }
    if (!$remote_contact) {
        if (local_user()) {
            $contact_id = $_SESSION['cid'];
            $contact = $a->contact;
        }
    }
    if ($a->data['user']['hidewall'] && local_user() != $owner_uid && !$remote_contact) {
        notice(t('Access to this item is restricted.') . EOL);
        return;
    }
    $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
    $o = "";
    // tabs
    $_is_owner = local_user() && local_user() == $owner_uid;
    $o .= profile_tabs($a, $_is_owner, $a->data['user']['nickname']);
    //
    // dispatch request
    //
    if ($datatype === 'upload') {
        if (!$can_post) {
            notice(t('Permission denied.'));
            return;
        }
        $selname = $datum ? hex2bin($datum) : '';
        $albumselect = '';
        $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
        if (count($a->data['albums'])) {
            foreach ($a->data['albums'] as $album) {
                if ($album['album'] === '' || $album['album'] === 'Contact Photos' || $album['album'] === t('Contact Photos')) {
                    continue;
                }
                $selected = $selname === $album['album'] ? ' selected="selected" ' : '';
                $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
            }
        }
        $celeb = $a->user['page-flags'] == PAGE_SOAPBOX || $a->user['page-flags'] == PAGE_COMMUNITY ? true : false;
        $uploader = '';
        $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'], 'addon_text' => $uploader, 'default_upload' => true);
        call_hooks('photo_upload_form', $ret);
        $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), array());
        $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), array('$submit' => t('Submit')));
        $usage_message = '';
        $limit = service_class_fetch($a->data['user']['uid'], 'photo_upload_limit');
        if ($limit !== false) {
            $r = q("select sum(datasize) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ", intval($a->data['user']['uid']));
            $usage_message = sprintf(t("You have used %1\$.2f Mbytes of %2\$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000);
        }
        // Private/public post links for the non-JS ACL form
        $private_post = 1;
        if ($_REQUEST['public']) {
            $private_post = 0;
        }
        $query_str = $a->query_string;
        if (strpos($query_str, 'public=1') !== false) {
            $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
        }
        // I think $a->query_string may never have ? in it, but I could be wrong
        // It looks like it's from the index.php?q=[etc] rewrite that the web
        // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
        if (strpos($query_str, '?') === false) {
            $public_post_link = '?public=1';
        } else {
            $public_post_link = '&public=1';
        }
        $tpl = get_markup_template('photos_upload.tpl');
        if ($a->theme['template_engine'] === 'internal') {
            $albumselect_e = template_escape($albumselect);
            $aclselect_e = $visitor ? '' : template_escape(populate_acl($a->user, $celeb));
        } else {
            $albumselect_e = $albumselect;
            $aclselect_e = $visitor ? '' : populate_acl($a->user, $celeb);
        }
        $o .= replace_macros($tpl, array('$pagename' => t('Upload Photos'), '$sessid' => session_id(), '$usage' => $usage_message, '$nickname' => $a->data['user']['nickname'], '$newalbum' => t('New album name: '), '$existalbumtext' => t('or existing album name: '), '$nosharetext' => t('Do not show a status post for this upload'), '$albumselect' => $albumselect_e, '$permissions' => t('Permissions'), '$aclselect' => $aclselect_e, '$alt_uploader' => $ret['addon_text'], '$default_upload_box' => $ret['default_upload'] ? $default_upload_box : '', '$default_upload_submit' => $ret['default_upload'] ? $default_upload_submit : '', '$uploadurl' => $ret['post_url'], '$acl_data' => construct_acl_data($a, $a->user), '$group_perms' => t('Show to Groups'), '$contact_perms' => t('Show to Contacts'), '$private' => t('Private Photo'), '$public' => t('Public Photo'), '$is_private' => $private_post, '$return_path' => $query_str, '$public_link' => $public_post_link));
        return $o;
    }
    if ($datatype === 'album') {
        $album = hex2bin($datum);
        $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s' \n\t\t\tAND `scale` <= 4 {$sql_extra} GROUP BY `resource-id`", intval($owner_uid), dbesc($album));
        if (count($r)) {
            $a->set_pager_total(count($r));
            $a->set_pager_itemspage(20);
        }
        if ($_GET['order'] === 'posted') {
            $order = 'ASC';
        } else {
            $order = 'DESC';
        }
        $r = q("SELECT `resource-id`, `id`, `filename`, type, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s' \n\t\t\tAND `scale` <= 4 {$sql_extra} GROUP BY `resource-id` ORDER BY `created` {$order} LIMIT %d , %d", intval($owner_uid), dbesc($album), intval($a->pager['start']), intval($a->pager['itemspage']));
        $o .= '<h3 id="photo-album-title">' . $album . '</h3>';
        if ($cmd === 'edit') {
            if ($album !== t('Profile Photos') && $album !== 'Contact Photos' && $album !== t('Contact Photos')) {
                if ($can_post) {
                    $edit_tpl = get_markup_template('album_edit.tpl');
                    if ($a->theme['template_engine'] === 'internal') {
                        $album_e = template_escape($album);
                    } else {
                        $album_e = $album;
                    }
                    $o .= replace_macros($edit_tpl, array('$nametext' => t('New album name: '), '$nickname' => $a->data['user']['nickname'], '$album' => $album_e, '$hexalbum' => bin2hex($album), '$submit' => t('Submit'), '$dropsubmit' => t('Delete Album')));
                }
            }
        } else {
            if ($album !== t('Profile Photos') && $album !== 'Contact Photos' && $album !== t('Contact Photos')) {
                if ($can_post) {
                    $o .= '<div id="album-edit-link"><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">' . t('Edit Album') . '</a></div>';
                }
            }
        }
        if ($_GET['order'] === 'posted') {
            $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '" >' . t('Show Newest First') . '</a></div>';
        } else {
            $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted" >' . t('Show Oldest First') . '</a></div>';
        }
        if ($can_post) {
            $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album) . '" >' . t('Upload New Photos') . '</a></div>';
        }
        $tpl = get_markup_template('photo_album.tpl');
        if (count($r)) {
            $twist = 'rotright';
        }
        foreach ($r as $rr) {
            if ($twist == 'rotright') {
                $twist = 'rotleft';
            } else {
                $twist = 'rotright';
            }
            $ext = $phototypes[$rr['type']];
            if ($a->theme['template_engine'] === 'internal') {
                $imgalt_e = template_escape($rr['filename']);
                $desc_e = template_escape($rr['desc']);
            } else {
                $imgalt_e = $rr['filename'];
                $desc_e = $rr['desc'];
            }
            $o .= replace_macros($tpl, array('$id' => $rr['id'], '$twist' => ' ' . $twist . rand(2, 4), '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'] . ($_GET['order'] === 'posted' ? '?f=&order=posted' : ''), '$phototitle' => t('View Photo'), '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' . $ext, '$imgalt' => $imgalt_e, '$desc' => $desc_e));
        }
        $o .= '<div id="photo-album-end"></div>';
        $o .= paginate($a);
        return $o;
    }
    if ($datatype === 'image') {
        //$o = '';
        // fetch image, item containing image, then comments
        $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' \n\t\t\t{$sql_extra} ORDER BY `scale` ASC ", intval($owner_uid), dbesc($datum));
        if (!count($ph)) {
            $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'\n\t\t\t\tLIMIT 1", intval($owner_uid), dbesc($datum));
            if (count($ph)) {
                notice(t('Permission denied. Access to this item may be restricted.'));
            } else {
                notice(t('Photo not available') . EOL);
            }
            return;
        }
        $prevlink = '';
        $nextlink = '';
        if ($_GET['order'] === 'posted') {
            $order = 'ASC';
        } else {
            $order = 'DESC';
        }
        $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0\n\t\t\t{$sql_extra} ORDER BY `created` {$order} ", dbesc($ph[0]['album']), intval($owner_uid));
        if (count($prvnxt)) {
            for ($z = 0; $z < count($prvnxt); $z++) {
                if ($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
                    $prv = $z - 1;
                    $nxt = $z + 1;
                    if ($prv < 0) {
                        $prv = count($prvnxt) - 1;
                    }
                    if ($nxt >= count($prvnxt)) {
                        $nxt = 0;
                    }
                    break;
                }
            }
            $edit_suffix = $cmd === 'edit' && $can_post ? '/edit' : '';
            $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . ($_GET['order'] === 'posted' ? '?f=&order=posted' : '');
            $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . ($_GET['order'] === 'posted' ? '?f=&order=posted' : '');
        }
        if (count($ph) == 1) {
            $hires = $lores = $ph[0];
        }
        if (count($ph) > 1) {
            if ($ph[1]['scale'] == 2) {
                // original is 640 or less, we can display it directly
                $hires = $lores = $ph[0];
            } else {
                $hires = $ph[0];
                $lores = $ph[1];
            }
        }
        $album_link = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
        $tools = Null;
        $lock = Null;
        if ($can_post && $ph[0]['uid'] == $owner_uid) {
            $tools = array('edit' => array($a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . ($cmd === 'edit' ? '' : '/edit'), $cmd === 'edit' ? t('View photo') : t('Edit photo')), 'profile' => array($a->get_baseurl() . '/profile_photo/use/' . $ph[0]['resource-id'], t('Use as profile photo')));
            // lock
            $lock = $ph[0]['uid'] == local_user() && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) ? t('Private Message') : Null;
        }
        if ($cmd === 'edit') {
            $tpl = get_markup_template('photo_edit_head.tpl');
            $a->page['htmlhead'] .= replace_macros($tpl, array('$prevlink' => $prevlink, '$nextlink' => $nextlink));
        }
        if ($prevlink) {
            $prevlink = array($prevlink, '<div class="icon prev"></div>');
        }
        $photo = array('href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']], 'title' => t('View Full Size'), 'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('', '', '', 'ymdhis'), 'height' => $hires['height'], 'width' => $hires['width'], 'album' => $hires['album'], 'filename' => $hires['filename']);
        if ($nextlink) {
            $nextlink = array($nextlink, '<div class="icon next"></div>');
        }
        // Do we have an item for this photo?
        // FIXME! - replace following code to display the conversation with our normal
        // conversation functions so that it works correctly and tracks changes
        // in the evolving conversation code.
        // The difference is that we won't be displaying the conversation head item
        // as a "post" but displaying instead the photo it is linked to
        $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' {$sql_extra} LIMIT 1", dbesc($datum));
        if (count($linked_items)) {
            $link_item = $linked_items[0];
            $r = q("SELECT COUNT(*) AS `total`\n\t\t\t\tFROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\t\t\tWHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0\n\t\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\t\tAND `item`.`uid` = %d\n\t\t\t\t{$sql_extra} ", dbesc($link_item['uri']), dbesc($link_item['uri']), intval($link_item['uid']));
            if (count($r)) {
                $a->set_pager_total($r[0]['total']);
            }
            $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,\n\t\t\t\t`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,\n\t\t\t\t`contact`.`rel`, `contact`.`thumb`, `contact`.`self`,\n\t\t\t\t`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`\n\t\t\t\tFROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\t\t\tWHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0\n\t\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\t\tAND `item`.`uid` = %d\n\t\t\t\t{$sql_extra}\n\t\t\t\tORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ", dbesc($link_item['uri']), dbesc($link_item['uri']), intval($link_item['uid']), intval($a->pager['start']), intval($a->pager['itemspage']));
            if (local_user() && local_user() == $link_item['uid']) {
                q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d", intval($link_item['parent']), intval(local_user()));
                update_thread($link_item['parent']);
            }
        }
        $tags = Null;
        if (count($linked_items) && strlen($link_item['tag'])) {
            $arr = explode(',', $link_item['tag']);
            // parse tags and add links
            $tag_str = '';
            foreach ($arr as $t) {
                if (strlen($tag_str)) {
                    $tag_str .= ', ';
                }
                $tag_str .= bbcode($t);
            }
            $tags = array(t('Tags: '), $tag_str);
            if ($cmd === 'edit') {
                $tags[] = $a->get_baseurl() . '/tagrm/' . $link_item['id'];
                $tags[] = t('[Remove any tag]');
            }
        }
        $edit = Null;
        if ($cmd === 'edit' && $can_post) {
            $edit_tpl = get_markup_template('photo_edit.tpl');
            // Private/public post links for the non-JS ACL form
            $private_post = 1;
            if ($_REQUEST['public']) {
                $private_post = 0;
            }
            $query_str = $a->query_string;
            if (strpos($query_str, 'public=1') !== false) {
                $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
            }
            // I think $a->query_string may never have ? in it, but I could be wrong
            // It looks like it's from the index.php?q=[etc] rewrite that the web
            // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
            if (strpos($query_str, '?') === false) {
                $public_post_link = '?public=1';
            } else {
                $public_post_link = '&public=1';
            }
            if ($a->theme['template_engine'] === 'internal') {
                $album_e = template_escape($ph[0]['album']);
                $caption_e = template_escape($ph[0]['desc']);
                $aclselect_e = template_escape(populate_acl($ph[0]));
            } else {
                $album_e = $ph[0]['album'];
                $caption_e = $ph[0]['desc'];
                $aclselect_e = populate_acl($ph[0]);
            }
            $edit = replace_macros($edit_tpl, array('$id' => $ph[0]['id'], '$rotatecw' => t('Rotate CW (right)'), '$rotateccw' => t('Rotate CCW (left)'), '$album' => $album_e, '$newalbum' => t('New album name'), '$nickname' => $a->data['user']['nickname'], '$resource_id' => $ph[0]['resource-id'], '$capt_label' => t('Caption'), '$caption' => $caption_e, '$tag_label' => t('Add a Tag'), '$tags' => $link_item['tag'], '$permissions' => t('Permissions'), '$aclselect' => $aclselect_e, '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'), '$item_id' => count($linked_items) ? $link_item['id'] : 0, '$submit' => t('Submit'), '$delete' => t('Delete Photo'), '$acl_data' => construct_acl_data($a, $ph[0]), '$group_perms' => t('Show to Groups'), '$contact_perms' => t('Show to Contacts'), '$private' => t('Private photo'), '$public' => t('Public photo'), '$is_private' => $private_post, '$return_path' => $query_str, '$public_link' => $public_post_link));
        }
        if (count($linked_items)) {
            $cmnt_tpl = get_markup_template('comment_item.tpl');
            $tpl = get_markup_template('photo_item.tpl');
            $return_url = $a->cmd;
            $like_tpl = get_markup_template('like_noshare.tpl');
            $likebuttons = '';
            if ($can_post || can_write_wall($a, $owner_uid)) {
                $likebuttons = replace_macros($like_tpl, array('$id' => $link_item['id'], '$likethis' => t("I like this (toggle)"), '$nolike' => feature_enabled(local_user(), 'dislike') ? t("I don't like this (toggle)") : '', '$share' => t('Share'), '$wait' => t('Please wait'), '$return_path' => $a->query_string));
            }
            $comments = '';
            if (!count($r)) {
                if ($can_post || can_write_wall($a, $owner_uid)) {
                    if ($link_item['last-child']) {
                        $comments .= replace_macros($cmnt_tpl, array('$return_path' => '', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $link_item['id'], '$parent' => $link_item['id'], '$profile_uid' => $owner_uid, '$mylink' => $contact['url'], '$mytitle' => t('This is you'), '$myphoto' => $contact['thumb'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$preview' => t('Preview'), '$sourceapp' => t($a->sourcename), '$ww' => '', '$rand_num' => random_digits(12)));
                    }
                }
            }
            $alike = array();
            $dlike = array();
            $like = '';
            $dislike = '';
            // display comments
            if (count($r)) {
                foreach ($r as $item) {
                    like_puller($a, $item, $alike, 'like');
                    like_puller($a, $item, $dlike, 'dislike');
                }
                $like = isset($alike[$link_item['id']]) ? format_like($alike[$link_item['id']], $alike[$link_item['id'] . '-l'], 'like', $link_item['id']) : '';
                $dislike = isset($dlike[$link_item['id']]) ? format_like($dlike[$link_item['id']], $dlike[$link_item['id'] . '-l'], 'dislike', $link_item['id']) : '';
                if ($can_post || can_write_wall($a, $owner_uid)) {
                    if ($link_item['last-child']) {
                        $comments .= replace_macros($cmnt_tpl, array('$return_path' => '', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $link_item['id'], '$parent' => $link_item['id'], '$profile_uid' => $owner_uid, '$mylink' => $contact['url'], '$mytitle' => t('This is you'), '$myphoto' => $contact['thumb'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$preview' => t('Preview'), '$sourceapp' => t($a->sourcename), '$ww' => '', '$rand_num' => random_digits(12)));
                    }
                }
                foreach ($r as $item) {
                    $comment = '';
                    $template = $tpl;
                    $sparkle = '';
                    if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && $item['id'] != $item['parent']) {
                        continue;
                    }
                    $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'];
                    if (local_user() && $item['contact-uid'] == local_user() && $item['network'] == 'dfrn' && !$item['self']) {
                        $profile_url = $redirect_url;
                        $sparkle = ' sparkle';
                    } else {
                        $profile_url = $item['url'];
                        $sparkle = '';
                    }
                    $diff_author = $item['url'] !== $item['author-link'] ? true : false;
                    $profile_name = strlen($item['author-name']) && $diff_author ? $item['author-name'] : $item['name'];
                    $profile_avatar = strlen($item['author-avatar']) && $diff_author ? $item['author-avatar'] : $item['thumb'];
                    $profile_link = $profile_url;
                    $dropping = $item['contact-id'] == $contact_id || $item['uid'] == local_user();
                    $drop = array('dropping' => $dropping, 'pagedrop' => false, 'select' => t('Select'), 'delete' => t('Delete'));
                    if ($a->theme['template_engine'] === 'internal') {
                        $name_e = template_escape($profile_name);
                        $title_e = template_escape($item['title']);
                        $body_e = template_escape(bbcode($item['body']));
                    } else {
                        $name_e = $profile_name;
                        $title_e = $item['title'];
                        $body_e = bbcode($item['body']);
                    }
                    $comments .= replace_macros($template, array('$id' => $item['item_id'], '$profile_url' => $profile_link, '$name' => $name_e, '$thumb' => $profile_avatar, '$sparkle' => $sparkle, '$title' => $title_e, '$body' => $body_e, '$ago' => relative_date($item['created']), '$indent' => $item['parent'] != $item['item_id'] ? ' comment' : '', '$drop' => $drop, '$comment' => $comment));
                    if ($can_post || can_write_wall($a, $owner_uid)) {
                        if ($item['last-child']) {
                            $comments .= replace_macros($cmnt_tpl, array('$return_path' => '', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $item['item_id'], '$parent' => $item['parent'], '$profile_uid' => $owner_uid, '$mylink' => $contact['url'], '$mytitle' => t('This is you'), '$myphoto' => $contact['thumb'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$preview' => t('Preview'), '$sourceapp' => t($a->sourcename), '$ww' => '', '$rand_num' => random_digits(12)));
                        }
                    }
                }
            }
            $paginate = paginate($a);
        }
        $photo_tpl = get_markup_template('photo_view.tpl');
        if ($a->theme['template_engine'] === 'internal') {
            $album_e = array($album_link, template_escape($ph[0]['album']));
            $tags_e = template_escape($tags);
            $like_e = template_escape($like);
            $dislike_e = template_escape($dislike);
        } else {
            $album_e = array($album_link, $ph[0]['album']);
            $tags_e = $tags;
            $like_e = $like;
            $dislike_e = $dislike;
        }
        $o .= replace_macros($photo_tpl, array('$id' => $ph[0]['id'], '$album' => $album_e, '$tools' => $tools, '$lock' => $lock, '$photo' => $photo, '$prevlink' => $prevlink, '$nextlink' => $nextlink, '$desc' => $ph[0]['desc'], '$tags' => $tags_e, '$edit' => $edit, '$likebuttons' => $likebuttons, '$like' => $like_e, '$dislike' => $dikslike_e, '$comments' => $comments, '$paginate' => $paginate));
        $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="photo" />' . "\n";
        $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
        $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . $photo["href"] . '" />' . "\n";
        $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
        $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
        return $o;
    }
    // Default - show recent photos with upload link (if applicable)
    //$o = '';
    $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' \n\t\t{$sql_extra} GROUP BY `resource-id`", intval($a->data['user']['uid']), dbesc('Contact Photos'), dbesc(t('Contact Photos')));
    if (count($r)) {
        $a->set_pager_total(count($r));
        $a->set_pager_itemspage(20);
    }
    $r = q("SELECT `resource-id`, `id`, `filename`, type, `album`, max(`scale`) AS `scale` FROM `photo`\n\t\tWHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'  \n\t\t{$sql_extra} GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d", intval($a->data['user']['uid']), dbesc('Contact Photos'), dbesc(t('Contact Photos')), intval($a->pager['start']), intval($a->pager['itemspage']));
    $photos = array();
    if (count($r)) {
        $twist = 'rotright';
        foreach ($r as $rr) {
            if ($twist == 'rotright') {
                $twist = 'rotleft';
            } else {
                $twist = 'rotright';
            }
            $ext = $phototypes[$rr['type']];
            if ($a->theme['template_engine'] === 'internal') {
                $alt_e = template_escape($rr['filename']);
                $name_e = template_escape($rr['album']);
            } else {
                $alt_e = $rr['filename'];
                $name_e = $rr['album'];
            }
            $photos[] = array('id' => $rr['id'], 'twist' => ' ' . $twist . rand(2, 4), 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'], 'title' => t('View Photo'), 'src' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ($rr['scale'] == 6 ? 4 : $rr['scale']) . '.' . $ext, 'alt' => $alt_e, 'album' => array('link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']), 'name' => $name_e, 'alt' => t('View Album')));
        }
    }
    $tpl = get_markup_template('photos_recent.tpl');
    $o .= replace_macros($tpl, array('$title' => t('Recent Photos'), '$can_post' => $can_post, '$upload' => array(t('Upload New Photos'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload'), '$photos' => $photos));
    $o .= paginate($a);
    return $o;
}
Example #9
0
function photos_content(&$a)
{
    // URLs:
    // photos/name
    // photos/name/upload
    // photos/name/upload/xxxxx (xxxxx is album name)
    // photos/name/album/xxxxx
    // photos/name/album/xxxxx/edit
    // photos/name/image/xxxxx
    // photos/name/image/xxxxx/edit
    if (get_config('system', 'block_public') && !local_user() && !remote_user()) {
        notice(t('Public access denied.') . EOL);
        return;
    }
    require_once 'include/bbcode.php';
    require_once 'include/security.php';
    require_once 'include/conversation.php';
    if (!x($a->data, 'user')) {
        notice(t('No photos selected') . EOL);
        return;
    }
    $_SESSION['photo_return'] = $a->cmd;
    //
    // Parse arguments
    //
    if ($a->argc > 3) {
        $datatype = $a->argv[2];
        $datum = $a->argv[3];
    } elseif ($a->argc > 2 && $a->argv[2] === 'upload') {
        $datatype = 'upload';
    } else {
        $datatype = 'summary';
    }
    if ($a->argc > 4) {
        $cmd = $a->argv[4];
    } else {
        $cmd = 'view';
    }
    //
    // Setup permissions structures
    //
    $can_post = false;
    $visitor = 0;
    $contact = null;
    $remote_contact = false;
    $owner_uid = $a->data['user']['uid'];
    $community_page = $a->data['user']['page-flags'] == PAGE_COMMUNITY ? true : false;
    if (local_user() && local_user() == $owner_uid) {
        $can_post = true;
    } else {
        if ($community_page && remote_user()) {
            $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", intval(remote_user()), intval($owner_uid));
            if (count($r)) {
                $can_post = true;
                $contact = $r[0];
                $remote_contact = true;
                $visitor = remote_user();
            }
        }
    }
    // perhaps they're visiting - but not a community page, so they wouldn't have write access
    if (remote_user() && !$visitor) {
        $contact_id = $_SESSION['visitor_id'];
        $groups = init_groups_visitor($contact_id);
        $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", intval(remote_user()), intval($owner_uid));
        if (count($r)) {
            $contact = $r[0];
            $remote_contact = true;
        }
    }
    if (!$remote_contact) {
        if (local_user()) {
            $contact_id = $_SESSION['cid'];
            $contact = $a->contact;
        }
    }
    if ($a->data['user']['hidewall'] && local_user() != $owner_uid && !$remote_contact) {
        notice(t('Access to this item is restricted.') . EOL);
        return;
    }
    $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
    $o = "";
    // tabs
    $_is_owner = local_user() && local_user() == $owner_uid;
    $o .= profile_tabs($a, $_is_owner, $a->data['user']['nickname']);
    //
    // dispatch request
    //
    if ($datatype === 'upload') {
        if (!$can_post) {
            notice(t('Permission denied.'));
            return;
        }
        $selname = $datum ? hex2bin($datum) : '';
        $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
        $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
        if (count($a->data['albums'])) {
            foreach ($a->data['albums'] as $album) {
                if ($album['album'] === '' || $album['album'] === 'Contact Photos' || $album['album'] === t('Contact Photos')) {
                    continue;
                }
                $selected = $selname === $album['album'] ? ' selected="selected" ' : '';
                $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
            }
        }
        $celeb = $a->user['page-flags'] == PAGE_SOAPBOX || $a->user['page-flags'] == PAGE_COMMUNITY ? true : false;
        $albumselect .= '</select>';
        $uploader = '';
        $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'], 'addon_text' => $uploader, 'default_upload' => true);
        call_hooks('photo_upload_form', $ret);
        $default_upload = '<input type="file" name="userfile" /> 	<div class="photos-upload-submit-wrapper" >
		<input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>';
        $tpl = get_markup_template('photos_upload.tpl');
        $o .= replace_macros($tpl, array('$pagename' => t('Upload Photos'), '$sessid' => session_id(), '$nickname' => $a->data['user']['nickname'], '$newalbum' => t('New album name: '), '$existalbumtext' => t('or existing album name: '), '$nosharetext' => t('Do not show a status post for this upload'), '$albumselect' => template_escape($albumselect), '$permissions' => t('Permissions'), '$aclselect' => $visitor ? '' : template_escape(populate_acl($a->user, $celeb)), '$uploader' => $ret['addon_text'], '$default' => $ret['default_upload'] ? $default_upload : '', '$uploadurl' => $ret['post_url']));
        return $o;
    }
    if ($datatype === 'album') {
        $album = hex2bin($datum);
        $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s' \n\t\t\tAND `scale` <= 4 {$sql_extra} GROUP BY `resource-id`", intval($owner_uid), dbesc($album));
        if (count($r)) {
            $a->set_pager_total(count($r));
            $a->set_pager_itemspage(20);
        }
        $r = q("SELECT `resource-id`, `id`, `filename`, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s' \n\t\t\tAND `scale` <= 4 {$sql_extra} GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d", intval($owner_uid), dbesc($album), intval($a->pager['start']), intval($a->pager['itemspage']));
        $o .= '<h3>' . $album . '</h3>';
        if ($cmd === 'edit') {
            if ($album !== t('Profile Photos') && $album !== 'Contact Photos' && $album !== t('Contact Photos')) {
                if ($can_post) {
                    $edit_tpl = get_markup_template('album_edit.tpl');
                    $o .= replace_macros($edit_tpl, array('$nametext' => t('New album name: '), '$nickname' => $a->data['user']['nickname'], '$album' => template_escape($album), '$hexalbum' => bin2hex($album), '$submit' => t('Submit'), '$dropsubmit' => t('Delete Album')));
                }
            }
        } else {
            if ($album !== t('Profile Photos') && $album !== 'Contact Photos' && $album !== t('Contact Photos')) {
                if ($can_post) {
                    $o .= '<div id="album-edit-link"><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">' . t('Edit Album') . '</a></div>';
                }
            }
        }
        if ($can_post) {
            $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album) . '" >' . t('Upload New Photos') . '</a></div>';
        }
        $tpl = get_markup_template('photo_album.tpl');
        if (count($r)) {
            $twist = 'rotright';
        }
        foreach ($r as $rr) {
            if ($twist == 'rotright') {
                $twist = 'rotleft';
            } else {
                $twist = 'rotright';
            }
            $o .= replace_macros($tpl, array('$id' => $rr['id'], '$twist' => ' ' . $twist . rand(2, 4), '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'], '$phototitle' => t('View Photo'), '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg', '$imgalt' => template_escape($rr['filename']), '$desc' => template_escape($rr['desc'])));
        }
        $o .= '<div id="photo-album-end"></div>';
        $o .= paginate($a);
        return $o;
    }
    if ($datatype === 'image') {
        //$o = '';
        // fetch image, item containing image, then comments
        $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' \n\t\t\t{$sql_extra} ORDER BY `scale` ASC ", intval($owner_uid), dbesc($datum));
        if (!count($ph)) {
            $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' \n\t\t\t\tLIMIT 1", intval($owner_uid), dbesc($datum));
            if (count($ph)) {
                notice(t('Permission denied. Access to this item may be restricted.'));
            } else {
                notice(t('Photo not available') . EOL);
            }
            return;
        }
        $prevlink = '';
        $nextlink = '';
        $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0 \n\t\t\t{$sql_extra} ORDER BY `created` DESC ", dbesc($ph[0]['album']), intval($owner_uid));
        if (count($prvnxt)) {
            for ($z = 0; $z < count($prvnxt); $z++) {
                if ($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
                    $prv = $z - 1;
                    $nxt = $z + 1;
                    if ($prv < 0) {
                        $prv = count($prvnxt) - 1;
                    }
                    if ($nxt >= count($prvnxt)) {
                        $nxt = 0;
                    }
                    break;
                }
            }
            $edit_suffix = $cmd === 'edit' && $can_post ? '/edit' : '';
            $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix;
            $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix;
        }
        if (count($ph) == 1) {
            $hires = $lores = $ph[0];
        }
        if (count($ph) > 1) {
            if ($ph[1]['scale'] == 2) {
                // original is 640 or less, we can display it directly
                $hires = $lores = $ph[0];
            } else {
                $hires = $ph[0];
                $lores = $ph[1];
            }
        }
        $album_link = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
        $tools = Null;
        $lock = Null;
        if ($can_post && $ph[0]['uid'] == $owner_uid) {
            $tools = array('edit' => array($a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . ($cmd === 'edit' ? '' : '/edit'), $cmd === 'edit' ? t('View photo') : t('Edit photo')), 'profile' => array($a->get_baseurl() . '/profile_photo/use/' . $ph[0]['resource-id'], t('Use as profile photo')));
            // lock
            $lock = $ph[0]['uid'] == local_user() && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) ? t('Private Message') : Null;
        }
        if (!$cmd !== 'edit') {
            $a->page['htmlhead'] .= '<script>
				$(document).keydown(function(event) {' . "\n";
            if ($prevlink) {
                $a->page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 37) { event.preventDefault(); window.location.href = \'' . $prevlink . '\'; }' . "\n";
            }
            if ($nextlink) {
                $a->page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 39) { event.preventDefault(); window.location.href = \'' . $nextlink . '\'; }' . "\n";
            }
            $a->page['htmlhead'] .= '});</script>';
        }
        if ($prevlink) {
            $prevlink = array($prevlink, '<div class="icon prev"></div>');
        }
        $photo = array('href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg', 'title' => t('View Full Size'), 'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg' . '?f=&_u=' . datetime_convert('', '', '', 'ymdhis'));
        if ($nextlink) {
            $nextlink = array($nextlink, '<div class="icon next"></div>');
        }
        // Do we have an item for this photo?
        $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' {$sql_extra} LIMIT 1", dbesc($datum));
        if (count($linked_items)) {
            $link_item = $linked_items[0];
            $r = q("SELECT COUNT(*) AS `total`\n\t\t\t\tFROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\t\t\tWHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0\n\t\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\t\tAND `item`.`uid` = %d \n\t\t\t\t{$sql_extra} ", dbesc($link_item['uri']), dbesc($link_item['uri']), intval($link_item['uid']));
            if (count($r)) {
                $a->set_pager_total($r[0]['total']);
            }
            $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, \n\t\t\t\t`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`, \n\t\t\t\t`contact`.`rel`, `contact`.`thumb`, `contact`.`self`, \n\t\t\t\t`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`\n\t\t\t\tFROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\t\t\tWHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0\n\t\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\t\tAND `item`.`uid` = %d\n\t\t\t\t{$sql_extra}\n\t\t\t\tORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ", dbesc($link_item['uri']), dbesc($link_item['uri']), intval($link_item['uid']), intval($a->pager['start']), intval($a->pager['itemspage']));
            if (local_user() && local_user() == $link_item['uid']) {
                q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d", intval($link_item['parent']), intval(local_user()));
            }
        }
        $tags = Null;
        if (count($linked_items) && strlen($link_item['tag'])) {
            $arr = explode(',', $link_item['tag']);
            // parse tags and add links
            $tag_str = '';
            foreach ($arr as $t) {
                if (strlen($tag_str)) {
                    $tag_str .= ', ';
                }
                $tag_str .= bbcode($t);
            }
            $tags = array(t('Tags: '), $tag_str);
            if ($cmd === 'edit') {
                $tags[] = $a->get_baseurl() . '/tagrm/' . $link_item['id'];
                $tags[] = t('[Remove any tag]');
            }
        }
        $edit = Null;
        if ($cmd === 'edit' && $can_post) {
            $edit_tpl = get_markup_template('photo_edit.tpl');
            $edit = replace_macros($edit_tpl, array('$id' => $ph[0]['id'], '$rotate' => t('Rotate CW'), '$album' => template_escape($ph[0]['album']), '$newalbum' => t('New album name'), '$nickname' => $a->data['user']['nickname'], '$resource_id' => $ph[0]['resource-id'], '$capt_label' => t('Caption'), '$caption' => template_escape($ph[0]['desc']), '$tag_label' => t('Add a Tag'), '$tags' => $link_item['tag'], '$permissions' => t('Permissions'), '$aclselect' => template_escape(populate_acl($ph[0])), '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'), '$item_id' => count($linked_items) ? $link_item['id'] : 0, '$submit' => t('Submit'), '$delete' => t('Delete Photo')));
        }
        if (count($linked_items)) {
            $cmnt_tpl = get_markup_template('comment_item.tpl');
            $tpl = get_markup_template('photo_item.tpl');
            $return_url = $a->cmd;
            $like_tpl = get_markup_template('like_noshare.tpl');
            $likebuttons = '';
            if ($can_post || can_write_wall($a, $owner_uid)) {
                $likebuttons = replace_macros($like_tpl, array('$id' => $link_item['id'], '$likethis' => t("I like this (toggle)"), '$nolike' => t("I don't like this (toggle)"), '$share' => t('Share'), '$wait' => t('Please wait')));
            }
            $comments = '';
            if (!count($r)) {
                if ($can_post || can_write_wall($a, $owner_uid)) {
                    if ($link_item['last-child']) {
                        $comments .= replace_macros($cmnt_tpl, array('$return_path' => '', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $link_item['id'], '$parent' => $link_item['id'], '$profile_uid' => $owner_uid, '$mylink' => $contact['url'], '$mytitle' => t('This is you'), '$myphoto' => $contact['thumb'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$preview' => t('Preview'), '$ww' => ''));
                    }
                }
            }
            $alike = array();
            $dlike = array();
            $like = '';
            $dislike = '';
            // display comments
            if (count($r)) {
                foreach ($r as $item) {
                    like_puller($a, $item, $alike, 'like');
                    like_puller($a, $item, $dlike, 'dislike');
                }
                $like = isset($alike[$link_item['id']]) ? format_like($alike[$link_item['id']], $alike[$link_item['id'] . '-l'], 'like', $link_item['id']) : '';
                $dislike = isset($dlike[$link_item['id']]) ? format_like($dlike[$link_item['id']], $dlike[$link_item['id'] . '-l'], 'dislike', $link_item['id']) : '';
                if ($can_post || can_write_wall($a, $owner_uid)) {
                    if ($link_item['last-child']) {
                        $comments .= replace_macros($cmnt_tpl, array('$return_path' => '', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $link_item['id'], '$parent' => $link_item['id'], '$profile_uid' => $owner_uid, '$mylink' => $contact['url'], '$mytitle' => t('This is you'), '$myphoto' => $contact['thumb'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$ww' => ''));
                    }
                }
                foreach ($r as $item) {
                    $comment = '';
                    $template = $tpl;
                    $sparkle = '';
                    if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && $item['id'] != $item['parent']) {
                        continue;
                    }
                    $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'];
                    if ($can_post || can_write_wall($a, $owner_uid)) {
                        if ($item['last-child']) {
                            $comments .= replace_macros($cmnt_tpl, array('$return_path' => '', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $item['item_id'], '$parent' => $item['parent'], '$profile_uid' => $owner_uid, '$mylink' => $contact['url'], '$mytitle' => t('This is you'), '$myphoto' => $contact['thumb'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$ww' => ''));
                        }
                    }
                    if (local_user() && $item['contact-uid'] == local_user() && $item['network'] == 'dfrn' && !$item['self']) {
                        $profile_url = $redirect_url;
                        $sparkle = ' sparkle';
                    } else {
                        $profile_url = $item['url'];
                        $sparkle = '';
                    }
                    $diff_author = $item['url'] !== $item['author-link'] ? true : false;
                    $profile_name = strlen($item['author-name']) && $diff_author ? $item['author-name'] : $item['name'];
                    $profile_avatar = strlen($item['author-avatar']) && $diff_author ? $item['author-avatar'] : $item['thumb'];
                    $profile_link = $profile_url;
                    $drop = '';
                    if ($item['contact-id'] == remote_user() || $item['uid'] == local_user()) {
                        $drop = replace_macros(get_markup_template('photo_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
                    }
                    $comments .= replace_macros($template, array('$id' => $item['item_id'], '$profile_url' => $profile_link, '$name' => template_escape($profile_name), '$thumb' => $profile_avatar, '$sparkle' => $sparkle, '$title' => template_escape($item['title']), '$body' => template_escape(bbcode($item['body'])), '$ago' => relative_date($item['created']), '$indent' => $item['parent'] != $item['item_id'] ? ' comment' : '', '$drop' => $drop, '$comment' => $comment));
                }
            }
            $paginate = paginate($a);
        }
        $photo_tpl = get_markup_template('photo_view.tpl');
        $o .= replace_macros($photo_tpl, array('$id' => $ph[0]['id'], '$album' => array($album_link, template_escape($ph[0]['album'])), '$tools' => $tools, '$lock' => $lock, '$photo' => $photo, '$prevlink' => $prevlink, '$nextlink' => $nextlink, '$desc' => $ph[0]['desc'], '$tags' => template_escape($tags), '$edit' => $edit, '$likebuttons' => $likebuttons, '$like' => template_escape($like), '$dislike' => template_escape($dislike), '$comments' => $comments, '$paginate' => $paginate));
        return $o;
    }
    // Default - show recent photos with upload link (if applicable)
    //$o = '';
    $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' \n\t\t{$sql_extra} GROUP BY `resource-id`", intval($a->data['user']['uid']), dbesc('Contact Photos'), dbesc(t('Contact Photos')));
    if (count($r)) {
        $a->set_pager_total(count($r));
        $a->set_pager_itemspage(20);
    }
    $r = q("SELECT `resource-id`, `id`, `filename`, `album`, max(`scale`) AS `scale` FROM `photo`\n\t\tWHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'  \n\t\t{$sql_extra} GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d", intval($a->data['user']['uid']), dbesc('Contact Photos'), dbesc(t('Contact Photos')), intval($a->pager['start']), intval($a->pager['itemspage']));
    $photos = array();
    if (count($r)) {
        $twist = 'rotright';
        foreach ($r as $rr) {
            if ($twist == 'rotright') {
                $twist = 'rotleft';
            } else {
                $twist = 'rotright';
            }
            $photos[] = array('id' => $rr['id'], 'twist' => ' ' . $twist . rand(2, 4), 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'], 'title' => t('View Photo'), 'src' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ($rr['scale'] == 6 ? 4 : $rr['scale']) . '.jpg', 'alt' => template_escape($rr['filename']), 'album' => array('link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']), 'name' => template_escape($rr['album']), 'alt' => t('View Album')));
        }
    }
    $tpl = get_markup_template('photos_recent.tpl');
    $o .= replace_macros($tpl, array('$title' => t('Recent Photos'), '$can_post' => $can_post, '$upload' => array(t('Upload New Photos'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload'), '$photos' => $photos));
    $o .= paginate($a);
    return $o;
}
Example #10
0
 function get($update = 0, $load = false)
 {
     if ($load) {
         $_SESSION['loadtime'] = datetime_convert();
     }
     $checkjs = new \Zotlabs\Web\CheckJS(1);
     $category = $datequery = $datequery2 = '';
     $mid = x($_REQUEST, 'mid') ? $_REQUEST['mid'] : '';
     $datequery = x($_GET, 'dend') && is_a_date_arg($_GET['dend']) ? notags($_GET['dend']) : '';
     $datequery2 = x($_GET, 'dbegin') && is_a_date_arg($_GET['dbegin']) ? notags($_GET['dbegin']) : '';
     if (observer_prohibited(true)) {
         return login();
     }
     $category = x($_REQUEST, 'cat') ? $_REQUEST['cat'] : '';
     $hashtags = x($_REQUEST, 'tag') ? $_REQUEST['tag'] : '';
     $groups = array();
     $o = '';
     if ($update) {
         // Ensure we've got a profile owner if updating.
         \App::$profile['profile_uid'] = \App::$profile_uid = $update;
     } else {
         if (\App::$profile['profile_uid'] == local_channel()) {
             nav_set_selected('home');
         }
     }
     $is_owner = local_channel() && \App::$profile['profile_uid'] == local_channel() ? true : false;
     $channel = \App::get_channel();
     $observer = \App::get_observer();
     $ob_hash = $observer ? $observer['xchan_hash'] : '';
     $perms = get_all_perms(\App::$profile['profile_uid'], $ob_hash);
     if (!$perms['view_stream']) {
         // We may want to make the target of this redirect configurable
         if ($perms['view_profile']) {
             notice(t('Insufficient permissions.  Request redirected to profile page.') . EOL);
             goaway(z_root() . "/profile/" . \App::$profile['channel_address']);
         }
         notice(t('Permission denied.') . EOL);
         return;
     }
     if (!$update) {
         $o .= profile_tabs($a, $is_owner, \App::$profile['channel_address']);
         $o .= common_friends_visitor_widget(\App::$profile['profile_uid']);
         if ($channel && $is_owner) {
             $channel_acl = array('allow_cid' => $channel['channel_allow_cid'], 'allow_gid' => $channel['channel_allow_gid'], 'deny_cid' => $channel['channel_deny_cid'], 'deny_gid' => $channel['channel_deny_gid']);
         } else {
             $channel_acl = array();
         }
         if ($perms['post_wall']) {
             $x = array('is_owner' => $is_owner, 'allow_location' => ($is_owner || $observer) && intval(get_pconfig(\App::$profile['profile_uid'], 'system', 'use_browser_location')) ? true : false, 'default_location' => $is_owner ? \App::$profile['channel_location'] : '', 'nickname' => \App::$profile['channel_address'], 'lockstate' => strlen(\App::$profile['channel_allow_cid']) || strlen(\App::$profile['channel_allow_gid']) || strlen(\App::$profile['channel_deny_cid']) || strlen(\App::$profile['channel_deny_gid']) ? 'lock' : 'unlock', 'acl' => $is_owner ? populate_acl($channel_acl, true, \PermissionDescription::fromGlobalPermission('view_stream'), get_post_aclDialogDescription(), 'acl_dialog_post') : '', 'showacl' => $is_owner ? 'yes' : '', 'bang' => '', 'visitor' => $is_owner || $observer ? true : false, 'profile_uid' => \App::$profile['profile_uid'], 'editor_autocomplete' => true, 'bbco_autocomplete' => 'bbcode', 'bbcode' => true);
             $o .= status_editor($a, $x);
         }
     }
     /**
      * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
      */
     $item_normal = item_normal();
     $sql_extra = item_permissions_sql(\App::$profile['profile_uid']);
     if (get_pconfig(\App::$profile['profile_uid'], 'system', 'channel_list_mode') && !$mid) {
         $page_mode = 'list';
     } else {
         $page_mode = 'client';
     }
     $abook_uids = " and abook.abook_channel = " . intval(\App::$profile['profile_uid']) . " ";
     $simple_update = $update ? " AND item_unseen = 1 " : '';
     \App::$page['htmlhead'] .= "\r\n" . '<link rel="alternate" type="application/json+oembed" href="' . z_root() . '/oep?f=&url=' . urlencode(z_root() . '/' . \App::$query_string) . '" title="oembed" />' . "\r\n";
     if ($update && $_SESSION['loadtime']) {
         $simple_update = " AND (( item_unseen = 1 AND item.changed > '" . datetime_convert('UTC', 'UTC', $_SESSION['loadtime']) . "' )  OR item.changed > '" . datetime_convert('UTC', 'UTC', $_SESSION['loadtime']) . "' ) ";
     }
     if ($load) {
         $simple_update = '';
     }
     if ($update && !$load) {
         if ($mid) {
             $r = q("SELECT parent AS item_id from item where mid like '%s' and uid = %d {$item_normal}\n\t\t\t\t\tAND item_wall = 1 AND item_unseen = 1 {$sql_extra} limit 1", dbesc($mid . '%'), intval(\App::$profile['profile_uid']));
         } else {
             $r = q("SELECT distinct parent AS `item_id`, created from item\n\t\t\t\t\tleft join abook on ( item.owner_xchan = abook.abook_xchan {$abook_uids} )\n\t\t\t\t\tWHERE uid = %d {$item_normal}\n\t\t\t\t\tAND item_wall = 1 {$simple_update}\n\t\t\t\t\tAND (abook.abook_blocked = 0 or abook.abook_flags is null)\n\t\t\t\t\t{$sql_extra}\n\t\t\t\t\tORDER BY created DESC", intval(\App::$profile['profile_uid']));
             $_SESSION['loadtime'] = datetime_convert();
         }
     } else {
         if (x($category)) {
             $sql_extra .= protect_sprintf(term_query('item', $category, TERM_CATEGORY));
         }
         if (x($hashtags)) {
             $sql_extra .= protect_sprintf(term_query('item', $hashtags, TERM_HASHTAG, TERM_COMMUNITYTAG));
         }
         if ($datequery) {
             $sql_extra2 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(), '', $datequery))));
         }
         if ($datequery2) {
             $sql_extra2 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(), '', $datequery2))));
         }
         $itemspage = get_pconfig(local_channel(), 'system', 'itemspage');
         \App::set_pager_itemspage(intval($itemspage) ? $itemspage : 20);
         $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start']));
         if ($load || $checkjs->disabled()) {
             if ($mid) {
                 $r = q("SELECT parent AS item_id from item where mid = '%s' and uid = %d {$item_normal}\n\t\t\t\t\t\tAND item_wall = 1 {$sql_extra} limit 1", dbesc($mid), intval(\App::$profile['profile_uid']));
                 if (!$r) {
                     notice(t('Permission denied.') . EOL);
                 }
             } else {
                 $r = q("SELECT distinct id AS item_id, created FROM item \n\t\t\t\t\t\tleft join abook on item.author_xchan = abook.abook_xchan\n\t\t\t\t\t\tWHERE uid = %d {$item_normal}\n\t\t\t\t\t\tAND item_wall = 1 and item_thread_top = 1\n\t\t\t\t\t\tAND (abook_blocked = 0 or abook.abook_flags is null)\n\t\t\t\t\t\t{$sql_extra} {$sql_extra2}\n\t\t\t\t\t\tORDER BY created DESC {$pager_sql} ", intval(\App::$profile['profile_uid']));
             }
         } else {
             $r = array();
         }
     }
     if ($r) {
         $parents_str = ids_to_querystr($r, 'item_id');
         $items = q("SELECT `item`.*, `item`.`id` AS `item_id` \n\t\t\t\tFROM `item`\n\t\t\t\tWHERE `item`.`uid` = %d {$item_normal}\n\t\t\t\tAND `item`.`parent` IN ( %s )\n\t\t\t\t{$sql_extra} ", intval(\App::$profile['profile_uid']), dbesc($parents_str));
         xchan_query($items);
         $items = fetch_post_tags($items, true);
         $items = conv_sort($items, 'created');
         if ($load && $mid && !count($items)) {
             // This will happen if we don't have sufficient permissions
             // to view the parent item (or the item itself if it is toplevel)
             notice(t('Permission denied.') . EOL);
         }
     } else {
         $items = array();
     }
     if (!$update && !$load) {
         // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
         // because browser prefetching might change it on us. We have to deliver it with the page.
         $maxheight = get_pconfig(\App::$profile['profile_uid'], 'system', 'channel_divmore_height');
         if (!$maxheight) {
             $maxheight = 400;
         }
         $o .= '<div id="live-channel"></div>' . "\r\n";
         $o .= "<script> var profile_uid = " . \App::$profile['profile_uid'] . "; var netargs = '?f='; var profile_page = " . \App::$pager['page'] . "; divmore_height = " . intval($maxheight) . "; </script>\r\n";
         \App::$page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"), array('$baseurl' => z_root(), '$pgtype' => 'channel', '$uid' => \App::$profile['profile_uid'] ? \App::$profile['profile_uid'] : '0', '$gid' => '0', '$cid' => '0', '$cmin' => '0', '$cmax' => '0', '$star' => '0', '$liked' => '0', '$conv' => '0', '$spam' => '0', '$nouveau' => '0', '$wall' => '1', '$fh' => '0', '$page' => \App::$pager['page'] != 1 ? \App::$pager['page'] : 1, '$search' => '', '$order' => '', '$list' => x($_REQUEST, 'list') ? intval($_REQUEST['list']) : 0, '$file' => '', '$cats' => $category ? $category : '', '$tags' => $hashtags ? $hashtags : '', '$mid' => $mid, '$verb' => '', '$dend' => $datequery, '$dbegin' => $datequery2));
     }
     $update_unseen = '';
     if ($page_mode === 'list') {
         /**
          * in "list mode", only mark the parent item and any like activities as "seen". 
          * We won't distinguish between comment likes and post likes. The important thing
          * is that the number of unseen comments will be accurate. The SQL to separate the
          * comment likes could also get somewhat hairy. 
          */
         if ($parents_str) {
             $update_unseen = " AND ( id IN ( " . dbesc($parents_str) . " )";
             $update_unseen .= " OR ( parent IN ( " . dbesc($parents_str) . " ) AND verb in ( '" . dbesc(ACTIVITY_LIKE) . "','" . dbesc(ACTIVITY_DISLIKE) . "' ))) ";
         }
     } else {
         if ($parents_str) {
             $update_unseen = " AND parent IN ( " . dbesc($parents_str) . " )";
         }
     }
     if ($is_owner && $update_unseen) {
         $r = q("UPDATE item SET item_unseen = 0 where item_unseen = 1 and item_wall = 1 AND uid = %d {$update_unseen}", intval(local_channel()));
     }
     if ($checkjs->disabled()) {
         $o .= conversation($a, $items, 'channel', $update, 'traditional');
     } else {
         $o .= conversation($a, $items, 'channel', $update, $page_mode);
     }
     if (!$update || $checkjs->disabled()) {
         $o .= alt_pager($a, count($items));
         if ($mid && $items[0]['title']) {
             \App::$page['title'] = $items[0]['title'] . " - " . \App::$page['title'];
         }
     }
     if ($mid) {
         $o .= '<div id="content-complete"></div>';
     }
     return $o;
 }
Example #11
0
function events_content(&$a)
{
    if (!local_channel()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    nav_set_selected('all_events');
    if (argc() > 2 && argv(1) === 'ignore' && intval(argv(2))) {
        $r = q("update event set ignore = 1 where id = %d and uid = %d", intval(argv(2)), intval(local_channel()));
    }
    if (argc() > 2 && argv(1) === 'unignore' && intval(argv(2))) {
        $r = q("update event set ignore = 0 where id = %d and uid = %d", intval(argv(2)), intval(local_channel()));
    }
    $plaintext = true;
    //	if(feature_enabled(local_channel(),'richtext'))
    //		$plaintext = false;
    $htpl = get_markup_template('event_head.tpl');
    $a->page['htmlhead'] .= replace_macros($htpl, array('$baseurl' => $a->get_baseurl(), '$editselect' => $plaintext ? 'none' : 'textareas'));
    $o = "";
    // tabs
    $channel = $a->get_channel();
    $tabs = profile_tabs($a, True, $channel['channel_address']);
    $mode = 'view';
    $y = 0;
    $m = 0;
    $ignored = x($_REQUEST, 'ignored') ? " and ignored = " . intval($_REQUEST['ignored']) . " " : '';
    if (argc() > 1) {
        if (argc() > 2 && argv(1) == 'event') {
            $mode = 'edit';
            $event_id = argv(2);
        }
        if (argc() > 2 && argv(1) === 'add') {
            $mode = 'add';
            $item_id = intval(argv(2));
        }
        if (argc() > 2 && argv(1) === 'drop') {
            $mode = 'drop';
            $event_id = argv(2);
        }
        if (argv(1) === 'new') {
            $mode = 'new';
            $event_id = '';
        }
        if (argc() > 2 && intval(argv(1)) && intval(argv(2))) {
            $mode = 'view';
            $y = intval(argv(1));
            $m = intval(argv(2));
        }
    }
    if ($mode === 'add') {
        event_addtocal($item_id, local_channel());
        killme();
    }
    if ($mode == 'view') {
        $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
        $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
        if (!$y) {
            $y = intval($thisyear);
        }
        if (!$m) {
            $m = intval($thismonth);
        }
        $export = false;
        if (argc() === 4 && argv(3) === 'export') {
            $export = true;
        }
        // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
        // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
        if ($y < 1901) {
            $y = 1900;
        }
        if ($y > 2099) {
            $y = 2100;
        }
        $nextyear = $y;
        $nextmonth = $m + 1;
        if ($nextmonth > 12) {
            $nextmonth = 1;
            $nextyear++;
        }
        $prevyear = $y;
        if ($m > 1) {
            $prevmonth = $m - 1;
        } else {
            $prevmonth = 12;
            $prevyear--;
        }
        $dim = get_dim($y, $m);
        $start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
        $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
        if (argv(1) === 'json') {
            if (x($_GET, 'start')) {
                $start = date("Y-m-d h:i:s", $_GET['start']);
            }
            if (x($_GET, 'end')) {
                $finish = date("Y-m-d h:i:s", $_GET['end']);
            }
        }
        $start = datetime_convert('UTC', 'UTC', $start);
        $finish = datetime_convert('UTC', 'UTC', $finish);
        $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
        $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
        if (x($_GET, 'id')) {
            $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan\n                                from event left join item on resource_id = event_hash where resource_type = 'event' and event.uid = %d and event.id = %d limit 1", intval(local_channel()), intval($_GET['id']));
        } else {
            // fixed an issue with "nofinish" events not showing up in the calendar.
            // There's still an issue if the finish date crosses the end of month.
            // Noting this for now - it will need to be fixed here and in Friendica.
            // Ultimately the finish date shouldn't be involved in the query.
            $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan\n                              from event left join item on event_hash = resource_id \n\t\t\t\twhere resource_type = 'event' and event.uid = %d {$ignored}\n\t\t\t\tAND (( `adjust` = 0 AND ( `finish` >= '%s' or nofinish = 1 ) AND `start` <= '%s' ) \n\t\t\t\tOR  (  `adjust` = 1 AND ( `finish` >= '%s' or nofinish = 1 ) AND `start` <= '%s' )) ", intval(local_channel()), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_finish));
        }
        $links = array();
        if ($r) {
            xchan_query($r);
            $r = fetch_post_tags($r, true);
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                if (!x($links, $j)) {
                    $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j;
                }
            }
        }
        $events = array();
        $last_date = '';
        $fmt = t('l, F j');
        if ($r) {
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                $d = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], $fmt) : datetime_convert('UTC', 'UTC', $rr['start'], $fmt);
                $d = day_translate($d);
                $start = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'c') : datetime_convert('UTC', 'UTC', $rr['start'], 'c');
                if ($rr['nofinish']) {
                    $end = null;
                } else {
                    $end = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['finish'], 'c') : datetime_convert('UTC', 'UTC', $rr['finish'], 'c');
                }
                $is_first = $d !== $last_date;
                $last_date = $d;
                // FIXME
                $edit = $rr['item_flags'] & ITEM_WALL ? array($a->get_baseurl() . '/events/event/' . $rr['event_hash'], t('Edit event'), '', '') : null;
                $drop = array($a->get_baseurl() . '/events/drop/' . $rr['event_hash'], t('Delete event'), '', '');
                $title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
                if (!$title) {
                    list($title, $_trash) = explode("<br", bbcode($rr['desc']), 2);
                    $title = strip_tags(html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
                }
                $html = format_event_html($rr);
                $rr['desc'] = bbcode($rr['desc']);
                $rr['location'] = bbcode($rr['location']);
                $events[] = array('id' => $rr['id'], 'hash' => $rr['event_hash'], 'start' => $start, 'end' => $end, 'drop' => $drop, 'allDay' => false, 'title' => $title, 'j' => $j, 'd' => $d, 'edit' => $edit, 'is_first' => $is_first, 'item' => $rr, 'html' => $html, 'plink' => array($rr['plink'], t('Link to Source'), '', ''));
            }
        }
        if ($export) {
            header('Content-type: text/calendar');
            header('content-disposition: attachment; filename="' . t('calendar') . '-' . $channel['channel_address'] . '.ics"');
            echo ical_wrapper($r);
            killme();
        }
        if ($a->argv[1] === 'json') {
            echo json_encode($events);
            killme();
        }
        // links: array('href', 'text', 'extra css classes', 'title')
        if (x($_GET, 'id')) {
            $tpl = get_markup_template("event.tpl");
        } else {
            $tpl = get_markup_template("events-js.tpl");
        }
        $o = replace_macros($tpl, array('$baseurl' => $a->get_baseurl(), '$tabs' => $tabs, '$title' => t('Events'), '$new_event' => array($a->get_baseurl() . '/events/new', t('Create New Event'), '', ''), '$previus' => array($a->get_baseurl() . "/events/{$prevyear}/{$prevmonth}", t('Previous'), '', ''), '$next' => array($a->get_baseurl() . "/events/{$nextyear}/{$nextmonth}", t('Next'), '', ''), '$export' => array($a->get_baseurl() . "/events/{$y}/{$m}/export", t('Export'), '', ''), '$calendar' => cal($y, $m, $links, ' eventcal'), '$events' => $events));
        if (x($_GET, 'id')) {
            echo $o;
            killme();
        }
        return $o;
    }
    if ($mode === 'drop' && $event_id) {
        $r = q("SELECT * FROM `event` WHERE event_hash = '%s' AND `uid` = %d LIMIT 1", dbesc($event_id), intval(local_channel()));
        if ($r) {
            $r = q("delete from event where event_hash = '%s' and uid = %d limit 1", dbesc($event_id), intval(local_channel()));
            if ($r) {
                $r = q("update item set resource_type = '', resource_id = '' where resource_type = 'event' and resource_id = '%s' and uid = %d", dbesc($event_id), intval(local_channel()));
                info(t('Event removed') . EOL);
            } else {
                notice(t('Failed to remove event') . EOL);
            }
            goaway(z_root() . '/events');
        }
    }
    if ($mode === 'edit' && $event_id) {
        $r = q("SELECT * FROM `event` WHERE event_hash = '%s' AND `uid` = %d LIMIT 1", dbesc($event_id), intval(local_channel()));
        if (count($r)) {
            $orig_event = $r[0];
        }
    }
    $channel = $a->get_channel();
    // Passed parameters overrides anything found in the DB
    if ($mode === 'edit' || $mode === 'new') {
        if (!x($orig_event)) {
            $orig_event = array();
        }
        // In case of an error the browser is redirected back here, with these parameters filled in with the previous values
        if (x($_REQUEST, 'nofinish')) {
            $orig_event['nofinish'] = $_REQUEST['nofinish'];
        }
        if (x($_REQUEST, 'adjust')) {
            $orig_event['adjust'] = $_REQUEST['adjust'];
        }
        if (x($_REQUEST, 'summary')) {
            $orig_event['summary'] = $_REQUEST['summary'];
        }
        if (x($_REQUEST, 'description')) {
            $orig_event['description'] = $_REQUEST['description'];
        }
        if (x($_REQUEST, 'location')) {
            $orig_event['location'] = $_REQUEST['location'];
        }
        if (x($_REQUEST, 'start')) {
            $orig_event['start'] = $_REQUEST['start'];
        }
        if (x($_REQUEST, 'finish')) {
            $orig_event['finish'] = $_REQUEST['finish'];
        }
    }
    if ($mode === 'edit' || $mode === 'new') {
        $n_checked = x($orig_event) && $orig_event['nofinish'] ? ' checked="checked" ' : '';
        $a_checked = x($orig_event) && $orig_event['adjust'] ? ' checked="checked" ' : '';
        $t_orig = x($orig_event) ? $orig_event['summary'] : '';
        $d_orig = x($orig_event) ? $orig_event['description'] : '';
        $l_orig = x($orig_event) ? $orig_event['location'] : '';
        $eid = x($orig_event) ? $orig_event['id'] : 0;
        $event_xchan = x($orig_event) ? $orig_event['event_xchan'] : $channel['channel_hash'];
        $mid = x($orig_event) ? $orig_event['mid'] : '';
        if (!x($orig_event)) {
            $sh_checked = '';
        } else {
            $sh_checked = ($orig_event['allow_cid'] === '<' . $channel['channel_hash'] . '>' || !$orig_event['allow_cid']) && !$orig_event['allow_gid'] && !$orig_event['deny_cid'] && !$orig_event['deny_gid'] ? '' : ' checked="checked" ';
        }
        if ($orig_event['event_xchan']) {
            $sh_checked .= ' disabled="disabled" ';
        }
        $sdt = x($orig_event) ? $orig_event['start'] : 'now';
        $fdt = x($orig_event) ? $orig_event['finish'] : 'now';
        $tz = date_default_timezone_get();
        if (x($orig_event)) {
            $tz = $orig_event['adjust'] ? date_default_timezone_get() : 'UTC';
        }
        $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
        $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
        $sday = datetime_convert('UTC', $tz, $sdt, 'd');
        $shour = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'H') : 0;
        $sminute = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'i') : 0;
        $stext = datetime_convert('UTC', $tz, $sdt);
        $stext = substr($stext, 0, 14) . "00:00";
        $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
        $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
        $fday = datetime_convert('UTC', $tz, $fdt, 'd');
        $fhour = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'H') : 0;
        $fminute = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0;
        $ftext = datetime_convert('UTC', $tz, $fdt);
        $ftext = substr($ftext, 0, 14) . "00:00";
        $f = get_config('system', 'event_input_format');
        if (!$f) {
            $f = 'ymd';
        }
        $catsenabled = feature_enabled(local_channel(), 'categories');
        $category = '';
        if ($catsenabled && x($orig_event)) {
            $itm = q("select * from item where resource_type = 'event' and resource_id = '%s' and uid = %d limit 1", dbesc($orig_event['event_hash']), intval(local_channel()));
            $itm = fetch_post_tags($itm);
            if ($itm) {
                $cats = get_terms_oftype($itm[0]['term'], TERM_CATEGORY);
                foreach ($cats as $cat) {
                    if (strlen($category)) {
                        $category .= ', ';
                    }
                    $category .= $cat['term'];
                }
            }
        }
        require_once 'include/acl_selectors.php';
        $perm_defaults = array('allow_cid' => $channel['channel_allow_cid'], 'allow_gid' => $channel['channel_allow_gid'], 'deny_cid' => $channel['channel_deny_cid'], 'deny_gid' => $channel['channel_deny_gid']);
        $tpl = get_markup_template('event_form.tpl');
        $o .= replace_macros($tpl, array('$post' => $a->get_baseurl() . '/events', '$eid' => $eid, '$xchan' => $event_xchan, '$mid' => $mid, '$event_hash' => $event_id, '$title' => t('Event details'), '$desc' => t('Starting date and Title are required.'), '$catsenabled' => $catsenabled, '$placeholdercategory' => t('Categories (comma-separated list)'), '$category' => $category, '$s_text' => t('Event Starts:'), '$stext' => $stext, '$ftext' => $ftext, '$required' => ' <span class="required" title="' . t('Required') . '">*</span>', '$ModalCANCEL' => t('Cancel'), '$ModalOK' => t('OK'), '$s_dsel' => datetimesel($f, new DateTime(), DateTime::createFromFormat('Y', $syear + 5), DateTime::createFromFormat('Y-m-d H:i', "{$syear}-{$smonth}-{$sday} {$shour}:{$sminute}"), 'start_text', true, true, '', '', true), '$n_text' => t('Finish date/time is not known or not relevant'), '$n_checked' => $n_checked, '$f_text' => t('Event Finishes:'), '$f_dsel' => datetimesel($f, new DateTime(), DateTime::createFromFormat('Y', $fyear + 5), DateTime::createFromFormat('Y-m-d H:i', "{$fyear}-{$fmonth}-{$fday} {$fhour}:{$fminute}"), 'finish_text', true, true, 'start_text'), '$adjust' => array('adjust', t('Adjust for viewer timezone'), $a_checked, t('Important for events that happen in a particular place. Not practical for global holidays.')), '$a_text' => t('Adjust for viewer timezone'), '$d_text' => t('Description:'), '$d_orig' => $d_orig, '$l_text' => t('Location:'), '$l_orig' => $l_orig, '$t_text' => t('Title:'), '$t_orig' => $t_orig, '$sh_text' => t('Share this event'), '$sh_checked' => $sh_checked, '$preview' => t('Preview'), '$permissions' => t('Permissions'), '$acl' => $orig_event['event_xchan'] ? '' : populate_acl(x($orig_event) ? $orig_event : $perm_defaults, false), '$submit' => t('Submit')));
        return $o;
    }
}
Example #12
0
// CicapEnabled
//ini_set('html_errors',0);ini_set('display_errors', 1);ini_set('error_reporting', E_ALL);ini_set('error_prepend_string','');ini_set('error_append_string','');
$user = new usersMenus();
if ($user->AsDansGuardianAdministrator == false) {
    die('not allowed');
}
if (isset($_GET["profiles-list"])) {
    profiles_list();
    exit;
}
if (isset($_GET["profile-js"])) {
    profile_js();
    exit;
}
if (isset($_GET["profile-tabs"])) {
    profile_tabs();
    exit;
}
if (isset($_GET["profile-popup"])) {
    profile_popup();
    exit;
}
if (isset($_GET["delete-profile-js"])) {
    profile_delete_js();
    exit;
}
if (isset($_POST["rulename"])) {
    profile_save();
    exit;
}
if (isset($_POST["delete-profile"])) {
Example #13
0
function chat_content(&$a)
{
    if (local_channel()) {
        $channel = $a->get_channel();
    }
    $ob = $a->get_observer();
    $observer = get_observer_hash();
    if (!$observer) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    if (!perm_is_allowed($a->profile['profile_uid'], $observer, 'chat')) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    if (argc() > 3 && intval(argv(2)) && argv(3) === 'leave') {
        chatroom_leave($observer, argv(2), $_SERVER['REMOTE_ADDR']);
        goaway(z_root() . '/channel/' . argv(1));
    }
    if (argc() > 3 && intval(argv(2)) && argv(3) === 'status') {
        $ret = array('success' => false);
        $room_id = intval(argv(2));
        if (!$room_id || !$observer) {
            return;
        }
        $r = q("select * from chatroom where cr_id = %d limit 1", intval($room_id));
        if (!$r) {
            json_return_and_die($ret);
        }
        require_once 'include/security.php';
        $sql_extra = permissions_sql($r[0]['cr_uid']);
        $x = q("select * from chatroom where cr_id = %d and cr_uid = %d {$sql_extra} limit 1", intval($room_id), intval($r[0]['cr_uid']));
        if (!$x) {
            json_return_and_die($ret);
        }
        $y = q("select count(*) as total from chatpresence where cp_room = %d", intval($room_id));
        if ($y) {
            $ret['success'] = true;
            $ret['chatroom'] = $r[0]['cr_name'];
            $ret['inroom'] = $y[0]['total'];
        }
        // figure out how to present a timestamp of the last activity, since we don't know the observer's timezone.
        $z = q("select created from chat where chat_room = %d order by created desc limit 1", intval($room_id));
        if ($z) {
            $ret['last'] = $z[0]['created'];
        }
        json_return_and_die($ret);
    }
    if (argc() > 2 && intval(argv(2))) {
        $room_id = intval(argv(2));
        $bookmark_link = get_bookmark_link($ob);
        $x = chatroom_enter($observer, $room_id, 'online', $_SERVER['REMOTE_ADDR']);
        if (!$x) {
            return;
        }
        $x = q("select * from chatroom where cr_id = %d and cr_uid = %d {$sql_extra} limit 1", intval($room_id), intval($a->profile['profile_uid']));
        if ($x) {
            $acl = new AccessList(false);
            $acl->set($x[0]);
            $private = $acl->is_private();
            $room_name = $x[0]['cr_name'];
            if ($bookmark_link) {
                $bookmark_link .= '&url=' . z_root() . '/chat/' . argv(1) . '/' . argv(2) . '&title=' . urlencode($x[0]['cr_name']) . ($private ? '&private=1' : '') . '&ischat=1';
            }
        } else {
            notice(t('Room not found') . EOL);
            return;
        }
        $o = replace_macros(get_markup_template('chat.tpl'), array('$is_owner' => local_channel() && local_channel() == $x[0]['cr_uid'] ? true : false, '$room_name' => $room_name, '$room_id' => $room_id, '$baseurl' => z_root(), '$nickname' => argv(1), '$submit' => t('Submit'), '$leave' => t('Leave Room'), '$drop' => t('Delete This Room'), '$away' => t('I am away right now'), '$online' => t('I am online'), '$bookmark_link' => $bookmark_link, '$bookmark' => t('Bookmark this room')));
        return $o;
    }
    if (local_channel() && argc() > 2 && argv(2) === 'new') {
        $acl = new AccessList($channel);
        $channel_acl = $acl->get();
        require_once 'include/acl_selectors.php';
        $o = replace_macros(get_markup_template('chatroom_new.tpl'), array('$header' => t('New Chatroom'), '$name' => array('room_name', t('Chatroom Name'), '', ''), '$chat_expire' => array('chat_expire', t('Expiration of chats (minutes)'), 120, ''), '$permissions' => t('Permissions'), '$acl' => populate_acl($channel_acl, false), '$submit' => t('Submit')));
        return $o;
    }
    require_once 'include/conversation.php';
    $o = profile_tabs($a, local_channel() && local_channel() == $a->profile['profile_uid'] ? true : false, $a->profile['channel_address']);
    require_once 'include/widgets.php';
    $o .= replace_macros(get_markup_template('chatrooms.tpl'), array('$header' => sprintf(t('%1$s\'s Chatrooms'), $a->profile['name']), '$baseurl' => z_root(), '$nickname' => $channel['channel_address'], '$rooms' => widget_chatroom_list(array()), '$newroom' => t('New Chatroom'), '$is_owner' => local_channel() && local_channel() == $a->profile['profile_uid'] ? 1 : 0));
    return $o;
}
Example #14
0
function webpages_content(&$a)
{
    if (!App::$profile) {
        notice(t('Requested profile is not available.') . EOL);
        App::$error = 404;
        return;
    }
    $which = argv(1);
    $_SESSION['return_url'] = App::$query_string;
    $uid = local_channel();
    $owner = 0;
    $channel = null;
    $observer = App::get_observer();
    $channel = App::get_channel();
    if (App::$is_sys && is_site_admin()) {
        $sys = get_sys_channel();
        if ($sys && intval($sys['channel_id'])) {
            $uid = $owner = intval($sys['channel_id']);
            $channel = $sys;
            $observer = $sys;
        }
    }
    if (!$owner) {
        // Figure out who the page owner is.
        $r = q("select channel_id from channel where channel_address = '%s'", dbesc($which));
        if ($r) {
            $owner = intval($r[0]['channel_id']);
        }
    }
    $ob_hash = $observer ? $observer['xchan_hash'] : '';
    $perms = get_all_perms($owner, $ob_hash);
    if (!$perms['write_pages']) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $mimetype = $_REQUEST['mimetype'] ? $_REQUEST['mimetype'] : get_pconfig($owner, 'system', 'page_mimetype');
    if (!$mimetype) {
        $mimetype = 'choose';
    }
    $layout = $_REQUEST['layout'] ? $_REQUEST['layout'] : get_pconfig($owner, 'system', 'page_layout');
    if (!$layout) {
        $layout = 'choose';
    }
    // Create a status editor (for now - we'll need a WYSIWYG eventually) to create pages
    // Nickname is set to the observers xchan, and profile_uid to the owner's.
    // This lets you post pages at other people's channels.
    if (!$channel && $uid && $uid == App::$profile_uid) {
        $channel = App::get_channel();
    }
    if ($channel) {
        $channel_acl = array('allow_cid' => $channel['channel_allow_cid'], 'allow_gid' => $channel['channel_allow_gid'], 'deny_cid' => $channel['channel_deny_cid'], 'deny_gid' => $channel['channel_deny_gid']);
    } else {
        $channel_acl = array();
    }
    $is_owner = $uid && $uid == $owner;
    $o = profile_tabs($a, $is_owner, App::$profile['channel_address']);
    $x = array('webpage' => ITEM_TYPE_WEBPAGE, 'is_owner' => true, 'nickname' => App::$profile['channel_address'], 'lockstate' => $channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid'] ? 'lock' : 'unlock', 'bang' => '', 'acl' => $is_owner ? populate_acl($channel_acl, false) : '', 'showacl' => $is_owner ? true : false, 'visitor' => true, 'profile_uid' => intval($owner), 'mimetype' => $mimetype, 'layout' => $layout, 'expanded' => true, 'novoting' => true, 'bbco_autocomplete' => 'bbcode', 'bbcode' => true);
    if ($_REQUEST['title']) {
        $x['title'] = $_REQUEST['title'];
    }
    if ($_REQUEST['body']) {
        $x['body'] = $_REQUEST['body'];
    }
    if ($_REQUEST['pagetitle']) {
        $x['pagetitle'] = $_REQUEST['pagetitle'];
    }
    $editor = status_editor($a, $x);
    // Get a list of webpages.  We can't display all them because endless scroll makes that unusable,
    // so just list titles and an edit link.
    /** @TODO - this should be replaced with pagelist_widget */
    $sql_extra = item_permissions_sql($owner);
    $r = q("select * from item_id left join item on item_id.iid = item.id \n\t\twhere item_id.uid = %d and service = 'WEBPAGE' and item_type = %d {$sql_extra} order by item.created desc", intval($owner), intval(ITEM_TYPE_WEBPAGE));
    $pages = null;
    if ($r) {
        $pages = array();
        foreach ($r as $rr) {
            unobscure($rr);
            $lockstate = $rr['allow_cid'] || $rr['allow_gid'] || $rr['deny_cid'] || $rr['deny_gid'] ? 'lock' : 'unlock';
            $element_arr = array('type' => 'webpage', 'title' => $rr['title'], 'body' => $rr['body'], 'created' => $rr['created'], 'edited' => $rr['edited'], 'mimetype' => $rr['mimetype'], 'pagetitle' => $rr['sid'], 'mid' => $rr['mid'], 'layout_mid' => $rr['layout_mid']);
            $pages[$rr['iid']][] = array('url' => $rr['iid'], 'pagetitle' => $rr['sid'], 'title' => $rr['title'], 'created' => datetime_convert('UTC', date_default_timezone_get(), $rr['created']), 'edited' => datetime_convert('UTC', date_default_timezone_get(), $rr['edited']), 'bb_element' => '[element]' . base64url_encode(json_encode($element_arr)) . '[/element]', 'lockstate' => $lockstate);
        }
    }
    //Build the base URL for edit links
    $url = z_root() . '/editwebpage/' . $which;
    $o .= replace_macros(get_markup_template('webpagelist.tpl'), array('$listtitle' => t('Webpages'), '$baseurl' => $url, '$create' => t('Create'), '$edit' => t('Edit'), '$share' => t('Share'), '$delete' => t('Delete'), '$pages' => $pages, '$channel' => $which, '$editor' => $editor, '$view' => t('View'), '$preview' => t('Preview'), '$actions_txt' => t('Actions'), '$pagelink_txt' => t('Page Link'), '$title_txt' => t('Page Title'), '$created_txt' => t('Created'), '$edited_txt' => t('Edited')));
    return $o;
}
Example #15
0
File: reddav.php Project: Mauru/red
 /**
  * @brief Creates the directory listing for the given path.
  *
  * @param string $path which should be displayed
  */
 public function generateDirectoryIndex($path)
 {
     // (owner_id = channel_id) is visitor owner of this directory?
     $is_owner = local_user() && $this->auth->owner_id == local_user() ? true : false;
     if ($this->auth->timezone) {
         date_default_timezone_set($this->auth->timezone);
     }
     require_once 'include/conversation.php';
     if ($this->auth->owner_nick) {
         $html = profile_tabs(get_app(), $is_owner ? true : false, $this->auth->owner_nick);
     }
     $files = $this->server->getPropertiesForPath($path, array('{DAV:}displayname', '{DAV:}resourcetype', '{DAV:}getcontenttype', '{DAV:}getcontentlength', '{DAV:}getlastmodified'), 1);
     $parent = $this->server->tree->getNodeForPath($path);
     $parentpath = array();
     // only show parent if not leaving /cloud/; TODO how to improve this?
     if ($path && $path != "cloud") {
         list($parentUri) = DAV\URLUtil::splitPath($path);
         $fullPath = DAV\URLUtil::encodePath($this->server->getBaseUri() . $parentUri);
         $parentpath['icon'] = $this->enableAssets ? '<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl('icons/parent' . $this->iconExtension) . '" width="24" alt="' . t('parent') . '"></a>' : '';
         $parentpath['path'] = $fullPath;
     }
     $f = array();
     foreach ($files as $file) {
         $ft = array();
         $type = null;
         // This is the current directory, we can skip it
         if (rtrim($file['href'], '/') == $path) {
             continue;
         }
         list(, $name) = DAV\URLUtil::splitPath($file['href']);
         if (isset($file[200]['{DAV:}resourcetype'])) {
             $type = $file[200]['{DAV:}resourcetype']->getValue();
             // resourcetype can have multiple values
             if (!is_array($type)) {
                 $type = array($type);
             }
             foreach ($type as $k => $v) {
                 // Some name mapping is preferred
                 switch ($v) {
                     case '{DAV:}collection':
                         $type[$k] = t('Collection');
                         break;
                     case '{DAV:}principal':
                         $type[$k] = t('Principal');
                         break;
                     case '{urn:ietf:params:xml:ns:carddav}addressbook':
                         $type[$k] = t('Addressbook');
                         break;
                     case '{urn:ietf:params:xml:ns:caldav}calendar':
                         $type[$k] = t('Calendar');
                         break;
                     case '{urn:ietf:params:xml:ns:caldav}schedule-inbox':
                         $type[$k] = t('Schedule Inbox');
                         break;
                     case '{urn:ietf:params:xml:ns:caldav}schedule-outbox':
                         $type[$k] = t('Schedule Outbox');
                         break;
                     case '{http://calendarserver.org/ns/}calendar-proxy-read':
                         $type[$k] = 'Proxy-Read';
                         break;
                     case '{http://calendarserver.org/ns/}calendar-proxy-write':
                         $type[$k] = 'Proxy-Write';
                         break;
                 }
             }
             $type = implode(', ', $type);
         }
         // If no resourcetype was found, we attempt to use
         // the contenttype property
         if (!$type && isset($file[200]['{DAV:}getcontenttype'])) {
             $type = $file[200]['{DAV:}getcontenttype'];
         }
         if (!$type) {
             $type = t('Unknown');
         }
         $size = isset($file[200]['{DAV:}getcontentlength']) ? (int) $file[200]['{DAV:}getcontentlength'] : '';
         $lastmodified = isset($file[200]['{DAV:}getlastmodified']) ? $file[200]['{DAV:}getlastmodified']->getTime()->format('Y-m-d H:i:s') : '';
         $fullPath = DAV\URLUtil::encodePath('/' . trim($this->server->getBaseUri() . ($path ? $path . '/' : '') . $name, '/'));
         $displayName = isset($file[200]['{DAV:}displayname']) ? $file[200]['{DAV:}displayname'] : $name;
         $displayName = $this->escapeHTML($displayName);
         $type = $this->escapeHTML($type);
         $icon = '';
         if ($this->enableAssets) {
             $node = $this->server->tree->getNodeForPath(($path ? $path . '/' : '') . $name);
             foreach (array_reverse($this->iconMap) as $class => $iconName) {
                 if ($node instanceof $class) {
                     $icon = '<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl($iconName . $this->iconExtension) . '" alt="" width="24"></a>';
                     break;
                 }
             }
         }
         $parentHash = "";
         $owner = $this->auth->owner_id;
         $splitPath = split("/", $fullPath);
         if (count($splitPath) > 3) {
             for ($i = 3; $i < count($splitPath); $i++) {
                 $attachName = urldecode($splitPath[$i]);
                 $attachHash = $this->findAttachHash($owner, $parentHash, $attachName);
                 $parentHash = $attachHash;
             }
         }
         $attachIcon = "";
         // "<a href=\"attach/".$attachHash."\" title=\"".$displayName."\"><i class=\"icon-download\"></i></a>";
         // put the array for this file together
         $ft['attachId'] = $this->findAttachIdByHash($attachHash);
         $ft['fileStorageUrl'] = substr($fullPath, 0, strpos($fullPath, "cloud/")) . "filestorage/" . $this->auth->channel_name;
         $ft['icon'] = $icon;
         $ft['attachIcon'] = $size ? $attachIcon : '';
         // @todo Should this be an item value, not a global one?
         $ft['is_owner'] = $is_owner;
         $ft['fullPath'] = $fullPath;
         $ft['displayName'] = $displayName;
         $ft['type'] = $type;
         $ft['size'] = $size;
         $ft['sizeFormatted'] = $this->userReadableSize($size);
         $ft['lastmodified'] = $lastmodified ? datetime_convert('UTC', date_default_timezone_get(), $lastmodified) : '';
         $f[] = $ft;
     }
     // Storage and quota for the account (all channels of the owner of this directory)!
     $limit = service_class_fetch($owner, 'attach_upload_limit');
     $r = q("SELECT SUM(filesize) AS total FROM attach WHERE aid = %d", intval($this->auth->channel_account_id));
     $used = $r[0]['total'];
     if ($used) {
         $quotaDesc = t('%1$s used');
         $quotaDesc = sprintf($quotaDesc, $this->userReadableSize($used));
     }
     if ($limit && $used) {
         $quotaDesc = t('%1$s used of %2$s (%3$s&#37;)');
         $quotaDesc = sprintf($quotaDesc, $this->userReadableSize($used), $this->userReadableSize($limit), round($used / $limit, 1));
     }
     // prepare quota for template
     $quota['used'] = $used;
     $quota['limit'] = $limit;
     $quota['desc'] = $quotaDesc;
     $html .= replace_macros(get_markup_template('cloud_directory.tpl'), array('$header' => t('Files') . ": " . $this->escapeHTML($path) . "/", '$parentpath' => $parentpath, '$entries' => $f, '$quota' => $quota, '$name' => t('Name'), '$type' => t('Type'), '$size' => t('Size'), '$lastmod' => t('Last Modified'), '$parent' => t('parent'), '$edit' => t('Edit'), '$delete' => t('Delete'), '$total' => t('Total')));
     $output = '';
     if ($this->enablePost) {
         $this->server->broadcastEvent('onHTMLActionsPanel', array($parent, &$output));
     }
     $html .= $output;
     get_app()->page['content'] = $html;
     construct_page(get_app());
 }
Example #16
0
function videos_content(&$a)
{
    // URLs (most aren't currently implemented):
    // videos/name
    // videos/name/upload
    // videos/name/upload/xxxxx (xxxxx is album name)
    // videos/name/album/xxxxx
    // videos/name/album/xxxxx/edit
    // videos/name/video/xxxxx
    // videos/name/video/xxxxx/edit
    if (get_config('system', 'block_public') && !local_user() && !remote_user()) {
        notice(t('Public access denied.') . EOL);
        return;
    }
    require_once 'include/bbcode.php';
    require_once 'include/security.php';
    require_once 'include/conversation.php';
    if (!x($a->data, 'user')) {
        notice(t('No videos selected') . EOL);
        return;
    }
    //$phototypes = Photo::supportedTypes();
    $_SESSION['video_return'] = $a->cmd;
    //
    // Parse arguments
    //
    if ($a->argc > 3) {
        $datatype = $a->argv[2];
        $datum = $a->argv[3];
    } elseif ($a->argc > 2 && $a->argv[2] === 'upload') {
        $datatype = 'upload';
    } else {
        $datatype = 'summary';
    }
    if ($a->argc > 4) {
        $cmd = $a->argv[4];
    } else {
        $cmd = 'view';
    }
    //
    // Setup permissions structures
    //
    $can_post = false;
    $visitor = 0;
    $contact = null;
    $remote_contact = false;
    $contact_id = 0;
    $owner_uid = $a->data['user']['uid'];
    $community_page = $a->data['user']['page-flags'] == PAGE_COMMUNITY ? true : false;
    if (local_user() && local_user() == $owner_uid) {
        $can_post = true;
    } else {
        if ($community_page && remote_user()) {
            if (is_array($_SESSION['remote'])) {
                foreach ($_SESSION['remote'] as $v) {
                    if ($v['uid'] == $owner_uid) {
                        $contact_id = $v['cid'];
                        break;
                    }
                }
            }
            if ($contact_id) {
                $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), intval($owner_uid));
                if (count($r)) {
                    $can_post = true;
                    $contact = $r[0];
                    $remote_contact = true;
                    $visitor = $cid;
                }
            }
        }
    }
    // perhaps they're visiting - but not a community page, so they wouldn't have write access
    if (remote_user() && !$visitor) {
        $contact_id = 0;
        if (is_array($_SESSION['remote'])) {
            foreach ($_SESSION['remote'] as $v) {
                if ($v['uid'] == $owner_uid) {
                    $contact_id = $v['cid'];
                    break;
                }
            }
        }
        if ($contact_id) {
            $groups = init_groups_visitor($contact_id);
            $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), intval($owner_uid));
            if (count($r)) {
                $contact = $r[0];
                $remote_contact = true;
            }
        }
    }
    if (!$remote_contact) {
        if (local_user()) {
            $contact_id = $_SESSION['cid'];
            $contact = $a->contact;
        }
    }
    if ($a->data['user']['hidewall'] && local_user() != $owner_uid && !$remote_contact) {
        notice(t('Access to this item is restricted.') . EOL);
        return;
    }
    $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
    $o = "";
    // tabs
    $_is_owner = local_user() && local_user() == $owner_uid;
    $o .= profile_tabs($a, $_is_owner, $a->data['user']['nickname']);
    //
    // dispatch request
    //
    if ($datatype === 'upload') {
        return;
        // no uploading for now
        // DELETED -- look at mod/photos.php if you want to implement
    }
    if ($datatype === 'album') {
        return;
        // no albums for now
        // DELETED -- look at mod/photos.php if you want to implement
    }
    if ($datatype === 'video') {
        return;
        // no single video view for now
        // DELETED -- look at mod/photos.php if you want to implement
    }
    // Default - show recent videos (no upload link for now)
    //$o = '';
    $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'\n\t\t{$sql_extra} GROUP BY hash", intval($a->data['user']['uid']));
    if (count($r)) {
        $a->set_pager_total(count($r));
        $a->set_pager_itemspage(20);
    }
    $r = q("SELECT hash, `id`, `filename`, filetype FROM `attach`\n\t\tWHERE `uid` = %d AND filetype LIKE '%%video%%'\n\t\t{$sql_extra} GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d", intval($a->data['user']['uid']), intval($a->pager['start']), intval($a->pager['itemspage']));
    $videos = array();
    if (count($r)) {
        foreach ($r as $rr) {
            if ($a->theme['template_engine'] === 'internal') {
                $alt_e = template_escape($rr['filename']);
                $name_e = template_escape($rr['album']);
            } else {
                $alt_e = $rr['filename'];
                $name_e = $rr['album'];
            }
            $videos[] = array('id' => $rr['id'], 'link' => $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'], 'title' => t('View Video'), 'src' => $a->get_baseurl() . '/attach/' . $rr['id'] . '?attachment=0', 'alt' => $alt_e, 'mime' => $rr['filetype'], 'album' => array('link' => $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']), 'name' => $name_e, 'alt' => t('View Album')));
        }
    }
    $tpl = get_markup_template('videos_recent.tpl');
    $o .= replace_macros($tpl, array('$title' => t('Recent Videos'), '$can_post' => $can_post, '$upload' => array(t('Upload New Videos'), $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/upload'), '$videos' => $videos, '$delete_url' => $can_post ? $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] : False));
    $o .= paginate($a);
    return $o;
}
Example #17
0
 function get()
 {
     if (observer_prohibited(true)) {
         return login();
     }
     if (!feature_enabled(\App::$profile_uid, 'wiki')) {
         notice(t('Not found') . EOL);
         return;
     }
     $tab = 'wiki';
     require_once 'include/wiki.php';
     require_once 'include/acl_selectors.php';
     require_once 'include/conversation.php';
     // TODO: Combine the interface configuration into a unified object
     // Something like $interface = array('new_page_button' => false, 'new_wiki_button' => false, ...)
     $wiki_owner = false;
     $showNewWikiButton = false;
     $showCommitMsg = false;
     $hidePageHistory = false;
     $pageHistory = array();
     $local_observer = null;
     $resource_id = '';
     // init() should have forced the URL to redirect to /wiki/channel so assume argc() > 1
     $nick = argv(1);
     $channel = get_channel_by_nick($nick);
     // The channel who owns the wikis being viewed
     if (!$channel) {
         notice('Invalid channel' . EOL);
         goaway('/' . argv(0));
     }
     // Determine if the observer is the channel owner so the ACL dialog can be populated
     if (local_channel() === intval($channel['channel_id'])) {
         $local_observer = \App::get_channel();
         $wiki_owner = true;
         // Obtain the default permission settings of the channel
         $channel_acl = array('allow_cid' => $local_observer['channel_allow_cid'], 'allow_gid' => $local_observer['channel_allow_gid'], 'deny_cid' => $local_observer['channel_deny_cid'], 'deny_gid' => $local_observer['channel_deny_gid']);
         // Initialize the ACL to the channel default permissions
         $x = array('lockstate' => $local_observer['channel_allow_cid'] || $local_observer['channel_allow_gid'] || $local_observer['channel_deny_cid'] || $local_observer['channel_deny_gid'] ? 'lock' : 'unlock', 'acl' => populate_acl($channel_acl), 'bang' => '');
     } else {
         // Not the channel owner
         $channel_acl = $x = array();
     }
     switch (argc()) {
         case 2:
             // Configure page template
             $wikiheaderName = t('Wiki');
             $wikiheaderPage = t('Sandbox');
             require_once 'library/markdown.php';
             $content = t('"# Wiki Sandbox\\n\\nContent you **edit** and **preview** here *will not be saved*."');
             $renderedContent = Markdown(json_decode($content));
             $hide_editor = false;
             $showPageControls = false;
             $showNewWikiButton = $wiki_owner;
             $showNewPageButton = false;
             $hidePageHistory = true;
             $showCommitMsg = false;
             break;
         case 3:
             // /wiki/channel/wiki -> No page was specified, so redirect to Home.md
             $wikiUrlName = urlencode(argv(2));
             goaway('/' . argv(0) . '/' . argv(1) . '/' . $wikiUrlName . '/Home');
         case 4:
             // GET /wiki/channel/wiki/page
             // Fetch the wiki info and determine observer permissions
             $wikiUrlName = urlencode(argv(2));
             $pageUrlName = urlencode(argv(3));
             $w = wiki_exists_by_name($channel['channel_id'], $wikiUrlName);
             if (!$w['resource_id']) {
                 notice('Wiki not found' . EOL);
                 goaway('/' . argv(0) . '/' . argv(1));
             }
             $resource_id = $w['resource_id'];
             if (!$wiki_owner) {
                 // Check for observer permissions
                 $observer_hash = get_observer_hash();
                 $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash);
                 if (!$perms['read']) {
                     notice('Permission denied.' . EOL);
                     goaway('/' . argv(0) . '/' . argv(1));
                 }
                 if ($perms['write']) {
                     $wiki_editor = true;
                 } else {
                     $wiki_editor = false;
                 }
             } else {
                 $wiki_editor = true;
             }
             $wikiheaderName = urldecode($wikiUrlName);
             $wikiheaderPage = urldecode($pageUrlName);
             $p = wiki_get_page_content(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
             if (!$p['success']) {
                 notice('Error retrieving page content' . EOL);
                 goaway('/' . argv(0) . '/' . argv(1) . '/' . $wikiUrlName);
             }
             $content = $p['content'] !== '' ? htmlspecialchars_decode($p['content'], ENT_COMPAT) : '"# New page\\n"';
             // Render the Markdown-formatted page content in HTML
             require_once 'library/markdown.php';
             $html = wiki_generate_toc(purify_html(Markdown(json_decode($content))));
             $renderedContent = wiki_convert_links($html, argv(0) . '/' . argv(1) . '/' . $wikiUrlName);
             $hide_editor = false;
             $showPageControls = $wiki_editor;
             $showNewWikiButton = $wiki_owner;
             $showNewPageButton = $wiki_editor;
             $hidePageHistory = false;
             $showCommitMsg = true;
             $pageHistory = wiki_page_history(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
             break;
         default:
             // Strip the extraneous URL components
             goaway('/' . argv(0) . '/' . argv(1) . '/' . $wikiUrlName . '/' . $pageUrlName);
     }
     $wikiModalID = random_string(3);
     $wikiModal = replace_macros(get_markup_template('generic_modal.tpl'), array('$id' => $wikiModalID, '$title' => t('Revision Comparison'), '$ok' => t('Revert'), '$cancel' => t('Cancel')));
     $is_owner = local_channel() && local_channel() == \App::$profile['profile_uid'] ? true : false;
     $o .= profile_tabs($a, $is_owner, \App::$profile['channel_address']);
     $o .= replace_macros(get_markup_template('wiki.tpl'), array('$wikiheaderName' => $wikiheaderName, '$wikiheaderPage' => $wikiheaderPage, '$hideEditor' => $hide_editor, '$showPageControls' => $showPageControls, '$showNewWikiButton' => $showNewWikiButton, '$showNewPageButton' => $showNewPageButton, '$hidePageHistory' => $hidePageHistory, '$showCommitMsg' => $showCommitMsg, '$channel' => $channel['channel_address'], '$resource_id' => $resource_id, '$page' => $pageUrlName, '$lockstate' => $x['lockstate'], '$acl' => $x['acl'], '$bang' => $x['bang'], '$content' => $content, '$renderedContent' => $renderedContent, '$wikiName' => array('wikiName', t('Enter the name of your new wiki:'), '', ''), '$pageName' => array('pageName', t('Enter the name of the new page:'), '', ''), '$pageRename' => array('pageRename', t('Enter the new name:'), '', ''), '$commitMsg' => array('commitMsg', '', '', '', '', 'placeholder="(optional) Enter a custom message when saving the page..."'), '$pageHistory' => $pageHistory['history'], '$wikiModal' => $wikiModal, '$wikiModalID' => $wikiModalID, '$commit' => 'HEAD', '$embedPhotos' => t('Embed image from photo albums'), '$embedPhotosModalTitle' => t('Embed an image from your albums'), '$embedPhotosModalCancel' => t('Cancel'), '$embedPhotosModalOK' => t('OK'), '$modalchooseimages' => t('Choose images to embed'), '$modalchoosealbum' => t('Choose an album'), '$modaldiffalbum' => t('Choose a different album...'), '$modalerrorlist' => t('Error getting album list'), '$modalerrorlink' => t('Error getting photo link'), '$modalerroralbum' => t('Error getting album')));
     head_add_js('library/ace/ace.js');
     // Ace Code Editor
     return $o;
 }
Example #18
0
 function get()
 {
     if (observer_prohibited()) {
         return;
     }
     $channel = null;
     if (argc() > 1) {
         $channel = channelx_by_nick(argv(1));
     }
     if (!$channel) {
         notice(t('Channel not found.') . EOL);
         return;
     }
     // since we don't currently have an event permission - use the stream permission
     if (!perm_is_allowed($channel['channel_id'], get_observer_hash(), 'view_stream')) {
         notice(t('Permissions denied.') . EOL);
         return;
     }
     $sql_extra = permissions_sql($channel['channel_id'], get_observer_hash(), 'event');
     $first_day = get_pconfig(local_channel(), 'system', 'cal_first_day');
     $first_day = $first_day ? $first_day : 0;
     $htpl = get_markup_template('event_head.tpl');
     \App::$page['htmlhead'] .= replace_macros($htpl, array('$baseurl' => z_root(), '$module_url' => '/cal/' . $channel['channel_address'], '$modparams' => 2, '$lang' => \App::$language, '$first_day' => $first_day));
     $o = '';
     $tabs = profile_tabs($a, True, $channel['channel_address']);
     $mode = 'view';
     $y = 0;
     $m = 0;
     $ignored = x($_REQUEST, 'ignored') ? " and dismissed = " . intval($_REQUEST['ignored']) . " " : '';
     // logger('args: ' . print_r(\App::$argv,true));
     if (argc() > 3 && intval(argv(2)) && intval(argv(3))) {
         $mode = 'view';
         $y = intval(argv(2));
         $m = intval(argv(3));
     }
     if (argc() <= 3) {
         $mode = 'view';
         $event_id = argv(2);
     }
     if ($mode == 'view') {
         /* edit/create form */
         if ($event_id) {
             $r = q("SELECT * FROM `event` WHERE event_hash = '%s' AND `uid` = %d LIMIT 1", dbesc($event_id), intval($channel['channel_id']));
             if (count($r)) {
                 $orig_event = $r[0];
             }
         }
         // Passed parameters overrides anything found in the DB
         if (!x($orig_event)) {
             $orig_event = array();
         }
         $tz = date_default_timezone_get();
         if (x($orig_event)) {
             $tz = $orig_event['adjust'] ? date_default_timezone_get() : 'UTC';
         }
         $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
         $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
         $sday = datetime_convert('UTC', $tz, $sdt, 'd');
         $shour = datetime_convert('UTC', $tz, $sdt, 'H');
         $sminute = datetime_convert('UTC', $tz, $sdt, 'i');
         $stext = datetime_convert('UTC', $tz, $sdt);
         $stext = substr($stext, 0, 14) . "00:00";
         $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
         $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
         $fday = datetime_convert('UTC', $tz, $fdt, 'd');
         $fhour = datetime_convert('UTC', $tz, $fdt, 'H');
         $fminute = datetime_convert('UTC', $tz, $fdt, 'i');
         $ftext = datetime_convert('UTC', $tz, $fdt);
         $ftext = substr($ftext, 0, 14) . "00:00";
         $type = x($orig_event) ? $orig_event['etype'] : 'event';
         $f = get_config('system', 'event_input_format');
         if (!$f) {
             $f = 'ymd';
         }
         $catsenabled = feature_enabled($channel['channel_id'], 'categories');
         $show_bd = perm_is_allowed($channel['channel_id'], get_observer_hash(), 'view_contacts');
         if (!$show_bd) {
             $sql_extra .= " and event.etype != 'birthday' ";
         }
         $category = '';
         $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
         $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
         if (!$y) {
             $y = intval($thisyear);
         }
         if (!$m) {
             $m = intval($thismonth);
         }
         // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
         // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
         if ($y < 1901) {
             $y = 1900;
         }
         if ($y > 2099) {
             $y = 2100;
         }
         $nextyear = $y;
         $nextmonth = $m + 1;
         if ($nextmonth > 12) {
             $nextmonth = 1;
             $nextyear++;
         }
         $prevyear = $y;
         if ($m > 1) {
             $prevmonth = $m - 1;
         } else {
             $prevmonth = 12;
             $prevyear--;
         }
         $dim = get_dim($y, $m);
         $start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
         $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
         if (argv(2) === 'json') {
             if (x($_GET, 'start')) {
                 $start = $_GET['start'];
             }
             if (x($_GET, 'end')) {
                 $finish = $_GET['end'];
             }
         }
         $start = datetime_convert('UTC', 'UTC', $start);
         $finish = datetime_convert('UTC', 'UTC', $finish);
         $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
         $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
         if (x($_GET, 'id')) {
             $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan\n\t                                from event left join item on resource_id = event_hash where resource_type = 'event' and event.uid = %d and event.id = %d {$sql_extra} limit 1", intval($channel['channel_id']), intval($_GET['id']));
         } else {
             // fixed an issue with "nofinish" events not showing up in the calendar.
             // There's still an issue if the finish date crosses the end of month.
             // Noting this for now - it will need to be fixed here and in Friendica.
             // Ultimately the finish date shouldn't be involved in the query.
             $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan\n\t                              from event left join item on event_hash = resource_id \n\t\t\t\t\twhere resource_type = 'event' and event.uid = %d {$ignored} \n\t\t\t\t\tAND (( adjust = 0 AND ( dtend >= '%s' or nofinish = 1 ) AND dtstart <= '%s' ) \n\t\t\t\t\tOR  (  adjust = 1 AND ( dtend >= '%s' or nofinish = 1 ) AND dtstart <= '%s' )) {$sql_extra} ", intval($channel['channel_id']), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_finish));
         }
         $links = array();
         if ($r) {
             xchan_query($r);
             $r = fetch_post_tags($r, true);
             $r = sort_by_date($r);
         }
         if ($r) {
             foreach ($r as $rr) {
                 $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'j');
                 if (!x($links, $j)) {
                     $links[$j] = z_root() . '/' . \App::$cmd . '#link-' . $j;
                 }
             }
         }
         $events = array();
         $last_date = '';
         $fmt = t('l, F j');
         if ($r) {
             foreach ($r as $rr) {
                 $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'j');
                 $d = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], $fmt) : datetime_convert('UTC', 'UTC', $rr['dtstart'], $fmt);
                 $d = day_translate($d);
                 $start = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'c');
                 if ($rr['nofinish']) {
                     $end = null;
                 } else {
                     $end = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtend'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtend'], 'c');
                 }
                 $is_first = $d !== $last_date;
                 $last_date = $d;
                 $edit = false;
                 $drop = false;
                 $title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
                 if (!$title) {
                     list($title, $_trash) = explode("<br", bbcode($rr['desc']), 2);
                     $title = strip_tags(html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
                 }
                 $html = format_event_html($rr);
                 $rr['desc'] = bbcode($rr['desc']);
                 $rr['location'] = bbcode($rr['location']);
                 $events[] = array('id' => $rr['id'], 'hash' => $rr['event_hash'], 'start' => $start, 'end' => $end, 'drop' => $drop, 'allDay' => false, 'title' => $title, 'j' => $j, 'd' => $d, 'edit' => $edit, 'is_first' => $is_first, 'item' => $rr, 'html' => $html, 'plink' => array($rr['plink'], t('Link to Source'), '', ''));
             }
         }
         if (argv(2) === 'json') {
             echo json_encode($events);
             killme();
         }
         // links: array('href', 'text', 'extra css classes', 'title')
         if (x($_GET, 'id')) {
             $tpl = get_markup_template("event_cal.tpl");
         } else {
             $tpl = get_markup_template("events_cal-js.tpl");
         }
         $nick = $channel['channel_address'];
         $o = replace_macros($tpl, array('$baseurl' => z_root(), '$new_event' => array(z_root() . '/cal', $event_id ? t('Edit Event') : t('Create Event'), '', ''), '$previus' => array(z_root() . "/cal/{$nick}/{$prevyear}/{$prevmonth}", t('Previous'), '', ''), '$next' => array(z_root() . "/cal/{$nick}/{$nextyear}/{$nextmonth}", t('Next'), '', ''), '$export' => array(z_root() . "/cal/{$nick}/{$y}/{$m}/export", t('Export'), '', ''), '$calendar' => cal($y, $m, $links, ' eventcal'), '$events' => $events, '$upload' => t('Import'), '$submit' => t('Submit'), '$prev' => t('Previous'), '$next' => t('Next'), '$today' => t('Today'), '$form' => $form, '$expandform' => x($_GET, 'expandform') ? true : false, '$tabs' => $tabs));
         if (x($_GET, 'id')) {
             echo $o;
             killme();
         }
         return $o;
     }
 }
Example #19
0
function events_content(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $htpl = get_markup_template('event_head.tpl');
    $a->page['htmlhead'] .= replace_macros($htpl, array('$baseurl' => $a->get_baseurl()));
    $o = "";
    // tabs
    $tabs = profile_tabs($a, True);
    $mode = 'view';
    $y = 0;
    $m = 0;
    if ($a->argc > 1) {
        if ($a->argc > 2 && $a->argv[1] == 'event') {
            $mode = 'edit';
            $event_id = intval($a->argv[2]);
        }
        if ($a->argv[1] === 'new') {
            $mode = 'new';
            $event_id = 0;
        }
        if ($a->argc > 2 && intval($a->argv[1]) && intval($a->argv[2])) {
            $mode = 'view';
            $y = intval($a->argv[1]);
            $m = intval($a->argv[2]);
        }
    }
    if ($mode == 'view') {
        $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
        $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
        if (!$y) {
            $y = intval($thisyear);
        }
        if (!$m) {
            $m = intval($thismonth);
        }
        // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
        // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
        if ($y < 1901) {
            $y = 1900;
        }
        if ($y > 2099) {
            $y = 2100;
        }
        $nextyear = $y;
        $nextmonth = $m + 1;
        if ($nextmonth > 12) {
            $nextmonth = 1;
            $nextyear++;
        }
        $prevyear = $y;
        if ($m > 1) {
            $prevmonth = $m - 1;
        } else {
            $prevmonth = 12;
            $prevyear--;
        }
        $dim = get_dim($y, $m);
        $start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
        $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
        if ($a->argv[1] === 'json') {
            if (x($_GET, 'start')) {
                $start = date("Y-m-d h:i:s", $_GET['start']);
            }
            if (x($_GET, 'end')) {
                $finish = date("Y-m-d h:i:s", $_GET['end']);
            }
        }
        $start = datetime_convert('UTC', 'UTC', $start);
        $finish = datetime_convert('UTC', 'UTC', $finish);
        $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
        $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
        if (x($_GET, 'id')) {
            $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,\n\t\t\t\t`item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event` LEFT JOIN `item` ON `item`.`event-id` = `event`.`id` \n\t\t\t\tWHERE `event`.`uid` = %d AND `event`.`id` = %d", intval(local_user()), intval($_GET['id']));
        } else {
            $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,\n\t\t\t\t`item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event` LEFT JOIN `item` ON `item`.`event-id` = `event`.`id` \n\t\t\t\tWHERE `event`.`uid` = %d\n\t\t\t\tAND (( `adjust` = 0 AND `start` >= '%s' AND `start` <= '%s' ) \n\t\t\t\tOR  (  `adjust` = 1 AND `start` >= '%s' AND `start` <= '%s' )) ", intval(local_user()), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_finish));
        }
        $links = array();
        if (count($r)) {
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                if (!x($links, $j)) {
                    $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j;
                }
            }
        }
        $events = array();
        $last_date = '';
        $fmt = t('l, F j');
        if (count($r)) {
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                $d = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], $fmt) : datetime_convert('UTC', 'UTC', $rr['start'], $fmt);
                $d = day_translate($d);
                $start = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'c') : datetime_convert('UTC', 'UTC', $rr['start'], 'c');
                if ($rr['nofinish']) {
                    $end = null;
                } else {
                    $end = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['finish'], 'c') : datetime_convert('UTC', 'UTC', $rr['finish'], 'c');
                }
                $is_first = $d !== $last_date;
                $last_date = $d;
                $edit = !$rr['cid'] ? array($a->get_baseurl() . '/events/event/' . $rr['id'], t('Edit event'), '', '') : null;
                list($title, $_trash) = explode("<br", bbcode($rr['desc']), 2);
                $title = strip_tags($title);
                $html = format_event_html($rr);
                $rr['desc'] = bbcode($rr['desc']);
                $rr['location'] = bbcode($rr['location']);
                $events[] = array('id' => $rr['id'], 'start' => $start, 'end' => $end, 'allDay' => false, 'title' => $title, 'j' => $j, 'd' => $d, 'edit' => $edit, 'is_first' => $is_first, 'item' => $rr, 'html' => $html, 'plink' => array($rr['plink'], t('link to source'), '', ''));
            }
        }
        if ($a->argv[1] === 'json') {
            echo json_encode($events);
            killme();
        }
        // links: array('href', 'text', 'extra css classes', 'title')
        if (x($_GET, 'id')) {
            $tpl = get_markup_template("event.tpl");
        } else {
            if (get_config('experimentals', 'new_calendar') == 1) {
                $tpl = get_markup_template("events-js.tpl");
            } else {
                $tpl = get_markup_template("events.tpl");
            }
        }
        $o = replace_macros($tpl, array('$baseurl' => $a->get_baseurl(), '$tabs' => $tabs, '$title' => t('Events'), '$new_event' => array($a->get_baseurl() . '/events/new', t('Create New Event'), '', ''), '$previus' => array($a->get_baseurl() . "/events/{$prevyear}/{$prevmonth}", t('Previous'), '', ''), '$next' => array($a->get_baseurl() . "/events/{$nextyear}/{$nextmonth}", t('Next'), '', ''), '$calendar' => cal($y, $m, $links, ' eventcal'), '$events' => $events));
        if (x($_GET, 'id')) {
            echo $o;
            killme();
        }
        return $o;
    }
    if ($mode === 'edit' && $event_id) {
        $r = q("SELECT * FROM `event` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($event_id), intval(local_user()));
        if (count($r)) {
            $orig_event = $r[0];
        }
    }
    if ($mode === 'edit' || $mode === 'new') {
        $n_checked = x($orig_event) && $orig_event['nofinish'] ? ' checked="checked" ' : '';
        $a_checked = x($orig_event) && $orig_event['adjust'] ? ' checked="checked" ' : '';
        $d_orig = x($orig_event) ? $orig_event['desc'] : '';
        $l_orig = x($orig_event) ? $orig_event['location'] : '';
        $eid = x($orig_event) ? $orig_event['id'] : 0;
        $cid = x($orig_event) ? $orig_event['cid'] : 0;
        $uri = x($orig_event) ? $orig_event['uri'] : '';
        if (!x($orig_event)) {
            $sh_checked = '';
        } else {
            $sh_checked = $orig_event['allow_cid'] === '<' . local_user() . '>' && !$orig_event['allow_gid'] && !$orig_event['deny_cid'] && !$orig_event['deny_gid'] ? '' : ' checked="checked" ';
        }
        if ($cid) {
            $sh_checked .= ' disabled="disabled" ';
        }
        $tpl = get_markup_template('event_form.tpl');
        $sdt = x($orig_event) ? $orig_event['start'] : 'now';
        $fdt = x($orig_event) ? $orig_event['finish'] : 'now';
        $tz = date_default_timezone_get();
        if (x($orig_event)) {
            $tz = $orig_event['adjust'] ? date_default_timezone_get() : 'UTC';
        }
        $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
        $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
        $sday = datetime_convert('UTC', $tz, $sdt, 'd');
        $shour = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'H') : 0;
        $sminute = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'i') : 0;
        $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
        $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
        $fday = datetime_convert('UTC', $tz, $fdt, 'd');
        $fhour = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'H') : 0;
        $fminute = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0;
        $f = get_config('system', 'event_input_format');
        if (!$f) {
            $f = 'ymd';
        }
        $dateformat = datesel_format($f);
        $timeformat = t('hour:minute');
        require_once 'include/acl_selectors.php';
        $o .= replace_macros($tpl, array('$post' => $a->get_baseurl() . '/events', '$eid' => $eid, '$cid' => $cid, '$uri' => $uri, '$title' => t('Event details'), '$desc' => sprintf(t('Format is %s %s. Starting date and Description are required.'), $dateformat, $timeformat), '$s_text' => t('Event Starts:') . ' <span class="required">*</span> ', '$s_dsel' => datesel($f, 'start', $syear + 5, $syear, false, $syear, $smonth, $sday), '$s_tsel' => timesel('start', $shour, $sminute), '$n_text' => t('Finish date/time is not known or not relevant'), '$n_checked' => $n_checked, '$f_text' => t('Event Finishes:'), '$f_dsel' => datesel($f, 'finish', $fyear + 5, $fyear, false, $fyear, $fmonth, $fday), '$f_tsel' => timesel('finish', $fhour, $fminute), '$a_text' => t('Adjust for viewer timezone'), '$a_checked' => $a_checked, '$d_text' => t('Description:') . ' <span class="required">*</span>', '$d_orig' => $d_orig, '$l_text' => t('Location:'), '$l_orig' => $l_orig, '$sh_text' => t('Share this event'), '$sh_checked' => $sh_checked, '$acl' => $cid ? '' : populate_acl(x($orig_event) ? $orig_event : $a->user, false), '$submit' => t('Submit')));
        return $o;
    }
}
Example #20
0
function profile_content(&$a, $update = 0)
{
    if (get_config('system', 'block_public') && !local_user() && !remote_user()) {
        return login();
    }
    require_once "include/bbcode.php";
    require_once 'include/security.php';
    require_once 'include/conversation.php';
    require_once 'include/acl_selectors.php';
    $groups = array();
    $tab = 'posts';
    $o = '';
    if ($update) {
        // Ensure we've got a profile owner if updating.
        $a->profile['profile_uid'] = $update;
    } else {
        if ($a->profile['profile_uid'] == local_user()) {
            nav_set_selected('home');
        }
    }
    $contact = null;
    $remote_contact = false;
    if (remote_user()) {
        $contact_id = $_SESSION['visitor_id'];
        $groups = init_groups_visitor($contact_id);
        $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), intval($a->profile['profile_uid']));
        if (count($r)) {
            $contact = $r[0];
            $remote_contact = true;
        }
    }
    if (!$remote_contact) {
        if (local_user()) {
            $contact_id = $_SESSION['cid'];
            $contact = $a->contact;
        }
    }
    $is_owner = local_user() && local_user() == $a->profile['profile_uid'] ? true : false;
    if ($a->profile['hidewall'] && !$is_owner && !$remote_contact) {
        notice(t('Access to this profile has been restricted.') . EOL);
        return;
    }
    if (!$update) {
        if (x($_GET, 'tab')) {
            $tab = notags(trim($_GET['tab']));
        }
        $o .= profile_tabs($a, $is_owner, $a->profile['nickname']);
        if ($tab === 'profile') {
            require_once 'include/profile_advanced.php';
            $o .= advanced_profile($a);
            call_hooks('profile_advanced', $o);
            return $o;
        }
        if (x($_SESSION, 'new_member') && $_SESSION['new_member'] && $is_owner) {
            $o .= '<a href="newmember">' . t('Tips for New Members') . '</a>' . EOL;
        }
        $commpage = $a->profile['page-flags'] == PAGE_COMMUNITY ? true : false;
        $commvisitor = $commpage && $remote_contact == true ? true : false;
        $celeb = $a->profile['page-flags'] == PAGE_SOAPBOX || $a->profile['page-flags'] == PAGE_COMMUNITY ? true : false;
        if (can_write_wall($a, $a->profile['profile_uid'])) {
            $x = array('is_owner' => $is_owner, 'allow_location' => ($is_owner || $commvisitor) && $a->profile['allow_location'] ? true : false, 'default_location' => $is_owner ? $a->user['default-location'] : '', 'nickname' => $a->profile['nickname'], 'lockstate' => is_array($a->user) && (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) || strlen($a->user['deny_cid']) || strlen($a->user['deny_gid'])) ? 'lock' : 'unlock', 'acl' => $is_owner ? populate_acl($a->user, $celeb) : '', 'bang' => '', 'visitor' => $is_owner || $commvisitor ? 'block' : 'none', 'profile_uid' => $a->profile['profile_uid']);
            $o .= status_editor($a, $x);
        }
    }
    if ($is_owner) {
        $r = q("UPDATE `item` SET `unseen` = 0 \n\t\t\tWHERE `wall` = 1 AND `unseen` = 1 AND `uid` = %d", intval(local_user()));
    }
    /**
     * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
     */
    $sql_extra = permissions_sql($a->profile['profile_uid'], $remote_contact, $groups);
    $r = q("SELECT COUNT(*) AS `total`\n\t\tFROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\tWHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0\n\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 \n\t\tAND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1\n\t\t{$sql_extra} ", intval($a->profile['profile_uid']));
    if (count($r)) {
        $a->set_pager_total($r[0]['total']);
        $a->set_pager_itemspage(40);
    }
    $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact-uid`\n\t\tFROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\tWHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0\n\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\tAND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1\n\t\t{$sql_extra}\n\t\tORDER BY `item`.`created` DESC LIMIT %d ,%d ", intval($a->profile['profile_uid']), intval($a->pager['start']), intval($a->pager['itemspage']));
    $parents_arr = array();
    $parents_str = '';
    if (count($r)) {
        foreach ($r as $rr) {
            $parents_arr[] = $rr['item_id'];
        }
        $parents_str = implode(', ', $parents_arr);
        $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, \n\t\t\t`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`, `contact`.`rel`, \n\t\t\t`contact`.`thumb`, `contact`.`self`, `contact`.`writable`, \n\t\t\t`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`\n\t\t\tFROM `item`, (SELECT `p`.`id`,`p`.`created` FROM `item` AS `p` WHERE `p`.`parent` = `p`.`id`) AS `parentitem`, `contact`\n\t\t\tWHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0\n\t\t\tAND `contact`.`id` = `item`.`contact-id`\n\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\tAND `item`.`parent` = `parentitem`.`id` AND `item`.`parent` IN ( %s )\n\t\t\t{$sql_extra}\n\t\t\tORDER BY `parentitem`.`created` DESC, `gravity` ASC, `item`.`created` ASC ", intval($a->profile['profile_uid']), dbesc($parents_str));
    }
    if ($is_owner && !$update) {
        $o .= get_birthdays();
        $o .= get_events();
    }
    if (!$update && $tab === 'posts') {
        // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
        // because browser prefetching might change it on us. We have to deliver it with the page.
        $o .= '<div id="live-profile"></div>' . "\r\n";
        $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] . "; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
    }
    $o .= conversation($a, $r, 'profile', $update);
    if (!$update) {
        $o .= paginate($a);
    }
    return $o;
}
Example #21
0
function events_content(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $o = "";
    // tabs
    $o .= profile_tabs($a, True);
    $o .= '<h2>' . t('Events') . '</h2>';
    $mode = 'view';
    $y = 0;
    $m = 0;
    if ($a->argc > 1) {
        if ($a->argc > 2 && $a->argv[1] == 'event') {
            $mode = 'edit';
            $event_id = intval($a->argv[2]);
        }
        if ($a->argv[1] === 'new') {
            $mode = 'new';
            $event_id = 0;
        }
        if ($a->argc > 2 && intval($a->argv[1]) && intval($a->argv[2])) {
            $mode = 'view';
            $y = intval($a->argv[1]);
            $m = intval($a->argv[2]);
        }
    }
    if ($mode == 'view') {
        $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
        $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
        if (!$y) {
            $y = intval($thisyear);
        }
        if (!$m) {
            $m = intval($thismonth);
        }
        // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
        // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
        if ($y < 1901) {
            $y = 1900;
        }
        if ($y > 2099) {
            $y = 2100;
        }
        $nextyear = $y;
        $nextmonth = $m + 1;
        if ($nextmonth > 12) {
            $nextmonth = 1;
            $nextyear++;
        }
        $prevyear = $y;
        if ($m > 1) {
            $prevmonth = $m - 1;
        } else {
            $prevmonth = 12;
            $prevyear--;
        }
        $dim = get_dim($y, $m);
        $start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
        $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
        $start = datetime_convert('UTC', 'UTC', $start);
        $finish = datetime_convert('UTC', 'UTC', $finish);
        $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
        $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
        $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,\n\t\t\t`item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event` LEFT JOIN `item` ON `item`.`event-id` = `event`.`id` \n\t\t\tWHERE `event`.`uid` = %d\n\t\t\tAND (( `adjust` = 0 AND `start` >= '%s' AND `start` <= '%s' ) \n\t\t\tOR  (  `adjust` = 1 AND `start` >= '%s' AND `start` <= '%s' )) ", intval(local_user()), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_finish));
        $links = array();
        if (count($r)) {
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                if (!x($links, $j)) {
                    $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j;
                }
            }
        }
        $o .= '<div id="new-event-link"><a href="' . $a->get_baseurl() . '/events/new' . '" >' . t('Create New Event') . '</a></div>';
        $o .= '<div id="event-calendar-wrapper">';
        $o .= '<a href="' . $a->get_baseurl() . '/events/' . $prevyear . '/' . $prevmonth . '" class="prevcal"><div id="event-calendar-prev" class="icon prev" title="' . t('Previous') . '"></div></a>';
        $o .= cal($y, $m, $links, ' eventcal');
        $o .= '<a href="' . $a->get_baseurl() . '/events/' . $nextyear . '/' . $nextmonth . '" class="nextcal"><div id="event-calendar-next" class="icon next" title="' . t('Next') . '"></div></a>';
        $o .= '</div>';
        $o .= '<div class="event-calendar-end"></div>';
        $last_date = '';
        $fmt = t('l, F j');
        if (count($r)) {
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                $d = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], $fmt) : datetime_convert('UTC', 'UTC', $rr['start'], $fmt);
                $d = day_translate($d);
                if ($d !== $last_date) {
                    $o .= '<hr /><a name="link-' . $j . '" ><div class="event-list-date">' . $d . '</div></a>';
                }
                $last_date = $d;
                if ($rr['author-name']) {
                    $o .= '<a href="' . $rr['author-link'] . '" ><img src="' . $rr['author-avatar'] . '" height="32" width="32" />' . $rr['author-name'] . '</a>';
                }
                $o .= format_event_html($rr);
                $o .= !$rr['cid'] ? '<a href="' . $a->get_baseurl() . '/events/event/' . $rr['id'] . '" title="' . t('Edit event') . '" class="edit-event-link icon pencil"></a>' : '';
                if ($rr['plink']) {
                    $o .= '<a href="' . $rr['plink'] . '" title="' . t('link to source') . '" target="external-link" class="plink-event-link icon remote-link"></a></div>';
                }
                $o .= '<div class="clear"></div>';
            }
        }
        return $o;
    }
    if ($mode === 'edit' && $event_id) {
        $r = q("SELECT * FROM `event` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($event_id), intval(local_user()));
        if (count($r)) {
            $orig_event = $r[0];
        }
    }
    if ($mode === 'edit' || $mode === 'new') {
        $n_checked = x($orig_event) && $orig_event['nofinish'] ? ' checked="checked" ' : '';
        $a_checked = x($orig_event) && $orig_event['adjust'] ? ' checked="checked" ' : '';
        $d_orig = x($orig_event) ? $orig_event['desc'] : '';
        $l_orig = x($orig_event) ? $orig_event['location'] : '';
        $eid = x($orig_event) ? $orig_event['id'] : 0;
        $cid = x($orig_event) ? $orig_event['cid'] : 0;
        $uri = x($orig_event) ? $orig_event['uri'] : '';
        if (!x($orig_event)) {
            $sh_checked = '';
        } else {
            $sh_checked = $orig_event['allow_cid'] === '<' . local_user() . '>' && !$orig_event['allow_gid'] && !$orig_event['deny_cid'] && !$orig_event['deny_gid'] ? '' : ' checked="checked" ';
        }
        if ($cid) {
            $sh_checked .= ' disabled="disabled" ';
        }
        $htpl = get_markup_template('event_head.tpl');
        $a->page['htmlhead'] .= replace_macros($htpl, array('$baseurl' => $a->get_baseurl()));
        $tpl = get_markup_template('event_form.tpl');
        $sdt = x($orig_event) ? $orig_event['start'] : 'now';
        $fdt = x($orig_event) ? $orig_event['finish'] : 'now';
        $tz = x($orig_event) && $orig_event['adjust'] ? date_default_timezone_get() : 'UTC';
        $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
        $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
        $sday = datetime_convert('UTC', $tz, $sdt, 'd');
        $shour = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'H') : 0;
        $sminute = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'i') : 0;
        $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
        $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
        $fday = datetime_convert('UTC', $tz, $fdt, 'd');
        $fhour = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'H') : 0;
        $fminute = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0;
        $f = get_config('system', 'event_input_format');
        if (!$f) {
            $f = 'ymd';
        }
        $dateformat = datesel_format($f);
        $timeformat = t('hour:minute');
        require_once 'include/acl_selectors.php';
        $o .= replace_macros($tpl, array('$post' => $a->get_baseurl() . '/events', '$eid' => $eid, '$cid' => $cid, '$uri' => $uri, '$e_text' => t('Event details'), '$e_desc' => sprintf(t('Format is %s %s. Starting date and Description are required.'), $dateformat, $timeformat), '$s_text' => t('Event Starts:') . ' <span class="required">*</span> ', '$s_dsel' => datesel($f, 'start', $syear + 5, $syear, false, $syear, $smonth, $sday), '$s_tsel' => timesel('start', $shour, $sminute), '$n_text' => t('Finish date/time is not known or not relevant'), '$n_checked' => $n_checked, '$f_text' => t('Event Finishes:'), '$f_dsel' => datesel($f, 'finish', $fyear + 5, $fyear, false, $fyear, $fmonth, $fday), '$f_tsel' => timesel('finish', $fhour, $fminute), '$a_text' => t('Adjust for viewer timezone'), '$a_checked' => $a_checked, '$d_text' => t('Description:') . ' <span class="required">*</span>', '$d_orig' => $d_orig, '$l_text' => t('Location:'), '$l_orig' => $l_orig, '$sh_text' => t('Share this event'), '$sh_checked' => $sh_checked, '$acl' => $cid ? '' : populate_acl(x($orig_event) ? $orig_event : $a->user, false), '$submit' => t('Submit')));
        return $o;
    }
}
Example #22
0
function events_content(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    if ($a->argc == 1) {
        $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
    }
    if ($a->argc > 2 && $a->argv[1] === 'ignore' && intval($a->argv[2])) {
        $r = q("update event set ignore = 1 where id = %d and uid = %d", intval($a->argv[2]), intval(local_user()));
    }
    if ($a->argc > 2 && $a->argv[1] === 'unignore' && intval($a->argv[2])) {
        $r = q("update event set ignore = 0 where id = %d and uid = %d", intval($a->argv[2]), intval(local_user()));
    }
    if ($a->theme_events_in_profile) {
        nav_set_selected('home');
    } else {
        nav_set_selected('events');
    }
    $editselect = 'none';
    if (feature_enabled(local_user(), 'richtext')) {
        $editselect = 'textareas';
    }
    // First day of the week (0 = Sunday)
    $firstDay = get_pconfig(local_user(), 'system', 'first_day_of_week');
    if ($firstDay === false) {
        $firstDay = 0;
    }
    $i18n = array("firstDay" => $firstDay, "Sun" => t("Sun"), "Mon" => t("Mon"), "Tue" => t("Tue"), "Wed" => t("Wed"), "Thu" => t("Thu"), "Fri" => t("Fri"), "Sat" => t("Sat"), "Sunday" => t("Sunday"), "Monday" => t("Monday"), "Tuesday" => t("Tuesday"), "Wednesday" => t("Wednesday"), "Thursday" => t("Thursday"), "Friday" => t("Friday"), "Saturday" => t("Saturday"), "Jan" => t("Jan"), "Feb" => t("Feb"), "Mar" => t("Mar"), "Apr" => t("Apr"), "May" => t("May"), "Jun" => t("Jun"), "Jul" => t("Jul"), "Aug" => t("Aug"), "Sep" => t("Sept"), "Oct" => t("Oct"), "Nov" => t("Nov"), "Dec" => t("Dec"), "January" => t("January"), "February" => t("February"), "March" => t("March"), "April" => t("April"), "May" => t("May"), "June" => t("June"), "July" => t("July"), "August" => t("August"), "September" => t("September"), "October" => t("October"), "November" => t("November"), "December" => t("December"), "today" => t("today"), "month" => t("month"), "week" => t("week"), "day" => t("day"));
    $htpl = get_markup_template('event_head.tpl');
    $a->page['htmlhead'] .= replace_macros($htpl, array('$baseurl' => $a->get_baseurl(), '$i18n' => $i18n, '$editselect' => $editselect));
    $etpl = get_markup_template('event_end.tpl');
    $a->page['end'] .= replace_macros($etpl, array('$baseurl' => $a->get_baseurl(), '$editselect' => $editselect));
    $o = "";
    // tabs
    if ($a->theme_events_in_profile) {
        $tabs = profile_tabs($a, True);
    }
    $mode = 'view';
    $y = 0;
    $m = 0;
    $ignored = x($_REQUEST, 'ignored') ? intval($_REQUEST['ignored']) : 0;
    if ($a->argc > 1) {
        if ($a->argc > 2 && $a->argv[1] == 'event') {
            $mode = 'edit';
            $event_id = intval($a->argv[2]);
        }
        if ($a->argv[1] === 'new') {
            $mode = 'new';
            $event_id = 0;
        }
        if ($a->argc > 2 && intval($a->argv[1]) && intval($a->argv[2])) {
            $mode = 'view';
            $y = intval($a->argv[1]);
            $m = intval($a->argv[2]);
        }
    }
    if ($mode == 'view') {
        $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
        $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
        if (!$y) {
            $y = intval($thisyear);
        }
        if (!$m) {
            $m = intval($thismonth);
        }
        // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
        // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
        if ($y < 1901) {
            $y = 1900;
        }
        if ($y > 2099) {
            $y = 2100;
        }
        $nextyear = $y;
        $nextmonth = $m + 1;
        if ($nextmonth > 12) {
            $nextmonth = 1;
            $nextyear++;
        }
        $prevyear = $y;
        if ($m > 1) {
            $prevmonth = $m - 1;
        } else {
            $prevmonth = 12;
            $prevyear--;
        }
        $dim = get_dim($y, $m);
        $start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
        $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
        if ($a->argv[1] === 'json') {
            if (x($_GET, 'start')) {
                $start = date("Y-m-d h:i:s", $_GET['start']);
            }
            if (x($_GET, 'end')) {
                $finish = date("Y-m-d h:i:s", $_GET['end']);
            }
        }
        $start = datetime_convert('UTC', 'UTC', $start);
        $finish = datetime_convert('UTC', 'UTC', $finish);
        $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
        $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
        if (x($_GET, 'id')) {
            $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,\n\t\t\t\t`item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event`\n\t\t\t\tLEFT JOIN `item` ON `item`.`event-id` = `event`.`id` AND `item`.`uid` = `event`.`uid`\n\t\t\t\tWHERE `event`.`uid` = %d AND `event`.`id` = %d", intval(local_user()), intval($_GET['id']));
        } else {
            $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,\n\t\t\t\t`item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event`\n\t\t\t\tLEFT JOIN `item` ON `item`.`event-id` = `event`.`id` AND `item`.`uid` = `event`.`uid`\n\t\t\t\tWHERE `event`.`uid` = %d and event.ignore = %d\n\t\t\t\tAND ((`adjust` = 0 AND (`finish` >= '%s' OR (nofinish AND start >= '%s')) AND `start` <= '%s')\n\t\t\t\tOR  (`adjust` = 1 AND (`finish` >= '%s' OR (nofinish AND start >= '%s')) AND `start` <= '%s')) ", intval(local_user()), intval($ignored), dbesc($start), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_start), dbesc($adjust_finish));
        }
        $links = array();
        if (count($r)) {
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                if (!x($links, $j)) {
                    $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j;
                }
            }
        }
        $events = array();
        $last_date = '';
        $fmt = t('l, F j');
        if (count($r)) {
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                $d = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], $fmt) : datetime_convert('UTC', 'UTC', $rr['start'], $fmt);
                $d = day_translate($d);
                $start = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'c') : datetime_convert('UTC', 'UTC', $rr['start'], 'c');
                if ($rr['nofinish']) {
                    $end = null;
                } else {
                    $end = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['finish'], 'c') : datetime_convert('UTC', 'UTC', $rr['finish'], 'c');
                }
                $is_first = $d !== $last_date;
                $last_date = $d;
                $edit = !$rr['cid'] ? array($a->get_baseurl() . '/events/event/' . $rr['id'], t('Edit event'), '', '') : null;
                $title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
                if (!$title) {
                    list($title, $_trash) = explode("<br", bbcode($rr['desc']), 2);
                    $title = strip_tags(html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
                }
                $html = format_event_html($rr);
                $rr['desc'] = bbcode($rr['desc']);
                $rr['location'] = bbcode($rr['location']);
                $events[] = array('id' => $rr['id'], 'start' => $start, 'end' => $end, 'allDay' => false, 'title' => $title, 'j' => $j, 'd' => $d, 'edit' => $edit, 'is_first' => $is_first, 'item' => $rr, 'html' => $html, 'plink' => array($rr['plink'], t('link to source'), '', ''));
            }
        }
        if ($a->argv[1] === 'json') {
            echo json_encode($events);
            killme();
        }
        // links: array('href', 'text', 'extra css classes', 'title')
        if (x($_GET, 'id')) {
            $tpl = get_markup_template("event.tpl");
        } else {
            //			if (get_config('experimentals','new_calendar')==1){
            $tpl = get_markup_template("events-js.tpl");
            //			} else {
            //				$tpl = get_markup_template("events.tpl");
            //			}
        }
        // Get rid of dashes in key names, Smarty3 can't handle them
        foreach ($events as $key => $event) {
            $event_item = array();
            foreach ($event['item'] as $k => $v) {
                $k = str_replace('-', '_', $k);
                $event_item[$k] = $v;
            }
            $events[$key]['item'] = $event_item;
        }
        $o = replace_macros($tpl, array('$baseurl' => $a->get_baseurl(), '$tabs' => $tabs, '$title' => t('Events'), '$new_event' => array($a->get_baseurl() . '/events/new', t('Create New Event'), '', ''), '$previus' => array($a->get_baseurl() . "/events/{$prevyear}/{$prevmonth}", t('Previous'), '', ''), '$next' => array($a->get_baseurl() . "/events/{$nextyear}/{$nextmonth}", t('Next'), '', ''), '$calendar' => cal($y, $m, $links, ' eventcal'), '$events' => $events));
        if (x($_GET, 'id')) {
            echo $o;
            killme();
        }
        return $o;
    }
    if ($mode === 'edit' && $event_id) {
        $r = q("SELECT * FROM `event` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($event_id), intval(local_user()));
        if (count($r)) {
            $orig_event = $r[0];
        }
    }
    // Passed parameters overrides anything found in the DB
    if ($mode === 'edit' || $mode === 'new') {
        if (!x($orig_event)) {
            $orig_event = array();
        }
        // In case of an error the browser is redirected back here, with these parameters filled in with the previous values
        if (x($_REQUEST, 'nofinish')) {
            $orig_event['nofinish'] = $_REQUEST['nofinish'];
        }
        if (x($_REQUEST, 'adjust')) {
            $orig_event['adjust'] = $_REQUEST['adjust'];
        }
        if (x($_REQUEST, 'summary')) {
            $orig_event['summary'] = $_REQUEST['summary'];
        }
        if (x($_REQUEST, 'description')) {
            $orig_event['description'] = $_REQUEST['description'];
        }
        if (x($_REQUEST, 'location')) {
            $orig_event['location'] = $_REQUEST['location'];
        }
        if (x($_REQUEST, 'start')) {
            $orig_event['start'] = $_REQUEST['start'];
        }
        if (x($_REQUEST, 'finish')) {
            $orig_event['finish'] = $_REQUEST['finish'];
        }
    }
    if ($mode === 'edit' || $mode === 'new') {
        $n_checked = x($orig_event) && $orig_event['nofinish'] ? ' checked="checked" ' : '';
        $a_checked = x($orig_event) && $orig_event['adjust'] ? ' checked="checked" ' : '';
        $t_orig = x($orig_event) ? $orig_event['summary'] : '';
        $d_orig = x($orig_event) ? $orig_event['desc'] : '';
        $l_orig = x($orig_event) ? $orig_event['location'] : '';
        $eid = x($orig_event) ? $orig_event['id'] : 0;
        $cid = x($orig_event) ? $orig_event['cid'] : 0;
        $uri = x($orig_event) ? $orig_event['uri'] : '';
        if (!x($orig_event)) {
            $sh_checked = '';
        } else {
            $sh_checked = $orig_event['allow_cid'] === '<' . local_user() . '>' && !$orig_event['allow_gid'] && !$orig_event['deny_cid'] && !$orig_event['deny_gid'] ? '' : ' checked="checked" ';
        }
        if ($cid or $mode !== 'new') {
            $sh_checked .= ' disabled="disabled" ';
        }
        $sdt = x($orig_event) ? $orig_event['start'] : 'now';
        $fdt = x($orig_event) ? $orig_event['finish'] : 'now';
        $tz = date_default_timezone_get();
        if (x($orig_event)) {
            $tz = $orig_event['adjust'] ? date_default_timezone_get() : 'UTC';
        }
        $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
        $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
        $sday = datetime_convert('UTC', $tz, $sdt, 'd');
        $shour = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'H') : 0;
        $sminute = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'i') : 0;
        $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
        $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
        $fday = datetime_convert('UTC', $tz, $fdt, 'd');
        $fhour = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'H') : 0;
        $fminute = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0;
        $f = get_config('system', 'event_input_format');
        if (!$f) {
            $f = 'ymd';
        }
        require_once 'include/acl_selectors.php';
        if ($mode === 'new') {
            $acl = $cid ? '' : populate_acl(x($orig_event) ? $orig_event : $a->user);
        }
        $tpl = get_markup_template('event_form.tpl');
        $o .= replace_macros($tpl, array('$post' => $a->get_baseurl() . '/events', '$eid' => $eid, '$cid' => $cid, '$uri' => $uri, '$title' => t('Event details'), '$desc' => t('Starting date and Title are required.'), '$s_text' => t('Event Starts:') . ' <span class="required" title="' . t('Required') . '">*</span>', '$s_dsel' => datetimesel($f, new DateTime(), DateTime::createFromFormat('Y', $syear + 5), DateTime::createFromFormat('Y-m-d H:i', "{$syear}-{$smonth}-{$sday} {$shour}:{$sminute}"), 'start_text', true, true, '', '', true), '$n_text' => t('Finish date/time is not known or not relevant'), '$n_checked' => $n_checked, '$f_text' => t('Event Finishes:'), '$f_dsel' => datetimesel($f, new DateTime(), DateTime::createFromFormat('Y', $fyear + 5), DateTime::createFromFormat('Y-m-d H:i', "{$fyear}-{$fmonth}-{$fday} {$fhour}:{$fminute}"), 'finish_text', true, true, 'start_text'), '$a_text' => t('Adjust for viewer timezone'), '$a_checked' => $a_checked, '$d_text' => t('Description:'), '$d_orig' => $d_orig, '$l_text' => t('Location:'), '$l_orig' => $l_orig, '$t_text' => t('Title:') . ' <span class="required" title="' . t('Required') . '">*</span>', '$t_orig' => $t_orig, '$sh_text' => t('Share this event'), '$sh_checked' => $sh_checked, '$preview' => t('Preview'), '$acl' => $acl, '$submit' => t('Submit')));
        return $o;
    }
}
Example #23
0
File: photos.php Project: Mauru/red
function photos_content(&$a)
{
    // URLs:
    // photos/name
    // photos/name/upload
    // photos/name/upload/xxxxx (xxxxx is album name)
    // photos/name/album/xxxxx
    // photos/name/album/xxxxx/edit
    // photos/name/image/xxxxx
    // photos/name/image/xxxxx/edit
    if (get_config('system', 'block_public') && !local_user() && !remote_user()) {
        notice(t('Public access denied.') . EOL);
        return;
    }
    require_once 'include/bbcode.php';
    require_once 'include/security.php';
    require_once 'include/conversation.php';
    if (!x($a->data, 'channel')) {
        notice(t('No photos selected') . EOL);
        return;
    }
    $ph = photo_factory('');
    $phototypes = $ph->supportedTypes();
    $_SESSION['photo_return'] = $a->cmd;
    //
    // Parse arguments
    //
    $can_comment = perm_is_allowed($a->profile['profile_uid'], get_observer_hash(), 'post_comments');
    if (argc() > 3) {
        $datatype = argv(2);
        $datum = argv(3);
    } elseif (argc() > 2 && argv(2) === 'upload') {
        $datatype = 'upload';
    } else {
        $datatype = 'summary';
    }
    if (argc() > 4) {
        $cmd = argv(4);
    } else {
        $cmd = 'view';
    }
    //
    // Setup permissions structures
    //
    $can_post = false;
    $visitor = 0;
    $owner_uid = $a->data['channel']['channel_id'];
    $owner_aid = $a->data['channel']['channel_account_id'];
    $observer = $a->get_observer();
    $can_post = perm_is_allowed($owner_uid, $observer['xchan_hash'], 'post_photos');
    $can_view = perm_is_allowed($owner_uid, $observer['xchan_hash'], 'view_photos');
    if (!$can_view) {
        notice(t('Access to this item is restricted.') . EOL);
        return;
    }
    $sql_extra = permissions_sql($owner_uid);
    $o = "";
    $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
    // tabs
    $_is_owner = local_user() && local_user() == $owner_uid;
    $o .= profile_tabs($a, $_is_owner, $a->data['channel']['channel_address']);
    //
    // dispatch request
    //
    /**
     * Display upload form
     */
    if ($datatype === 'upload') {
        if (!$can_post) {
            notice(t('Permission denied.'));
            return;
        }
        if (array_key_exists('albums', $a->data)) {
            $albums = get_app()->data['albums'];
        } else {
            $albums = photos_albums_list($a->data['channel'], $a->data['observer']);
        }
        $selname = $datum ? hex2bin($datum) : '';
        $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
        $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
        if (count($albums['albums'])) {
            foreach ($albums['albums'] as $album) {
                if (!$album['text']) {
                    continue;
                }
                $selected = $selname === $album['text'] ? ' selected="selected" ' : '';
                $albumselect .= '<option value="' . $album['text'] . '"' . $selected . '>' . $album['text'] . '</option>';
            }
        }
        $albumselect .= '</select>';
        $uploader = '';
        $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'], 'addon_text' => $uploader, 'default_upload' => true);
        call_hooks('photo_upload_form', $ret);
        $default_upload = '<input id="photos-upload-choose" type="file" name="userfile" /> 	<div class="photos-upload-submit-wrapper" >
		<input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>';
        /* Show space usage */
        $r = q("select sum(size) as total from photo where aid = %d and scale = 0 ", intval($a->data['channel']['channel_account_id']));
        $limit = service_class_fetch($a->data['channel']['channel_id'], 'photo_upload_limit');
        if ($limit !== false) {
            $usage_message = sprintf(t("You have used %1\$.2f Mbytes of %2\$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000);
        } else {
            $usage_message = sprintf(t('You have used %1$.2f Mbytes of photo storage.'), $r[0]['total'] / 1024000);
        }
        if ($_is_owner) {
            $channel = $a->get_channel();
            $channel_acl = array('allow_cid' => $channel['channel_allow_cid'], 'allow_gid' => $channel['channel_allow_gid'], 'deny_cid' => $channel['channel_deny_cid'], 'deny_gid' => $channel['channel_deny_gid']);
        }
        $albumselect_e = $albumselect;
        $aclselect_e = $_is_owner ? populate_acl($channel_acl, false) : '';
        $tpl = get_markup_template('photos_upload.tpl');
        $o .= replace_macros($tpl, array('$pagename' => t('Upload Photos'), '$sessid' => session_id(), '$usage' => $usage_message, '$nickname' => $a->data['channel']['channel_address'], '$newalbum' => t('New album name: '), '$existalbumtext' => t('or existing album name: '), '$nosharetext' => t('Do not show a status post for this upload'), '$albumselect' => $albumselect_e, '$permissions' => t('Permissions'), '$aclselect' => $aclselect_e, '$uploader' => $ret['addon_text'], '$default' => $ret['default_upload'] ? $default_upload : '', '$uploadurl' => $ret['post_url']));
        return $o;
    }
    /*
     * Display a single photo album
     */
    if ($datatype === 'album') {
        if (strlen($datum) & 1 || !ctype_xdigit($datum)) {
            notice(t('Album name could not be decoded') . EOL);
            logger('mod_photos: illegal album encoding: ' . $datum);
            $datum = '';
        }
        $album = hex2bin($datum);
        $r = q("SELECT `resource_id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s' \n\t\t\tAND `scale` <= 4 and (photo_flags = %d or photo_flags = %d ) {$sql_extra} GROUP BY `resource_id`", intval($owner_uid), dbesc($album), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE));
        if (count($r)) {
            $a->set_pager_total(count($r));
            $a->set_pager_itemspage(60);
        }
        if ($_GET['order'] === 'posted') {
            $order = 'ASC';
        } else {
            $order = 'DESC';
        }
        $r = q("SELECT `resource_id`, `id`, `filename`, type, max(`scale`) AS `scale`, `description` FROM `photo` WHERE `uid` = %d AND `album` = '%s' \n\t\t\tAND `scale` <= 4 and (photo_flags = %d or photo_flags = %d ) {$sql_extra} GROUP BY `resource_id` ORDER BY `created` {$order} LIMIT %d , %d", intval($owner_uid), dbesc($album), intvaL(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($a->pager['start']), intval($a->pager['itemspage']));
        $o .= '<h3>' . $album . '</h3>';
        if ($cmd === 'edit') {
            if ($album !== t('Profile Photos') && $album !== 'Contact Photos' && $album !== t('Contact Photos')) {
                if ($can_post) {
                    if ($a->get_template_engine() === 'internal') {
                        $album_e = template_escape($album);
                    } else {
                        $album_e = $album;
                    }
                    $edit_tpl = get_markup_template('album_edit.tpl');
                    $o .= replace_macros($edit_tpl, array('$nametext' => t('New album name: '), '$nickname' => $a->data['channel']['channel_address'], '$album' => $album_e, '$hexalbum' => bin2hex($album), '$submit' => t('Submit'), '$dropsubmit' => t('Delete Album')));
                }
            }
        } else {
            if ($album !== t('Profile Photos') && $album !== 'Contact Photos' && $album !== t('Contact Photos')) {
                if ($can_post) {
                    $o .= '<div id="album-edit-link"><a href="' . $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($album) . '/edit' . '">' . t('Edit Album') . '</a></div>';
                }
            }
        }
        if ($_GET['order'] === 'posted') {
            $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($album) . '" >' . t('Show Newest First') . '</a></div>';
        } else {
            $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($album) . '?f=&order=posted" >' . t('Show Oldest First') . '</a></div>';
        }
        if ($can_post) {
            $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/upload/' . bin2hex($album) . '" >' . t('Upload New Photos') . '</a></div>';
        }
        $ajaxout = '';
        $tpl = get_markup_template('photo_album.tpl');
        if (count($r)) {
            $twist = 'rotright';
            $o .= "<script> var page_query = '" . $_GET['q'] . "'; var extra_args = '" . extra_query_args() . "' ; </script>";
            $o .= '<div id="photo-album-contents">';
            foreach ($r as $rr) {
                if ($twist == 'rotright') {
                    $twist = 'rotleft';
                } else {
                    $twist = 'rotright';
                }
                $ext = $phototypes[$rr['type']];
                $imgalt_e = $rr['filename'];
                $desc_e = $rr['description'];
                // prettyphoto has potential license issues, so we can no longer include it in core
                // The following lines would need to be modified so that they are provided in theme specific files
                // instead of core modules for themes that wish to make use of prettyphoto. I would suggest
                // the feature as a per-theme display option and putting the rel line inside a template.
                //				if(feature_enabled($a->data['channel']['channel_id'],'prettyphoto')){
                //				      $imagelink = ($a->get_baseurl() . '/photo/' . $rr['resource_id'] . '.' . $ext );
                //				      $rel=("prettyPhoto[pp_gal]");
                //				}
                //				else {
                $imagelink = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $rr['resource_id'] . ($_GET['order'] === 'posted' ? '?f=&order=posted' : '');
                $rel = "photo";
                //				}
                $tmp = replace_macros($tpl, array('$id' => $rr['id'], '$twist' => ' ' . $twist . rand(2, 4), '$photolink' => $imagelink, '$rel' => $rel, '$phototitle' => t('View Photo'), '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource_id'] . '-' . $rr['scale'] . '.' . $ext, '$imgalt' => $imgalt_e, '$desc' => $desc_e, '$ext' => $ext, '$hash' => $rr['resource_id']));
                if ($_REQUEST['aj']) {
                    $ajaxout .= $tmp;
                } else {
                    $o .= $tmp;
                }
            }
        }
        if ($_REQUEST['aj']) {
            if (!$r) {
                $ajaxout .= '<div id="content-complete"></div>';
            }
            echo $ajaxout;
            killme();
        }
        $o .= '<div id="page-end"></div>';
        $o .= '</div>';
        // photo-album-contents
        $o .= '<div id="photo-album-end"></div>';
        $o .= '<script>$(document).ready(function() { loadingPage = false;});</script>';
        $o .= '<div id="page-spinner"></div>';
        //		$o .= paginate($a);
        return $o;
    }
    /** 
     * Display one photo
     */
    if ($datatype === 'image') {
        // fetch image, item containing image, then comments
        $ph = q("SELECT aid,uid,xchan,resource_id,created,edited,title,`description`,album,filename,`type`,height,width,`size`,scale,profile,photo_flags,allow_cid,allow_gid,deny_cid,deny_gid FROM `photo` WHERE `uid` = %d AND `resource_id` = '%s' \n\t\t\tand (photo_flags = %d or photo_flags = %d ) {$sql_extra} ORDER BY `scale` ASC ", intval($owner_uid), dbesc($datum), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE));
        if (!$ph) {
            /* Check again - this time without specifying permissions */
            $ph = q("SELECT id FROM photo WHERE uid = %d AND resource_id = '%s' \n\t\t\t\tand ( photo_flags = %d or photo_flags = %d )\n\t\t\t\tLIMIT 1", intval($owner_uid), dbesc($datum), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE));
            if ($ph) {
                notice(t('Permission denied. Access to this item may be restricted.') . EOL);
            } else {
                notice(t('Photo not available') . EOL);
            }
            return;
        }
        $prevlink = '';
        $nextlink = '';
        if ($_GET['order'] === 'posted') {
            $order = 'ASC';
        } else {
            $order = 'DESC';
        }
        $prvnxt = q("SELECT `resource_id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0 \n\t\t\tand ( photo_flags = %d or photo_flags = %d ) {$sql_extra} ORDER BY `created` {$order} ", dbesc($ph[0]['album']), intval($owner_uid), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE));
        if (count($prvnxt)) {
            for ($z = 0; $z < count($prvnxt); $z++) {
                if ($prvnxt[$z]['resource_id'] == $ph[0]['resource_id']) {
                    $prv = $z - 1;
                    $nxt = $z + 1;
                    if ($prv < 0) {
                        $prv = count($prvnxt) - 1;
                    }
                    if ($nxt >= count($prvnxt)) {
                        $nxt = 0;
                    }
                    break;
                }
            }
            $prevlink = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $prvnxt[$prv]['resource_id'] . ($_GET['order'] === 'posted' ? '?f=&order=posted' : '');
            $nextlink = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $prvnxt[$nxt]['resource_id'] . ($_GET['order'] === 'posted' ? '?f=&order=posted' : '');
        }
        if (count($ph) == 1) {
            $hires = $lores = $ph[0];
        }
        if (count($ph) > 1) {
            if ($ph[1]['scale'] == 2) {
                // original is 640 or less, we can display it directly
                $hires = $lores = $ph[0];
            } else {
                $hires = $ph[0];
                $lores = $ph[1];
            }
        }
        $album_link = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($ph[0]['album']);
        $tools = Null;
        $lock = Null;
        if ($can_post && $ph[0]['uid'] == $owner_uid) {
            $tools = array('profile' => array($a->get_baseurl() . '/profile_photo/use/' . $ph[0]['resource_id'], t('Use as profile photo')));
            // lock
            $lock = $ph[0]['uid'] == local_user() && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) ? t('Private Message') : Null;
        }
        $a->page['htmlhead'] .= '<script>$(document).keydown(function(event) {' . "\n";
        if ($prevlink) {
            $a->page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 37) { event.preventDefault(); window.location.href = \'' . $prevlink . '\'; }' . "\n";
        }
        if ($nextlink) {
            $a->page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 39) { event.preventDefault(); window.location.href = \'' . $nextlink . '\'; }' . "\n";
        }
        $a->page['htmlhead'] .= '});</script>';
        if ($prevlink) {
            $prevlink = array($prevlink, '<i class="icon-backward photo-icons""></i>');
        }
        $photo = array('href' => $a->get_baseurl() . '/photo/' . $hires['resource_id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']], 'title' => t('View Full Size'), 'src' => $a->get_baseurl() . '/photo/' . $lores['resource_id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('', '', '', 'ymdhis'));
        if ($nextlink) {
            $nextlink = array($nextlink, '<i class="icon-forward photo-icons"></i>');
        }
        // Do we have an item for this photo?
        $linked_items = q("SELECT * FROM item WHERE resource_id = '%s' and resource_type = 'photo' \n\t\t\t{$sql_extra} LIMIT 1", dbesc($datum));
        if ($linked_items) {
            xchan_query($linked_items);
            $linked_items = fetch_post_tags($linked_items, true);
            $link_item = $linked_items[0];
            $r = q("select * from item where parent_mid = '%s' \n\t\t\t\tand item_restrict = 0 and uid = %d {$sql_extra} ", dbesc($link_item['mid']), intval($link_item['uid']));
            if ($r) {
                xchan_query($r);
                $r = fetch_post_tags($r, true);
                $r = conv_sort($r, 'commented');
            }
            $tags = array();
            if ($link_item['term']) {
                $cnt = 0;
                foreach ($link_item['term'] as $t) {
                    $tags[$cnt] = array(0 => format_term_for_display($t));
                }
                if ($can_post && $ph[0]['uid'] == $owner_uid) {
                    $tags[$cnt][1] = 'tagrm?f=&item=' . $link_item['id'];
                    $tags[$cnt][2] = t('Remove');
                }
                $cnt++;
            }
            if (local_user() && local_user() == $link_item['uid']) {
                q("UPDATE `item` SET item_flags = (item_flags ^ %d) WHERE parent = %d and uid = %d and (item_flags & %d)", intval(ITEM_UNSEEN), intval($link_item['parent']), intval(local_user()), intval(ITEM_UNSEEN));
            }
        }
        //		logger('mod_photo: link_item' . print_r($link_item,true));
        // FIXME - remove this when we move to conversation module
        $r = $r[0]['children'];
        $edit = null;
        if ($can_post) {
            if (array_key_exists('albums', $a->data)) {
                $albums = get_app()->data['albums'];
            } else {
                $albums = photos_albums_list($a->data['channel'], $a->data['observer']);
            }
            $album_e = $ph[0]['album'];
            $caption_e = $ph[0]['description'];
            $aclselect_e = populate_acl($ph[0]);
            $edit = array('edit' => t('Edit photo'), 'id' => $ph[0]['id'], 'rotatecw' => t('Rotate CW (right)'), 'rotateccw' => t('Rotate CCW (left)'), 'albums' => $albums['albums'], 'album' => $album_e, 'newalbum' => t('New album name'), 'nickname' => $a->data['channel']['channel_address'], 'resource_id' => $ph[0]['resource_id'], 'capt_label' => t('Caption'), 'caption' => $caption_e, 'tag_label' => t('Add a Tag'), 'permissions' => t('Permissions'), 'aclselect' => $aclselect_e, 'help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'), 'item_id' => count($linked_items) ? $link_item['id'] : 0, 'submit' => t('Submit'), 'delete' => t('Delete Photo'));
        }
        if (count($linked_items)) {
            $cmnt_tpl = get_markup_template('comment_item.tpl');
            $tpl = get_markup_template('photo_item.tpl');
            $return_url = $a->cmd;
            $like_tpl = get_markup_template('like_noshare.tpl');
            $likebuttons = '';
            if ($can_post || $can_comment) {
                $likebuttons = replace_macros($like_tpl, array('$id' => $link_item['id'], '$likethis' => t("I like this (toggle)"), '$nolike' => t("I don't like this (toggle)"), '$share' => t('Share'), '$wait' => t('Please wait')));
            }
            $comments = '';
            if (!count($r)) {
                if ($can_post || $can_comment) {
                    $comments .= replace_macros($cmnt_tpl, array('$return_path' => '', '$mode' => 'photos', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $link_item['id'], '$parent' => $link_item['id'], '$profile_uid' => $owner_uid, '$mylink' => $observer['xchan_url'], '$mytitle' => t('This is you'), '$myphoto' => $observer['xchan_photo_s'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$preview' => t('Preview'), '$ww' => '', '$feature_encrypt' => false));
                }
            }
            $alike = array();
            $dlike = array();
            $like = '';
            $dislike = '';
            // display comments
            if ($r) {
                foreach ($r as $item) {
                    like_puller($a, $item, $alike, 'like');
                    like_puller($a, $item, $dlike, 'dislike');
                }
                $like = isset($alike[$link_item['id']]) ? format_like($alike[$link_item['id']], $alike[$link_item['id'] . '-l'], 'like', $link_item['id']) : '';
                $dislike = isset($dlike[$link_item['id']]) ? format_like($dlike[$link_item['id']], $dlike[$link_item['id'] . '-l'], 'dislike', $link_item['id']) : '';
                foreach ($r as $item) {
                    $comment = '';
                    $template = $tpl;
                    $sparkle = '';
                    if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && $item['id'] != $item['parent']) {
                        continue;
                    }
                    $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'];
                    $profile_url = zid($item['author']['xchan_url']);
                    $sparkle = '';
                    $profile_name = $item['author']['xchan_name'];
                    $profile_avatar = $item['author']['xchan_photo_m'];
                    $profile_link = $profile_url;
                    $drop = '';
                    if ($observer['xchan_hash'] === $item['author_xchan'] || $observer['xchan_hash'] === $item['owner_xchan']) {
                        $drop = replace_macros(get_markup_template('photo_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
                    }
                    $name_e = $profile_name;
                    $title_e = $item['title'];
                    unobscure($item);
                    $body_e = prepare_text($item['body'], $item['mimetype']);
                    $comments .= replace_macros($template, array('$id' => $item['item_id'], '$mode' => 'photos', '$profile_url' => $profile_link, '$name' => $name_e, '$thumb' => $profile_avatar, '$sparkle' => $sparkle, '$title' => $title_e, '$body' => $body_e, '$ago' => relative_date($item['created']), '$indent' => $item['parent'] != $item['item_id'] ? ' comment' : '', '$drop' => $drop, '$comment' => $comment));
                }
                if ($can_post || $can_comment) {
                    $comments .= replace_macros($cmnt_tpl, array('$return_path' => '', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $link_item['id'], '$parent' => $link_item['id'], '$profile_uid' => $owner_uid, '$mylink' => $observer['xchan_url'], '$mytitle' => t('This is you'), '$myphoto' => $observer['xchan_photo_s'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$ww' => ''));
                }
            }
            $paginate = paginate($a);
        }
        $album_e = array($album_link, $ph[0]['album']);
        $like_e = $like;
        $dislike_e = $dislike;
        $photo_tpl = get_markup_template('photo_view.tpl');
        $o .= replace_macros($photo_tpl, array('$id' => $ph[0]['id'], '$album' => $album_e, '$tools' => $tools, '$lock' => $lock, '$photo' => $photo, '$prevlink' => $prevlink, '$nextlink' => $nextlink, '$desc' => $ph[0]['description'], '$tag_hdr' => t('In This Photo:'), '$tags' => $tags, '$edit' => $edit, '$likebuttons' => $likebuttons, '$like' => $like_e, '$dislike' => $dislike_e, '$comments' => $comments, '$paginate' => $paginate));
        $a->data['photo_html'] = $o;
        return $o;
    }
    // Default - show recent photos with upload link (if applicable)
    //$o = '';
    $r = q("SELECT `resource_id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' \n\t\tand ( photo_flags = %d or photo_flags = %d ) {$sql_extra} GROUP BY `resource_id`", intval($a->data['channel']['channel_id']), dbesc('Contact Photos'), dbesc(t('Contact Photos')), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE));
    if (count($r)) {
        $a->set_pager_total(count($r));
        $a->set_pager_itemspage(60);
    }
    $r = q("SELECT `resource_id`, `id`, `filename`, type, `album`, max(`scale`) AS `scale` FROM `photo`\n\t\tWHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'\n\t\tand ( photo_flags = %d or photo_flags = %d )  \n\t\t{$sql_extra} GROUP BY `resource_id` ORDER BY `created` DESC LIMIT %d , %d", intval($a->data['channel']['channel_id']), dbesc('Contact Photos'), dbesc(t('Contact Photos')), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($a->pager['start']), intval($a->pager['itemspage']));
    $photos = array();
    if (count($r)) {
        $twist = 'rotright';
        foreach ($r as $rr) {
            if ($twist == 'rotright') {
                $twist = 'rotleft';
            } else {
                $twist = 'rotright';
            }
            $ext = $phototypes[$rr['type']];
            if ($a->get_template_engine() === 'internal') {
                $alt_e = template_escape($rr['filename']);
                $name_e = template_escape($rr['album']);
            } else {
                $alt_e = $rr['filename'];
                $name_e = $rr['album'];
            }
            $photos[] = array('id' => $rr['id'], 'twist' => ' ' . $twist . rand(2, 4), 'link' => $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $rr['resource_id'], 'title' => t('View Photo'), 'src' => $a->get_baseurl() . '/photo/' . $rr['resource_id'] . '-' . ($rr['scale'] == 6 ? 4 : $rr['scale']) . '.' . $ext, 'alt' => $alt_e, 'album' => array('link' => $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($rr['album']), 'name' => $name_e, 'alt' => t('View Album')));
        }
    }
    if ($_REQUEST['aj']) {
        if ($photos) {
            $o = replace_macros(get_markup_template('photosajax.tpl'), array('$photos' => $photos));
        } else {
            $o = '<div id="content-complete"></div>';
        }
        echo $o;
        killme();
    } else {
        $o .= "<script> var page_query = '" . $_GET['q'] . "'; var extra_args = '" . extra_query_args() . "' ; </script>";
        $tpl = get_markup_template('photos_recent.tpl');
        $o .= replace_macros($tpl, array('$title' => t('Recent Photos'), '$can_post' => $can_post, '$upload' => array(t('Upload New Photos'), $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/upload'), '$photos' => $photos));
    }
    if (!$photos && $_REQUEST['aj']) {
        $o .= '<div id="content-complete"></div>';
        echo $o;
        killme();
    }
    //	$o .= paginate($a);
    return $o;
}
Example #24
0
function photos_content(&$a)
{
    // URLs:
    // photos/name
    // photos/name/album/xxxxx (xxxxx is album name)
    // photos/name/image/xxxxx
    if (get_config('system', 'block_public') && !local_channel() && !remote_channel()) {
        notice(t('Public access denied.') . EOL);
        return;
    }
    $unsafe = array_key_exists('unsafe', $_REQUEST) && $_REQUEST['unsafe'] ? 1 : 0;
    require_once 'include/bbcode.php';
    require_once 'include/security.php';
    require_once 'include/conversation.php';
    if (!x($a->data, 'channel')) {
        notice(t('No photos selected') . EOL);
        return;
    }
    $ph = photo_factory('');
    $phototypes = $ph->supportedTypes();
    $_SESSION['photo_return'] = $a->cmd;
    //
    // Parse arguments
    //
    $can_comment = perm_is_allowed($a->profile['profile_uid'], get_observer_hash(), 'post_comments');
    if (argc() > 3) {
        $datatype = argv(2);
        $datum = argv(3);
    } else {
        if (argc() > 2) {
            $datatype = argv(2);
            $datum = '';
        } else {
            $datatype = 'summary';
        }
    }
    if (argc() > 4) {
        $cmd = argv(4);
    } else {
        $cmd = 'view';
    }
    //
    // Setup permissions structures
    //
    $can_post = false;
    $visitor = 0;
    $owner_uid = $a->data['channel']['channel_id'];
    $owner_aid = $a->data['channel']['channel_account_id'];
    $observer = $a->get_observer();
    $can_post = perm_is_allowed($owner_uid, $observer['xchan_hash'], 'write_storage');
    $can_view = perm_is_allowed($owner_uid, $observer['xchan_hash'], 'view_storage');
    if (!$can_view) {
        notice(t('Access to this item is restricted.') . EOL);
        return;
    }
    $sql_extra = permissions_sql($owner_uid);
    $o = "";
    $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
    // tabs
    $_is_owner = local_channel() && local_channel() == $owner_uid;
    $o .= profile_tabs($a, $_is_owner, $a->data['channel']['channel_address']);
    /**
     * Display upload form
     */
    if ($can_post) {
        $uploader = '';
        $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'], 'addon_text' => $uploader, 'default_upload' => true);
        call_hooks('photo_upload_form', $ret);
        /* Show space usage */
        $r = q("select sum(size) as total from photo where aid = %d and scale = 0 ", intval($a->data['channel']['channel_account_id']));
        $limit = service_class_fetch($a->data['channel']['channel_id'], 'photo_upload_limit');
        if ($limit !== false) {
            $usage_message = sprintf(t("%1\$.2f MB of %2\$.2f MB photo storage used."), $r[0]['total'] / 1024000, $limit / 1024000);
        } else {
            $usage_message = sprintf(t('%1$.2f MB photo storage used.'), $r[0]['total'] / 1024000);
        }
        if ($_is_owner) {
            $channel = $a->get_channel();
            $acl = new AccessList($channel);
            $channel_acl = $acl->get();
            $lockstate = $acl->is_private() ? 'lock' : 'unlock';
        }
        $aclselect = $_is_owner ? populate_acl($channel_acl, false) : '';
        $selname = $datum ? hex2bin($datum) : '';
        $albums = array_key_exists('albums', $a->data) ? $a->data['albums'] : photos_albums_list($a->data['channel'], $a->data['observer']);
        if (!$selname) {
            $def_album = get_pconfig($a->data['channel']['channel_id'], 'system', 'photo_path');
            if ($def_album) {
                $selname = filepath_macro($def_album);
                $albums['album'][] = array('text' => $selname);
            }
        }
        $tpl = get_markup_template('photos_upload.tpl');
        $upload_form = replace_macros($tpl, array('$pagename' => t('Upload Photos'), '$sessid' => session_id(), '$usage' => $usage_message, '$nickname' => $a->data['channel']['channel_address'], '$newalbum_label' => t('Enter an album name'), '$newalbum_placeholder' => t('or select an existing album (doubleclick)'), '$visible' => array('visible', t('Create a status post for this upload'), 0, '', array(t('No'), t('Yes'))), '$albums' => $albums['albums'], '$selname' => $selname, '$permissions' => t('Permissions'), '$aclselect' => $aclselect, '$lockstate' => $lockstate, '$uploader' => $ret['addon_text'], '$default' => $ret['default_upload'] ? true : false, '$uploadurl' => $ret['post_url'], '$submit' => t('Submit')));
    }
    //
    // dispatch request
    //
    /*
     * Display a single photo album
     */
    if ($datatype === 'album') {
        if (strlen($datum)) {
            if (strlen($datum) & 1 || !ctype_xdigit($datum)) {
                notice(t('Album name could not be decoded') . EOL);
                logger('mod_photos: illegal album encoding: ' . $datum);
                $datum = '';
            }
        }
        $album = $datum ? hex2bin($datum) : '';
        $r = q("SELECT `resource_id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s' \n\t\t\tAND `scale` <= 4 and photo_usage IN ( %d, %d ) and is_nsfw = %d {$sql_extra} GROUP BY `resource_id`", intval($owner_uid), dbesc($album), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($unsafe));
        if (count($r)) {
            $a->set_pager_total(count($r));
            $a->set_pager_itemspage(60);
        } else {
            goaway($a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address']);
        }
        if ($_GET['order'] === 'posted') {
            $order = 'ASC';
        } else {
            $order = 'DESC';
        }
        $r = q("SELECT p.resource_id, p.id, p.filename, p.type, p.scale, p.description, p.created FROM photo p INNER JOIN\n\t\t\t\t(SELECT resource_id, max(scale) scale FROM photo WHERE uid = %d AND album = '%s' AND scale <= 4 AND photo_usage IN ( %d, %d ) and is_nsfw = %d {$sql_extra} GROUP BY resource_id) ph \n\t\t\t\tON (p.resource_id = ph.resource_id AND p.scale = ph.scale)\n\t\t\tORDER BY created {$order} LIMIT %d OFFSET %d", intval($owner_uid), dbesc($album), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($unsafe), intval($a->pager['itemspage']), intval($a->pager['start']));
        //edit album name
        $album_edit = null;
        if ($album !== t('Profile Photos') && $album !== 'Profile Photos' && $album !== 'Contact Photos' && $album !== t('Contact Photos')) {
            if ($can_post) {
                if ($a->get_template_engine() === 'internal') {
                    $album_e = template_escape($album);
                } else {
                    $album_e = $album;
                }
                $albums = array_key_exists('albums', $a->data) ? $a->data['albums'] : photos_albums_list($a->data['channel'], $a->data['observer']);
                // @fixme - syncronise actions with DAV
                //				$edit_tpl = get_markup_template('album_edit.tpl');
                //				$album_edit = replace_macros($edit_tpl,array(
                //					'$nametext' => t('Enter a new album name'),
                //					'$name_placeholder' => t('or select an existing one (doubleclick)'),
                //					'$nickname' => $a->data['channel']['channel_address'],
                //					'$album' => $album_e,
                //					'$albums' => $albums['albums'],
                //					'$hexalbum' => bin2hex($album),
                //					'$submit' => t('Submit'),
                //					'$dropsubmit' => t('Delete Album')
                //				));
            }
        }
        if ($_GET['order'] === 'posted') {
            $order = array(t('Show Newest First'), $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($album));
        } else {
            $order = array(t('Show Oldest First'), $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($album) . '?f=&order=posted');
        }
        $photos = array();
        if (count($r)) {
            $twist = 'rotright';
            foreach ($r as $rr) {
                if ($twist == 'rotright') {
                    $twist = 'rotleft';
                } else {
                    $twist = 'rotright';
                }
                $ext = $phototypes[$rr['type']];
                $imgalt_e = $rr['filename'];
                $desc_e = $rr['description'];
                $imagelink = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $rr['resource_id'] . ($_GET['order'] === 'posted' ? '?f=&order=posted' : '');
                $photos[] = array('id' => $rr['id'], 'twist' => ' ' . $twist . rand(2, 4), 'link' => $imagelink, 'title' => t('View Photo'), 'src' => $a->get_baseurl() . '/photo/' . $rr['resource_id'] . '-' . $rr['scale'] . '.' . $ext, 'alt' => $imgalt_e, 'desc' => $desc_e, 'ext' => $ext, 'hash' => $rr['resource_id'], 'unknown' => t('Unknown'));
            }
        }
        if ($_REQUEST['aj']) {
            if ($photos) {
                $o = replace_macros(get_markup_template('photosajax.tpl'), array('$photos' => $photos));
            } else {
                $o = '<div id="content-complete"></div>';
            }
            echo $o;
            killme();
        } else {
            $o .= "<script> var page_query = '" . $_GET['q'] . "'; var extra_args = '" . extra_query_args() . "' ; </script>";
            $tpl = get_markup_template('photo_album.tpl');
            $o .= replace_macros($tpl, array('$photos' => $photos, '$album' => $album, '$album_edit' => array(t('Edit Album'), $album_edit), '$can_post' => $can_post, '$upload' => array(t('Upload'), $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/upload/' . bin2hex($album)), '$order' => $order, '$upload_form' => $upload_form, '$usage' => $usage_message));
        }
        if (!$photos && $_REQUEST['aj']) {
            $o .= '<div id="content-complete"></div>';
            echo $o;
            killme();
        }
        //		$o .= paginate($a);
        return $o;
    }
    /** 
     * Display one photo
     */
    if ($datatype === 'image') {
        // fetch image, item containing image, then comments
        $ph = q("SELECT id,aid,uid,xchan,resource_id,created,edited,title,`description`,album,filename,`type`,height,width,`size`,scale,photo_usage,is_nsfw,allow_cid,allow_gid,deny_cid,deny_gid FROM `photo` WHERE `uid` = %d AND `resource_id` = '%s' \n\t\t\t{$sql_extra} ORDER BY `scale` ASC ", intval($owner_uid), dbesc($datum));
        if (!$ph) {
            /* Check again - this time without specifying permissions */
            $ph = q("SELECT id FROM photo WHERE uid = %d AND resource_id = '%s' LIMIT 1", intval($owner_uid), dbesc($datum));
            if ($ph) {
                notice(t('Permission denied. Access to this item may be restricted.') . EOL);
            } else {
                notice(t('Photo not available') . EOL);
            }
            return;
        }
        $prevlink = '';
        $nextlink = '';
        if ($_GET['order'] === 'posted') {
            $order = 'ASC';
        } else {
            $order = 'DESC';
        }
        $prvnxt = q("SELECT `resource_id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0 \n\t\t\t{$sql_extra} ORDER BY `created` {$order} ", dbesc($ph[0]['album']), intval($owner_uid));
        if (count($prvnxt)) {
            for ($z = 0; $z < count($prvnxt); $z++) {
                if ($prvnxt[$z]['resource_id'] == $ph[0]['resource_id']) {
                    $prv = $z - 1;
                    $nxt = $z + 1;
                    if ($prv < 0) {
                        $prv = count($prvnxt) - 1;
                    }
                    if ($nxt >= count($prvnxt)) {
                        $nxt = 0;
                    }
                    break;
                }
            }
            $prevlink = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $prvnxt[$prv]['resource_id'] . ($_GET['order'] === 'posted' ? '?f=&order=posted' : '');
            $nextlink = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $prvnxt[$nxt]['resource_id'] . ($_GET['order'] === 'posted' ? '?f=&order=posted' : '');
        }
        if (count($ph) == 1) {
            $hires = $lores = $ph[0];
        }
        if (count($ph) > 1) {
            if ($ph[1]['scale'] == 2) {
                // original is 640 or less, we can display it directly
                $hires = $lores = $ph[0];
            } else {
                $hires = $ph[0];
                $lores = $ph[1];
            }
        }
        $album_link = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($ph[0]['album']);
        $tools = Null;
        $lock = Null;
        if ($can_post && $ph[0]['uid'] == $owner_uid) {
            $tools = array('profile' => array($a->get_baseurl() . '/profile_photo/use/' . $ph[0]['resource_id'], t('Use as profile photo')));
        }
        // lockstate
        $lockstate = strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']) ? array('lock', t('Private Photo')) : array('unlock', Null);
        $a->page['htmlhead'] .= '<script>$(document).keydown(function(event) {' . "\n";
        if ($prevlink) {
            $a->page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 37) { event.preventDefault(); window.location.href = \'' . $prevlink . '\'; }' . "\n";
        }
        if ($nextlink) {
            $a->page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 39) { event.preventDefault(); window.location.href = \'' . $nextlink . '\'; }' . "\n";
        }
        $a->page['htmlhead'] .= '});</script>';
        if ($prevlink) {
            $prevlink = array($prevlink, t('Previous'));
        }
        $photo = array('href' => $a->get_baseurl() . '/photo/' . $hires['resource_id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']], 'title' => t('View Full Size'), 'src' => $a->get_baseurl() . '/photo/' . $lores['resource_id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('', '', '', 'ymdhis'));
        if ($nextlink) {
            $nextlink = array($nextlink, t('Next'));
        }
        // Do we have an item for this photo?
        $linked_items = q("SELECT * FROM item WHERE resource_id = '%s' and resource_type = 'photo' \n\t\t\t{$sql_extra} LIMIT 1", dbesc($datum));
        $map = null;
        if ($linked_items) {
            xchan_query($linked_items);
            $linked_items = fetch_post_tags($linked_items, true);
            $link_item = $linked_items[0];
            $item_normal = item_normal();
            $r = q("select * from item where parent_mid = '%s' \n\t\t\t\t{$item_normal} and uid = %d {$sql_extra} ", dbesc($link_item['mid']), intval($link_item['uid']));
            if ($r) {
                xchan_query($r);
                $r = fetch_post_tags($r, true);
                $r = conv_sort($r, 'commented');
            }
            $tags = array();
            if ($link_item['term']) {
                $cnt = 0;
                foreach ($link_item['term'] as $t) {
                    $tags[$cnt] = array(0 => format_term_for_display($t));
                    if ($can_post && $ph[0]['uid'] == $owner_uid) {
                        $tags[$cnt][1] = 'tagrm/drop/' . $link_item['id'] . '/' . bin2hex($t['term']);
                        //?f=&item=' . $link_item['id'];
                        $tags[$cnt][2] = t('Remove');
                    }
                    $cnt++;
                }
            }
            if (local_channel() && local_channel() == $link_item['uid']) {
                q("UPDATE `item` SET item_unseen = 0 WHERE parent = %d and uid = %d and item_unseen = 1", intval($link_item['parent']), intval(local_channel()));
            }
            if ($link_item['coord']) {
                $map = generate_map($link_item['coord']);
            }
        }
        //		logger('mod_photo: link_item' . print_r($link_item,true));
        // FIXME - remove this when we move to conversation module
        $r = $r[0]['children'];
        $edit = null;
        if ($can_post) {
            $album_e = $ph[0]['album'];
            $caption_e = $ph[0]['description'];
            $aclselect_e = $_is_owner ? populate_acl($ph[0]) : '';
            $albums = array_key_exists('albums', $a->data) ? $a->data['albums'] : photos_albums_list($a->data['channel'], $a->data['observer']);
            $_SESSION['album_return'] = bin2hex($ph[0]['album']);
            $edit = array('edit' => t('Edit photo'), 'id' => $link_item['id'], 'rotatecw' => t('Rotate CW (right)'), 'rotateccw' => t('Rotate CCW (left)'), 'albums' => $albums['albums'], 'album' => $album_e, 'newalbum_label' => t('Enter a new album name'), 'newalbum_placeholder' => t('or select an existing one (doubleclick)'), 'nickname' => $a->data['channel']['channel_address'], 'resource_id' => $ph[0]['resource_id'], 'capt_label' => t('Caption'), 'caption' => $caption_e, 'tag_label' => t('Add a Tag'), 'permissions' => t('Permissions'), 'aclselect' => $aclselect_e, 'lockstate' => $lockstate[0], 'help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com'), 'item_id' => count($linked_items) ? $link_item['id'] : 0, 'adult_enabled' => feature_enabled($owner_uid, 'adult_photo_flagging'), 'adult' => array('adult', t('Flag as adult in album view'), intval($ph[0]['is_nsfw']), ''), 'submit' => t('Submit'), 'delete' => t('Delete Photo'));
        }
        if (count($linked_items)) {
            $cmnt_tpl = get_markup_template('comment_item.tpl');
            $tpl = get_markup_template('photo_item.tpl');
            $return_url = $a->cmd;
            $like_tpl = get_markup_template('like_noshare.tpl');
            $likebuttons = '';
            if ($can_post || $can_comment) {
                $likebuttons = array('id' => $link_item['id'], 'likethis' => t("I like this (toggle)"), 'nolike' => t("I don't like this (toggle)"), 'share' => t('Share'), 'wait' => t('Please wait'));
            }
            $comments = '';
            if (!count($r)) {
                if ($can_post || $can_comment) {
                    $commentbox = replace_macros($cmnt_tpl, array('$return_path' => '', '$mode' => 'photos', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $link_item['id'], '$parent' => $link_item['id'], '$profile_uid' => $owner_uid, '$mylink' => $observer['xchan_url'], '$mytitle' => t('This is you'), '$myphoto' => $observer['xchan_photo_s'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$preview' => t('Preview'), '$ww' => '', '$feature_encrypt' => false));
                }
            }
            $alike = array();
            $dlike = array();
            $like = '';
            $dislike = '';
            $conv_responses = array('like' => array('title' => t('Likes', 'title')), 'dislike' => array('title' => t('Dislikes', 'title')), 'agree' => array('title' => t('Agree', 'title')), 'disagree' => array('title' => t('Disagree', 'title')), 'abstain' => array('title' => t('Abstain', 'title')), 'attendyes' => array('title' => t('Attending', 'title')), 'attendno' => array('title' => t('Not attending', 'title')), 'attendmaybe' => array('title' => t('Might attend', 'title')));
            if ($r) {
                foreach ($r as $item) {
                    builtin_activity_puller($item, $conv_responses);
                }
                $like_count = x($alike, $link_item['mid']) ? $alike[$link_item['mid']] : '';
                $like_list = x($alike, $link_item['mid']) ? $alike[$link_item['mid'] . '-l'] : '';
                if (count($like_list) > MAX_LIKERS) {
                    $like_list_part = array_slice($like_list, 0, MAX_LIKERS);
                    array_push($like_list_part, '<a href="#" data-toggle="modal" data-target="#likeModal-' . $this->get_id() . '"><b>' . t('View all') . '</b></a>');
                } else {
                    $like_list_part = '';
                }
                $like_button_label = tt('Like', 'Likes', $like_count, 'noun');
                //if (feature_enabled($conv->get_profile_owner(),'dislike')) {
                $dislike_count = x($dlike, $link_item['mid']) ? $dlike[$link_item['mid']] : '';
                $dislike_list = x($dlike, $link_item['mid']) ? $dlike[$link_item['mid'] . '-l'] : '';
                $dislike_button_label = tt('Dislike', 'Dislikes', $dislike_count, 'noun');
                if (count($dislike_list) > MAX_LIKERS) {
                    $dislike_list_part = array_slice($dislike_list, 0, MAX_LIKERS);
                    array_push($dislike_list_part, '<a href="#" data-toggle="modal" data-target="#dislikeModal-' . $this->get_id() . '"><b>' . t('View all') . '</b></a>');
                } else {
                    $dislike_list_part = '';
                }
                //}
                $like = isset($alike[$link_item['mid']]) ? format_like($alike[$link_item['mid']], $alike[$link_item['mid'] . '-l'], 'like', $link_item['mid']) : '';
                $dislike = isset($dlike[$link_item['mid']]) ? format_like($dlike[$link_item['mid']], $dlike[$link_item['mid'] . '-l'], 'dislike', $link_item['mid']) : '';
                // display comments
                foreach ($r as $item) {
                    $comment = '';
                    $template = $tpl;
                    $sparkle = '';
                    if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && $item['id'] != $item['parent']) {
                        continue;
                    }
                    $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'];
                    $profile_url = zid($item['author']['xchan_url']);
                    $sparkle = '';
                    $profile_name = $item['author']['xchan_name'];
                    $profile_avatar = $item['author']['xchan_photo_m'];
                    $profile_link = $profile_url;
                    $drop = '';
                    if ($observer['xchan_hash'] === $item['author_xchan'] || $observer['xchan_hash'] === $item['owner_xchan']) {
                        $drop = replace_macros(get_markup_template('photo_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
                    }
                    $name_e = $profile_name;
                    $title_e = $item['title'];
                    unobscure($item);
                    $body_e = prepare_text($item['body'], $item['mimetype']);
                    $comments .= replace_macros($template, array('$id' => $item['id'], '$mode' => 'photos', '$profile_url' => $profile_link, '$name' => $name_e, '$thumb' => $profile_avatar, '$sparkle' => $sparkle, '$title' => $title_e, '$body' => $body_e, '$ago' => relative_date($item['created']), '$indent' => $item['parent'] != $item['id'] ? ' comment' : '', '$drop' => $drop, '$comment' => $comment));
                }
                if ($can_post || $can_comment) {
                    $commentbox = replace_macros($cmnt_tpl, array('$return_path' => '', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $link_item['id'], '$parent' => $link_item['id'], '$profile_uid' => $owner_uid, '$mylink' => $observer['xchan_url'], '$mytitle' => t('This is you'), '$myphoto' => $observer['xchan_photo_s'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$ww' => ''));
                }
            }
            $paginate = paginate($a);
        }
        $album_e = array($album_link, $ph[0]['album']);
        $like_e = $like;
        $dislike_e = $dislike;
        $response_verbs = array('like');
        if (feature_enabled($owner_uid, 'dislike')) {
            $response_verbs[] = 'dislike';
        }
        $responses = get_responses($conv_responses, $response_verbs, '', $link_item);
        $photo_tpl = get_markup_template('photo_view.tpl');
        $o .= replace_macros($photo_tpl, array('$id' => $ph[0]['id'], '$album' => $album_e, '$tools' => $tools, '$lock' => $lockstate[1], '$photo' => $photo, '$prevlink' => $prevlink, '$nextlink' => $nextlink, '$desc' => $ph[0]['description'], '$filename' => $ph[0]['filename'], '$unknown' => t('Unknown'), '$tag_hdr' => t('In This Photo:'), '$tags' => $tags, 'responses' => $responses, '$edit' => $edit, '$map' => $map, '$map_text' => t('Map'), '$likebuttons' => $likebuttons, '$like' => $like_e, '$dislike' => $dislike_e, '$like_count' => $like_count, '$like_list' => $like_list, '$like_list_part' => $like_list_part, '$like_button_label' => $like_button_label, '$like_modal_title' => t('Likes', 'noun'), '$dislike_modal_title' => t('Dislikes', 'noun'), '$dislike_count' => $dislike_count, '$dislike_list' => $dislike_list, '$dislike_list_part' => $dislike_list_part, '$dislike_button_label' => $dislike_button_label, '$modal_dismiss' => t('Close'), '$comments' => $comments, '$commentbox' => $commentbox, '$paginate' => $paginate));
        $a->data['photo_html'] = $o;
        return $o;
    }
    // Default - show recent photos with upload link (if applicable)
    //$o = '';
    $r = q("SELECT `resource_id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' \n\t\tand photo_usage in ( %d, %d ) and is_nsfw = %d {$sql_extra} GROUP BY `resource_id`", intval($a->data['channel']['channel_id']), dbesc('Contact Photos'), dbesc(t('Contact Photos')), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($unsafe));
    if (count($r)) {
        $a->set_pager_total(count($r));
        $a->set_pager_itemspage(60);
    }
    $r = q("SELECT p.resource_id, p.id, p.filename, p.type, p.album, p.scale, p.created FROM photo p INNER JOIN \n\t\t(SELECT resource_id, max(scale) scale FROM photo \n\t\t\tWHERE uid=%d AND album != '%s' AND album != '%s' \n\t\t\tAND photo_usage IN ( %d, %d ) and is_nsfw = %d {$sql_extra} group by resource_id) ph \n\t\tON (p.resource_id = ph.resource_id and p.scale = ph.scale) ORDER by p.created DESC LIMIT %d OFFSET %d", intval($a->data['channel']['channel_id']), dbesc('Contact Photos'), dbesc(t('Contact Photos')), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($unsafe), intval($a->pager['itemspage']), intval($a->pager['start']));
    $photos = array();
    if (count($r)) {
        $twist = 'rotright';
        foreach ($r as $rr) {
            if ($twist == 'rotright') {
                $twist = 'rotleft';
            } else {
                $twist = 'rotright';
            }
            $ext = $phototypes[$rr['type']];
            if ($a->get_template_engine() === 'internal') {
                $alt_e = template_escape($rr['filename']);
                $name_e = template_escape($rr['album']);
            } else {
                $alt_e = $rr['filename'];
                $name_e = $rr['album'];
            }
            $photos[] = array('id' => $rr['id'], 'twist' => ' ' . $twist . rand(2, 4), 'link' => $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $rr['resource_id'], 'title' => t('View Photo'), 'src' => $a->get_baseurl() . '/photo/' . $rr['resource_id'] . '-' . ($rr['scale'] == 6 ? 4 : $rr['scale']) . '.' . $ext, 'alt' => $alt_e, 'album' => array('link' => $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($rr['album']), 'name' => $name_e, 'alt' => t('View Album')));
        }
    }
    if ($_REQUEST['aj']) {
        if ($photos) {
            $o = replace_macros(get_markup_template('photosajax.tpl'), array('$photos' => $photos));
        } else {
            $o = '<div id="content-complete"></div>';
        }
        echo $o;
        killme();
    } else {
        $o .= "<script> var page_query = '" . $_GET['q'] . "'; var extra_args = '" . extra_query_args() . "' ; </script>";
        $tpl = get_markup_template('photos_recent.tpl');
        $o .= replace_macros($tpl, array('$title' => t('Recent Photos'), '$can_post' => $can_post, '$upload' => array(t('Upload'), $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/upload'), '$photos' => $photos, '$upload_form' => $upload_form, '$usage' => $usage_message));
    }
    if (!$photos && $_REQUEST['aj']) {
        $o .= '<div id="content-complete"></div>';
        echo $o;
        killme();
    }
    //	paginate($a);
    return $o;
}
Example #25
0
function channel_content(&$a, $update = 0, $load = false)
{
    $category = $datequery = $datequery2 = '';
    $mid = $_GET['mid'];
    $datequery = x($_GET, 'dend') && is_a_date_arg($_GET['dend']) ? notags($_GET['dend']) : '';
    $datequery2 = x($_GET, 'dbegin') && is_a_date_arg($_GET['dbegin']) ? notags($_GET['dbegin']) : '';
    if (get_config('system', 'block_public') && !get_account_id() && !remote_user()) {
        return login();
    }
    $category = x($_REQUEST, 'cat') ? $_REQUEST['cat'] : '';
    $groups = array();
    $o = '';
    if ($update) {
        // Ensure we've got a profile owner if updating.
        $a->profile['profile_uid'] = $update;
    } else {
        if ($a->profile['profile_uid'] == local_user()) {
            nav_set_selected('home');
        }
    }
    $is_owner = local_user() && $a->profile['profile_uid'] == local_user() ? true : false;
    $channel = $a->get_channel();
    $observer = $a->get_observer();
    $ob_hash = $observer ? $observer['xchan_hash'] : '';
    $perms = get_all_perms($a->profile['profile_uid'], $ob_hash);
    if (!$perms['view_stream']) {
        // We may want to make the target of this redirect configurable
        if ($perms['view_profile']) {
            notice(t('Insufficient permissions.  Request redirected to profile page.') . EOL);
            goaway(z_root() . "/profile/" . $a->profile['channel_address']);
        }
        notice(t('Permission denied.') . EOL);
        return;
    }
    if (!$update) {
        $o .= profile_tabs($a, $is_owner, $a->profile['channel_address']);
        $o .= common_friends_visitor_widget($a->profile['profile_uid']);
        if ($channel && $is_owner) {
            $channel_acl = array('allow_cid' => $channel['channel_allow_cid'], 'allow_gid' => $channel['channel_allow_gid'], 'deny_cid' => $channel['channel_deny_cid'], 'deny_gid' => $channel['channel_deny_gid']);
        } else {
            $channel_acl = array();
        }
        if ($perms['post_wall']) {
            $x = array('is_owner' => $is_owner, 'allow_location' => ($is_owner || $observer) && intval(get_pconfig($a->profile['profile_uid'], 'system', 'use_browser_location')) ? true : false, 'default_location' => $is_owner ? $a->profile['channel_location'] : '', 'nickname' => $a->profile['channel_address'], 'lockstate' => strlen($a->profile['channel_allow_cid']) || strlen($a->profile['channel_allow_gid']) || strlen($a->profile['channel_deny_cid']) || strlen($a->profile['channel_deny_gid']) ? 'lock' : 'unlock', 'acl' => $is_owner ? populate_acl($channel_acl) : '', 'showacl' => $is_owner ? 'yes' : '', 'bang' => '', 'visitor' => $is_owner || $observer ? true : false, 'profile_uid' => $a->profile['profile_uid']);
            $o .= status_editor($a, $x);
        }
    }
    /**
     * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
     */
    $sql_extra = item_permissions_sql($a->profile['profile_uid'], $remote_contact, $groups);
    if ($update && !$load) {
        if ($mid) {
            $r = q("SELECT parent AS item_id from item where mid = '%s' and uid = %d AND item_restrict = 0\n\t\t\t\tAND (item_flags &  %d) AND (item_flags & %d) {$sql_extra} limit 1", dbesc($mid), intval($a->profile['profile_uid']), intval(ITEM_WALL), intval(ITEM_UNSEEN));
        } else {
            $r = q("SELECT distinct parent AS `item_id` from item\n\t\t\t\tleft join abook on item.author_xchan = abook.abook_xchan\n\t\t\t\tWHERE uid = %d AND item_restrict = 0\n\t\t\t\tAND (item_flags &  %d) AND ( item_flags & %d ) \n\t\t\t\tAND ((abook.abook_flags & %d) = 0 or abook.abook_flags is null)\n\t\t\t\t{$sql_extra}\n\t\t\t\tORDER BY created DESC", intval($a->profile['profile_uid']), intval(ITEM_WALL), intval(ITEM_UNSEEN), intval(ABOOK_FLAG_BLOCKED));
        }
    } else {
        if (x($category)) {
            $sql_extra .= protect_sprintf(term_query('item', $category, TERM_CATEGORY));
        }
        if ($datequery) {
            $sql_extra2 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(), '', $datequery))));
        }
        if ($datequery2) {
            $sql_extra2 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(), '', $datequery2))));
        }
        $itemspage = get_pconfig(local_user(), 'system', 'itemspage');
        $a->set_pager_itemspage(intval($itemspage) ? $itemspage : 20);
        $pager_sql = sprintf(" LIMIT %d, %d ", intval($a->pager['start']), intval($a->pager['itemspage']));
        if ($load || $_COOKIE['jsAvailable'] != 1) {
            if ($mid) {
                $r = q("SELECT parent AS item_id from item where mid = '%s' and uid = %d AND item_restrict = 0\n\t\t\t\t\tAND (item_flags &  %d) {$sql_extra} limit 1", dbesc($mid), intval($a->profile['profile_uid']), intval(ITEM_WALL));
                if (!$r) {
                    notice(t('Permission denied.') . EOL);
                }
            } else {
                $r = q("SELECT distinct id AS item_id FROM item \n\t\t\t\t\tleft join abook on item.author_xchan = abook.abook_xchan\n\t\t\t\t\tWHERE uid = %d AND item_restrict = 0\n\t\t\t\t\tAND (item_flags &  %d) and (item_flags & %d)\n\t\t\t\t\tAND ((abook.abook_flags & %d) = 0 or abook.abook_flags is null)\n\t\t\t\t\t{$sql_extra} {$sql_extra2}\n\t\t\t\t\tORDER BY created DESC {$pager_sql} ", intval($a->profile['profile_uid']), intval(ITEM_WALL), intval(ITEM_THREAD_TOP), intval(ABOOK_FLAG_BLOCKED));
            }
        } else {
            $r = array();
        }
    }
    if ($r) {
        $parents_str = ids_to_querystr($r, 'item_id');
        $items = q("SELECT `item`.*, `item`.`id` AS `item_id` \n\t\t\tFROM `item`\n\t\t\tWHERE `item`.`uid` = %d AND `item`.`item_restrict` = 0\n\t\t\tAND `item`.`parent` IN ( %s )\n\t\t\t{$sql_extra} ", intval($a->profile['profile_uid']), dbesc($parents_str));
        xchan_query($items);
        $items = fetch_post_tags($items, true);
        $items = conv_sort($items, 'created');
        if ($load && $mid && !count($items)) {
            // This will happen if we don't have sufficient permissions
            // to view the parent item (or the item itself if it is toplevel)
            notice(t('Permission denied.') . EOL);
        }
    } else {
        $items = array();
    }
    if (!$update && !$load) {
        // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
        // because browser prefetching might change it on us. We have to deliver it with the page.
        $o .= '<div id="live-channel"></div>' . "\r\n";
        $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
        $a->page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"), array('$baseurl' => z_root(), '$pgtype' => 'channel', '$uid' => $a->profile['profile_uid'] ? $a->profile['profile_uid'] : '0', '$gid' => '0', '$cid' => '0', '$cmin' => '0', '$cmax' => '0', '$star' => '0', '$liked' => '0', '$conv' => '0', '$spam' => '0', '$nouveau' => '0', '$wall' => '1', '$fh' => '0', '$page' => $a->pager['page'] != 1 ? $a->pager['page'] : 1, '$search' => '', '$order' => '', '$list' => x($_REQUEST, 'list') ? intval($_REQUEST['list']) : 0, '$file' => '', '$cats' => $category ? $category : '', '$mid' => $mid, '$dend' => $datequery, '$dbegin' => $datequery2));
    }
    if ($is_owner) {
        $r = q("UPDATE item SET item_flags = (item_flags ^ %d)\n\t\t\tWHERE (item_flags & %d) AND (item_flags & %d) AND uid = %d ", intval(ITEM_UNSEEN), intval(ITEM_UNSEEN), intval(ITEM_WALL), intval(local_user()));
    }
    if ($_COOKIE['jsAvailable'] == 1) {
        $o .= conversation($a, $items, 'channel', $update, 'client');
    } else {
        $o .= conversation($a, $items, 'channel', $update, 'traditional');
    }
    if (!$update || $_COOKIE['jsAvailable'] != 1) {
        $o .= alt_pager($a, count($items));
    }
    if ($mid) {
        $o .= '<div id="content-complete"></div>';
    }
    return $o;
}
Example #26
0
function profile_content(&$a, $update = 0)
{
    $category = $datequery = $datequery2 = '';
    if ($a->argc > 2) {
        for ($x = 2; $x < $a->argc; $x++) {
            if (is_a_date_arg($a->argv[$x])) {
                if ($datequery) {
                    $datequery2 = escape_tags($a->argv[$x]);
                } else {
                    $datequery = escape_tags($a->argv[$x]);
                }
            } else {
                $category = $a->argv[$x];
            }
        }
    }
    if (!x($category)) {
        $category = x($_GET, 'category') ? $_GET['category'] : '';
    }
    if (get_config('system', 'block_public') && !local_user() && !remote_user()) {
        return login();
    }
    require_once "include/bbcode.php";
    require_once 'include/security.php';
    require_once 'include/conversation.php';
    require_once 'include/acl_selectors.php';
    require_once 'include/items.php';
    $groups = array();
    $tab = 'posts';
    $o = '';
    if ($update) {
        // Ensure we've got a profile owner if updating.
        $a->profile['profile_uid'] = $update;
    } else {
        if ($a->profile['profile_uid'] == local_user()) {
            nav_set_selected('home');
        }
    }
    $contact = null;
    $remote_contact = false;
    $contact_id = 0;
    if (is_array($_SESSION['remote'])) {
        foreach ($_SESSION['remote'] as $v) {
            if ($v['uid'] == $a->profile['profile_uid']) {
                $contact_id = $v['cid'];
                break;
            }
        }
    }
    if ($contact_id) {
        $groups = init_groups_visitor($contact_id);
        $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), intval($a->profile['profile_uid']));
        if (count($r)) {
            $contact = $r[0];
            $remote_contact = true;
        }
    }
    if (!$remote_contact) {
        if (local_user()) {
            $contact_id = $_SESSION['cid'];
            $contact = $a->contact;
        }
    }
    $is_owner = local_user() && local_user() == $a->profile['profile_uid'] ? true : false;
    if ($a->profile['hidewall'] && !$is_owner && !$remote_contact) {
        notice(t('Access to this profile has been restricted.') . EOL);
        return;
    }
    if (!$update) {
        if (x($_GET, 'tab')) {
            $tab = notags(trim($_GET['tab']));
        }
        $o .= profile_tabs($a, $is_owner, $a->profile['nickname']);
        if ($tab === 'profile') {
            $o .= advanced_profile($a);
            call_hooks('profile_advanced', $o);
            return $o;
        }
        $o .= common_friends_visitor_widget($a->profile['profile_uid']);
        if (x($_SESSION, 'new_member') && $_SESSION['new_member'] && $is_owner) {
            $o .= '<a href="newmember" id="newmember-tips" style="font-size: 1.2em;"><b>' . t('Tips for New Members') . '</b></a>' . EOL;
        }
        $commpage = $a->profile['page-flags'] == PAGE_COMMUNITY ? true : false;
        $commvisitor = $commpage && $remote_contact == true ? true : false;
        $a->page['aside'] .= posted_date_widget($a->get_baseurl(true) . '/profile/' . $a->profile['nickname'], $a->profile['profile_uid'], true);
        $a->page['aside'] .= categories_widget($a->get_baseurl(true) . '/profile/' . $a->profile['nickname'], x($category) ? xmlify($category) : '');
        if (can_write_wall($a, $a->profile['profile_uid'])) {
            $x = array('is_owner' => $is_owner, 'allow_location' => ($is_owner || $commvisitor) && $a->profile['allow_location'] ? true : false, 'default_location' => $is_owner ? $a->user['default-location'] : '', 'nickname' => $a->profile['nickname'], 'lockstate' => is_array($a->user) && (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) || strlen($a->user['deny_cid']) || strlen($a->user['deny_gid'])) ? 'lock' : 'unlock', 'acl' => $is_owner ? populate_acl($a->user, true) : '', 'bang' => '', 'visitor' => $is_owner || $commvisitor ? 'block' : 'none', 'profile_uid' => $a->profile['profile_uid'], 'acl_data' => $is_owner ? construct_acl_data($a, $a->user) : '');
            $o .= status_editor($a, $x);
        }
    }
    /**
     * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
     */
    $sql_extra = item_permissions_sql($a->profile['profile_uid'], $remote_contact, $groups);
    if ($update) {
        $r = q("SELECT distinct(parent) AS `item_id`, `item`.`network` AS `item_network`,\n\t\t\t`contact`.`uid` AS `contact-uid`\n\t\t\tFROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\tWHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND\n\t\t\t(`item`.`deleted` = 0 OR item.verb = '" . ACTIVITY_LIKE . "' OR item.verb = '" . ACTIVITY_DISLIKE . "')\n\t\t\tand `item`.`moderated` = 0 and `item`.`unseen` = 1\n\t\t\tAND `item`.`wall` = 1\n\t\t\t{$sql_extra}\n\t\t\tORDER BY `item`.`created` DESC", intval($a->profile['profile_uid']));
    } else {
        $sql_post_table = "";
        if (x($category)) {
            $sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ", dbesc(protect_sprintf($category)), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), intval($a->profile['profile_uid']));
            //$sql_extra .= protect_sprintf(file_tag_file_query('item',$category,'category'));
        }
        if ($datequery) {
            $sql_extra2 .= protect_sprintf(sprintf(" AND `thread`.`created` <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(), '', $datequery))));
        }
        if ($datequery2) {
            $sql_extra2 .= protect_sprintf(sprintf(" AND `thread`.`created` >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(), '', $datequery2))));
        }
        if (get_config('system', 'old_pager')) {
            $r = q("SELECT COUNT(*) AS `total`\n\t\t\t    FROM `thread` INNER JOIN `item` ON `item`.`id` = `thread`.`iid`\n\t\t\t    {$sql_post_table} INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`\n\t\t\t    AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\t    WHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0\n\t\t\t    and `thread`.`moderated` = 0\n\t\t\t    AND `thread`.`wall` = 1\n\t\t\t    {$sql_extra} {$sql_extra2} ", intval($a->profile['profile_uid']));
            if (count($r)) {
                $a->set_pager_total($r[0]['total']);
            }
        }
        //  check if we serve a mobile device and get the user settings
        //  accordingly
        if ($a->is_mobile) {
            $itemspage_network = get_pconfig(local_user(), 'system', 'itemspage_mobile_network');
            $itemspage_network = intval($itemspage_network) ? $itemspage_network : 20;
        } else {
            $itemspage_network = get_pconfig(local_user(), 'system', 'itemspage_network');
            $itemspage_network = intval($itemspage_network) ? $itemspage_network : 40;
        }
        //  now that we have the user settings, see if the theme forces
        //  a maximum item number which is lower then the user choice
        if ($a->force_max_items > 0 && $a->force_max_items < $itemspage_network) {
            $itemspage_network = $a->force_max_items;
        }
        $a->set_pager_itemspage($itemspage_network);
        $pager_sql = sprintf(" LIMIT %d, %d ", intval($a->pager['start']), intval($a->pager['itemspage']));
        $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`,\n\t\t\t`thread`.`uid` AS `contact-uid`\n\t\t\tFROM `thread` INNER JOIN `item` ON `item`.`id` = `thread`.`iid`\n\t\t\t{$sql_post_table} INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`\n\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\tWHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0\n\t\t\tand `thread`.`moderated` = 0\n\t\t\tAND `thread`.`wall` = 1\n\t\t\t{$sql_extra} {$sql_extra2}\n\t\t\tORDER BY `thread`.`created` DESC {$pager_sql} ", intval($a->profile['profile_uid']));
    }
    $parents_arr = array();
    $parents_str = '';
    if (count($r)) {
        foreach ($r as $rr) {
            $parents_arr[] = $rr['item_id'];
        }
        $parents_str = implode(', ', $parents_arr);
        $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,\n\t\t\t`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`network`, `contact`.`rel`,\n\t\t\t`contact`.`thumb`, `contact`.`self`, `contact`.`writable`,\n\t\t\t`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`\n\t\t\tFROM `item`, `contact`\n\t\t\tWHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0\n\t\t\tand `item`.`moderated` = 0\n\t\t\tAND `contact`.`id` = `item`.`contact-id`\n\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\tAND `item`.`parent` IN ( %s )\n\t\t\t{$sql_extra} ", intval($a->profile['profile_uid']), dbesc($parents_str));
        $items = conv_sort($items, 'created');
    } else {
        $items = array();
    }
    if ($is_owner && !$update && !get_config('theme', 'hide_eventlist')) {
        $o .= get_birthdays();
        $o .= get_events();
    }
    if ($is_owner) {
        $r = q("UPDATE `item` SET `unseen` = 0\n\t\t\tWHERE `wall` = 1 AND `unseen` = 1 AND `uid` = %d", intval(local_user()));
    }
    $o .= conversation($a, $items, 'profile', $update);
    if (!$update) {
        if (!get_config('system', 'old_pager')) {
            $o .= alt_pager($a, count($items));
        } else {
            $o .= paginate($a);
        }
    }
    return $o;
}
Example #27
0
 function get()
 {
     if (local_channel()) {
         $channel = \App::get_channel();
     }
     $ob = \App::get_observer();
     $observer = get_observer_hash();
     if (!$observer) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     if (!perm_is_allowed(\App::$profile['profile_uid'], $observer, 'chat')) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     if (argc() > 3 && intval(argv(2)) && argv(3) === 'leave') {
         Zlib\Chatroom::leave($observer, argv(2), $_SERVER['REMOTE_ADDR']);
         goaway(z_root() . '/channel/' . argv(1));
     }
     if (argc() > 3 && intval(argv(2)) && argv(3) === 'status') {
         $ret = array('success' => false);
         $room_id = intval(argv(2));
         if (!$room_id || !$observer) {
             return;
         }
         $r = q("select * from chatroom where cr_id = %d limit 1", intval($room_id));
         if (!$r) {
             json_return_and_die($ret);
         }
         require_once 'include/security.php';
         $sql_extra = permissions_sql($r[0]['cr_uid']);
         $x = q("select * from chatroom where cr_id = %d and cr_uid = %d {$sql_extra} limit 1", intval($room_id), intval($r[0]['cr_uid']));
         if (!$x) {
             json_return_and_die($ret);
         }
         $y = q("select count(*) as total from chatpresence where cp_room = %d", intval($room_id));
         if ($y) {
             $ret['success'] = true;
             $ret['chatroom'] = $r[0]['cr_name'];
             $ret['inroom'] = $y[0]['total'];
         }
         // figure out how to present a timestamp of the last activity, since we don't know the observer's timezone.
         $z = q("select created from chat where chat_room = %d order by created desc limit 1", intval($room_id));
         if ($z) {
             $ret['last'] = $z[0]['created'];
         }
         json_return_and_die($ret);
     }
     if (argc() > 2 && intval(argv(2))) {
         $room_id = intval(argv(2));
         $bookmark_link = get_bookmark_link($ob);
         $x = Zlib\Chatroom::enter($observer, $room_id, 'online', $_SERVER['REMOTE_ADDR']);
         if (!$x) {
             return;
         }
         $x = q("select * from chatroom where cr_id = %d and cr_uid = %d {$sql_extra} limit 1", intval($room_id), intval(\App::$profile['profile_uid']));
         if ($x) {
             $acl = new \Zotlabs\Access\AccessList(false);
             $acl->set($x[0]);
             $private = $acl->is_private();
             $room_name = $x[0]['cr_name'];
             if ($bookmark_link) {
                 $bookmark_link .= '&url=' . z_root() . '/chat/' . argv(1) . '/' . argv(2) . '&title=' . urlencode($x[0]['cr_name']) . ($private ? '&private=1' : '') . '&ischat=1';
             }
         } else {
             notice(t('Room not found') . EOL);
             return;
         }
         $cipher = get_pconfig(local_channel(), 'system', 'default_cipher');
         if (!$cipher) {
             $cipher = 'aes256';
         }
         $o = replace_macros(get_markup_template('chat.tpl'), array('$is_owner' => local_channel() && local_channel() == $x[0]['cr_uid'] ? true : false, '$room_name' => $room_name, '$room_id' => $room_id, '$baseurl' => z_root(), '$nickname' => argv(1), '$submit' => t('Submit'), '$leave' => t('Leave Room'), '$drop' => t('Delete Room'), '$away' => t('I am away right now'), '$online' => t('I am online'), '$bookmark_link' => $bookmark_link, '$bookmark' => t('Bookmark this room'), '$feature_encrypt' => feature_enabled(local_channel(), 'content_encrypt') ? true : false, '$cipher' => $cipher, '$linkurl' => t('Please enter a link URL:'), '$encrypt' => t('Encrypt text'), '$insert' => t('Insert web link')));
         return $o;
     }
     require_once 'include/conversation.php';
     $o = profile_tabs($a, local_channel() && local_channel() == \App::$profile['profile_uid'] ? true : false, \App::$profile['channel_address']);
     if (!feature_enabled(\App::$profile['profile_uid'], 'ajaxchat')) {
         notice(t('Feature disabled.') . EOL);
         return $o;
     }
     $acl = new \Zotlabs\Access\AccessList($channel);
     $channel_acl = $acl->get();
     $lockstate = $channel_acl['allow_cid'] || $channel_acl['allow_gid'] || $channel_acl['deny_cid'] || $channel_acl['deny_gid'] ? 'lock' : 'unlock';
     require_once 'include/acl_selectors.php';
     $chatroom_new = '';
     if (local_channel()) {
         $chatroom_new = replace_macros(get_markup_template('chatroom_new.tpl'), array('$header' => t('New Chatroom'), '$name' => array('room_name', t('Chatroom name'), '', ''), '$chat_expire' => array('chat_expire', t('Expiration of chats (minutes)'), 120, ''), '$permissions' => t('Permissions'), '$acl' => populate_acl($channel_acl, false), '$lockstate' => $lockstate, '$submit' => t('Submit')));
     }
     $rooms = Zlib\Chatroom::roomlist(\App::$profile['profile_uid']);
     $o .= replace_macros(get_markup_template('chatrooms.tpl'), array('$header' => sprintf(t('%1$s\'s Chatrooms'), \App::$profile['fullname']), '$name' => t('Name'), '$baseurl' => z_root(), '$nickname' => \App::$profile['channel_address'], '$rooms' => $rooms, '$norooms' => t('No chatrooms available'), '$newroom' => t('Create New'), '$is_owner' => local_channel() && local_channel() == \App::$profile['profile_uid'] ? 1 : 0, '$chatroom_new' => $chatroom_new, '$expire' => t('Expiration'), '$expire_unit' => t('min')));
     return $o;
 }
Example #28
0
 /**
  * @brief Creates the directory listing for the given path.
  *
  * @param string $path which should be displayed
  */
 public function generateDirectoryIndex($path)
 {
     // (owner_id = channel_id) is visitor owner of this directory?
     $is_owner = local_channel() && $this->auth->owner_id == local_channel() ? true : false;
     if ($this->auth->getTimezone()) {
         date_default_timezone_set($this->auth->getTimezone());
     }
     require_once 'include/conversation.php';
     require_once 'include/text.php';
     if ($this->auth->owner_nick) {
         $html = profile_tabs(get_app(), $is_owner ? true : false, $this->auth->owner_nick);
     }
     $files = $this->server->getPropertiesForPath($path, array('{DAV:}displayname', '{DAV:}resourcetype', '{DAV:}getcontenttype', '{DAV:}getcontentlength', '{DAV:}getlastmodified'), 1);
     $parent = $this->server->tree->getNodeForPath($path);
     $parentpath = array();
     // only show parent if not leaving /cloud/; TODO how to improve this?
     if ($path && $path != "cloud") {
         list($parentUri) = \Sabre\HTTP\URLUtil::splitPath($path);
         $fullPath = \Sabre\HTTP\URLUtil::encodePath($this->server->getBaseUri() . $parentUri);
         $parentpath['icon'] = $this->enableAssets ? '<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl('icons/parent' . $this->iconExtension) . '" width="24" alt="' . t('parent') . '"></a>' : '';
         $parentpath['path'] = $fullPath;
     }
     $f = array();
     foreach ($files as $file) {
         $ft = array();
         $type = null;
         // This is the current directory, we can skip it
         if (rtrim($file['href'], '/') == $path) {
             continue;
         }
         list(, $name) = \Sabre\HTTP\URLUtil::splitPath($file['href']);
         if (isset($file[200]['{DAV:}resourcetype'])) {
             $type = $file[200]['{DAV:}resourcetype']->getValue();
             // resourcetype can have multiple values
             if (!is_array($type)) {
                 $type = array($type);
             }
             foreach ($type as $k => $v) {
                 // Some name mapping is preferred
                 switch ($v) {
                     case '{DAV:}collection':
                         $type[$k] = t('Collection');
                         break;
                     case '{DAV:}principal':
                         $type[$k] = t('Principal');
                         break;
                     case '{urn:ietf:params:xml:ns:carddav}addressbook':
                         $type[$k] = t('Addressbook');
                         break;
                     case '{urn:ietf:params:xml:ns:caldav}calendar':
                         $type[$k] = t('Calendar');
                         break;
                     case '{urn:ietf:params:xml:ns:caldav}schedule-inbox':
                         $type[$k] = t('Schedule Inbox');
                         break;
                     case '{urn:ietf:params:xml:ns:caldav}schedule-outbox':
                         $type[$k] = t('Schedule Outbox');
                         break;
                     case '{http://calendarserver.org/ns/}calendar-proxy-read':
                         $type[$k] = 'Proxy-Read';
                         break;
                     case '{http://calendarserver.org/ns/}calendar-proxy-write':
                         $type[$k] = 'Proxy-Write';
                         break;
                 }
             }
             $type = implode(', ', $type);
         }
         // If no resourcetype was found, we attempt to use
         // the contenttype property
         if (!$type && isset($file[200]['{DAV:}getcontenttype'])) {
             $type = $file[200]['{DAV:}getcontenttype'];
         }
         if (!$type) {
             $type = t('Unknown');
         }
         $size = isset($file[200]['{DAV:}getcontentlength']) ? (int) $file[200]['{DAV:}getcontentlength'] : '';
         $lastmodified = isset($file[200]['{DAV:}getlastmodified']) ? $file[200]['{DAV:}getlastmodified']->getTime()->format('Y-m-d H:i:s') : '';
         $fullPath = \Sabre\HTTP\URLUtil::encodePath('/' . trim($this->server->getBaseUri() . ($path ? $path . '/' : '') . $name, '/'));
         $displayName = isset($file[200]['{DAV:}displayname']) ? $file[200]['{DAV:}displayname'] : $name;
         $displayName = $this->escapeHTML($displayName);
         $type = $this->escapeHTML($type);
         $icon = '';
         if ($this->enableAssets) {
             $node = $this->server->tree->getNodeForPath(($path ? $path . '/' : '') . $name);
             foreach (array_reverse($this->iconMap) as $class => $iconName) {
                 if ($node instanceof $class) {
                     $icon = '<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl($iconName . $this->iconExtension) . '" alt="" width="24"></a>';
                     break;
                 }
             }
         }
         $parentHash = '';
         $owner = $this->auth->owner_id;
         $splitPath = explode('/', $fullPath);
         if (count($splitPath) > 3) {
             for ($i = 3; $i < count($splitPath); $i++) {
                 $attachName = urldecode($splitPath[$i]);
                 $attachHash = $this->findAttachHash($owner, $parentHash, $attachName);
                 $parentHash = $attachHash;
             }
         }
         $attachIcon = "";
         // "<a href=\"attach/".$attachHash."\" title=\"".$displayName."\"><i class=\"fa fa-arrow-circle-o-down\"></i></a>";
         // put the array for this file together
         $ft['attachId'] = $this->findAttachIdByHash($attachHash);
         $ft['fileStorageUrl'] = substr($fullPath, 0, strpos($fullPath, "cloud/")) . "filestorage/" . $this->auth->getCurrentUser();
         $ft['icon'] = $icon;
         $ft['attachIcon'] = $size ? $attachIcon : '';
         // @todo Should this be an item value, not a global one?
         $ft['is_owner'] = $is_owner;
         $ft['fullPath'] = $fullPath;
         $ft['displayName'] = $displayName;
         $ft['type'] = $type;
         $ft['size'] = $size;
         $ft['sizeFormatted'] = userReadableSize($size);
         $ft['lastmodified'] = $lastmodified ? datetime_convert('UTC', date_default_timezone_get(), $lastmodified) : '';
         $ft['iconFromType'] = getIconFromType($type);
         $f[] = $ft;
     }
     $output = '';
     if ($this->enablePost) {
         $this->server->emit('onHTMLActionsPanel', array($parent, &$output));
     }
     $html .= replace_macros(get_markup_template('cloud.tpl'), array('$header' => t('Files') . ": " . $this->escapeHTML($path) . "/", '$total' => t('Total'), '$actionspanel' => $output, '$shared' => t('Shared'), '$create' => t('Create'), '$upload' => t('Upload'), '$is_owner' => $is_owner, '$parentpath' => $parentpath, '$entries' => $f, '$name' => t('Name'), '$type' => t('Type'), '$size' => t('Size'), '$lastmod' => t('Last Modified'), '$parent' => t('parent'), '$edit' => t('Edit'), '$delete' => t('Delete'), '$nick' => $this->auth->getCurrentUser()));
     $a = get_app();
     \App::$page['content'] = $html;
     load_pdl($a);
     $theme_info_file = "view/theme/" . current_theme() . "/php/theme.php";
     if (file_exists($theme_info_file)) {
         require_once $theme_info_file;
         if (function_exists(str_replace('-', '_', current_theme()) . '_init')) {
             $func = str_replace('-', '_', current_theme()) . '_init';
             $func($a);
         }
     }
     construct_page($a);
 }
Example #29
0
function webpages_content(&$a)
{
    if (argc() > 1) {
        $which = argv(1);
    } else {
        notice(t('Requested profile is not available.') . EOL);
        $a->error = 404;
        return;
    }
    $profile = 0;
    $channel = $a->get_channel();
    if (local_user() && argc() > 2 && argv(2) === 'view') {
        $which = $channel['channel_address'];
        $profile = argv(1);
    }
    profile_load($a, $which, $profile);
    // Figure out who the page owner is.
    $r = q("select channel_id from channel where channel_address = '%s'", dbesc($which));
    if ($r) {
        $owner = intval($r[0]['channel_id']);
    }
    // Get the observer, check their permissions
    $observer = $a->get_observer();
    $ob_hash = $observer ? $observer['xchan_hash'] : '';
    $perms = get_all_perms($owner, $ob_hash);
    if (!$perms['write_pages']) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    //		if(local_user() && local_user() == $owner) {
    //			$a->set_widget('design',design_tools());
    //		}
    if (feature_enabled($owner, 'expert_mode')) {
        $mimetype = $_REQUEST['mimetype'] ? $_REQUEST['mimetype'] : get_pconfig($owner, 'system', 'page_mimetype');
        if (!$mimetype) {
            $mimetype = 'choose';
        }
    } else {
        $mimetype = 'text/bbcode';
    }
    $layout = $_REQUEST['layout'] ? $_REQUEST['layout'] : get_pconfig($owner, 'system', 'page_layout');
    if (!$layout) {
        $layout = 'choose';
    }
    // Create a status editor (for now - we'll need a WYSIWYG eventually) to create pages
    // Nickname is set to the observers xchan, and profile_uid to the owners.  This lets you post pages at other people's channels.
    require_once 'include/conversation.php';
    require_once 'include/acl_selectors.php';
    if (local_user() && local_user() == $a->profile_uid) {
        $channel = $a->get_channel();
        $channel_acl = array('allow_cid' => $channel['channel_allow_cid'], 'allow_gid' => $channel['channel_allow_gid'], 'deny_cid' => $channel['channel_deny_cid'], 'deny_gid' => $channel['channel_deny_gid']);
    } else {
        $channel_acl = array();
    }
    require_once 'include/conversation.php';
    $o = profile_tabs($a, true);
    $o .= '<h2>' . t('Webpages') . '</h2>';
    $x = array('webpage' => ITEM_WEBPAGE, 'is_owner' => true, 'nickname' => $a->profile['channel_address'], 'lockstate' => $group || $cid || $channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid'] ? 'lock' : 'unlock', 'bang' => $group || $cid ? '!' : '', 'acl' => local_user() && local_user() == $owner ? populate_acl($channel_acl, false) : '', 'visitor' => true, 'profile_uid' => intval($owner), 'mimetype' => $mimetype, 'layout' => $layout);
    if ($_REQUEST['title']) {
        $x['title'] = $_REQUEST['title'];
    }
    if ($_REQUEST['body']) {
        $x['body'] = $_REQUEST['body'];
    }
    if ($_REQUEST['pagetitle']) {
        $x['pagetitle'] = $_REQUEST['pagetitle'];
    }
    $o .= status_editor($a, $x);
    // Get a list of webpages.  We can't display all them because endless scroll makes that unusable, so just list titles and an edit link.
    //TODO - this should be replaced with pagelist_widget
    $r = q("select * from item_id left join item on item_id.iid = item.id where item_id.uid = %d and service = 'WEBPAGE' order by item.created desc", intval($owner));
    $pages = null;
    if ($r) {
        $pages = array();
        foreach ($r as $rr) {
            unobscure($rr);
            $pages[$rr['iid']][] = array('url' => $rr['iid'], 'pagetitle' => $rr['sid'], 'title' => $rr['title'], 'created' => datetime_convert('UTC', date_default_timezone_get(), $rr['created']), 'edited' => datetime_convert('UTC', date_default_timezone_get(), $rr['edited']));
        }
    }
    //Build the base URL for edit links
    $url = z_root() . "/editwebpage/" . $which;
    // This isn't pretty, but it works.  Until I figure out what to do with the UI, it's Good Enough(TM).
    return $o . replace_macros(get_markup_template("webpagelist.tpl"), array('$baseurl' => $url, '$edit' => t('Edit'), '$pages' => $pages, '$channel' => $which, '$view' => t('View'), '$preview' => t('Preview'), '$actions_txt' => t('Actions'), '$pagelink_txt' => t('Page Link'), '$title_txt' => t('Title'), '$created_txt' => t('Created'), '$edited_txt' => t('Edited')));
}