function fetch()
 {
     if (isset($_GET['fType']) && $_GET['fType'] != '') {
         $filterType = $_GET['fType'];
     } else {
         $filterType = 'all';
     }
     //$code = '<link rel="stylesheet" href="'.URL_CALLBACK.'?p=cache&type=css&cf=hdFacebook_1235766581.css" type="text/css" charset="utf_8" />';
     //$code.='<style type="text/css">'.htmlentities(file_get_contents(PATH_FACEBOOK_STYLES.'/default.css', true)).'</style>';
     $code = $this->page->streamStyles();
     require_once PATH_CORE . '/classes/home.class.php';
     $homeObj = new home($this->db);
     $code .= '<div id="pageBody">';
     $code .= '<div id="pageContent">';
     //$code .= '<script type="text/javascript">'.htmlentities(file_get_contents(PATH_SCRIPTS.'/newsroom.js')).'</script>';
     //$code .= '<h1>Abe\'s CLIMATE CHANGE APP!*!*!*!*!</h1>';
     //$code .= '<a class="btn_1" href="'.SITE_URL.'">Visit the '.SITE_TITLE.' Application</a>';
     //$code .= '<br /><br /><hr />';
     $code .= '<div id="col_left"><!-- begin left side -->';
     $code .= '<div id="featurePanel" class="clearfix">';
     $code .= $this->page->buildPanelBar('Featured Stories', '<a href="?p=stories&o=sponsor">More from ' . SITE_SPONSOR . ' editors</a>');
     $code .= $homeObj->fetchFeature();
     $code .= '</div><!--end "featurePanel"--><div class="panel_1">';
     require_once PATH_FACEBOOK . '/classes/actionFeed.class.php';
     $actionFeed = new actionFeed(&$this->db, true);
     require_once PATH_FACEBOOK . '/classes/actionTeam.class.php';
     $actionTeam = new actionTeam(&$this->page);
     //$code .= $actionFeed->fetchFeed('all', 1, $this->siteUserId);
     $feed = $actionFeed->fetchFeed($filterType, 1, $this->siteUserId);
     $code .= preg_replace_callback('/<div class="subFilter">.*?<\\/div>/s', array($this, 'changeFilterString'), $feed);
     $code .= '</div><!-- end panel_1 -->';
     $code .= '</div><!-- end col_left -->';
     $code .= '<div id="col_right">';
     // hack to give fbId to action team class session
     $actionTeam->setAppTabMode($this->fbUserPageId);
     $code .= $this->fetchPromo();
     $code .= $actionTeam->fetchSidePanel('appTab', 3);
     $code .= '</div><!-- end col_right -->';
     $code .= '</div><!-- end pageContent -->';
     $code .= '</div><!-- end pageBody -->';
     // Hack this to the app tab
     $code = preg_replace('/on[cC]lick="[^"]+"/', '', $code);
     // $code = preg_replace('/<fb:profile-pic[^>]+>/', '', $code);
     $code = preg_replace('/href="\\/?index.php([^"]+)/', 'href="' . URL_CANVAS . '/$1&referfbid=' . $this->fbUserPageId, $code);
     $code = preg_replace('/href="\\?p=([^"]+)/', 'href="' . URL_CANVAS . '/?p=$1&referfbid=' . $this->fbUserPageId, $code);
     $code = preg_replace_callback('/<div class="pages">.*?<\\/div>/s', array($this, 'changeFilterString'), $code);
     return $code;
 }
 function updateProfileBox($fbId = 0, $refHandle = '')
 {
     require_once PATH_FACEBOOK . '/classes/actionTeam.class.php';
     // hack: because someone didnt use the correct interface
     $dummyApp = new app(NULL, true);
     require_once PATH_FACEBOOK . '/classes/pages.class.php';
     $dummyPage = new pages($dummyApp, 0, true);
     $teamObj = new actionTeam($dummyPage);
     if ($refHandle == 'default') {
         $passFbid = 0;
     } else {
         $passFbid = $fbId;
     }
     $markup = $teamObj->fetchProfileSummaryForProfileBox($passFbid, URL_CANVAS . '?&referfbid=' . $fbId);
     //if ($fbId==693311688) $this->db->log('log entry for jeff'.$markup);
     $fbml = '<fb:fbml><fb:narrow>' . $markup . '</fb:narrow></fb:fbml>';
     try {
         $errs = $this->facebook->api_client->profile_setFBML(NULL, $fbId, $fbml, '', '', $fbml);
     } catch (Exception $e) {
         $this->db->log($e, PATH_LOG_FB);
         $this->db->log($errs, PATH_LOG_FB);
     }
     return $errs;
 }
    function fetch()
    {
        if ($this->memberid === false) {
            $this->page->go404('Member not found');
            exit;
        }
        require_once PATH_FACEBOOK . '/classes/actionTeam.class.php';
        $actionTeam = new actionTeam(&$this->page);
        if ($_GET['message']) {
            $inside .= $this->page->buildMessage('success', "Submission successful", urldecode($_GET['message']));
        }
        $this->updateUserCachedPoints($this->memberid, $this->isProfileOwner || $this->session->u->isAdmin || $this->session->u->isModerator);
        // update immediately under any of these circumstances
        $inside .= ' <div id="col_left">
					<script>
						<!-- 
						updateProfileTabName(' . $this->session->fbId . ',' . $this->memberid . '); 
						//-->
					</script>
			          <!-- begin left side -->


					<div id="myProfile">
					    	
						<!-- profileSummary goes here -->
					    ' . $actionTeam->fetchProfileSummaryPanelForProfilePage($this->memberid, $this->isProfileOwner, true, false) . '    
					</div><!-- end "myProfile"-->
					
					<!--  profileBio here -->
					' . self::fetchBio($this->isProfileOwner, $this->memberid) . '
					<!--  pending challenges here -->
					' . (ENABLE_ACTION_CHALLENGES ? $this->fetchPendingChallenges() : '') . '
					<!--  orders summary goes here -->					
					' . $this->fetchRedeemLinks() . '
					<!--  orders summary goes here -->					
					' . $this->fetchOrderList() . '
					

					<!--  admin -challenge submit div goes here -->
					' . (isset($_GET['viewSubmitted']) ? $this->fetchChallengesSubmittedFeedBox() : '') . '
					
					
					<!--  feed div goes here -->
					' . (isset($_GET['viewHistory']) ? $this->fetchPlainHistoryBox() : $this->fetchFeedBox()) . '

					
					
					</div><!--end "col_left"-->
					
					<div id="col_right">';
        if ($this->session->isAdmin && isset($_GET['showAdminPanel'])) {
            $inside .= $this->fetchAdminPanel();
            // not implemented now, but potentially useful
        }
        // Blog posts by this user (if any)
        $q = $this->db->queryC("SELECT UserBlogs.blogid,UserInfo.fbId,UserInfo.userid FROM UserBlogs LEFT JOIN UserInfo ON UserInfo.userid=UserBlogs.userid WHERE UserInfo.fbId=" . $this->memberid . " AND UserBlogs.status='published';");
        if ($q !== false) {
            $data = $this->db->readQ($q);
            $this->templateObj->registerTemplates(MODULE_ACTIVE, 'read');
            $this->templateObj->db->result = $this->templateObj->db->query("SELECT * FROM Content WHERE isBlogEntry=1 AND userid=" . $data->userid . " ORDER BY date DESC LIMIT 10 ");
            $this->templateObj->db->setTemplateCallback('mbrLink', array($this->templateObj, 'memberLink'), 'userid');
            $inside .= '<div class="panel_1"><div class="panelBar clearfix"><h2>Blog posts by <a href="?p=profile&memberid=' . $this->memberid . '" onclick="return switchPage(\'profile\', \'\', ' . $this->memberid . ';"><fb:name ifcantsee="Anonymous" uid="' . $this->memberid . '" capitalize="true" firstnameonly="false" linked="false" /></a></h2></div><!-- end panelbar --><br />';
            $inside .= $this->templateObj->mergeTemplate($this->templateObj->templates['otherStoryList'], $this->templateObj->templates['otherStoryItem']);
            $inside .= '</div><!-- end panel_1 -->';
        }
        if (!$this->isProfileOwner) {
            $adjPage = 'otherProfile';
        } else {
            $adjPage = 'myProfile';
        }
        $inside .= $actionTeam->fetchSidePanel($adjPage);
        $inside .= '</div><!--end "col_right"-->';
        /*
        		$profileSummary = $actionTeam->fetchProfileSummary($this->memberid, $this->isProfileOwner, true, false, true);
        		$inside .= $profileSummary; 
        		
        		$inside .= self::fetchBio($this->isProfileOwner, $this->memberid);
        		//$inside.='<p><strong>Challenges I\'ve Completed</strong><p>';
        		//$inside.= $this->fetchChallengesCompleted(isset($_GET['currentPage']) ? $_GET['currentPage'] : 1);
        		//$inside.='<br />';
        		//$inside.='<p><strong>Stories I\'ve posted</strong><p>';
        		//$inside.=$this->fetchPostedStories();
        $inside .= $this->fetchPendingChallenges();
        		$inside .= $this->fetchOrderList();
        		$inside .= $this->fetchFeedBox();
        		$inside.='<br />';
        */
        if ($this->page->isAjax) {
            return $inside;
        }
        // build the profile page
        $code = $this->page->constructPage('profile', $inside);
        return $code;
    }
 function fetchFeedElements($pt = 'story', $selId = 0, $referfbid = 0)
 {
     switch ($pt) {
         case 'story':
             $postArray = array();
             require_once PATH_CORE . '/classes/newswire.class.php';
             $nwObj = new newswire($this->db);
             $feedElements = $nwObj->fetchPostedStoryInfo($selId);
             break;
         case 'challenge':
             require_once PATH_CORE . '/classes/challenges.class.php';
             $challengesObj = new challenges($this->db);
             $feedElements = $challengesObj->fetchPostedChallengeInfo($selId);
             break;
         case 'reward':
             require_once PATH_CORE . '/classes/prizes.class.php';
             $rewardsObj = new rewards($this->db);
             $feedElements = $rewardsObj->fetchPostedRewardInfo($selId);
             break;
         case 'invite':
             $feedElements = array();
             $feedElements['title'] = 'Check out ' . SITE_TITLE;
             require_once PATH_FACEBOOK . '/classes/actionTeam.class.php';
             $teamObj = new actionTeam($this->db);
             if ($referfbid == 0) {
                 $feedElements['story'] = $teamObj->fetchProfileSummaryForProfileBox(0);
             } else {
                 $feedElements['story'] = $teamObj->fetchProfileSummaryForProfileBox(0, URL_CANVAS . '/?referfbid=' . $referfbid);
             }
             //$feedElements['story']=$this->fetchInviteText();
             $feedElements['image'] = '';
             $feedElements['storyLink'] = URL_CANVAS;
             break;
     }
     $feedElements['pubType'] = $pt;
     return $feedElements;
 }
 function fetchTeamPrizes()
 {
     //require_once(PATH_CORE. '/classes/prizes.class.php');
     //$rewards = new rewards($this->db);
     //$code .= $rewards->fetchRewardsPage('pointCost', 1);
     require_once PATH_FACEBOOK . '/classes/actionTeam.class.php';
     $at = new actionTeam(&$this->page);
     $code .= $at->fetchRewardsRandom();
     return $code;
 }