Esempio n. 1
0
 public function __construct()
 {
     parent::__construct();
     if (Glucose::config('user', 'stats')) {
         http_auth(Glucose::config('user', 'stats'), Glucose::config('pass', 'stats'));
     }
 }
Esempio n. 2
0
function static_asset_version()
{
    static $timestamp = null;
    if ($timestamp === null) {
        $timestamp = strtotime(Glucose::config('version', 'assets'));
    }
    return $timestamp;
}
Esempio n. 3
0
 public function set($key, $value, $compressed = null, $time = null)
 {
     $this->quick_cache[$key] = $value;
     if (!$this->memcached) {
         return false;
     }
     $key = $this->key_prefix . $key;
     $compressed = $compressed ? MEMCACHE_COMPRESSED : 0;
     $time = $time !== null ? $time : time() + Glucose::config('expiration', 'memcached');
     return $this->memcached->set($key, $value, $compressed, $time);
 }
Esempio n. 4
0
 private function bootstrap()
 {
     if (!@(include BASE_PATH . '/config.php')) {
         Glucose::fatalError('Could not load configuration file.');
     }
     self::$config = $config;
     $this->loadClass('request');
     $this->loadClass('response');
     $this->loadClass('template');
     $this->loadClass('memcached');
     $this->loadClass('router');
     $this->router->dispatch($this->request);
 }
Esempio n. 5
0
 private function applyCustomRoutes($url)
 {
     $route = array('module' => $this->module, 'controller' => $this->controller, 'action' => $this->action, 'args' => $this->args);
     if (is_array(Glucose::config('routes'))) {
         foreach (Glucose::config('routes') as $regex => $c_route) {
             // Fill placeholders
             $regex = str_replace('{{base_url}}', addcslashes(Glucose::config('base_url', 'site'), '.'), $regex);
             if (preg_match($regex, $url)) {
                 $route = array_merge($route, $c_route);
                 break;
             }
         }
     }
     $this->module = $route['module'];
     $this->controller = $route['controller'];
     $this->action = $route['action'];
     $this->args = $route['args'];
 }
Esempio n. 6
0
 public function __construct()
 {
     if (!($this->dbh = mysql_connect(Glucose::config('host', 'database'), config_item('user', 'database'), config_item('pass', 'database'))) || !mysql_select_db(Glucose::config('database', 'database'), $this->dbh)) {
         fatal_error('Could not connect to database.');
     }
 }
Esempio n. 7
0
 /**
  * conversations
  *
  * Retrieve conversations surrounding a URL
  *
  * @param string url
  * @return mixed
  */
 public function conversations($url)
 {
     // Check cache
     $cached = $this->memcached->get('conversations:' . $url);
     if ($cached !== false) {
         return $cached === '' ? false : $cached;
     }
     $curlh = curl_init();
     curl_setopt($curlh, CURLOPT_URL, 'http://api.contextvoice.com/1.1/reactions/?apikey=' . Glucose::config('contextvoice_api_key', 'misc') . '&format=json&url=' . urlencode($url));
     curl_setopt($curlh, CURLOPT_CONNECTTIMEOUT, 10);
     curl_setopt($curlh, CURLOPT_TIMEOUT, 10);
     curl_setopt($curlh, CURLOPT_USERAGENT, 'LongURL API');
     curl_setopt($curlh, CURLOPT_REFERER, 'http://longurl.org');
     curl_setopt($curlh, CURLOPT_RETURNTRANSFER, true);
     $response = curl_exec($curlh);
     $info = curl_getinfo($curlh);
     curl_close($curlh);
     if ($info['http_code'] === 200) {
         $this->memcached->set('conversations:' . $url, (array) json_decode($response));
         return (array) json_decode($response);
     }
     $this->memcached->set('conversations:' . $url, '');
     return false;
 }
Esempio n. 8
0
 /**
  * @todo This is messy. Clean it up.
  */
 private function versionFileAssets($url)
 {
     if (strpos($url, 'http') === 0) {
         return $url;
     }
     $cache_name = md5($url) . '.versioned.css';
     $cache_path = BASE_PATH . Glucose::config('cache_dir', 'template') . $cache_name;
     $orig_mtime = Glucose::config('dynamic', 'assets') == true ? filemtime($this->urlToPath($url)) : static_asset_version();
     if (file_exists($cache_path) && $orig_mtime < filemtime($cache_path)) {
         $file = Glucose::config('cache_dir', 'template') . $cache_name;
         $file_path = $cache_path;
         if (Glucose::config('dynmaic', 'assets') == false) {
             return $file;
         }
     } else {
         $file = $url;
         $file_path = $this->urlToPath($url);
     }
     $file_contents = file_get_contents($file_path);
     $new_contents = $this->versionAssets($file_contents);
     if ($file_contents !== $new_contents) {
         file_put_contents($cache_path, $new_contents);
         return Glucose::config('cache_dir', 'template') . $cache_name;
     } else {
         return $file;
     }
 }
Esempio n. 9
0
 public function contact()
 {
     if ($_POST) {
         include_once BASE_PATH . '/libraries/Email.php';
         $config['mailtype'] = 'html';
         $email =& new CI_Email($config);
         $valid = true;
         // Validate the form data
         if (!post('contact_name')) {
             $this->GC->response->addMsg('Please enter your name.');
             $valid = false;
         }
         if (!$email->valid_email(post('email'))) {
             $this->GC->response->addMsg('Please enter a valid email address.');
             $valid = false;
         }
         if (!post('message')) {
             $this->GC->response->addMsg('Please enter a message.');
             $valid = false;
         }
         // Send the email
         if ($valid) {
             $email->to(Glucose::config('admin_email', 'site'));
             $email->from(post('email'), post('contact_name'));
             $email->subject('Message from LongURL website');
             $message = '<b>Name:</b> ' . post('contact_name') . '<br />';
             $message .= '<b>Email:</b> ' . post('email') . '<br />';
             $message .= '<b>IP:</b> ' . $_SERVER['REMOTE_ADDR'] . '<br />';
             $message .= '<b>Message:</b> ' . post('message') . '<br /><br /><br />';
             $email->message($message);
             if ($email->send()) {
                 $this->GC->response->addMsg('Your message was sent successfully.', 'success');
             } else {
                 $this->GC->response->addMsg('Unable to deliver your message. Please use ' . Glucose::config('admin_email', 'site') . ' instead.');
             }
         }
     }
     $this->GC->loadView('contact');
 }