Example #1
0
 public static function cache_init($options = false)
 {
     $defaultCacheExpire = Config::get_mandatory("DEFAULT_CACHE_EXPIRE");
     if (empty($defaultCacheExpire)) {
         $defaultCacheExpire = 0;
     }
     $lifetime = isset($options["lifetime"]) ? $options["lifetime"] : $defaultCacheExpire;
     $cacheExists = false;
     if (!empty(self::$_caches[$lifetime])) {
         $cacheExists = true;
     }
     if (!$cacheExists && Config::get_optional("MEMCACHE_ON") == true) {
         $servers = array('host' => Config::get_mandatory("memcache_host"), 'port' => Config::get_mandatory("memcache_port"), 'persistent' => Zend_Cache_Backend_Memcached::DEFAULT_PERSISTENT, 'weight' => 1);
         $frontendOptions = array('lifetime' => $lifetime, 'automatic_serialization' => true);
         $backendOptions = array('servers' => $servers);
         $memcache = Zend_Cache::factory('Core', 'Memcached', $frontendOptions, $backendOptions);
         // test memcache & clean out old entries if they exist
         if (@$memcache->save("test", "test_id")) {
             $num = mt_rand(0, 100);
             if ($num == 1) {
                 $memcache->clean(Zend_Cache::CLEANING_MODE_OLD);
                 Logger::log("cache cleaned: " . __METHOD__ . " line: " . __LINE__, Logger::DEBUG);
             }
             self::$_caches[$expire] = $memcache;
         } else {
             self::$_caches[$expire] = false;
         }
     } elseif (!$cacheExists) {
         $frontendOptions = array('lifetime' => $lifetime, 'automatic_serialization' => true, 'cache_id_prefix' => Config::get_optional('CACHE_ID_PREFIX'));
         $backendOptions = array('cache_dir' => sprintf("%s/../%s/", DOCUMENT_ROOT, Config::get_mandatory("CACHE_DIR")));
         self::$_caches[$lifetime] = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
         self::doClean($options);
     }
     return self::$_caches[$lifetime];
 }
Example #2
0
 public function serverSideGoogleAnalytics()
 {
     $var_utmac = Config::get_mandatory('googleAnalyticsID');
     //enter the new urchin code
     $var_utmhn = $_SERVER['HTTP_HOST'];
     //enter your domain
     $var_utmn = rand(1000000000, 9999999999);
     //random request number
     $var_cookie = rand(10000000, 99999999);
     //random cookie number
     $var_random = rand(1000000000, 2147483647);
     //number under 2147483647
     $var_today = time();
     //today
     $var_referer = @$_SERVER['HTTP_REFERER'];
     //referer url
     if (ArtemisUtilities::loggedInIFAUser()) {
         //if session is set then we can get the user id - else send anonymous
         $var_uservar = ArtemisUtilities::loggedInIFAUser();
     } else {
         $var_uservar = "anonymous";
     }
     $var_utmp = '[ini_protocol]' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     $urchinUrl = '[ini_protocol]www.google-analytics.com/__utm.gif?utmwv=1&utmn=' . $var_utmn . '&utmsr=-&utmsc=-&utmul=-&utmje=0&utmfl=-&utmdt=-&utmhn=' . $var_utmhn . '&utmr=' . $var_referer . '&utmp=' . $var_utmp . '&utmac=' . $var_utmac . '&utmcc=__utma%3D' . $var_cookie . '.' . $var_random . '.' . $var_today . '.' . $var_today . '.' . $var_today . '.2%3B%2B__utmb%3D' . $var_cookie . '%3B%2B__utmc%3D' . $var_cookie . '%3B%2B__utmz%3D' . $var_cookie . '.' . $var_today . '.2.2.utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)%3B%2B__utmv%3D' . $var_cookie . '.' . $var_uservar . '%3B';
     $handle = fopen($urchinUrl, "r");
     $test = fgets($handle);
     fclose($handle);
     return true;
 }
Example #3
0
 private function __construct()
 {
     // setup file error logging
     $file_writer = new Logger_Errorlog();
     if (Config::get_optional("DEBUG_LOG") == false) {
         $file_writer->addFilter(Zend_Log::INFO);
     }
     $log = new Zend_Log();
     $log->addWriter($file_writer);
     // setup email error logging
     if (Config::get_optional("log_to_email") == true) {
         $mail = new Zend_Mail();
         $mail->setFrom(Config::get_mandatory('log_email_from'));
         $mail->addTo(Config::get_mandatory('log_email_to'));
         // setup email template
         $layout = new Zend_Layout();
         $layout->setLayoutPath(DOCUMENT_ROOT . Config::get_mandatory("log_email_template"));
         $layout->setLayout('error-logger');
         $layout_formatter = new Zend_Log_Formatter_Simple('<li>.' . Zend_Log_Formatter_Simple::DEFAULT_FORMAT . '</li>');
         // Use default HTML layout.
         $email_writer = new Zend_Log_Writer_Mail($mail, $layout);
         $email_writer->setLayoutFormatter($layout_formatter);
         $email_writer->setSubjectPrependText(Config::get_mandatory('log_email_subject_prepend'));
         $email_writer->addFilter(Zend_Log::ERR);
         $log->addWriter($email_writer);
     }
     self::$logger = $log;
 }
Example #4
0
 public static function appDbConnect()
 {
     try {
         $db = Zend_Db::factory("Pdo_Mysql", array("host" => Config::get_mandatory('app_hostname'), "username" => Config::get_mandatory('app_username'), "password" => Config::get_mandatory('app_password'), "dbname" => Config::get_mandatory('app_database'), "persistent" => true, "charset" => "utf8", "profiler" => true));
         $output = $db;
     } catch (Zend_Db_Adapter_Exception $e) {
         // perhaps a failed login credential, or perhaps the RDBMS is not running
         Logger::log("NO APP DB CONNECTION: " . $e->getMessage(), Logger::CRIT);
         $output = false;
     } catch (Zend_Exception $e) {
         // perhaps factory() failed to load the specified Adapter class
         Logger::log("NO APP DB CONNECTION - failed to load Adapter class: " . $e->getMessage(), Logger::CRIT);
         $output = false;
     }
     return $output;
 }
Example #5
0
 private function connectToWebpurify($secure = 0)
 {
     $prefix = $secure == 0 ? "http://" : "https://";
     $oFilter = new Zend_Rest_Client($prefix . Config::get_mandatory('purifyURL'));
     return $oFilter->api_key(Config::get_mandatory('webpurifyAPIKey'));
 }
Example #6
0
 function saveSignedRequest()
 {
     $signed_request = $_POST['signed_request'];
     $secret = Config::get_mandatory('fb_secret');
     list($encoded_sig, $payload) = explode('.', $signed_request, 2);
     // decode the data
     $sig = Fb::base64_url_decode($encoded_sig);
     $data = json_decode(Fb::base64_url_decode($payload), true);
     if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
         error_log('Unknown algorithm. Expected HMAC-SHA256');
         return null;
     }
     // check sig
     $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
     if ($sig !== $expected_sig) {
         error_log('Bad Signed JSON signature!');
         return null;
     }
     // save to session, so we have it throughout app
     $_SESSION['signed_request'] = $data;
     return $data;
 }
Example #7
0
 public function getSecretQuestion($username = false)
 {
     if (!$username) {
         return false;
     }
     $db = db::appDbConnect();
     try {
         $sql = sprintf("SELECT id, secret_question, AES_DECRYPT(secret_answer, '%s') AS answer FROM users WHERE username = AES_ENCRYPT(?, '%s') LIMIT 1", Config::get_mandatory('encrypt_salt'), Config::get_mandatory('encrypt_salt'));
         $res = $db->fetchRow($sql, array($username));
         if (count($res) > 0) {
             return $res;
         } else {
             return false;
         }
     } catch (Exception $e) {
         var_dump($e);
         return false;
     }
 }
Example #8
0
 /**
  * displays debug profiler
  *
  * @return string
  */
 public function debugMode($pageParams = false)
 {
     if (Config::get_mandatory("dev") && isset($_REQUEST['debug']) && $pageParams) {
         $endTime = microtime();
         $diffTime = $endTime - $this->startProfile;
         $dbugStr = "";
         $dbugStr .= "<div id='debugModule' style='background:#000; color:#fff; font-size:14px; line-height:1.0em; text-align:left;'><pre>" . print_r($pageParams, 1) . "</pre>";
         $dbugStr .= "<p>build-time: " . (double) $diffTime . " secs</p>";
         $dbugStr .= "</div>";
         return $dbugStr;
     }
 }
Example #9
0
// $_SERVER['DOCUMENT_ROOT'] is now set - you can use it as usual...
if (!empty($_SERVER['DOCUMENT_ROOT'])) {
    define('DOCUMENT_ROOT', $_SERVER['DOCUMENT_ROOT']);
    define('SERVER_NAME', $_SERVER['SERVER_NAME']);
} else {
    //works for phpunit
    define('DOCUMENT_ROOT', dirname(__FILE__) . "/../web");
    define('SERVER_NAME', "test");
}
function init_autoload($class)
{
    require_once sprintf("%s.php", str_replace("_", "/", $class));
}
spl_autoload_register("init_autoload");
$include_path = array(sprintf("%s/../lib", DOCUMENT_ROOT), sprintf("%s/../lib/classes", DOCUMENT_ROOT), sprintf("%s/../views", DOCUMENT_ROOT), sprintf("%s/../lib/Facebook", DOCUMENT_ROOT));
ini_set("include_path", join(PATH_SEPARATOR, $include_path));
Config::load(sprintf("%s/../config/default.ini", DOCUMENT_ROOT));
Config::load(sprintf("%s/../config/%s.ini", DOCUMENT_ROOT, SERVER_NAME));
//GLOBALS
define('DEFAULT_LANG', Config::get_mandatory("DEFAULT_LANG"));
$tsn = Config::get_optional("THIS_SERVER_NAME") ? Config::get_optional("THIS_SERVER_NAME") : SERVER_NAME;
$tsll = Config::get_optional("THIS_SSL_SERVER_NAME") ? Config::get_optional("THIS_SERVER_NAME") : SERVER_NAME;
define('THIS_SERVER_NAME', $tsn);
define('THIS_SSL_SERVER_NAME', $tsll);
$isDev = Config::get_optional("dev") === "1" ? true : false;
ini_set("display_errors", (bool) $isDev);
ini_set("html_errors", (bool) $isDev);
ini_set("log_errors", (bool) $isDev);
if ($isDev) {
    ini_set("error_reporting", E_ALL);
}
Example #10
0
 public function auth($options = array())
 {
     $output = false;
     // Get User ID
     $user = $this->facebook->getUser();
     // set redirect uri
     $redirect_uri = Config::get_mandatory('fb_canvas_page');
     if (!empty($options['redirect_uri'])) {
         $redirect_uri = $options['redirect_uri'];
     }
     // set next uri
     $next = Config::get_mandatory('fb_canvas_page');
     if (!empty($options['next'])) {
         $next = $options['next'];
     }
     // set cancel uri
     $cancel_uri = Config::get_mandatory('fb_canvas_page');
     if (!empty($options['cancel_uri'])) {
         $cancel_uri = $options['cancel_uri'];
     }
     // 	  var_dump($user);
     // We may or may not have this data based on whether the user is logged in.
     //
     // If we have a $user id here, it means we know the user is logged into
     // Facebook, but we don't know if the access token is valid. An access
     // token is invalid if the user logged out of Facebook.
     if ($user) {
         try {
             // Proceed knowing you have a logged in user who's authenticated.
             $profile = $this->facebook->api('/me');
         } catch (FacebookApiException $e) {
             Logger::log($e->getMessage(), Logger::DEBUG);
             $profile = null;
         }
     }
     // 	  var_dump($output);
     // if we have no user with access token then redirect to login/permissions grant
     if (empty($profile)) {
         $url = $this->facebook->getLoginUrl(array('canvas' => 1, 'fbconnect' => 0, 'scope' => Config::get_mandatory('fb_scope'), 'redirect_uri' => $redirect_uri, 'next' => $next, 'cancel_url' => $cancel_uri));
         // we need to do a js redirect as facebook uses iframes
         // @todo figure out how to redirect server-side instead of using js for fb auth (impossible?)
         printf('<script>top.location.href="%s"</script>', $url);
         echo '<noscript><h1>Error</h1><p>Your web browser must have Javascript enabled to use this application.</p></noscript>';
         die;
     }
     $this->populate($profile);
     return $this;
 }