Пример #1
0
 function init()
 {
     $ret = array();
     call_hooks('home_init', $ret);
     $splash = argc() > 1 && argv(1) === 'splash' ? true : false;
     $channel = \App::get_channel();
     if (local_channel() && $channel && $channel['xchan_url'] && !$splash) {
         $dest = $channel['channel_startpage'];
         if (!$dest) {
             $dest = get_pconfig(local_channel(), 'system', 'startpage');
         }
         if (!$dest) {
             $dest = get_config('system', 'startpage');
         }
         if (!$dest) {
             $dest = z_root() . '/network';
         }
         goaway($dest);
     }
     if (remote_channel() && !$splash && $_SESSION['atoken']) {
         $r = q("select * from atoken where atoken_id = %d", intval($_SESSION['atoken']));
         if ($r) {
             $x = channelx_by_n($r[0]['atoken_uid']);
             if ($x) {
                 goaway(z_root() . '/channel/' . $x['channel_address']);
             }
         }
     }
     if (get_account_id() && !$splash) {
         goaway(z_root() . '/new_channel');
     }
 }
 public function __construct($owner = '')
 {
     global $phpgw, $phpgw_info;
     $this->db = $phpgw->db;
     if (isset($phpgw_info['user']['preferences']['common']['country']) && $phpgw_info['user']['preferences']['common']['country']) {
         $this->users['user'] = $phpgw_info['user']['preferences']['common']['country'];
     } else {
         $this->users['user'] = '******';
     }
     $owner_id = get_account_id($owner);
     if ($owner_id != $phpgw_info['user']['account_id']) {
         $owner_pref = CreateObject('phpgwapi.preferences', $owner_id);
         $owner_prefs = $owner_pref->read();
         if (isset($owner_prefs['calendar']['locale']) && $owner_prefs['common']['country']) {
             $this->users['owner'] = $owner_prefs['common']['country'];
         } else {
             $this->users['owner'] = 'US';
         }
     }
     if ($phpgw_info['server']['auto_load_holidays'] == True) {
         while (list($key, $value) = each($this->users)) {
             $this->is_network_load_needed($value);
         }
     }
 }
Пример #3
0
 function post()
 {
     if (!local_channel()) {
         return;
     }
     if ($_SESSION['delegate']) {
         return;
     }
     if (!x($_POST, 'qxz_password') || !strlen(trim($_POST['qxz_password']))) {
         return;
     }
     if (!x($_POST, 'verify') || !strlen(trim($_POST['verify']))) {
         return;
     }
     if ($_POST['verify'] !== $_SESSION['remove_account_verify']) {
         return;
     }
     $account = \App::get_account();
     $account_id = get_account_id();
     if (!account_verify_password($account['account_email'], $_POST['qxz_password'])) {
         return;
     }
     if ($account['account_password_changed'] != NULL_DATE) {
         $d1 = datetime_convert('UTC', 'UTC', 'now - 48 hours');
         if ($account['account_password_changed'] > d1) {
             notice(t('Account removals are not allowed within 48 hours of changing the account password.') . EOL);
             return;
         }
     }
     $global_remove = intval($_POST['global']);
     account_remove($account_id, 1 - $global_remove);
 }
 function calendar_holiday($owner = '')
 {
     $this->datetime = CreateObject('phpgwapi.datetime');
     $this->db = $GLOBALS['phpgw']->db;
     if (@$GLOBALS['phpgw_info']['user']['preferences']['common']['country']) {
         $this->users['user'] = $GLOBALS['phpgw_info']['user']['preferences']['common']['country'];
     } else {
         $this->users['user'] = '******';
     }
     $owner_id = get_account_id($owner);
     if ($owner_id != $GLOBALS['phpgw_info']['user']['account_id']) {
         $owner_pref = CreateObject('phpgwapi.preferences', $owner_id);
         $owner_prefs = $owner_pref->read_repository();
         if (isset($owner_prefs['calendar']['locale']) && $owner_prefs['common']['country']) {
             $this->users['owner'] = $owner_prefs['common']['country'];
         } else {
             $this->users['owner'] = 'US';
         }
     }
     if ($GLOBALS['phpgw_info']['server']['auto_load_holidays'] == True) {
         while (list($key, $value) = each($this->users)) {
             $this->is_network_load_needed($value);
         }
     }
 }
Пример #5
0
 function init()
 {
     $result = array('success' => false);
     $mindate = $_REQUEST['mindate'] ? datetime_convert('UTC', 'UTC', $_REQUEST['mindate']) : '';
     if (!$mindate) {
         $mindate = datetime_convert('UTC', 'UTC', 'now - 14 days');
     }
     if (get_config('system', 'block_public') && !get_account_id() && !remote_channel()) {
         $result['message'] = 'Public access denied';
         json_return_and_die($result);
     }
     $observer = \App::get_observer();
     $channel_address = argc() > 1 ? argv(1) : '';
     if ($channel_address) {
         $r = q("select channel_id, channel_name from channel where channel_address = '%s' and channel_removed = 0 limit 1", dbesc(argv(1)));
     } else {
         $x = get_sys_channel();
         if ($x) {
             $r = array($x);
         }
         $mindate = datetime_convert('UTC', 'UTC', 'now - 14 days');
     }
     if (!$r) {
         $result['message'] = 'Channel not found.';
         json_return_and_die($result);
     }
     logger('zotfeed request: ' . $r[0]['channel_name'], LOGGER_DEBUG);
     $result['messages'] = zot_feed($r[0]['channel_id'], $observer['xchan_hash'], array('mindate' => $mindate));
     $result['success'] = true;
     json_return_and_die($result);
 }
Пример #6
0
function new_channel_content(&$a)
{
    $acc = App::get_account();
    if (!$acc || $acc['account_id'] != get_account_id()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $default_role = '';
    $aid = get_account_id();
    if ($aid) {
        $r = q("select count(channel_id) as total from channel where channel_account_id = %d", intval($aid));
        if ($r && !intval($r[0]['total'])) {
            $default_role = get_config('system', 'default_permissions_role');
        }
        $limit = account_service_class_fetch(get_account_id(), 'total_identities');
        if ($r && $limit !== false) {
            $channel_usage_message = sprintf(t("You have created %1\$.0f of %2\$.0f allowed channels."), $r[0]['total'], $limit);
        } else {
            $channel_usage_message = '';
        }
    }
    $name = array('name', t('Name or caption'), x($_REQUEST, 'name') ? $_REQUEST['name'] : '', t('Examples: "Bob Jameson", "Lisa and her Horses", "Soccer", "Aviation Group"'));
    $nickhub = '@' . App::get_hostname();
    $nickname = array('nickname', t('Choose a short nickname'), x($_REQUEST, 'nickname') ? $_REQUEST['nickname'] : '', sprintf(t('Your nickname will be used to create an easy to remember channel address e.g. nickname%s'), $nickhub));
    $privacy_role = x($_REQUEST, 'permissions_role') ? $_REQUEST['permissions_role'] : "";
    $role = array('permissions_role', t('Channel role and privacy'), $privacy_role ? $privacy_role : 'social', t('Select a channel role with your privacy requirements.') . ' <a href="help/roles" target="_blank">' . t('Read more about roles') . '</a>', get_roles());
    $o = replace_macros(get_markup_template('new_channel.tpl'), array('$title' => t('Create Channel'), '$desc' => t('A channel is your identity on this network. It can represent a person, a blog, or a forum to name a few. Channels can make connections with other channels to share information with highly detailed permissions.'), '$label_import' => t('or <a href="import">import an existing channel</a> from another location.'), '$name' => $name, '$role' => $role, '$default_role' => $default_role, '$nickname' => $nickname, '$submit' => t('Create'), '$channel_usage_message' => $channel_usage_message));
    return $o;
}
Пример #7
0
function removeaccount_post(&$a)
{
    if (!local_user()) {
        return;
    }
    if (x($_SESSION, 'submanage') && intval($_SESSION['submanage'])) {
        return;
    }
    if (!x($_POST, 'qxz_password') || !strlen(trim($_POST['qxz_password']))) {
        return;
    }
    if (!x($_POST, 'verify') || !strlen(trim($_POST['verify']))) {
        return;
    }
    if ($_POST['verify'] !== $_SESSION['remove_account_verify']) {
        return;
    }
    $account = $a->get_account();
    $account_id = get_account_id();
    if (!account_verify_password($account['account_email'], $_POST['qxz_password'])) {
        return;
    }
    if ($account['account_password_changed'] != NULL_DATE) {
        $d1 = datetime_convert('UTC', 'UTC', 'now - 48 hours');
        if ($account['account_password_changed'] > d1) {
            notice(t('Account removals are not allowed within 48 hours of changing the account password.') . EOL);
            return;
        }
    }
    require_once 'include/Contact.php';
    $global_remove = intval($_POST['global']);
    account_remove($account_id, true);
}
Пример #8
0
function feed_init(&$a)
{
    $params = array();
    $params['begin'] = x($_REQUEST, 'date_begin') ? $_REQUEST['date_begin'] : NULL_DATE;
    $params['end'] = x($_REQUEST, 'date_end') ? $_REQUEST['date_end'] : '';
    $params['type'] = stristr(argv(0), 'json') ? 'json' : 'xml';
    $params['pages'] = x($_REQUEST, 'pages') ? intval($_REQUEST['pages']) : 0;
    $params['top'] = x($_REQUEST, 'top') ? intval($_REQUEST['top']) : 0;
    $params['start'] = x($params, 'start') ? intval($params['start']) : 0;
    $params['records'] = x($params, 'records') ? intval($params['records']) : 40;
    $params['direction'] = x($params, 'direction') ? dbesc($params['direction']) : 'desc';
    $params['cat'] = x($_REQUEST, 'cat') ? escape_tags($_REQUEST['cat']) : '';
    $channel = '';
    if (argc() > 1) {
        $r = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_address = '%s' limit 1", dbesc(argv(1)));
        if (!($r && count($r))) {
            killme();
        }
        $channel = $r[0];
        if (intval(get_config('system', 'block_public')) && !get_account_id()) {
            killme();
        }
        logger('mod_feed: public feed request from ' . $_SERVER['REMOTE_ADDR'] . ' for ' . $channel['channel_address']);
        echo get_public_feed($channel, $params);
        killme();
    }
}
Пример #9
0
function change_channel($change_channel)
{
    $ret = false;
    if ($change_channel) {
        $r = q("select channel.*, xchan.* from channel left join xchan on channel.channel_hash = xchan.xchan_hash where channel_id = %d and channel_account_id = %d and not ( channel_pageflags & %d) limit 1", intval($change_channel), intval(get_account_id()), intval(PAGE_REMOVED));
        if ($r) {
            $hash = $r[0]['channel_hash'];
            $_SESSION['uid'] = intval($r[0]['channel_id']);
            get_app()->set_channel($r[0]);
            $_SESSION['theme'] = $r[0]['channel_theme'];
            $_SESSION['mobile_theme'] = get_pconfig(local_user(), 'system', 'mobile_theme');
            date_default_timezone_set($r[0]['channel_timezone']);
            $ret = $r[0];
        }
        $x = q("select * from xchan where xchan_hash = '%s' limit 1", dbesc($hash));
        if ($x) {
            $_SESSION['my_url'] = $x[0]['xchan_url'];
            $_SESSION['my_address'] = $r[0]['channel_address'] . '@' . substr(get_app()->get_baseurl(), strpos(get_app()->get_baseurl(), '://') + 3);
            get_app()->set_observer($x[0]);
            get_app()->set_perms(get_all_perms(local_user(), $hash));
        }
        if (!is_dir('store/' . $r[0]['channel_address'])) {
            @os_mkdir('store/' . $r[0]['channel_address'], STORAGE_DEFAULT_PERMISSIONS, true);
        }
    }
    return $ret;
}
Пример #10
0
/**
 * @brief Change to another channel with current logged-in account.
 *
 * @param int $change_channel The channel_id of the channel you want to change to
 *
 * @return bool|array false or channel record of the new channel
 */
function change_channel($change_channel)
{
    $ret = false;
    if ($change_channel) {
        $r = q("select channel.*, xchan.* from channel left join xchan on channel.channel_hash = xchan.xchan_hash where channel_id = %d and channel_account_id = %d and channel_removed = 0 limit 1", intval($change_channel), intval(get_account_id()));
        // It's not there.  Is this an administrator, and is this the sys channel?
        if (is_developer()) {
            if (!$r) {
                if (is_site_admin()) {
                    $r = q("select channel.*, xchan.* from channel left join xchan on channel.channel_hash = xchan.xchan_hash where channel_id = %d and channel_system = 1 and channel_removed = 0 limit 1", intval($change_channel));
                }
            }
        }
        if ($r) {
            $hash = $r[0]['channel_hash'];
            $_SESSION['uid'] = intval($r[0]['channel_id']);
            get_app()->set_channel($r[0]);
            $_SESSION['theme'] = $r[0]['channel_theme'];
            $_SESSION['mobile_theme'] = get_pconfig(local_channel(), 'system', 'mobile_theme');
            date_default_timezone_set($r[0]['channel_timezone']);
            $ret = $r[0];
        }
        $x = q("select * from xchan where xchan_hash = '%s' limit 1", dbesc($hash));
        if ($x) {
            $_SESSION['my_url'] = $x[0]['xchan_url'];
            $_SESSION['my_address'] = $r[0]['channel_address'] . '@' . substr(get_app()->get_baseurl(), strpos(get_app()->get_baseurl(), '://') + 3);
            get_app()->set_observer($x[0]);
            get_app()->set_perms(get_all_perms(local_channel(), $hash));
        }
        if (!is_dir('store/' . $r[0]['channel_address'])) {
            @os_mkdir('store/' . $r[0]['channel_address'], STORAGE_DEFAULT_PERMISSIONS, true);
        }
    }
    return $ret;
}
 /**
  * Constructor
  *
  * @param integer $accountid Account id
  * @param string $app_name Application name defaults to current application
  */
 function __construct($accountid = '', $app_name = '', $location = '')
 {
     $account_id = (int) get_account_id($accountid);
     if (!$app_name) {
         $app_name = $GLOBALS['phpgw_info']['flags']['currentapp'];
     }
     $this->account_id = (int) $account_id;
     $this->db =& $GLOBALS['phpgw']->db;
     $this->set_appname($app_name, $location);
 }
Пример #12
0
function new_channel_content(&$a)
{
    if (!get_account_id()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $name = x($_REQUEST, 'name') ? $_REQUEST['name'] : "";
    $nickname = x($_REQUEST, 'nickname') ? $_REQUEST['nickname'] : "";
    $o = replace_macros(get_markup_template('new_channel.tpl'), array('$title' => t('Add a Channel'), '$desc' => t('A channel is your own collection of related web pages. A channel can be used to hold social network profiles, blogs, conversation groups and forums, celebrity pages, and much more. You may create as many channels as your service provider allows.'), '$label_name' => t('Channel Name'), '$help_name' => t('Examples: "Bob Jameson", "Lisa and her Horses", "Soccer", "Aviation Group" '), '$label_nick' => t('Choose a short nickname'), '$nick_desc' => t('Your nickname will be used to create an easily remembered channel address (like an email address) which you can share with others.'), '$label_import' => t('Or <a href="import">import an existing channel</a> from another location'), '$name' => $name, '$nickname' => $nickname, '$submit' => t('Create')));
    return $o;
}
Пример #13
0
function new_channel_content(&$a)
{
    if (!get_account_id()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $name = x($_REQUEST, 'name') ? $_REQUEST['name'] : "";
    $nickname = x($_REQUEST, 'nickname') ? $_REQUEST['nickname'] : "";
    $privacy_role = x($_REQUEST, 'permissions_role') ? $_REQUEST['permissions_role'] : "";
    $o = replace_macros(get_markup_template('new_channel.tpl'), array('$title' => t('Add a Channel'), '$desc' => t('A channel is your own collection of related web pages. A channel can be used to hold social network profiles, blogs, conversation groups and forums, celebrity pages, and much more. You may create as many channels as your service provider allows.'), '$label_name' => t('Channel Name'), '$help_name' => t('Examples: "Bob Jameson", "Lisa and her Horses", "Soccer", "Aviation Group" '), '$label_nick' => t('Choose a short nickname'), '$nick_desc' => t('Your nickname will be used to create an easily remembered channel address (like an email address) which you can share with others.'), '$label_import' => t('Or <a href="import">import an existing channel</a> from another location'), '$name' => $name, '$help_role' => t('Please choose a channel type (such as social networking or community forum) and privacy requirements so we can select the best permissions for you'), '$role' => array('permissions_role', t('Channel Type'), $privacy_role ? $privacy_role : 'social', '<a href="help/roles" target="_blank">' . t('Read more about roles') . '</a>', get_roles()), '$nickname' => $nickname, '$submit' => t('Create')));
    return $o;
}
 function categories($accountid = '', $app_name = '')
 {
     $account_id = get_account_id($accountid);
     if (!$app_name) {
         $app_name = $GLOBALS['phpgw_info']['flags']['currentapp'];
     }
     $this->account_id = $account_id;
     $this->app_name = $GLOBALS['phpgw']->db->db_addslashes($app_name);
     $this->db = $GLOBALS['phpgw']->db;
     $this->db2 = $this->db;
     $this->grants = $GLOBALS['phpgw']->acl->get_grants($app_name);
 }
Пример #15
0
function import_profiles($channel, $profiles)
{
    if ($channel && $profiles) {
        foreach ($profiles as $profile) {
            unset($profile['id']);
            $profile['aid'] = get_account_id();
            $profile['uid'] = $channel['channel_id'];
            // we are going to reset all profile photos to the original
            // somebody will have to fix this later and put all the applicable photos into the export
            $profile['photo'] = z_root() . '/photo/profile/l/' . $channel['channel_id'];
            $profile['thumb'] = z_root() . '/photo/profile/m/' . $channel['channel_id'];
            dbesc_array($profile);
            $r = dbq("INSERT INTO profile (`" . implode("`, `", array_keys($profile)) . "`) VALUES ('" . implode("', '", array_values($profile)) . "')");
        }
    }
}
Пример #16
0
function api_user()
{
    $aid = get_account_id();
    $channel = get_app()->get_channel();
    if ($aid && x($_REQUEST, 'channel')) {
        // Only change channel if it is different than the current channel
        if ($channel && x($channel, 'channel_address') && $channel['channel_address'] != $_REQUEST['channel']) {
            $c = q("select channel_id from channel where channel_address = '%s' and channel_account_id = %d limit 1", dbesc($_REQUEST['channel']), intval($aid));
            if (!$c || !change_channel($c[0]['channel_id'])) {
                return false;
            }
        }
    }
    if ($_SESSION["allow_api"]) {
        return local_channel();
    }
    return false;
}
Пример #17
0
Файл: home.php Проект: Mauru/red
function home_init(&$a)
{
    $ret = array();
    call_hooks('home_init', $ret);
    $channel = $a->get_channel();
    if (local_user() && $channel && $channel['xchan_url']) {
        $dest = $channel['channel_startpage'];
        if (!$dest) {
            $dest = get_pconfig(local_user(), 'system', 'startpage');
        }
        if (!$dest) {
            $dest = get_config('system', 'startpage');
        }
        if (!$dest) {
            $dest = z_root() . '/apps';
        }
        goaway($dest);
    }
    if (get_account_id()) {
        goaway(z_root() . '/new_channel');
    }
}
Пример #18
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;
}
Пример #19
0
 function get()
 {
     if (get_config('system', 'block_public') && !get_account_id() && !remote_channel()) {
         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;
 }
Пример #20
0
function home_init(&$a)
{
    $ret = array();
    call_hooks('home_init', $ret);
    $splash = argc() > 1 && argv(1) === 'splash' ? true : false;
    $channel = $a->get_channel();
    if (local_channel() && $channel && $channel['xchan_url'] && !$splash) {
        $dest = $channel['channel_startpage'];
        if (!$dest) {
            $dest = get_pconfig(local_channel(), 'system', 'startpage');
        }
        if (!$dest) {
            $dest = get_config('system', 'startpage');
        }
        if (!$dest) {
            $dest = z_root() . '/network';
        }
        goaway($dest);
    }
    if (get_account_id() && !$splash) {
        goaway(z_root() . '/new_channel');
    }
}
 function delete_user()
 {
     if (isset($_POST['cancel']) || $GLOBALS['phpgw']->acl->check('account_access', 32, 'admin')) {
         ExecMethod('admin.uiaccounts.list_users');
         return False;
     } elseif ($_POST['delete_account']) {
         $accountid = $_POST['account_id'];
         settype($account_id, 'integer');
         $account_id = get_account_id($accountid);
         // make this information also in hook available
         $lid = $GLOBALS['phpgw']->accounts->id2name($account_id);
         $GLOBALS['hook_values']['account_id'] = $account_id;
         $GLOBALS['hook_values']['account_lid'] = $lid;
         $singleHookValues = $GLOBALS['hook_values'] + array('location' => 'deleteaccount');
         $db = $GLOBALS['phpgw']->db;
         $db->query('SELECT app_name,app_order FROM phpgw_applications WHERE app_enabled!=0 ORDER BY app_order', __LINE__, __FILE__);
         if ($db->num_rows()) {
             while ($db->next_record()) {
                 $appname = $db->f('app_name');
                 if ($appname != 'admin' || $appname != 'preferences') {
                     $GLOBALS['phpgw']->hooks->single($singleHookValues, $appname);
                 }
             }
         }
         $GLOBALS['phpgw']->hooks->single('deleteaccount', 'preferences');
         $GLOBALS['phpgw']->hooks->single('deleteaccount', 'admin');
         $basedir = $GLOBALS['phpgw_info']['server']['files_dir'] . SEP . 'users' . SEP;
         if (!@rmdir($basedir . $lid)) {
             $cd = 34;
         } else {
             $cd = 29;
         }
         ExecMethod('admin.uiaccounts.list_users');
         return False;
     }
 }
Пример #22
0
 function get()
 {
     if (!get_account_id() || $_SESSION['delegate']) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     require_once 'include/security.php';
     $change_channel = argc() > 1 ? intval(argv(1)) : 0;
     if (argc() > 2 && argv(2) === 'default') {
         $r = q("select channel_id from channel where channel_id = %d and channel_account_id = %d limit 1", intval($change_channel), intval(get_account_id()));
         if ($r) {
             q("update account set account_default_channel = %d where account_id = %d", intval($change_channel), intval(get_account_id()));
         }
         goaway(z_root() . '/manage');
     }
     if ($change_channel) {
         $r = change_channel($change_channel);
         if (argc() > 2 && !(argv(2) === 'default')) {
             goaway(z_root() . '/' . implode('/', array_slice(\App::$argv, 2)));
             // Go to whatever is after /manage/, but with the new channel
         } else {
             if ($r && $r['channel_startpage']) {
                 goaway(z_root() . '/' . $r['channel_startpage']);
             }
             // If nothing extra is specified, go to the default page
         }
         goaway(z_root());
     }
     $channels = null;
     if (local_channel()) {
         $r = q("select channel.*, xchan.* from channel left join xchan on channel.channel_hash = xchan.xchan_hash where channel.channel_account_id = %d and channel_removed = 0 order by channel_name ", intval(get_account_id()));
         $account = \App::get_account();
         if ($r && count($r)) {
             $channels = $r;
             for ($x = 0; $x < count($channels); $x++) {
                 $channels[$x]['link'] = 'manage/' . intval($channels[$x]['channel_id']);
                 $channels[$x]['default'] = $channels[$x]['channel_id'] == $account['account_default_channel'] ? "1" : '';
                 $channels[$x]['default_links'] = '1';
                 $c = q("SELECT id, item_wall FROM item\n\t\t\t\t\t\tWHERE item_unseen = 1 and uid = %d " . item_normal(), intval($channels[$x]['channel_id']));
                 if ($c) {
                     foreach ($c as $it) {
                         if (intval($it['item_wall'])) {
                             $channels[$x]['home']++;
                         } else {
                             $channels[$x]['network']++;
                         }
                     }
                 }
                 $intr = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and abook_pending = 1 and abook_self = 0 and abook_ignored = 0 and xchan_deleted = 0 and xchan_orphan = 0 ", intval($channels[$x]['channel_id']));
                 if ($intr) {
                     $channels[$x]['intros'] = intval($intr[0]['total']);
                 }
                 $mails = q("SELECT count(id) as total from mail WHERE channel_id = %d AND mail_seen = 0 and from_xchan != '%s' ", intval($channels[$x]['channel_id']), dbesc($channels[$x]['channel_hash']));
                 if ($mails) {
                     $channels[$x]['mail'] = intval($mails[0]['total']);
                 }
                 $events = q("SELECT type, start, adjust FROM `event`\n\t\t\t\t\t\tWHERE `event`.`uid` = %d AND start < '%s' AND start > '%s' and `ignore` = 0\n\t\t\t\t\t\tORDER BY `start` ASC ", intval($channels[$x]['channel_id']), dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now + 7 days')), dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now - 1 days')));
                 if ($events) {
                     $channels[$x]['all_events'] = count($events);
                     if ($channels[$x]['all_events']) {
                         $str_now = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y-m-d');
                         foreach ($events as $e) {
                             $bd = false;
                             if ($e['type'] === 'birthday') {
                                 $channels[$x]['birthdays']++;
                                 $bd = true;
                             } else {
                                 $channels[$x]['events']++;
                             }
                             if (datetime_convert('UTC', intval($e['adjust']) ? date_default_timezone_get() : 'UTC', $e['start'], 'Y-m-d') === $str_now) {
                                 $channels[$x]['all_events_today']++;
                                 if ($bd) {
                                     $channels[$x]['birthdays_today']++;
                                 } else {
                                     $channels[$x]['events_today']++;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $r = q("select count(channel_id) as total from channel where channel_account_id = %d and channel_removed = 0", intval(get_account_id()));
         $limit = account_service_class_fetch(get_account_id(), 'total_identities');
         if ($limit !== false) {
             $channel_usage_message = sprintf(t("You have created %1\$.0f of %2\$.0f allowed channels."), $r[0]['total'], $limit);
         } else {
             $channel_usage_message = '';
         }
     }
     $create = array('new_channel', t('Create a new channel'), t('Create New'));
     $delegates = q("select * from abook left join xchan on abook_xchan = xchan_hash where \n\t\t\tabook_channel = %d and (abook_their_perms & %d) > 0", intval(local_channel()), intval(PERMS_A_DELEGATE));
     if ($delegates) {
         for ($x = 0; $x < count($delegates); $x++) {
             $delegates[$x]['link'] = 'magic?f=&dest=' . urlencode($delegates[$x]['xchan_url']) . '&delegate=' . urlencode($delegates[$x]['xchan_addr']);
             $delegates[$x]['channel_name'] = $delegates[$x]['xchan_name'];
             $delegates[$x]['delegate'] = 1;
         }
     } else {
         $delegates = null;
     }
     $o = replace_macros(get_markup_template('channels.tpl'), array('$header' => t('Channel Manager'), '$msg_selected' => t('Current Channel'), '$selected' => local_channel(), '$desc' => t('Switch to one of your channels by selecting it.'), '$msg_default' => t('Default Channel'), '$msg_make_default' => t('Make Default'), '$create' => $create, '$all_channels' => $channels, '$mail_format' => t('%d new messages'), '$intros_format' => t('%d new introductions'), '$channel_usage_message' => $channel_usage_message, '$delegated_desc' => t('Delegated Channel'), '$delegates' => $delegates));
     return $o;
 }
 function update_lastlogin($account_id, $ip)
 {
     $account_id = get_account_id($account_id);
     $GLOBALS['phpgw']->db->query("update phpgw_accounts set account_lastloginfrom='" . "{$ip}', account_lastlogin='******' where account_id='{$account_id}'", __LINE__, __FILE__);
 }
Пример #24
0
function profile_photo_post(&$a)
{
    if (!local_channel()) {
        return;
    }
    check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo');
    if (x($_POST, 'cropfinal') && $_POST['cropfinal'] == 1) {
        // unless proven otherwise
        $is_default_profile = 1;
        if ($_REQUEST['profile']) {
            $r = q("select id, profile_guid, is_default, gender from profile where id = %d and uid = %d limit 1", intval($_REQUEST['profile']), intval(local_channel()));
            if ($r) {
                $profile = $r[0];
                if (!intval($profile['is_default'])) {
                    $is_default_profile = 0;
                }
            }
        }
        // phase 2 - we have finished cropping
        if (argc() != 2) {
            notice(t('Image uploaded but image cropping failed.') . EOL);
            return;
        }
        $image_id = argv(1);
        if (substr($image_id, -2, 1) == '-') {
            $scale = substr($image_id, -1, 1);
            $image_id = substr($image_id, 0, -2);
        }
        $srcX = $_POST['xstart'];
        $srcY = $_POST['ystart'];
        $srcW = $_POST['xfinal'] - $srcX;
        $srcH = $_POST['yfinal'] - $srcY;
        $r = q("SELECT * FROM photo WHERE resource_id = '%s' AND uid = %d AND scale = %d LIMIT 1", dbesc($image_id), dbesc(local_channel()), intval($scale));
        if ($r) {
            $base_image = $r[0];
            $base_image['data'] = $r[0]['os_storage'] ? @file_get_contents($base_image['data']) : dbunescbin($base_image['data']);
            $im = photo_factory($base_image['data'], $base_image['type']);
            if ($im->is_valid()) {
                $im->cropImage(300, $srcX, $srcY, $srcW, $srcH);
                $aid = get_account_id();
                $p = array('aid' => $aid, 'uid' => local_channel(), 'resource_id' => $base_image['resource_id'], 'filename' => $base_image['filename'], 'album' => t('Profile Photos'));
                $p['scale'] = 4;
                $p['photo_usage'] = $is_default_profile ? PHOTO_PROFILE : PHOTO_NORMAL;
                $r1 = $im->save($p);
                $im->scaleImage(80);
                $p['scale'] = 5;
                $r2 = $im->save($p);
                $im->scaleImage(48);
                $p['scale'] = 6;
                $r3 = $im->save($p);
                if ($r1 === false || $r2 === false || $r3 === false) {
                    // if one failed, delete them all so we can start over.
                    notice(t('Image resize failed.') . EOL);
                    $x = q("delete from photo where resource_id = '%s' and uid = %d and scale >= 4 ", dbesc($base_image['resource_id']), local_channel());
                    return;
                }
                $channel = App::get_channel();
                // If setting for the default profile, unset the profile photo flag from any other photos I own
                if ($is_default_profile) {
                    $r = q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d\n\t\t\t\t\t\tAND resource_id != '%s' AND `uid` = %d", intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), dbesc($base_image['resource_id']), intval(local_channel()));
                    send_profile_photo_activity($channel, $base_image, $profile);
                } else {
                    $r = q("update profile set photo = '%s', thumb = '%s' where id = %d and uid = %d", dbesc(z_root() . '/photo/' . $base_image['resource_id'] . '-4'), dbesc(z_root() . '/photo/' . $base_image['resource_id'] . '-5'), intval($_REQUEST['profile']), intval(local_channel()));
                }
                profiles_build_sync(local_channel());
                // We'll set the updated profile-photo timestamp even if it isn't the default profile,
                // so that browsers will do a cache update unconditionally
                $r = q("UPDATE xchan set xchan_photo_mimetype = '%s', xchan_photo_date = '%s' \n\t\t\t\t\twhere xchan_hash = '%s'", dbesc($im->getType()), dbesc(datetime_convert()), dbesc($channel['xchan_hash']));
                info(t('Shift-reload the page or clear browser cache if the new photo does not display immediately.') . EOL);
                // Update directory in background
                proc_run('php', "include/directory.php", $channel['channel_id']);
                // Now copy profile-permissions to pictures, to prevent privacyleaks by automatically created folder 'Profile Pictures'
                profile_photo_set_profile_perms($_REQUEST['profile']);
            } else {
                notice(t('Unable to process image') . EOL);
            }
        }
        goaway(z_root() . '/profiles');
        return;
        // NOTREACHED
    }
    $hash = photo_new_resource();
    $smallest = 0;
    require_once 'include/attach.php';
    $res = attach_store(App::get_channel(), get_observer_hash(), '', array('album' => t('Profile Photos'), 'hash' => $hash));
    logger('attach_store: ' . print_r($res, true));
    if ($res && intval($res['data']['is_photo'])) {
        $i = q("select * from photo where resource_id = '%s' and uid = %d order by scale", dbesc($hash), intval(local_channel()));
        if (!$i) {
            notice(t('Image upload failed.') . EOL);
            return;
        }
        $os_storage = false;
        foreach ($i as $ii) {
            if (intval($ii['scale']) < 2) {
                $smallest = intval($ii['scale']);
                $os_storage = intval($ii['os_storage']);
                $imagedata = $ii['data'];
                $filetype = $ii['type'];
            }
        }
    }
    $imagedata = $os_storage ? @file_get_contents($imagedata) : $imagedata;
    $ph = photo_factory($imagedata, $filetype);
    if (!$ph->is_valid()) {
        notice(t('Unable to process image.') . EOL);
        return;
    }
    return profile_photo_crop_ui_head($a, $ph, $hash, $smallest);
}
 function delete_cache($accountid = '')
 {
     $account_id = get_account_id($accountid, $this->account_id);
     $GLOBALS['phpgw_session']['phpgw_app_sessions']['phpgwapi']['phpgw_info_cache'] = '';
     session_register('phpgw_session');
     $_SESSION['phpgw_session'] = $GLOBALS['phpgw_session'];
 }
Пример #26
0
/**
 * remote post
 * 
 * https://yoursite/rpost?f=&title=&body=&remote_return=
 *
 * This can be called via either GET or POST, use POST for long body content as suhosin often limits GET parameter length
 *
 * f= placeholder, often required
 * title= Title of post
 * body= Body of post
 * url= URL which will be parsed and the results appended to the body
 * source= Source application
 * remote_return= absolute URL to return after posting is finished
 * type= choices are 'html' or 'bbcode', default is 'bbcode'
 *
 */
function rpost_content(&$a)
{
    $o = '';
    if (!local_channel()) {
        if (remote_channel()) {
            // redirect to your own site.
            // We can only do this with a GET request so you'll need to keep the text short or risk getting truncated
            // by the wretched beast called 'suhosin'. All the browsers now allow long GET requests, but suhosin
            // blocks them.
            $url = get_rpost_path($a->get_observer());
            // make sure we're not looping to our own hub
            if ($url && !stristr($url, $a->get_hostname())) {
                foreach ($_REQUEST as $key => $arg) {
                    $url .= '&' . $key . '=' . $arg;
                }
                goaway($url);
            }
        }
        // The login procedure is going to bugger our $_REQUEST variables
        // so save them in the session.
        if (array_key_exists('body', $_REQUEST)) {
            $_SESSION['rpost'] = $_REQUEST;
        }
        return login();
    }
    // If we have saved rpost session variables, but nothing in the current $_REQUEST, recover the saved variables
    if (!array_key_exists('body', $_REQUEST) && array_key_exists('rpost', $_SESSION)) {
        $_REQUEST = $_SESSION['rpost'];
        unset($_SESSION['rpost']);
    }
    if (array_key_exists('channel', $_REQUEST)) {
        $r = q("select channel_id from channel where channel_account_id = %d and channel_address = '%s' limit 1", intval(get_account_id()), dbesc($_REQUEST['channel']));
        if ($r) {
            require_once 'include/security.php';
            $change = change_channel($r[0]['channel_id']);
        }
    }
    if ($_REQUEST['remote_return']) {
        $_SESSION['remote_return'] = $_REQUEST['remote_return'];
    }
    if (argc() > 1 && argv(1) === 'return') {
        if ($_SESSION['remote_return']) {
            goaway($_SESSION['remote_return']);
        }
        goaway(z_root() . '/network');
    }
    $plaintext = true;
    //	if(feature_enabled(local_channel(),'richtext'))
    //		$plaintext = false;
    if (array_key_exists('type', $_REQUEST) && $_REQUEST['type'] === 'html') {
        require_once 'include/html2bbcode.php';
        $_REQUEST['body'] = html2bbcode($_REQUEST['body']);
    }
    $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']);
    if ($_REQUEST['url']) {
        $x = z_fetch_url(z_root() . '/parse_url?f=&url=' . urlencode($_REQUEST['url']));
        if ($x['success']) {
            $_REQUEST['body'] = $_REQUEST['body'] . $x['body'];
        }
    }
    $x = array('is_owner' => true, 'allow_location' => intval(get_pconfig($channel['channel_id'], 'system', 'use_browser_location')) ? '1' : '', 'default_location' => $channel['channel_location'], 'nickname' => $channel['channel_address'], 'lockstate' => $channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid'] ? 'lock' : 'unlock', 'acl' => populate_acl($channel_acl), 'bang' => '', 'visitor' => true, 'profile_uid' => local_channel(), 'title' => $_REQUEST['title'], 'body' => $_REQUEST['body'], 'attachment' => $_REQUEST['attachment'], 'source' => x($_REQUEST, 'source') ? strip_tags($_REQUEST['source']) : '', 'return_path' => 'rpost/return');
    $editor = status_editor($a, $x);
    $o .= replace_macros(get_markup_template('edpost_head.tpl'), array('$title' => t('Edit post'), '$editor' => $editor));
    return $o;
}
Пример #27
0
 function profile_photo_crop_ui_head(&$a, $ph)
 {
     $max_length = get_config('system', 'max_image_length');
     if (!$max_length) {
         $max_length = MAX_IMAGE_LENGTH;
     }
     if ($max_length > 0) {
         $ph->scaleImage($max_length);
     }
     $width = $ph->getWidth();
     $height = $ph->getHeight();
     if ($width < 175 || $height < 175) {
         $ph->scaleImageUp(200);
         $width = $ph->getWidth();
         $height = $ph->getHeight();
     }
     $hash = photo_new_resource();
     $smallest = 0;
     $p = array('aid' => get_account_id(), 'uid' => local_channel(), 'resource_id' => $hash, 'filename' => $filename, 'album' => t('Profile Photos'), 'scale' => 0);
     $r = $ph->save($p);
     if ($r) {
         info(t('Image uploaded successfully.') . EOL);
     } else {
         notice(t('Image upload failed.') . EOL);
     }
     if ($width > 640 || $height > 640) {
         $ph->scaleImage(640);
         $p['scale'] = 1;
         $r = $ph->save($p);
         if ($r === false) {
             notice(sprintf(t('Image size reduction [%s] failed.'), "640") . EOL);
         } else {
             $smallest = 1;
         }
     }
     $a->data['imagecrop'] = $hash;
     $a->data['imagecrop_resolution'] = $smallest;
     $a->data['imagecrop_ext'] = $ph->getExt();
     $a->page['htmlhead'] .= replace_macros(get_markup_template("crophead.tpl"), array());
     return;
 }
Пример #28
0
 /**
  * Set the account id of the class
  *
  * @param integer $account_id   the id of the user/group
  * @param string  $account_type the type of account - 'user'/'group'
  *
  * @return void
  */
 public function set_account($account_id = null, $account_type = null)
 {
     if (!is_null($account_id)) {
         $this->account_id = get_account_id($account_id);
     }
     if (!is_null($account_type)) {
         $this->account_type = $account_type;
     }
 }
Пример #29
0
 function get()
 {
     if (!get_account_id()) {
         notice(t('You must be logged in to use this feature.'));
         return '';
     }
     $o = replace_macros(get_markup_template('channel_import.tpl'), array('$title' => t('Import Channel'), '$desc' => t('Use this form to import an existing channel from a different server/hub. You may retrieve the channel identity from the old server/hub via the network or provide an export file.'), '$label_filename' => t('File to Upload'), '$choice' => t('Or provide the old server/hub details'), '$label_old_address' => t('Your old identity address (xyz@example.com)'), '$label_old_email' => t('Your old login email address'), '$label_old_pass' => t('Your old login password'), '$common' => t('For either option, please choose whether to make this hub your new primary address, or whether your old location should continue this role. You will be able to post from either location, but only one can be marked as the primary location for files, photos, and media.'), '$label_import_primary' => t('Make this hub my primary location'), '$label_import_posts' => t('Import existing posts if possible (experimental - limited by available memory'), '$pleasewait' => t('This process may take several minutes to complete. Please submit the form only once and leave this page open until finished.'), '$email' => '', '$pass' => '', '$submit' => t('Submit')));
     return $o;
 }
Пример #30
0
/**
 * @brief
 *
 * @return string
 */
function identity_selector()
{
    if (local_channel()) {
        $r = q("select channel.*, xchan.* from channel left join xchan on channel.channel_hash = xchan.xchan_hash where channel.channel_account_id = %d and channel_removed = 0 order by channel_name ", intval(get_account_id()));
        if (count($r) > 1) {
            //$account = get_app()->get_account();
            $o = replace_macros(get_markup_template('channel_id_select.tpl'), array('$channels' => $r, '$selected' => local_channel()));
            return $o;
        }
    }
    return '';
}