Пример #1
0
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;
    }
}
Пример #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 = $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);
     }
 }
Пример #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 = $o_config->get("session_lifetime");
     if (!$pb_dont_create_new_session) {
         session_save_path(__CA_APP_DIR__ . "/tmp");
         session_name($this->name);
         ini_set("session.gc_maxlifetime", $this->lifetime);
         session_set_cookie_params($this->lifetime, '/', $this->domain);
         session_start();
         $_SESSION['last_activity'] = $this->start_time;
         session_write_close();
         $this->sessionData = caGetCacheObject("ca_session_" . md5(session_id()), $this->lifetime > 0 ? $this->lifetime : 7 * 24 * 60 * 60);
     }
 }
Пример #4
0
 /**
  * Overrides base controller!
  */
 public function clearAndAddCriteria()
 {
     $o_cache = caGetCacheObject('ca_map_browser');
     $this->getDefaults();
     $this->opo_browse->setFacetGroup("map");
     $this->opo_browse->removeAllCriteria();
     $ps_facet_name = $this->request->getParameter('facet', pString);
     $vs_id = $this->request->getParameter('id', pString);
     $vs_md5_key = md5('EEMap/' . $ps_facet_name . '/' . $vs_id);
     $o_cache->load($vs_md5_key);
     if (false) {
         //($vs_content = $o_cache->load($vs_md5_key)) !== false) {
         $this->response->addContent($vs_content);
         $va_object_ids = $o_cache->load($vs_md5_key . '_id_list');
         $this->opo_result_context->setResultList($va_object_ids);
         $this->opo_result_context->saveContext();
     } else {
         $this->opo_browse->addCriteria('has_georefs', '1');
         if ($ps_facet_name) {
             $this->opo_browse->addCriteria($ps_facet_name, array($vs_id));
         }
         parent::Index(array('dontRenderView' => 1));
         $this->opo_result_context->setSearchExpression($this->opo_browse->getBrowseID());
         $this->view->setVar('current_view', 'map');
         $this->view->setVar('result_views', array('map' => 1));
         $vo_result = $this->view->getVar('result');
         $vo_result->seek(0);
         $vs_content = $this->render('Browse/map_controls_html.php');
         $vo_result->seek(0);
         $va_object_ids = array();
         while ($vo_result->nextHit()) {
             $va_object_ids[] = $vo_result->get('ca_objects.object_id');
         }
         $this->opo_result_context->setResultList($va_object_ids);
         $this->opo_result_context->saveContext();
         #$o_cache->load($vs_md5_key);
         $o_cache->save($vs_content);
         $o_cache->load($vs_md5_key . '_id_list');
         $o_cache->save($va_object_ids);
     }
 }
Пример #5
0
 /**
  *
  */
 public function GetAction()
 {
     $pn_action_id = $this->request->getParameter('action_id', pInteger);
     $pn_silo_id = $this->request->getParameter('silo_id', pInteger);
     $t_action = new ca_occurrences($pn_action_id);
     $va_action = array();
     $va_action["objects"] = $t_action->get('ca_objects', array("restrict_to_relationship_types" => array("display", "secondary"), "returnAsArray" => 1, 'checkAccess' => $this->opa_access_values));
     $va_action["label"] = $t_action->getLabelforDisplay();
     $va_action["georeference"] = $t_action->get('ca_occurrences.georeference.geocode');
     # --- get a bigger map if there are no objects to show
     if (is_array($va_action["objects"]) && sizeof($va_action["objects"]) > 0) {
         $o_map = new GeographicMap(250, 128, 'mapAction' . $pn_action_id . 'Silo' . $pn_silo_id);
     } else {
         $o_map = new GeographicMap(500, 300, 'mapAction' . $pn_action_id . 'Silo' . $pn_silo_id);
     }
     $o_map->mapFrom($t_action, "ca_occurrences.georeference.geocode");
     $vs_map = $o_map->render('HTML');
     $va_action["map"] = $vs_map;
     $va_action["description"] = $t_action->get('description');
     $va_action["occurrence_id"] = $t_action->get('occurrence_id');
     $va_action["entities"] = $t_action->get('ca_entities', array("returnAsArray" => 1, 'checkAccess' => $this->opa_access_values, 'sort' => 'surname'));
     $va_action["collections"] = $t_action->get('ca_collections', array("returnAsArray" => 1, 'checkAccess' => $this->opa_access_values));
     $va_action["occurrences"] = $t_action->get('ca_occurrences', array("returnAsArray" => 1, 'checkAccess' => $this->opa_access_values));
     $va_action["date"] = $t_action->get('date', array('template' => "^dates_value"));
     # --- get next and previous ids
     $o_cache = caGetCacheObject('MetabolicChronology', 3600);
     $va_silos = $o_cache->load('silo_list');
     $va_silo_actionmap = $va_silos[$pn_silo_id]['actionmap'];
     $pn_previous_id = "";
     $pn_next_id = "";
     foreach ($va_silo_actionmap as $i => $va_action_info) {
         if ($va_action_info["id"] == $pn_action_id) {
             $pn_previous_id = $va_silo_actionmap[$i - 1]["id"];
             $pn_next_id = $va_silo_actionmap[$i + 1]["id"];
             break;
         }
     }
     $this->view->setVar('previous_id', $pn_previous_id);
     $this->view->setVar('next_id', $pn_next_id);
     $this->view->setVar('action', $va_action);
     $this->view->setVar('silo_id', $pn_silo_id);
     $this->render('action_info_html.php');
 }
Пример #6
0
 /**
  * Set current job_id
  * 
  * @return string The job_id that was set
  */
 public function setJobID($ps_job_id)
 {
     $this->ops_job_id = $ps_job_id;
     if ($this->opo_cache = caGetCacheObject('caProgressBar', 3600 * 24)) {
         // load values from store
         if (is_array($va_data = $this->opo_cache->load($ps_job_id))) {
             $this->setTotal($va_data['total']);
         }
     }
     return $ps_job_id;
 }
 /**
  * Overrides base controller!
  */
 public function clearAndAddCriteria()
 {
     $o_cache = caGetCacheObject('ca_artists_browser');
     $this->getDefaults();
     $this->opo_browse->removeAllCriteria();
     $ps_facet_name = $this->request->getParameter('facet', pString);
     $vs_id = $this->request->getParameter('id', pString);
     $vs_md5_key = md5('EEartistBrowser/' . $ps_facet_name . '/' . $vs_id);
     if (($vs_content = $o_cache->load($vs_md5_key)) !== false) {
         $this->response->addContent($vs_content);
         $va_entity_ids = $o_cache->load($vs_md5_key . '_id_list');
         $this->opo_result_context->setResultList($va_entity_ids);
         $this->opo_result_context->saveContext();
     } else {
         $this->opo_browse->addCriteria('_search', 'ca_entities.source_id:' . $this->aoee_featured_source . ' or ca_entities.source_id:' . $this->aoee_source . ' or ca_entities.source_id:' . $this->aoee_priority_source);
         if ($ps_facet_name) {
             $this->opo_browse->addCriteria($ps_facet_name, array($vs_id));
         }
         $this->view->setVar('result_views', array('full'));
         parent::Index(true);
         $vo_result = $this->view->getVar('result');
         $vo_result->seek(0);
         $vs_content = $this->render('Browse/browse_controls_html.php', true);
         $vo_result->seek(0);
         $va_entity_ids = array();
         while ($vo_result->nextHit()) {
             $va_entity_ids[] = $vo_result->get('ca_entities.entity_id');
         }
         $this->opo_result_context->setResultList($va_entity_ids);
         $this->opo_result_context->saveContext();
         #$o_cache->load($vs_md5_key);
         $o_cache->save($vs_content);
         $o_cache->load($vs_md5_key . '_id_list');
         $o_cache->save($va_entity_ids);
     }
 }
Пример #8
0
 /**
  *
  */
 public static function _getCacheObject()
 {
     $o_config = Configuration::load();
     return caGetCacheObject('ca_browse_' . $o_config->get('app_name'));
 }
Пример #9
0
 /**
  * Stores a new resumption token record in the database
  *
  * @param string $verb OAI-PMH verb for the request
  * @param string $metadataPrefix Metadata prefix
  * @param int $cursor Offset in response to begin output at
  * @param mixed $set Optional set argument
  * @param string $from Optional from date argument
  * @param string $until Optional until date argument
  * @return array resumption token info
  */
 private function createResumptionToken($verb, $metadataPrefix, $cursor, $set, $from, $until)
 {
     $o_cache = caGetCacheObject('ca_oai_provider_' . $this->ops_provider);
     $va_token_info = array('verb' => $verb, 'metadata_prefix' => $metadataPrefix, 'cursor' => $cursor, 'set' => $set ? $set : null, 'from' => $from ? $from : null, 'until' => $until ? $until : null, 'expiration' => time() + $this->_tokenExpirationTime * 60);
     $vs_key = md5(print_r($va_token_info, true) . '/' . time() . '/' . rand(0, 1000000));
     $va_token_info['key'] = $vs_key;
     $o_cache->save($va_token_info, $vs_key);
     return $va_token_info;
 }
Пример #10
0
 /**
  *
  */
 private static function _loadData()
 {
     $vn_year = date("Y");
     $vn_day = date("j");
     // Does data exist in cache? Is it current?
     $o_cache = caGetCacheObject('ca_currency_conversion', 60 * 60 * 24);
     if (is_array($va_data = $o_cache->load('data')) && $va_data['year'] == $vn_year && $va_data['day'] == $vn_day) {
         return $va_data['rates'];
     }
     // Load data from source
     if ($vs_data = @file_get_contents(WLPlugCurrencyConversionEuroBank::CONVERSION_SERVICE_URL)) {
         if (!($o_data = new SimpleXMLElement($vs_data))) {
             throw new Exception(_t("Cannot parse data from %1", WLPlugCurrencyConversionEuroBank::CONVERSION_SERVICE_URL));
             return null;
         }
         $va_data = array('rates' => array(), 'year' => $vn_year, 'day' => $vn_day);
         foreach ($o_data->Cube->Cube->children() as $o_currency) {
             $o_attributes = $o_currency->attributes();
             $vs_currency = (string) $o_attributes->currency;
             $vn_rate = (string) $o_attributes->rate;
             $va_data['rates'][$vs_currency] = $vn_rate;
         }
         $va_data['rates']['EUR'] = 1.0;
         // add Euro to list
         if ($o_cache) {
             $o_cache->save($va_data, 'data');
         }
         return $va_data['rates'];
     }
     throw new Exception(_t("Cannot fetch data from %1", WLPlugCurrencyConversionEuroBank::CONVERSION_SERVICE_URL));
     return null;
 }
Пример #11
0
/**
 *
 *
 * @return array
 */
function caGetPrintTemplateDetails($ps_type, $ps_template, $pa_options = null)
{
    $vs_template_path = caGetPrintTemplateDirectoryPath($ps_type);
    if (file_exists("{$vs_template_path}/local/{$ps_template}.php")) {
        $vs_template_path = "{$vs_template_path}/local/{$ps_template}.php";
    } elseif (file_exists("{$vs_template_path}/{$ps_template}.php")) {
        $vs_template_path = "{$vs_template_path}/{$ps_template}.php";
    } else {
        return false;
    }
    if ($o_cache = caGetCacheObject('caPrintTemplatesList_' . $ps_type)) {
        $vs_cache_key = caMakeCacheKeyFromOptions($pa_options, $ps_type . '/' . $vs_template_path);
        if (($va_info = $o_cache->load($vs_cache_key)) && ($vn_mtime = $o_cache->load("{$vs_cache_key}_mtime")) >= filemtime($vs_template_path)) {
            return $va_info;
        }
    }
    $vs_template = file_get_contents($vs_template_path);
    $va_info = array();
    foreach (array("@name", "@type", "@pageSize", "@pageOrientation", "@tables", "@marginLeft", "@marginRight", "@marginTop", "@marginBottom", "@horizontalGutter", "@verticalGutter", "@labelWidth", "@labelHeight") as $vs_tag) {
        if (preg_match("!{$vs_tag}([^\n\n]+)!", $vs_template, $va_matches)) {
            $va_info[str_replace("@", "", $vs_tag)] = trim($va_matches[1]);
        } else {
            $va_info[str_replace("@", "", $vs_tag)] = null;
        }
    }
    $va_info['tables'] = preg_split("![,;]{1}!", $va_info['tables']);
    $va_info['path'] = $vs_template_path;
    if ($o_cache) {
        $o_cache->save($va_info, $vs_cache_key);
        $o_cache->save(filemtime($vs_template_path), "{$vs_cache_key}_mtime");
    }
    return $va_info;
}
Пример #12
0
 /**
  * Returns the most recently viewed items, up to a maximum of $pn_limit (default is 10)
  * Note that the limit is just that – a limit. getRecentlyViewedItems() may return fewer
  * than the limit either because there fewer viewed items than your limit or because fetching
  * additional views would take too long. (To ensure adequate performance getRecentlyViewedItems() uses a cache of 
  * recent views. If there is no cache available it will query the database to look at the most recent (4 x your limit) viewings. 
  * If there are many views of the same item in that group then it is possible that fewer items than your limit will be returned)
  *
  * @param int $pn_limit The maximum number of items to return. Default is 10.
  * @param array $pa_options Supported options are:
  *		restrictToTypes = array of type names or type_ids to restrict to. Only items with a type_id in the list will be returned.
  *		checkAccess = array of access values to filter results by; if defined only items with the specified access code(s) are returned
  *		hasRepresentations = if set to a non-zero (boolean true) value only items with representations will be returned
  *		dontUseCache = if set to true, forces list to be generated from database; default is false.
  * @return array List of primary key values for recently viewed items.
  */
 public function getRecentlyViewedItems($pn_limit = 10, $pa_options = null)
 {
     if (!isset($pa_options['dontUseCache']) || !$pa_options['dontUseCache']) {
         $o_cache = caGetCacheObject("caRecentlyViewedCache");
         $va_recently_viewed_items = $o_cache->load('recentlyViewed');
         $vn_table_num = $this->tableNum();
         if (is_array($va_recently_viewed_items) && is_array($va_recently_viewed_items[$vn_table_num])) {
             if (sizeof($va_recently_viewed_items[$vn_table_num]) > $pn_limit) {
                 $va_recently_viewed_items[$vn_table_num] = array_slice($va_recently_viewed_items[$vn_table_num], 0, $pn_limit);
             }
             return $va_recently_viewed_items[$vn_table_num];
         }
     }
     $o_db = $this->getDb();
     $vs_limit_sql = '';
     if ($pn_limit > 0) {
         $vs_limit_sql = "LIMIT " . intval($pn_limit) * 4;
     }
     $va_wheres = array('(civ.table_num = ' . intval($this->tableNum()) . ')');
     if (is_array($pa_options['checkAccess']) && sizeof($pa_options['checkAccess']) && $this->hasField('access')) {
         $va_wheres[] = 't.access IN (' . join(',', $pa_options['checkAccess']) . ')';
     }
     if (method_exists($this, 'getTypeFieldName') && ($vs_type_field_name = $this->getTypeFieldName())) {
         $va_types = caMergeTypeRestrictionLists($this, $pa_options);
         if (is_array($va_types) && sizeof($va_types)) {
             $va_wheres[] = 't.' . $vs_type_field_name . ' IN (' . join(',', $va_types) . ')';
         }
     }
     $vs_join_sql = '';
     if (isset($pa_options['hasRepresentations']) && $pa_options['hasRepresentations'] && $this->tableName() == 'ca_objects') {
         $vs_join_sql = ' INNER JOIN ca_objects_x_object_representations ON ca_objects_x_object_representations.object_id = t.object_id';
         $va_wheres[] = 'ca_objects_x_object_representations.is_primary = 1';
     }
     if ($this->hasField('deleted')) {
         $va_wheres[] = "(t.deleted = 0)";
     }
     if ($vs_where_sql = join(' AND ', $va_wheres)) {
         $vs_where_sql = ' WHERE ' . $vs_where_sql;
     }
     $qr_res = $o_db->query($vs_sql = "\n\t\t\tSELECT t." . $this->primaryKey() . "\n \t\t\tFROM " . $this->tableName() . " t\n \t\t\tINNER JOIN ca_item_views AS civ ON civ.row_id = t." . $this->primaryKey() . "\n \t\t\t{$vs_join_sql}\n\t\t\t{$vs_where_sql}\n\t\t\tORDER BY\n\t\t\t\tciv.view_id DESC\n\t\t\t{$vs_limit_sql}\n\t\t");
     $va_recently_viewed_items = array();
     $vn_c = 0;
     while ($qr_res->nextRow() && $vn_c < $pn_limit) {
         if (!isset($va_recently_viewed_items[$vn_id = $qr_res->get($this->primaryKey())])) {
             $va_recently_viewed_items[$vn_id] = true;
             $vn_c++;
         }
     }
     return array_keys($va_recently_viewed_items);
 }