function initializeLocale($g_ui_locale)
{
    global $_, $_locale;
    if (!file_exists($vs_locale_path = __CA_APP_DIR__ . '/locale/user/' . $g_ui_locale . '/messages.mo')) {
        $vs_locale_path = __CA_APP_DIR__ . '/locale/' . $g_ui_locale . '/messages.mo';
    }
    if (file_exists($vs_locale_path)) {
        // If the locale is valid, locale is set
        $_locale = new Zend_Locale($g_ui_locale);
        Zend_Registry::set('Zend_Locale', $_locale);
        if (!caIsRunFromCLI() && ($o_cache = caGetCacheObject('ca_translation', 3600 * 24))) {
            Zend_Translate::setCache($o_cache);
        }
        $_ = new Zend_Translate(array('adapter' => 'gettext', 'content' => $vs_locale_path, 'locale' => $_locale, 'tag' => 'CA'));
        $cookiepath = __CA_URL_ROOT__ == "" ? "/" : __CA_URL_ROOT__;
        if (!headers_sent()) {
            setcookie('CA_' . __CA_APP_NAME__ . '_ui_locale', $g_ui_locale, time() + 36000, $cookiepath);
        }
        return true;
    } else {
        // cookie invalid, deleting
        if (!headers_sent()) {
            setcookie('CA_' . __CA_APP_NAME__ . '_ui_locale', NULL, -1);
        }
        return false;
    }
}
Example #2
0
 /**
  * @param string $ps_app_name An app name to use if no app name is configured in the application configuration file.
  * @param bool $pb_dont_create_new_session No new session will be created if set to true. Default is false.
  */
 public function __construct($ps_app_name = null, $pb_dont_create_new_session = false)
 {
     $o_config = Configuration::load();
     # --- Init
     if (defined("__CA_MICROTIME_START_OF_REQUEST__")) {
         $this->start_time = __CA_MICROTIME_START_OF_REQUEST__;
     } else {
         $this->start_time = microtime();
     }
     # --- Read configuration
     $this->name = ($vs_app_name = $o_config->get("app_name")) ? $vs_app_name : $ps_app_name;
     $this->domain = $o_config->get("session_domain");
     $this->lifetime = (int) $o_config->get("session_lifetime");
     if (!$this->lifetime) {
         $this->lifetime = 3600 * 24 * 7;
     }
     if (!$pb_dont_create_new_session) {
         if (!($vs_key = $this->getSessionID())) {
             $vs_cookiepath = __CA_URL_ROOT__ == '' ? '/' : __CA_URL_ROOT__;
             if (!caIsRunFromCLI()) {
                 setcookie($this->name, $_COOKIE[$this->name] = $vs_session_id = caGenerateGUID(), $this->lifetime ? time() + $this->lifetime : null, $vs_cookiepath);
             }
         }
         // initialize session var storage
         if ($vs_key && !ExternalCache::contains($vs_key, 'SessionVars')) {
             ExternalCache::save($vs_key, array(), 'SessionVars', $this->lifetime);
         }
     }
 }
Example #3
0
 /**
  * @param string $ps_app_name An app name to use if no app name is configured in the application configuration file.
  * @param bool $pb_dont_create_new_session No new session will be created if set to true. Default is false.
  */
 public function __construct($ps_app_name = null, $pb_dont_create_new_session = false)
 {
     $o_config = Configuration::load();
     # --- Init
     if (defined("__CA_MICROTIME_START_OF_REQUEST__")) {
         $this->start_time = __CA_MICROTIME_START_OF_REQUEST__;
     } else {
         $this->start_time = microtime();
     }
     # --- Read configuration
     $this->name = ($vs_app_name = $o_config->get("app_name")) ? $vs_app_name : $ps_app_name;
     $this->domain = $o_config->get("session_domain");
     $this->lifetime = (int) $o_config->get("session_lifetime");
     if (!$this->lifetime) {
         $this->lifetime = 3600 * 24 * 7;
     }
     if (!$pb_dont_create_new_session) {
         // try to get session ID from cookie. if that doesn't work, generate a new one
         if (!($vs_session_id = $this->getSessionID())) {
             $vs_cookiepath = __CA_URL_ROOT__ == '' ? '/' : __CA_URL_ROOT__;
             if (!caIsRunFromCLI()) {
                 setcookie($this->name, $_COOKIE[$this->name] = $vs_session_id = $this->generateGUIDV4(), $this->lifetime ? time() + $this->lifetime : null, $vs_cookiepath);
             }
         }
         // initialize in-memory session var storage, either restored from external cache or newly initialized
         if ($this->getSessionID() && ExternalCache::contains($this->getSessionID(), 'SessionVars')) {
             $this->opa_session_vars = ExternalCache::fetch($this->getSessionID(), 'SessionVars');
         } else {
             $this->opa_session_vars = array();
             if ($this->getSessionID()) {
                 ExternalCache::delete($this->getSessionID(), 'SessionVars');
             }
             $this->opa_session_vars['session_end_timestamp'] = time() + $this->lifetime;
         }
         // kill session if it has ended or we don't have a timestamp
         if (!isset($this->opa_session_vars['session_end_timestamp']) || is_numeric($this->opa_session_vars['session_end_timestamp']) && time() > $this->opa_session_vars['session_end_timestamp']) {
             $this->opa_session_vars = array();
             ExternalCache::delete($this->getSessionID(), 'SessionVars');
         }
     }
 }
Example #4
0
 /**
  * @param string $ps_app_name An app name to use if no app name is configured in the application configuration file.
  * @param bool $pb_dont_create_new_session No new session will be created if set to true. Default is false.
  */
 public function __construct($ps_app_name = null, $pb_dont_create_new_session = false)
 {
     $o_config = Configuration::load();
     # --- Init
     if (defined("__CA_MICROTIME_START_OF_REQUEST__")) {
         $this->start_time = __CA_MICROTIME_START_OF_REQUEST__;
     } else {
         $this->start_time = microtime();
     }
     # --- Read configuration
     $this->name = ($vs_app_name = $o_config->get("app_name")) ? $vs_app_name : $ps_app_name;
     $this->domain = $o_config->get("session_domain");
     $this->lifetime = $o_config->get("session_lifetime");
     if (!$pb_dont_create_new_session) {
         if (!($vs_session_id = $this->getSessionID())) {
             $vs_cookiepath = __CA_URL_ROOT__ == '' ? '/' : __CA_URL_ROOT__;
             if (!caIsRunFromCLI()) {
                 setcookie($this->name, $_COOKIE[$this->name] = $vs_session_id = $this->generateGUIDV4(), $this->lifetime ? time() + $this->lifetime : null, $vs_cookiepath);
             }
         }
         $this->sessionData = caGetCacheObject("ca_session_" . str_replace("-", "_", $vs_session_id), 0);
     }
 }
Example #5
0
/**
 *
 */
function caDetermineWebServerUser()
{
    if (!caIsRunFromCLI() && ($vs_user = caGetProcessUserName())) {
        // we're running on the web server
        return $vs_user;
    }
    if (function_exists("posix_getpwnam")) {
        // Not running in web server so try to guess
        foreach (array('apache', 'www-data', 'www', 'httpd', 'nobody') as $vs_possible_user) {
            if (posix_getpwnam($vs_possible_user)) {
                return $vs_possible_user;
            }
        }
    }
    return null;
}
Example #6
0
 /**
  * Flush content buffer and write to index
  * @throws Elasticsearch\Common\Exceptions\NoNodesAvailableException
  */
 public function flushContentBuffer()
 {
     $this->refreshMapping();
     $va_bulk_params = array();
     // @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
     // @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_indexing_documents.html#_bulk_indexing
     // delete docs
     foreach (self::$s_delete_buffer as $vs_table_name => $va_rows) {
         foreach (array_unique($va_rows) as $vn_row_id) {
             $va_bulk_params['body'][] = array('delete' => array('_index' => $this->getIndexName(), '_type' => $vs_table_name, '_id' => $vn_row_id));
             // also make sure we don't do unessecary indexing for this record below
             unset(self::$s_update_content_buffer[$vs_table_name][$vn_row_id]);
         }
     }
     // newly indexed docs
     foreach (self::$s_doc_content_buffer as $vs_key => $va_doc_content_buffer) {
         $va_tmp = explode('/', $vs_key);
         $vs_table_name = $va_tmp[0];
         $vn_primary_key = intval($va_tmp[1]);
         $va_bulk_params['body'][] = array('index' => array('_index' => $this->getIndexName(), '_type' => $vs_table_name, '_id' => $vn_primary_key));
         // add changelog to index
         $va_doc_content_buffer = array_merge($va_doc_content_buffer, caGetChangeLogForElasticSearch($this->opo_db, $this->opo_datamodel->getTableNum($vs_table_name), $vn_primary_key));
         $va_bulk_params['body'][] = $va_doc_content_buffer;
     }
     // update existing docs
     foreach (self::$s_update_content_buffer as $vs_table_name => $va_rows) {
         foreach ($va_rows as $vn_row_id => $va_fragment) {
             $va_bulk_params['body'][] = array('update' => array('_index' => $this->getIndexName(), '_type' => $vs_table_name, '_id' => (int) $vn_row_id));
             // add changelog to fragment
             $va_fragment = array_merge($va_fragment, caGetChangeLogForElasticSearch($this->opo_db, $this->opo_datamodel->getTableNum($vs_table_name), $vn_row_id));
             $va_bulk_params['body'][] = array('doc' => $va_fragment);
         }
     }
     if (sizeof($va_bulk_params['body'])) {
         $this->getClient()->bulk($va_bulk_params);
         // we usually don't need indexing to be available *immediately* unless we're running automated tests of course :-)
         if (caIsRunFromCLI() && $this->getIndexName() && (!defined('__CollectiveAccess_IS_REINDEXING__') || !__CollectiveAccess_IS_REINDEXING__)) {
             $this->getClient()->indices()->refresh(array('index' => $this->getIndexName()));
         }
     }
     $this->opa_index_content_buffer = array();
     self::$s_doc_content_buffer = array();
     self::$s_update_content_buffer = array();
     self::$s_delete_buffer = array();
 }