public static function bootstrap(array $config) { if (!isset($config['mode'])) { $config['mode'] = Config::get('deploy')->mode; } Debug::init($config['debug']); self::$_MODE = $config['mode']; self::setErrorReporting($config['mode'] !== self::MODE_PRODUCTION); Cache::init(); Debug::getInstance()->addCheckpoint('bootstrapped'); }
/** * Fire the specified action, calling all the registered handlers for that action. **/ public static function triggerAction($action, $data = array()) { Debug::getInstance()->addCheckpoint($action); if (isset(self::$handlers[$action])) { foreach (self::$handlers[$action] as $priority => $handlers) { foreach ($handlers as $handler) { if (is_callable($handler)) { call_user_func_array($handler, $data); } } } } }
<?php $start_time = microtime(1); // no cache header("Expires: Thu, 01 Jan 1970 00:00:00 GMT"); header("Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT"); header("Pragma: no-cache"); header("Cache-Control: no-store, no-cache, must-revalidate"); require_once "init.php"; set_error_handler(array($debug = Debug::getInstance(), 'parsePHPError')); print "generated in: " . round(microtime(1) - $start_time, 3) . "s; query counter: " . Mysql::get_num_queries() . "; cache hits: " . Mysql::get_cache_hits() . "; cache miss: " . Mysql::get_cache_misses() . "; " . $debug->getErrorStr();
die('<strong>ERROR!</strong><br />CubeCart requires <a href="http://www.php.net">PHP</a> Version 5.2.3 or better. Your server is currently running PHP Version ' . PHP_VERSION); } define('ADMIN_CP', false); // Include core functions require CC_INCLUDES_DIR . 'functions.inc.php'; // Initialize Cache $GLOBALS['cache'] = Cache::getInstance(); // Initialise Database class, and fetch default configuration $GLOBALS['db'] = Database::getInstance($glob); // Initialise Config class $GLOBALS['config'] = Config::getInstance($glob); //We will not need this anymore unset($glob); $GLOBALS['config']->merge('config', '', $config_default); // Initialize debug $GLOBALS['debug'] = Debug::getInstance(); //Initialize sessions $GLOBALS['session'] = Session::getInstance(); //Initialize Smarty $GLOBALS['smarty'] = new Smarty(); $GLOBALS['smarty']->muteExpectedErrors(); $GLOBALS['smarty']->error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING; $GLOBALS['smarty']->compile_dir = CC_SKIN_CACHE_DIR; $GLOBALS['smarty']->config_dir = CC_SKIN_CACHE_DIR; $GLOBALS['smarty']->cache_dir = CC_SKIN_CACHE_DIR; $GLOBALS['smarty']->debugging = false; //Initialize language $GLOBALS['language'] = Language::getInstance(); //Initialize hooks $GLOBALS['hooks'] = HookLoader::getInstance(); //Initialize SEO
public function __construct() { session_start(); header('Content-type: text/json'); // Get the website user $userId = SessionManager::getInstance()->getUserId(); $json['result'] = 'true'; // Make sure a user is logged in if (!isset($userId)) { $json['result'] = 'false'; $json['title'] = (string) Content::c()->errors->session->title; $json['message'] = (string) Content::c()->errors->session->no_session; echo json_encode($json); exit; } // Validate input if (empty($_POST['introducee1Name']) || empty($_POST['introducee1FacebookId']) && empty($_POST['introducee1LinkedInId']) && empty($_POST['introducee1TwitterId']) || empty($_POST['introducee2Name']) || empty($_POST['introducee2FacebookId']) && empty($_POST['introducee2LinkedInId']) && empty($_POST['introducee2TwitterId'])) { $json['result'] = 'false'; $json['title'] = (string) Content::c()->errors->input->title; $json['message'] = (string) Content::c()->errors->input->introduction_not_created; echo json_encode($json); exit; } // Make sure the introducees are unique if (!empty($_POST['introducee1FacebookId']) && !empty($_POST['introducee2FacebookId']) && $_POST['introducee1FacebookId'] == $_POST['introducee2FacebookId'] || !empty($_POST['introducee1LinkedInId']) && !empty($_POST['introducee2LinkedInId']) && $_POST['introducee1LinkedInId'] == $_POST['introducee2LinkedInId'] || !empty($_POST['introducee1TwitterId']) && !empty($_POST['introducee2TwitterId']) && $_POST['introducee1TwitterId'] == $_POST['introducee2TwitterId']) { $json['result'] = 'false'; $json['title'] = (string) Content::c()->errors->input->title; $json['message'] = (string) Content::c()->errors->input->introduce_to_self; echo json_encode($json); exit; } // Connect to the database $db = Database::getInstance(); $introducee1 = new Person(array('name' => $_POST['introducee1Name'], 'facebookId' => !empty($_POST['introducee1FacebookId']) ? $_POST['introducee1FacebookId'] : '', 'linkedInId' => !empty($_POST['introducee1LinkedInId']) ? $_POST['introducee1LinkedInId'] : null, 'twitterId' => !empty($_POST['introducee1TwitterId']) ? $_POST['introducee1TwitterId'] : null)); $introducee2 = new Person(array('name' => $_POST['introducee2Name'], 'facebookId' => !empty($_POST['introducee2FacebookId']) ? $_POST['introducee2FacebookId'] : '', 'linkedInId' => !empty($_POST['introducee2LinkedInId']) ? $_POST['introducee2LinkedInId'] : null, 'twitterId' => !empty($_POST['introducee2TwitterId']) ? $_POST['introducee2TwitterId'] : null)); // See if the introducees are already in our database, that would be nice! if (!empty($_POST['introducee1FacebookId'])) { $introducee1->getDataFromFacebookId($_POST['introducee1FacebookId']); } elseif (!empty($_POST['introducee1LinkedInId'])) { $introducee1->getDataFromLinkedInId($_POST['introducee1LinkedInId']); } elseif (!empty($_POST['introducee1TwitterId'])) { $introducee1->getDataFromTwitterId($_POST['introducee1TwitterId']); } if (!empty($_POST['introducee2FacebookId'])) { $introducee2->getDataFromFacebookId($_POST['introducee2FacebookId']); } elseif (!empty($_POST['introducee2LinkedInId'])) { $introducee2->getDataFromLinkedInId($_POST['introducee2LinkedInId']); } elseif (!empty($_POST['introducee2TwitterId'])) { $introducee2->getDataFromTwitterId($_POST['introducee2TwitterId']); } // Make sure the introducees are still unique if ($introducee1->getFacebookId() != null && $introducee1->getFacebookId() == $introducee2->getFacebookId() || $introducee1->getLinkedInId() != null && $introducee1->getLinkedInId() == $introducee2->getLinkedInId() || $introducee1->getTwitterId() != null && $introducee1->getTwitterId() == $introducee2->getTwitterId()) { $json['result'] = 'false'; $json['title'] = (string) Content::c()->errors->input->title; $json['message'] = (string) Content::c()->errors->input->introduce_to_self; echo json_encode($json); exit; } // If the introducees aren't in the database yet, add them $introducee1->addToDatabase(); $introducee2->addToDatabase(); // If the introducees are on LinkedIn, add their public profile URL and picture to the DB if ($introducee1->getLinkedInId() != null || $introducee2->getLinkedInId() != null) { // Connect to LinkedIn API $sth = $db->prepare('SELECT id, access_token FROM linkedin WHERE person_id = :person_id'); $sth->execute(array(':person_id' => $userId)); $userDetails = $sth->fetch(PDO::FETCH_ASSOC); if (!empty($userDetails['access_token'])) { $linkedInAccessToken = $userDetails['access_token']; // Create LinkedIn object $API_CONFIG = array('appKey' => LI_API_KEY, 'appSecret' => LI_SECRET, 'callbackUrl' => ''); $OBJ_linkedin = new LinkedIn($API_CONFIG); $OBJ_linkedin->setTokenAccess(unserialize($linkedInAccessToken)); // Which introducees are on LinkedIn? $profilesToRequest = array(); if ($introducee1->getLinkedInId() != null) { $profilesToRequest[] = 'id=' . $introducee1->getLinkedInId(); } if ($introducee2->getLinkedInId() != null) { $profilesToRequest[] = 'id=' . $introducee2->getLinkedInId(); } try { $linkedInProfiles = $OBJ_linkedin->profileNew('::(' . implode(',', $profilesToRequest) . '):(id,public-profile-url,picture-url)'); } catch (ErrorException $e) { } if ($linkedInProfiles['success'] === TRUE) { $linkedInProfiles['linkedin'] = new SimpleXMLElement($linkedInProfiles['linkedin']); if ($linkedInProfiles['linkedin']->getName() == 'people') { foreach ($linkedInProfiles['linkedin']->person as $person) { $id = (string) $person->id; $url = (string) $person->{'public-profile-url'}; $pic = (string) $person->{'picture-url'}; if ($id && ($url || $pic)) { $update = $db->prepare('REPLACE INTO temp_linkedin SET linkedin_id = :linkedin_id, time=NOW(), profile_url = :profile_url, picture_url = :picture_url'); $update->execute(array(':linkedin_id' => $id, ':profile_url' => $url, ':picture_url' => $pic)); } } } } } } // If the introducees are on Twitter, add their screen name and picture to the DB if ($introducee1->getTwitterId() != null || $introducee2->getTwitterId() != null) { // Which introducees are on Twitter? $profilesToRequest = array(); if ($introducee1->getTwitterId() != null) { $profilesToRequest[] = $introducee1->getTwitterId(); } if ($introducee2->getTwitterId() != null) { $profilesToRequest[] = $introducee2->getTwitterId(); } // Connect to Twitter API $sth = $db->prepare('SELECT id, access_token FROM twitter WHERE person_id = :person_id'); $sth->execute(array(':person_id' => $userId)); $userDetails = $sth->fetch(PDO::FETCH_ASSOC); if (!empty($userDetails['access_token'])) { $twitterAccessToken = unserialize($userDetails['access_token']); try { $twitter = new TwitterOAuth(TW_CONSUMER, TW_SECRET, $twitterAccessToken['oauth_token'], $twitterAccessToken['oauth_token_secret']); $twitter->format = 'json'; $twitterProfiles = $twitter->get('users/lookup', array('user_id' => implode(',', $profilesToRequest))); foreach ($twitterProfiles as $friend) { $id = (string) $friend->id; $screenName = (string) $friend->screen_name; $pic = (string) $friend->profile_image_url; $protected = (string) $friend->protected; if ($id && ($screenName || $pic || $protected)) { $update = $db->prepare('REPLACE INTO temp_twitter SET twitter_id = :twitter_id, time=NOW(), screen_name = :screen_name, picture_url = :picture_url, protected = :protected'); $update->execute(array(':twitter_id' => $id, ':screen_name' => $screenName, ':picture_url' => $pic, ':protected' => $protected)); } } } catch (ErrorException $e) { // Could not post to Twitter. Bad access token? Debug::l('Error posting to Twitter ' . $e); } } } $linkPassword = BaseConvert::generatePassword(); // Add the introduction to the database $insert = $db->prepare('INSERT INTO introduction (introducer_id, introducee1_id, introducee2_id, time, link_password) VALUES (:introducer_id, :introducee1_id, :introducee2_id, NOW(), :link_password)'); $insert->execute(array(':introducer_id' => $userId, ':introducee1_id' => $introducee1->getId(), ':introducee2_id' => $introducee2->getId(), ':link_password' => $linkPassword)); $introId = $db->lastInsertId(); // Add the links for each introducee $linkPassword1 = BaseConvert::generatePassword(); $linkPassword2 = BaseConvert::generatePassword(); $insert = $db->prepare('INSERT INTO link (introduction_id, person_id, link_password) VALUES (:introduction_id, :person_id, :link_password)'); $insert->execute(array(':introduction_id' => $introId, ':person_id' => $introducee1->getId(), ':link_password' => $linkPassword1)); $insert->execute(array(':introduction_id' => $introId, ':person_id' => $introducee2->getId(), ':link_password' => $linkPassword2)); // If there is a message, add it to the database if (!empty($_POST["message"])) { $message = htmlentities(trim($_POST['message']), ENT_QUOTES, 'UTF-8'); if (!empty($message)) { $insert = $db->prepare('INSERT INTO message (body, time, introduction_id, writer_id) VALUES (:body, NOW(), :introduction_id, :writer_id)'); $insert->execute(array(':body' => $message, ':introduction_id' => $introId, ':writer_id' => $userId)); } } // Return the success message, which will tell the Javascript to redirect the user to the send-introduction page $json['result'] = 'true'; $json['link'] = APP_URL . '/' . Content::l() . '/send-introduction/'; $json['time'] = Debug::getInstance()->getTimeElapsed(); echo json_encode($json); }
/** * Display XML * @return XML */ public function output() { Debug::getInstance()->supress(); header('Content-Type: text/xml'); echo $this->getDocument(); }
private function printCachedFriendsIfSet($cache) { if (!empty($cache)) { for ($i = 0, $len = count($cache); $i < $len; $i++) { if (!empty($cache[$i]['facebook_id'])) { $json['friends'][$i]['facebookId'] = $cache[$i]['facebook_id']; } if (!empty($cache[$i]['linkedin_id'])) { $json['friends'][$i]['linkedInId'] = $cache[$i]['linkedin_id']; } if (!empty($cache[$i]['twitter_id'])) { $json['friends'][$i]['twitterId'] = $cache[$i]['twitter_id']; } $json['friends'][$i]['name'] = $cache[$i]['name']; } $json['result'] = 'true'; $json['time'] = Debug::getInstance()->getTimeElapsed(); echo json_encode($json); exit; } }