Example #1
0
 public function delete()
 {
     try {
         $this->deleteMedia();
     } catch (Exception $e) {
         Bbx_Log::debug('Unable to delete media ' . get_class($this) . ' id ' . $this->id . ' - ' . $e->getMessage());
     }
     parent::delete();
 }
Example #2
0
 private static function _clean($tags)
 {
     $san_tags = array();
     foreach ($tags as $k => $v) {
         $san_tags[$k] = preg_replace('/[^A-Za-z0-9_]/', '', $v);
     }
     Bbx_Log::write('Cleaning tags ' . print_r($san_tags, true));
     self::_cache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, $san_tags);
 }
Example #3
0
 protected function _throwUploadException($upload)
 {
     $msgs = $upload->getMessages();
     if (empty($msgs)) {
         $msgs = array('Unknown failure - please contact support.');
     }
     Bbx_Log::debug('Upload failed: ' . implode($msgs));
     throw new Bbx_Controller_Rest_Exception('Upload failed: ' . implode($msgs), 500);
 }
Example #4
0
 protected function _closeSession()
 {
     $this->_user = $this->_helper->Authenticate->getUser();
     $session = $this->_user->current_admin_session;
     try {
         $session->close();
     } catch (Exception $e) {
         Bbx_Log::debug("Unable to close session: " . $e->getMessage());
     }
 }
Example #5
0
 public function __call($method, $arguments)
 {
     if (method_exists('Bbx_Date', $method)) {
         try {
             return call_user_func_array(array('Bbx_Date', $method), $arguments);
         } catch (Exception $e) {
             Bbx_Log::debug($e->getMessage());
         }
     } else {
         Bbx_Log::debug('Bbx_Date has no method "' . $method . '"');
     }
 }
Example #6
0
 public function sync($start)
 {
     $root = realpath(APPLICATION_PATH . '/..');
     $root_length = strlen($root);
     $remote_path = $this->_streamPath();
     Bbx_Log::write("Starting sync at " . $root . $start, null, self::LOG);
     Bbx_Log::write("Syncing to " . $remote_path, null, self::LOG);
     $stack = array();
     array_push($stack, $root . $start);
     while (!empty($stack)) {
         $node = array_pop($stack);
         if (is_dir($node)) {
             $rel_path = substr($node, $root_length);
             Bbx_Log::write("found dir " . $node, null, self::LOG);
             Bbx_Log::write("checking remote dir " . $remote_path . $rel_path, null, self::LOG);
             if (!is_resource(opendir($remote_path . ${$rel_path}))) {
                 Bbx_Log::write($remote_path . $rel_path . ' does not exist, creating', null, self::LOG);
                 if (!mkdir($remote_path . $rel_path)) {
                     Bbx_Log::write('Unable to create directory, skipping', null, self::LOG);
                     continue;
                 }
             }
             Bbx_Log::write("dir OK", null, self::LOG);
             $dir_res = opendir($node);
             while (false !== ($dir_contents = readdir($dir_res))) {
                 if (substr($dir_contents, 0, 1) == '.') {
                     continue;
                 }
                 $path = $node . '/' . $dir_contents;
                 Bbx_Log::write("adding " . $path . " to stack", null, self::LOG);
                 array_push($stack, $path);
             }
         } else {
             if (is_file($node)) {
                 $rel_path = substr($node, $root_length);
                 Bbx_Log::write("copying " . $node . " to " . $remote_path . $rel_path, null, self::LOG);
                 if (!copy($node, $remote_path . $rel_path)) {
                     Bbx_Log::write("unable to copy " . $node . " to " . $remote_path . $rel_path, null, self::LOG);
                 } else {
                     Bbx_Log::write("copy OK", null, self::LOG);
                     if (!unlink($node)) {
                         Bbx_Log::write("unable to delete " . $node, null, self::LOG);
                     } else {
                         Bbx_Log::write("deleted " . $node, null, self::LOG);
                     }
                 }
             }
         }
     }
     $this->_syncing = false;
 }
Example #7
0
 public function notify(Exception $e)
 {
     if (isset(Bbx_Config::get()->site->support_address) && APPLICATION_ENV != 'development') {
         try {
             $mail = Bbx_Mail::instance();
             $mail->setFrom('error@' . Bbx_Config::get()->site->location, Bbx_Config::get()->site->location);
             $mail->setBodyText($this->getRequest()->getRequestUri() . "\n\n" . $e->getMessage());
             $mail->addTo(Bbx_Config::get()->site->support_address);
             $mail->setSubject('Error at ' . Bbx_Config::get()->site->location);
             $mail->sendAsync();
         } catch (Exception $exc) {
             Bbx_Log::debug(print_r($e, true));
             Bbx_Log::debug("Couldn't send mail: " . $exc->getMessage());
         }
     } else {
         Bbx_Log::debug(print_r($e, true));
     }
 }
Example #8
0
 protected function _httpAuth()
 {
     $config = array('accept_schemes' => 'digest', 'realm' => Bbx_Config::get()->site->location, 'digest_domains' => '/', 'nonce_timeout' => 3600);
     $adaptor = new Zend_Auth_Adapter_Http($config);
     $this->_resolver = new Bbx_Auth_Resolver_Db();
     $adaptor->setDigestResolver($this->_resolver)->setRequest($this->getRequest())->setResponse($this->getResponse());
     try {
         $auth = $adaptor->authenticate();
         if (!$auth->isValid()) {
             if (isset($this->_redirect)) {
                 $body = $this->_getRedirectBody();
             } else {
                 $body = $this->_get403Body();
             }
             $this->getResponse()->setHttpResponseCode(401)->setBody($body)->sendResponse();
             exit;
         }
         return $auth->isValid();
     } catch (Exception $e) {
         Bbx_Log::write('Exception during authentication: ' . $e->getMessage());
         throw new Bbx_Controller_Rest_Exception(null, 401);
     }
 }
Example #9
0
 protected function _documentExists($docId)
 {
     @($hits = $this->_index->find('docId:' . $docId));
     foreach ($hits as $hit) {
         if ($hit->docId == $docId) {
             Bbx_Log::write('Found existing document: ' . urldecode($hit->url), null, self::LOG);
             return $hit;
         }
     }
     return false;
 }
Example #10
0
<?php

require 'init.php';
$sentinel_file = APPLICATION_PATH . '/modules/' . MODULE_NAME . '/search/.indexing';
if (file_exists($sentinel_file)) {
    Bbx_Log::write('Spider is already indexing');
    exit;
}
touch($sentinel_file);
set_time_limit(21600);
$host = (string) $argv[1];
$spider = new Bbx_Search_Spider();
$spider->start('/', $host);
unlink($sentinel_file);
Example #11
0
 public static function debug($str, $type = 'info', $log = 'main_log')
 {
     return Bbx_Log::write('DEBUG: ' . $str, $type, $log);
 }
Example #12
0
 protected function _options()
 {
     Bbx_Log::debug("received OPTIONS request");
     $this->_helper->authenticate();
 }
Example #13
0
 public function hasLinkable($key)
 {
     $method = 'hasLinkable' . Inflector::camelize($key);
     if (method_exists($this, $method)) {
         return $this->{$method}();
     }
     try {
         return $this->{$key}->isLinkable();
     } catch (Exception $e) {
         Bbx_Log::write('Exception when checking isLinkable (' . $key . '): ' . $e->getMessage());
         return false;
     }
 }
Example #14
0
 protected function _resizeImage($size, $overwrite)
 {
     if (file_exists($this->getMediaPath($size)) && !$overwrite) {
         Bbx_Log::debug($size . ' exists (' . $this->getMediaPath($size) . ')');
         return;
     }
     $localPath = $this->getMediaPath('original', true);
     if (!is_readable($localPath)) {
         $cdnPath = $this->getMediaPath('original');
         if (!copy($cdnPath, $localPath)) {
             throw new Bbx_Model_Exception("Couldn't copy media from " . $cdnPath . " to " . $localPath);
         }
     }
     $img = Bbx_Media_Image::load($localPath);
     list($width, $height) = $this->_calculateImageGeometry($this->_sizes[$size], $this->width, $this->height);
     try {
         $img->resize((int) $width, (int) $height)->save($this->getMediaPath($size, true));
     } catch (Exception $e) {
         Bbx_Log::debug($e->getMessage());
         throw new Bbx_Model_Exception("Couldn't resize image " . $this->id . " to path " . $this->getMediaPath($size, true));
     }
 }
Example #15
0
<?php

require 'init.php';
Bbx_Log::write('Starting CDN Sync');
$sentinel_file = APPLICATION_PATH . '/../www/media/.cdn_syncing';
if (file_exists($sentinel_file)) {
    if (time() - filemtime($sentinel_file) < 86400) {
        Bbx_Log::write('CDN is already syncing');
        exit;
    }
}
if (!touch($sentinel_file)) {
    Bbx_Log::write('Unable to create sentinel file for CDN sync');
} else {
    set_time_limit(7200);
    $start = (string) $argv[1];
    $cdnType = (string) $argv[2];
    Bbx_Log::write('CDN syncing at ' . $start . ', CDN type is ' . $cdnType);
    switch ($cdnType) {
        case 's3':
            $cdn = Bbx_Model_Default_Media_Cdn_S3::init();
    }
    $cdn->sync($start);
    if (!unlink($sentinel_file)) {
        Bbx_Log::write('Unable to delete sentinel file for CDN sync');
    }
}
Example #16
0
 protected function _put($data = null)
 {
     $this->_helper->authenticate();
     try {
         $model = $this->_helper->Model->getModel();
         $method = $model->isEmpty() ? 'create' : 'update';
         if ($data === null) {
             $data = $this->_getBodyData();
         }
         $model->{$method}($data);
         Bbx_CacheManager::clean($this->getRequest(), 'put');
     } catch (Exception $e) {
         Bbx_Log::write('Unable to _put to model: ' . $e->getMessage());
         throw new Bbx_Controller_Rest_Exception(null, 405, array('allowed_methods' => 'GET,POST'));
     }
 }
Example #17
0
 protected function _checkLastLogin()
 {
     $session = $this->_user->last_admin_session;
     if (!$session instanceof Bbx_Model) {
         return;
     }
     try {
         if ($session->logged_out_at == '0000-00-00 00:00:00') {
             $session->close();
         }
     } catch (Exception $e) {
         Bbx_Log::debug("Unable to close session: " . $e->getMessage());
     }
 }
Example #18
0
 protected function _spider($url)
 {
     $queue = array();
     $visited = array();
     array_push($queue, $url);
     while (!empty($queue)) {
         $doc = null;
         $url = array_shift($queue);
         if ($url = $this->_sanitizeUrl($url)) {
             if (!in_array($url, $visited)) {
                 $visited[] = $url;
                 Bbx_Log::write('Spidering url ' . $url, null, Bbx_Search::LOG);
                 $cachePath = APPLICATION_PATH . '/../www/cached' . $url . '.html';
                 if (file_exists($cachePath)) {
                     Bbx_Log::write('Found file in cache', null, Bbx_Search::LOG);
                     try {
                         $doc = Zend_Search_Lucene_Document_Html::loadHTMLFile($cachePath, false, 'utf-8');
                     } catch (Exception $e) {
                         Bbx_Log::write('Unable to open file: ' . $cachePath, null, Bbx_Search::LOG);
                     }
                 } else {
                     $this->_client->setUri($this->_getAbsoluteUrl($url));
                     try {
                         $response = $this->_client->request();
                         $status = $response->getStatus();
                         Bbx_Log::write('Client response code ' . $status, null, Bbx_Search::LOG);
                         if ($status == '200') {
                             $data = $response->getBody();
                             $doc = Zend_Search_Lucene_Document_Html::loadHTML($data, false, 'utf-8');
                         }
                     } catch (Exception $e) {
                         Bbx_Log::write('Request failed: ' . $e->getMessage(), null, Bbx_Search::LOG);
                     }
                 }
                 if ($doc !== null) {
                     $this->_search()->indexDoc($doc, $url);
                     $this->_indexed++;
                     $links = array_diff($doc->getLinks(), $this->_visited);
                     if (count($visited) < $this->_maxLinks) {
                         $queue = array_merge($queue, $links);
                     } else {
                         Bbx_Log::write('Reached max number of links (' . $this->_maxLinks . '), exiting', null, Bbx_Search::LOG);
                         exit;
                     }
                 }
             }
         }
     }
 }
Example #19
0
 public function updateAllAction()
 {
     $this->_helper->authenticate();
     $model = $this->_getParam('model');
     try {
         $models = Bbx_Model::load($model)->findAll();
         foreach ($models as $m) {
             $m->update(array());
         }
     } catch (Exception $e) {
         Bbx_Log::debug($e->getMessage());
     }
     $this->getResponse()->sendResponse();
     exit;
 }
Example #20
0
<?php

require 'init.php';
$mail = Bbx_Mail::instance();
$mail->setFrom((string) $argv[1])->setBodyText((string) $argv[3])->setSubject((string) $argv[4]);
foreach (explode(',', (string) $argv[2]) as $to) {
    $mail->addTo($to);
}
try {
    $mail->send();
} catch (Exception $e) {
    Bbx_Log::write("Couldn't send mail: " . $e->getMessage());
}
Example #21
0
 protected function _set500()
 {
     Bbx_Log::write(print_r($this->_error, true));
     $this->getResponse()->setHttpResponseCode(500);
     $this->view->errorType = 'Server Error';
     $this->view->error = $this->_error['exception']->getMessage();
     $this->view->responseCode = '500';
     $url = $this->getRequest()->getRequestUri();
     $this->view->errorVars = array('url' => $url);
     $this->_notify();
 }