コード例 #1
0
ファイル: mx_account.php プロジェクト: nsystem1/OS-MusXpand
function mx_mnfbsetup($page, $option, $action)
{
    global $mxuser, $facebook;
    if (!$mxuser->fbdata['page']['admin']) {
        //error_log('User '.$mxuser->id.' ('.$mxuser->getname().') is on fbsetup for someone else\'s page!!');
        return;
        // weird, what is user doing here?
    }
    $pageuser = mx_getaccountfrompage($mxuser->fbdata['page']['id']);
    //$perms=$facebook->api('/me/permissions','GET');
    //error_log('perms='.print_r($perms,true));
    $buttons = array();
    $setupvalues = array();
    /*
    if ($perms['data'][0]['manage_pages']==1) {
    	$fbptitle=_('Add/Remove MusXpand\'s application to/from these pages');
    	$setuppages['fbpages']=array();
    	$pages=$facebook->api('/me/accounts','GET');
    	$setupvalues['fbpages']=array();
    	foreach ($pages['data'] as $page) {
    		$fbpage=new stdClass();
    		foreach($page as $k => $v) {
    			$fbpage->$k=$v;
    		}
    		$fbpage->select='<input type="checkbox" name="selpage[]" value="'.$page['id'].'">';
    		$pic=$facebook->api('/'.$page['id'],'GET');
    		if (array_key_exists('picture',$pic)) $fbpage->pic=$pic['picture'];
    		else $fbpage->pic='';
    		if (mx_getaccountfrompage($page['id'])==$mxuser->id) $fbpage->set=mx_icon('okmark');
    		else $fbpage->set='';
    		$setupvalues['fbpages'][]=$fbpage;
    	}
    	print_r($setuppages,true);
    	$buttons['fbpages']=array(
    		'fbaddpage' => _('Add to Page'),
    		'fbdelpage' => _('Remove from Page'),
    	);
    } else {
    	$fbptitle=sprintf(_('If you want us to add/remove MusXpand in your pages,'
    	.' you need to give us the corresponding Facebook permission ("<b>manage_pages</b>")'
    	.' by clicking the Authorize button below.<br/>'
    	.'Alternatively, you can visit our %s and add it to your pages,'
    	.' although you will also have to set them up too afterwards...'),
    	'<a href="http://www.facebook.com/apps/application.php?id=151278924909082&ref=ts">'._('Facebook App page').'</a>');
    	$buttons['fbpages']=array(
    		'fbauthorize' => _('Authorize'),
    	);
    }
    */
    switch ($action) {
        case 'fbsetup':
            if ($pageuser == $mxuser->id) {
                $msg = _('This page is now set up to this MusXpand account.');
                $title = _('Setup done');
            } else {
                $msg = sprintf(_('This Facebook page could not be associated with your account.<br/>Please %s.'), '<a href="mailto:support@example.com">' . _('contact us') . '</a>');
                $title = _('Error');
            }
            $buttons['thispage'] = array();
            break;
        default:
            $msg = '';
            if ($pageuser == $mxuser->id) {
                $msg .= _('This page is already setup to your MusXpand account.');
                $title = _('Setup done');
                $buttons['thispage'] = array();
            } else {
                if ($pageuser > 0) {
                    $user = $mxuser->getuserinfo($pageuser);
                    $msg .= sprintf(_('This page is already setup to: %s.', $user->artistname));
                    $title = _('Warning');
                } else {
                    $title = _('Confirmation');
                }
                if ($msg) {
                    $msg .= '<br/>';
                }
                $msg .= _('Please confirm you want to link this page to your MusXpand account.');
                $buttons['thispage'] = array('fbsetup' => _('Do it!'));
            }
            break;
    }
    $setupforms = array('thispage' => array(1, 'thispage' => array(-1, _('Linking your MusXpand Account'), '<b>' . $title . '</b>:<br/>' . $msg), 'a' => array(1, 'go', 'hidden')));
    $setuplist = array('mxpages', 0, _('Account Setup'), '', $buttons, $setupforms);
    mx_showlist($setuplist, $setupvalues, 'fbpages', true, false);
}
コード例 #2
0
ファイル: mx_page.php プロジェクト: nsystem1/OS-MusXpand
function mx_preheader()
{
    global $mx_ctxmenu, $mxuser;
    $page = mx_secureword($_GET['p']);
    $option = mx_secureword($_GET['o']);
    $action = mx_secureword($_REQUEST['a']);
    $section = mx_secureword($_REQUEST['k']);
    if ($_REQUEST['signed_request']) {
        //mx_checkfblogin(false);
        $facebook_page = mx_actionurl('main');
        $auth_url = 'https://www.facebook.com/dialog/oauth?client_id=' . FACEBOOK_APP_ID . '&redirect_uri=' . urlencode($facebook_page);
        $signed_request = $_REQUEST['signed_request'];
        list($encoded_sig, $payload) = explode('.', $signed_request, 2);
        $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
        $mxuser->fbdata = $data;
        if ($mxuser->fbdata['page']) {
            if (!is_pagelike() || !$mxuser->fbdata['user_id'] && !$mxuser->id) {
                $page = $_GET['p'] = $_REQUEST['p'] = 'fblikeus';
                $option = $_GET['o'] = $_REQUEST['o'] = '';
                $action = $_POST['a'] = $_REQUEST['a'] = '';
                $section = $_REQUEST['k'] = '';
            } else {
                if (($page == '' || $page == 'main') && ($pageuser = mx_getaccountfrompage($mxuser->fbdata['page']['id']))) {
                    // MX registered page
                    $page = $_GET['p'] = $_REQUEST['p'] = 'artists';
                    $option = $_GET['o'] = $_REQUEST['o'] = 'artprof';
                    $action = $_POST['a'] = $_REQUEST['a'] = $pageuser;
                    $section = $_REQUEST['k'] = '';
                }
            }
        } else {
        }
    }
    if ($page == '' || $page == 'main') {
        $page = 'main';
        $option = '';
        if (!$mxuser->id) {
            //$page='account';
            //$option='signin';
        } else {
            switch ($mxuser->status) {
                case MXACCTUNCONFIRMED:
                    $page = 'account';
                    $option = 'confirm';
                    break;
                case MXACCTEMAILCONFIRMED:
                    $page = 'account';
                    $option = 'setup';
                    break;
                default:
                    $page = 'main';
            }
        }
        $_GET['p'] = $_REQUEST['p'] = $page;
        $_GET['o'] = $_REQUEST['o'] = $option;
    }
    switch (mx_checkpage($page, $option)) {
        case MXUNKNOWNPAGE:
        case MXRESTRICTEDPAGE:
        case MXMAINPAGE:
            header('Location: ' . mx_pageurl('main'));
            break;
        case MXNOACCESS:
            header('Location: ' . mx_pageurl('noaccess'));
            break;
        case MXREDIRECT:
            $other = preg_replace('%[&]?(a|p|o|k|fbp|canvas)=[^&]*%', '', $_SERVER['QUERY_STRING']);
            $other = preg_replace('%^[&]+%', '', $other);
            header('Location: ' . mx_loginredirecturl($page, $option, $action, $section, $other));
            break;
    }
    if ($page != '') {
        $checkfunction = 'mx_ck' . $page;
        if (function_exists($checkfunction)) {
            $checkfunction($page, $option, $action);
        }
    }
    if ($option != '') {
        $checkfunction = 'mx_ck' . $option;
        if (function_exists($checkfunction)) {
            $checkfunction($page, $option, $action);
        }
    }
}