Permalink
Browse files

Added global StartupAPI class with a bunch of static functions

Replaced navbox include with StartupAPI::power_strip call
Added StartupAPI::head() function to be called by pages within <head> tag
  • Loading branch information...
sergeychernyshev committed Sep 12, 2012
1 parent 89e2f3e commit eaf5a3b469554561a584dc643416effe62cf2de2
View
@@ -2,7 +2,7 @@
/*
* Invitation class
*/
require_once(dirname(__FILE__).'/config.php');
require_once(dirname(__FILE__).'/global.php');
require_once(dirname(__FILE__).'/User.php');
class Invitation
View
@@ -0,0 +1,114 @@
<?php
require_once(dirname(__FILE__).'/User.php');
/**
* StartupAPI class contains some global static functions and entry points for API
*/
class StartupAPI {
// just a proxy to static methods in User class
static function getUser() {
return User::get();
}
// just a proxy to static methods in User class
static function requireLogin() {
return User::requireLogin();
}
/**
* This finction should be called within the head of HTML to insert
* styles, scripts and potentially meta-tags into the head of the pages on the site
*/
static function head() {
?><link rel="style/css" href="<?php echo UserConfig::$USERSROOTURL ?>/startupapi.css"><?php
}
/**
* This finction renders the power strip (navigation bar at the top right corner)
*/
static function power_strip()
{
$current_user = User::get();
$current_account = null;
$accounts = array();
if (UserConfig::$useAccounts && !is_null($current_user)) {
$accounts = Account::getUserAccounts($current_user);
$current_account = Account::getCurrentAccount($current_user);
}
?>
<div id="userbase-navbox">
<?php if (!is_null($current_user))
{
if ($current_user->isImpersonated()) {
?><b id="userbase-navbox-impersonating"><a href="<?php echo UserConfig::$USERSROOTURL ?>/admin/stopimpersonation.php" title="Impersonated by <?php echo UserTools::escape($current_user->getImpersonator()->getName())?>">Stop Impersonation</a></b> | <?php
}
if ($current_user->isAdmin()) {
?><b id="userbase-navbox-admin"><a href="<?php echo UserConfig::$USERSROOTURL ?>/admin/">Admin</a></b> | <?php
}
if (count($accounts) > 1)
{
$destination = "'+encodeURIComponent(document.location)+'";
if (!is_null(UserConfig::$accountSwitchDestination)) {
$destination = UserConfig::$accountSwitchDestination;
}
?><select id="userbase-navbox-account-picker" name="account" onchange="document.location.href='<?php echo UserConfig::$USERSROOTURL ?>/change_account.php?return=<?php echo $destination ?>&account='+this.value"><?php
foreach ($accounts as $account)
{
?><option value="<?php echo $account->getID()?>"<?php if ($current_account->isTheSameAs($account)) { echo ' selected'; } ?>><?php echo UserTools::escape($account->getName())?></option><?php
}
?></select>
<?php
}
if (!is_null(UserConfig::$onLoginStripLinks)) {
$links = call_user_func_array(
UserConfig::$onLoginStripLinks,
array($current_user, $current_account)
);
foreach ($links as $link) {
?><span<?php
if (array_key_exists('id', $link)) {
?> id="<?php echo $link['id'] ?>"<?php
}
?>><a href="<?php echo $link['url'] ?>"<?php
if (array_key_exists('title', $link)) {
?> title="<?php echo $link['title'] ?>"<?php
}
if (array_key_exists('target', $link)) {
?> target="<?php echo $link['target'] ?>"<?php
}
?>><?php echo $link['text'] ?></a></span> | <?php
}
}
?>
<span id="userbase-navbox-username"><a href="<?php echo UserConfig::$USERSROOTURL ?>/edit.php" title="<?php echo UserTools::escape($current_user->getName())?>'s user information"><?php echo UserTools::escape($current_user->getName()) ?></a></span> |
<span id="userbase-navbox-logout"><a href="<?php echo UserConfig::$USERSROOTURL ?>/logout.php">logout</a></span>
<?php
}
else
{
?>
<span id="userbase-navbox-signup"><a href="<?php echo UserConfig::$USERSROOTURL ?>/register.php">Sign Up Now!</a></span> |
<span id="userbase-navbox-login"><a href="<?php echo UserConfig::$USERSROOTURL ?>/login.php">log in</a></span>
<?php
}
?>
</div>
<?php
}
/**
* This function should be called after all configuration is loaded to initialize the system.
*/
static function _init() {
//currently empty
}
}
View
@@ -2,7 +2,7 @@
/*
* User class
*/
require_once(dirname(__FILE__).'/config.php');
require_once(dirname(__FILE__).'/global.php');
require_once(dirname(__FILE__).'/Account.php');
require_once(dirname(__FILE__).'/CookieStorage.php');
require_once(dirname(__FILE__).'/CampaignTracker.php');
View
@@ -1,5 +1,5 @@
<?php
require_once(dirname(dirname(__FILE__)).'/config.php');
require_once(dirname(dirname(__FILE__)).'/global.php');
require_once(dirname(dirname(__FILE__)).'/User.php');
$current_user = User::require_login(false);
View
@@ -1,6 +1,6 @@
<?php
// This script
require_once(dirname(__FILE__).'/config.php');
require_once(dirname(__FILE__).'/global.php');
function aggregatePoints() {
$db = UserConfig::getDB();
View
@@ -1,5 +1,5 @@
<?php
require_once(dirname(__FILE__).'/config.php');
require_once(dirname(__FILE__).'/global.php');
require_once(dirname(__FILE__).'/User.php');
require_once(dirname(__FILE__).'/Account.php');
View
@@ -6,7 +6,7 @@
* Note: this script should be versioned in your code repository so it always reflects current code's
* requirements for the database structure.
*/
require_once(dirname(__FILE__).'/config.php');
require_once(dirname(__FILE__).'/global.php');
require_once(dirname(__FILE__).'/dbupgrade/lib.php');
$versions = array();
View
@@ -1,5 +1,5 @@
<?php
require_once(dirname(__FILE__).'/config.php');
require_once(dirname(__FILE__).'/global.php');
require_once(dirname(__FILE__).'/User.php');
@@ -3,5 +3,9 @@
mb_internal_encoding('UTF-8');
header('Content-type: text/html; charset=utf-8');
require_once(dirname(__FILE__).'/StartupAPI.php');
require_once(dirname(__FILE__).'/default_config.php');
require_once(dirname(dirname(__FILE__)).'/users_config.php');
StartupAPI::_init();
View
@@ -3,6 +3,7 @@
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Users</title>
<?php StartupAPI::head() ?>
<style>
#userbase_body {
color: #666666;
@@ -90,7 +91,7 @@
<body id="userbase_body">
<div id="userbase_header">
<div id="userbase_navbox">
<?php include(dirname(__FILE__).'/navbox.php') ?>
<?php StartupAPI::power_strip() ?>
</div>
<a href="<?php echo UserConfig::$SITEROOTURL ?>"><img src="<?php echo UserConfig::$USERSROOTURL ?>/images/header_icon.png" id="userbase_header_icon" title="Powered by Startup API"/></a>
</div>
View
@@ -1,5 +1,5 @@
<?php
require_once(dirname(__FILE__).'/config.php');
require_once(dirname(__FILE__).'/global.php');
require_once(dirname(__FILE__).'/User.php');
View
@@ -1,5 +1,5 @@
<?php
require_once(dirname(__FILE__).'/config.php');
require_once(dirname(__FILE__).'/global.php');
require_once(dirname(__FILE__).'/User.php');
View
@@ -1,5 +1,5 @@
<?php
require_once(dirname(__FILE__).'/config.php');
require_once(dirname(__FILE__).'/global.php');
require_once(dirname(__FILE__).'/User.php');
/**
View
@@ -1,5 +1,5 @@
<?php
require_once(dirname(__FILE__).'/config.php');
require_once(dirname(__FILE__).'/global.php');
require_once(dirname(__FILE__).'/User.php');
View
@@ -2,7 +2,7 @@
/**
* @package StartupAPI
*/
require_once(dirname(__FILE__).'/config.php');
require_once(dirname(__FILE__).'/global.php');
interface IUserBaseModule
{
View
@@ -1,5 +1,5 @@
<?php
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(dirname(dirname(__FILE__))).'/global.php');
require_once(dirname(dirname(dirname(__FILE__))).'/User.php');
@@ -17,7 +17,7 @@
require_once dirname(__FILE__)."/php-sdk/src/base_facebook.php";
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(dirname(dirname(__FILE__))).'/global.php');
/**
* Extends the BaseFacebook class with the intent of using
@@ -1,5 +1,5 @@
<?php
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(dirname(dirname(__FILE__))).'/global.php');
require_once(dirname(dirname(dirname(__FILE__))).'/User.php');
@@ -1,5 +1,5 @@
<?php
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(dirname(dirname(__FILE__))).'/global.php');
require_once(dirname(dirname(dirname(__FILE__))).'/User.php');
@@ -1,5 +1,5 @@
<?php
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(dirname(dirname(__FILE__))).'/global.php');
require_once(dirname(dirname(dirname(__FILE__))).'/User.php');
View
@@ -1,82 +1 @@
<?php
function _USERBASE_render_navbox()
{
$current_user = User::get();
$current_account = null;
$accounts = array();
if (UserConfig::$useAccounts && !is_null($current_user)) {
$accounts = Account::getUserAccounts($current_user);
$current_account = Account::getCurrentAccount($current_user);
}
?>
<div id="userbase-navbox">
<?php if (!is_null($current_user))
{
if ($current_user->isImpersonated()) {
?><b id="userbase-navbox-impersonating"><a href="<?php echo UserConfig::$USERSROOTURL ?>/admin/stopimpersonation.php" title="Impersonated by <?php echo UserTools::escape($current_user->getImpersonator()->getName())?>">Stop Impersonation</a></b> | <?php
}
if ($current_user->isAdmin()) {
?><b id="userbase-navbox-admin"><a href="<?php echo UserConfig::$USERSROOTURL ?>/admin/">Admin</a></b> | <?php
}
if (count($accounts) > 1)
{
$destination = "'+encodeURIComponent(document.location)+'";
if (!is_null(UserConfig::$accountSwitchDestination)) {
$destination = UserConfig::$accountSwitchDestination;
}
?><select id="userbase-navbox-account-picker" name="account" onchange="document.location.href='<?php echo UserConfig::$USERSROOTURL ?>/change_account.php?return=<?php echo $destination ?>&account='+this.value"><?php
foreach ($accounts as $account)
{
?><option value="<?php echo $account->getID()?>"<?php if ($current_account->isTheSameAs($account)) { echo ' selected'; } ?>><?php echo UserTools::escape($account->getName())?></option><?php
}
?></select>
<?php
}
if (!is_null(UserConfig::$onLoginStripLinks)) {
$links = call_user_func_array(
UserConfig::$onLoginStripLinks,
array($current_user, $current_account)
);
foreach ($links as $link) {
?><span<?php
if (array_key_exists('id', $link)) {
?> id="<?php echo $link['id'] ?>"<?php
}
?>><a href="<?php echo $link['url'] ?>"<?php
if (array_key_exists('title', $link)) {
?> title="<?php echo $link['title'] ?>"<?php
}
if (array_key_exists('target', $link)) {
?> target="<?php echo $link['target'] ?>"<?php
}
?>><?php echo $link['text'] ?></a></span> | <?php
}
}
?>
<span id="userbase-navbox-username"><a href="<?php echo UserConfig::$USERSROOTURL ?>/edit.php" title="<?php echo UserTools::escape($current_user->getName())?>'s user information"><?php echo UserTools::escape($current_user->getName()) ?></a></span> |
<span id="userbase-navbox-logout"><a href="<?php echo UserConfig::$USERSROOTURL ?>/logout.php">logout</a></span>
<?php
}
else
{
?>
<span id="userbase-navbox-signup"><a href="<?php echo UserConfig::$USERSROOTURL ?>/register.php">Sign Up Now!</a></span> |
<span id="userbase-navbox-login"><a href="<?php echo UserConfig::$USERSROOTURL ?>/login.php">log in</a></span>
<?php
}
?>
</div>
<?php
}
_USERBASE_render_navbox();
<?php StartupAPI::power_strip();
View
@@ -1,5 +1,5 @@
<?php
require_once(dirname(__FILE__).'/config.php');
require_once(dirname(__FILE__).'/global.php');
require_once(dirname(__FILE__).'/User.php');
$current_user = User::get();
View
@@ -1,5 +1,5 @@
<?php
require_once(dirname(__FILE__).'/config.php');
require_once(dirname(__FILE__).'/global.php');
require_once(dirname(__FILE__).'/User.php');
require_once(dirname(__FILE__).'/Invitation.php');
View
@@ -17,7 +17,7 @@
<html>
<head><title>Sample page</title></head>
<body>
<div style="float: right"><?php include(dirname(__FILE__).'/users/navbox.php'); ?></div>
<div style="float: right"><?php StartupAPI::power_strip() ?></div>
<?php
if (!is_null($user)) {
View
No changes.
View
@@ -4,7 +4,7 @@
*
* This is a main file to be included into pap pages
*/
require_once(dirname(__FILE__).'/config.php');
require_once(dirname(__FILE__).'/global.php');
require_once(dirname(__FILE__).'/User.php');
require_once(dirname(__FILE__).'/Plan.php');

0 comments on commit eaf5a3b

Please sign in to comment.