function fnAddFavoriteTeam( $user ) { if ( isset( $_COOKIE['sports_sid'] ) ) { $sport_id = $_COOKIE['sports_sid']; $team_id = $_COOKIE['sports_tid']; $thought = $_COOKIE['thought']; if( !$team_id ) { $team_id = 0; } if( $sport_id != 0 ) { $s = new SportsTeams(); $s->addFavorite( $user->getID(), $sport_id, $team_id ); if( $thought ) { $b = new UserStatus(); $m = $b->addStatus( $sport_id, $team_id, $thought ); } } } return true; }
/** * Show the special page * * @param $par Mixed: parameter passed to the special page or null */ public function execute( $par ) { global $wgOut, $wgRequest, $wgScriptPath, $wgUser; if( !$wgUser->isLoggedIn() ) { $wgOut->setPageTitle( wfMsg( 'user-profile-sports-notloggedintitle' ) ); $wgOut->addHTML( wfMsg( 'user-profile-sports-notloggedintitle' ) ); return; } // If the database is in read-only mode, bail out if( wfReadOnly() ) { $wgOut->readOnlyPage(); return true; } $sports = $this->getSports(); // Error message when there are no sports in the database if ( empty( $sports ) ) { $wgOut->setPageTitle( wfMsg( 'sportsteams-error-no-sports-title' ) ); $wgOut->addWikiMsg( 'sportsteams-error-no-sports-message' ); return; } // Set the page title $wgOut->setPageTitle( wfMsg( 'user-profile-sports-title' ) ); // Add CSS and JS $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/SocialProfile/UserProfile/UserProfile.css' ); // This JS file was originally in its own directory (it was and is used // only by this special page and the LoginReg extension)...how silly. $wgOut->addScriptFile( $wgScriptPath . '/extensions/SportsTeams/DoubleCombo.js' ); // This JS file originally didn't even exist $wgOut->addScriptFile( $wgScriptPath . '/extensions/SportsTeams/UpdateFavoriteTeams.js' ); // This is annoying so I took it out for now. //$output = '<h1>' . wfMsg( 'user-profile-sports-title' ) . '</h1>'; // Build the top navigation tabs // @todo CHECKME: there should be a UserProfile method for building all // this, I think $output = '<div class="profile-tab-bar">'; $output .= '<div class="profile-tab">'; $output .= '<a href="' . SpecialPage::getTitleFor( 'UpdateProfile', 'basic' )->escapeFullURL() . '">' . wfMsg( 'user-profile-section-personal' ) . '</a>'; $output .= '</div>'; $output .= '<div class="profile-tab-on">'; $output .= wfMsg( 'user-profile-section-sportsteams' ); $output .= '</div>'; $output .= '<div class="profile-tab">'; $output .= '<a href="' . SpecialPage::getTitleFor( 'UpdateProfile', 'custom' )->escapeFullURL() . '">' . /*wfMsg( 'user-profile-section-sportstidbits' )*/wfMsg( 'custom-info-title' ) . '</a>'; $output .= '</div>'; $output .= '<div class="profile-tab">'; $output .= '<a href="' . SpecialPage::getTitleFor( 'UpdateProfile', 'personal' )->escapeFullURL() . '">' . wfMsg( 'user-profile-section-interests' ) . '</a>'; $output .= '</div>'; $output .= '<div class="profile-tab">'; $output .= '<a href="' . SpecialPage::getTitleFor( 'UploadAvatar' )->escapeFullURL() . '">' . wfMsg( 'user-profile-section-picture' ) . '</a>'; $output .= '</div>'; $output .= '<div class="profile-tab">'; $output .= '<a href="' . SpecialPage::getTitleFor( 'UpdateProfile', 'preferences' )->escapeFullURL() . '">' . wfMsg( 'user-profile-section-preferences' ) . '</a>'; $output .= '</div>'; $output .= '<div class="cleared"></div>'; $output .= '</div>'; $output .= '<div class="profile-info">'; // If the request was POSTed, add/delete teams accordingly if( $wgRequest->wasPosted() ) { if( $wgRequest->getVal( 'action' ) == 'delete' ) { SportsTeams::removeFavorite( $wgUser->getId(), $wgRequest->getVal( 's_id' ), $wgRequest->getVal( 't_id' ) ); SportsTeams::clearUserCache( $wgUser->getId() ); $wgOut->addHTML( '<br /><br /><span class="profile-on">' . wfMsg( 'user-profile-sports-teamremoved' ) . '</span><br /><br />' ); } if( $wgRequest->getVal( 'favorites' ) ) { // Clear user cache SportsTeams::clearUserCache( $wgUser->getId() ); $dbw = wfGetDB( DB_MASTER ); // Reset old favorites $res = $dbw->delete( 'sport_favorite', array( 'sf_user_id' => $wgUser->getId() ), __METHOD__ ); $items = explode( '|', $wgRequest->getVal( 'favorites' ) ); foreach( $items as $favorite ) { if( $favorite ) { $atts = explode( ',', $favorite ); $sport_id = $atts[0]; $team_id = $atts[1]; if( !$team_id ) { $team_id = 0; } $s = new SportsTeams(); $s->addFavorite( $wgUser->getId(), $sport_id, $team_id ); } } $wgOut->addHTML( '<br /><br /><span class="profile-on">' . wfMsg( 'user-profile-sports-teamsaved' ) . '</span><br /><br />' ); } } $favorites = $this->getFavorites(); foreach( $favorites as $favorite ) { $output .= $this->getSportsDropdown( $favorite['sport_id'], $favorite['team_id'] ); } $output .= '<div>'; if( count( $favorites ) > 0 ) { $output .= '<div style="display: block" id="add_more"></div>'; } for( $x = 0; $x <= ( 20 - count( $favorites ) ); $x++ ) { $output .= $this->getSportsDropdown(); } $output .= '<form action="" name="sports" method="post"> <input type="hidden" value="" name="favorites" /> <input type="hidden" value="save" name="action" />'; if( count( $favorites ) > 0 ) { $output .= '<input type="button" class="profile-update-button" onclick="UpdateFavoriteTeams.showNext()" value="' . wfMsg( 'user-profile-sports-addmore' ) . '" />'; } $output .= '<input type="button" class="profile-update-button" value="' . wfMsg( 'user-profile-update-button' ) . '" onclick="UpdateFavoriteTeams.saveTeams()" id="update-favorite-teams-save-button" /> </form> <form action="" name="sports_remove" method="post"> <input type="hidden" value="delete" name="action" /> <input type="hidden" value="" name="s_id" /> <input type="hidden" value="" name="t_id" /> </form> <script> UpdateFavoriteTeams.fav_count = ' . ( ( count( $favorites ) ) ? count( $favorites ) : 1 ) . '; </script> </div> </div>'; $wgOut->addHTML( $output ); }
/** * Show the special page * * @param $par Mixed: parameter passed to the special page or null */ public function execute( $par ) { global $wgOut, $wgRequest, $wgScriptPath, $wgUser; $output = ''; /** * Get query string variables */ $sport_id = $wgRequest->getVal( 'sport_id' ); $team_id = $wgRequest->getVal( 'team_id' ); // Add CSS if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) { $wgOut->addModuleStyles( 'ext.sportsTeams' ); } else { $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/SportsTeams/SportsTeams.css' ); } /** * Error message for URL with no team and sport specified */ if( !$team_id && !$sport_id ) { $wgOut->setPageTitle( wfMsg( 'sportsteams-network-woops-title' ) ); $out .= '<div class="relationship-request-message">' . wfMsg( 'sportsteams-network-woops-text' ) . '</div>'; $out .= '<div class="relationship-request-buttons">'; $out .= '<input type="button" class="site-button" value="' . wfMsg( 'sportsteams-network-main-page' ) . "\" onclick=\"window.location='" . Title::newMainPage()->escapeFullURL() . "'\"/>"; if ( $wgUser->isLoggedIn() ) { $out .= ' <input type="button" class="site-button" value="' . wfMsg( 'sportsteams-network-your-profile' ) . "\" onclick=\"window.location='" . Title::makeTitle( NS_USER, $wgUser->getName() )->escapeFullURL() . "'\"/>"; } $out .= '</div>'; $wgOut->addHTML( $out ); return false; } // If the database is in read-only mode, bail out if( wfReadOnly() ) { $wgOut->readOnlyPage(); return true; } if( $team_id ) { $team = SportsTeams::getTeam( $team_id ); $name = $team['name']; } else { $sport = SportsTeams::getSport( $sport_id ); $name = $sport['name']; } if( $wgRequest->wasPosted() ) { $s = new SportsTeams(); $s->addFavorite( $wgUser->getID(), $wgRequest->getVal( 's_id' ), $wgRequest->getVal( 't_id' ) ); $view_fans_title = SpecialPage::getTitleFor( 'ViewFans' ); $invite_title = SpecialPage::getTitleFor( 'InviteContacts' ); $wgOut->setPageTitle( wfMsg( 'sportsteams-network-now-member', $name ) ); $output .= '<div class="give-gift-message"> <input type="button" class="site-button" value="' . wfMsg( 'sportsteams-network-invite-more', $name ) . " \" onclick=\"window.location='{$invite_title->getFullURL()}'\"/> <input type=\"button\" class=\"site-button\" value=\"" . wfMsg( 'sportsteams-network-find-other', $name ) . " \" onclick=\"window.location='" . $view_fans_title->getFullURL( "sport_id={$sport_id}&team_id={$team_id}" ) . "'\"/> </div>"; } else { /** * Error message if you are already a fan */ if( SportsTeams::isFan( $wgUser->getID(), $sport_id, $team_id ) == true ) { $wgOut->setPageTitle( wfMsg( 'sportsteams-network-already-member', $name ) ); $out .= '<div class="relationship-request-message">' . wfMsg( 'sportsteams-network-no-need-join' ) . '</div>'; $out .= "<div class=\"relationship-request-buttons\">"; $out .= "<input type=\"button\" class=\"site-button\" value=\"" . wfMsg( 'sportsteams-network-main-page' ) . "\" onclick=\"window.location='" . Title::newMainPage()->escapeFullURL() . "'\"/>"; if ( $wgUser->isLoggedIn() ) { $out .= ' <input type="button" class="site-button" value="' . wfMsg( 'sportsteams-network-your-profile' ) . "\" onclick=\"window.location='" . Title::makeTitle( NS_USER, $wgUser->getName() )->escapeFullURL() . "'\"/>"; } $out .= '</div>'; $wgOut->addHTML( $out ); return false; } $wgOut->setPageTitle( wfMsg( 'sportsteams-network_join_named_network', $name ) ); $output .= '<form action="" method="post" enctype="multipart/form-data" name="form1"> <div class="give-gift-message" style="margin:0px 0px 0px 0px;">' . wfMsg( 'sportsteams-network-join-are-you-sure', $name ) . "</div> <div class=\"cleared\"></div> <div class=\"give-gift-buttons\"> <input type=\"hidden\" name=\"s_id\" value=\"{$sport_id}\" /> <input type=\"hidden\" name=\"t_id\" value=\"{$team_id}\" /> <input type=\"button\" class=\"site-button\" value=\"" . wfMsg( 'sportsteams-network-join-network' ) . "\" size=\"20\" onclick=\"document.form1.submit()\" /> <input type=\"button\" class=\"site-button\" value=\"" . wfMsg( 'cancel' ) . "\" size=\"20\" onclick=\"history.go(-1)\" /> </div> </form>"; } $wgOut->addHTML( $output ); }