public function DoLogin() { global $g_ui_locale; $vs_redirect_url = $this->request->getParameter('redirect', pString) ?: caNavUrl($this->request, null, null, null); if (!$this->request->doAuthentication(array('dont_redirect_to_login' => true, 'redirect' => $vs_redirect_url, 'noPublicUsers' => true, 'user_name' => $this->request->getParameter('username', pString), 'password' => $this->request->getParameter('password', pString)))) { $this->notification->addNotification(_t("Login was invalid"), __NOTIFICATION_TYPE_ERROR__); $this->view->setVar('notifications', $this->notification->getNotifications()); if (isset($_COOKIE['CA_' . __CA_APP_NAME__ . '_ui_locale'])) { if (!initializeLocale($_COOKIE['CA_' . __CA_APP_NAME__ . '_ui_locale'])) { die("Error loading locale " . $g_ui_locale); } } $this->render('login_html.php'); } else { // // Reset locale globals // global $g_ui_locale_id, $g_ui_locale, $g_ui_units_pref, $_, $_locale; $g_ui_locale_id = $this->request->user->getPreferredUILocaleID(); // get current UI locale as locale_id (available as global) $g_ui_locale = $this->request->user->getPreferredUILocale(); // get current UI locale as locale string (available as global) $g_ui_units_pref = $this->request->user->getPreference('units'); // user's selected display units for measurements (available as global) if (!initializeLocale($g_ui_locale)) { die("Error loading locale " . $g_ui_locale); } MemoryCache::flush('translation'); AppNavigation::clearMenuBarCache($this->request); // want to clear menu bar on login // Notify the user of the good news $this->notification->addNotification(_t("You are now logged in"), __NOTIFICATION_TYPE_INFO__); // Jump to redirect if set if ($vs_redirect_url) { $this->redirect($vs_redirect_url); } $this->render('welcome_html.php'); } }
public function Save() { $vs_view_name = 'preferences_html.php'; $vs_action = $this->request->getParameter('action', pString); switch ($vs_action) { case 'EditCataloguingPrefs': $vs_group = 'cataloguing'; $this->request->user->setPreference('cataloguing_locale', $this->request->getParameter('pref_cataloguing_locale', pString)); $va_ui_prefs = array(); foreach ($this->request->user->getValidPreferences($vs_group) as $vs_pref) { foreach ($_REQUEST as $vs_k => $vs_v) { if (preg_match("!pref_{$vs_pref}_([\\d]+)!", $vs_k, $va_matches)) { $va_ui_prefs[$vs_pref][$va_matches[1]] = $vs_v; } elseif (preg_match("!pref_{$vs_pref}__NONE_!", $vs_k)) { $va_ui_prefs[$vs_pref]['_NONE_'] = $vs_v; } } foreach ($va_ui_prefs as $vs_pref => $va_values) { $this->request->user->setPreference($vs_pref, $va_values); } } $vs_view_name = 'preferences_cataloguing_html.php'; break; case 'EditBatchPrefs': $vs_group = 'batch'; $va_ui_prefs = array(); foreach ($this->request->user->getValidPreferences($vs_group) as $vs_pref) { foreach ($_REQUEST as $vs_k => $vs_v) { if (preg_match("!pref_{$vs_pref}!", $vs_k, $va_matches)) { $this->request->user->setPreference($vs_pref, $vs_v); } } } $vs_view_name = 'preferences_batch_html.php'; break; case 'EditQuickAddPrefs': $vs_group = 'quickadd'; $va_ui_prefs = array(); foreach ($this->request->user->getValidPreferences($vs_group) as $vs_pref) { foreach ($_REQUEST as $vs_k => $vs_v) { if (preg_match("!pref_{$vs_pref}_([\\d]+)!", $vs_k, $va_matches)) { $va_ui_prefs[$vs_pref][$va_matches[1]] = $vs_v; } } foreach ($va_ui_prefs as $vs_pref => $va_values) { $this->request->user->setPreference($vs_pref, $va_values); } } $vs_view_name = 'preferences_quickadd_html.php'; break; case 'EditMediaPrefs': $vs_group = 'media'; foreach ($this->request->user->getValidPreferences($vs_group) as $vs_pref) { $this->request->user->setPreference($vs_pref, $this->request->getParameter('pref_' . $vs_pref, pString)); } break; case 'EditUnitsPrefs': $vs_group = 'units'; foreach ($this->request->user->getValidPreferences($vs_group) as $vs_pref) { $this->request->user->setPreference($vs_pref, $this->request->getParameter('pref_' . $vs_pref, pString)); } break; case 'EditProfilePrefs': $vs_group = 'profile'; foreach ($this->request->user->getValidPreferences($vs_group) as $vs_pref) { $this->request->user->setPreference($vs_pref, $this->request->getParameter('pref_' . $vs_pref, pString)); } break; case 'EditDuplicationPrefs': $vs_group = 'duplication'; foreach (array('ca_objects', 'ca_object_lots', 'ca_entities', 'ca_places', 'ca_occurrences', 'ca_collections', 'ca_storage_locations', 'ca_loans', 'ca_movements', 'ca_lists', 'ca_list_items', 'ca_tours', 'ca_tour_stops', 'ca_sets', 'ca_bundle_displays') as $vs_table) { foreach ($this->request->user->getValidPreferences($vs_group) as $vs_pref) { if ($vs_pref == 'duplicate_relationships') { $vs_val = $this->request->getParameter("pref_{$vs_table}_{$vs_pref}", pArray); } else { $vs_val = $this->request->getParameter("pref_{$vs_table}_{$vs_pref}", pString); } $this->request->user->setPreference("{$vs_table}_{$vs_pref}", $vs_val); } } $vs_view_name = 'preferences_duplication_html.php'; break; case 'EditUIPrefs': default: $vs_group = 'ui'; $vs_action = 'EditUIPrefs'; foreach ($this->request->user->getValidPreferences($vs_group) as $vs_pref) { $this->request->user->setPreference($vs_pref, $vs_locale = $this->request->getParameter('pref_' . $vs_pref, pString)); if ($vs_pref == 'ui_locale' && $vs_locale) { global $_, $g_ui_locale_id, $g_ui_locale, $_locale; // set UI locale for this request (causes UI language to change immediately - and in time - for this request) // if we didn't do this, you'd have to reload the page to see the locale change $this->request->user->setPreference('ui_locale', $vs_locale); $g_ui_locale_id = $this->request->user->getPreferredUILocaleID(); // get current UI locale as locale_id (available as global) $g_ui_locale = $this->request->user->getPreferredUILocale(); // get current UI locale as locale string (available as global) if (!initializeLocale($g_ui_locale)) { die("Error loading locale " . $g_ui_locale); } MemoryCache::flush('translation'); // reload menu bar AppNavigation::clearMenuBarCache($this->request); } if ($vs_pref == 'ui_theme') { // set the view path to use the new theme; if we didn't set this here you'd have to reload the page to // see the theme change. $this->view->setViewPath($this->request->getViewsDirectoryPath() . '/' . $this->request->getModulePath()); } } break; } $this->request->setAction($vs_action); $this->view->setVar('group', $vs_group); $this->notification->addNotification(_t("Saved preference settings"), __NOTIFICATION_TYPE_INFO__); $this->view->setVar('t_user', $this->request->user); $this->render($vs_view_name); }
require_once __CA_LIB_DIR__ . '/core/Datamodel.php'; require_once __CA_LIB_DIR__ . '/core/Configuration.php'; require_once __CA_LIB_DIR__ . '/core/Parsers/ZipFile.php'; require_once __CA_LIB_DIR__ . '/core/Logging/Eventlog.php'; require_once __CA_LIB_DIR__ . '/core/Utils/Encoding.php'; require_once __CA_LIB_DIR__ . '/core/Zend/Measure/Length.php'; # ---------------------------------------------------------------------- # String localization functions (getText) # ---------------------------------------------------------------------- /** * Translates the string in $ps_key into the current locale * You interpolate values into the returned string by embedding numbered placeholders in $ps_key * in the format %n (where n is a number). Each parameter passed after $ps_key corresponds to a * placeholder (ex. the first parameter replaces %1, the second %2) */ MemoryCache::flush('translation'); function _t($ps_key) { if (!$ps_key) { return ''; } global $_; if (!MemoryCache::contains($ps_key, 'translation')) { if (is_array($_)) { $vs_str = $ps_key; foreach ($_ as $o_locale) { if ($o_locale->isTranslated($ps_key)) { $vs_str = $o_locale->_($ps_key); break; } }
public function testFlushDifferentNS() { $vm_ret = MemoryCache::save('foo', 'data1', 'barNamespace'); $this->assertTrue($vm_ret, 'Setting item in cache should return true'); $vm_ret = MemoryCache::save('bar', 'data2'); $this->assertTrue($vm_ret, 'Setting item in cache should return true'); MemoryCache::flush('default'); $vm_ret = MemoryCache::contains('bar'); $this->assertFalse($vm_ret, 'Item should be gone after flushing default namespace.'); $vm_ret = MemoryCache::contains('foo', 'barNamespace'); $this->assertTrue($vm_ret, 'Item should still be there after flushing different namespace'); }
/** * Removes all cached configuration */ public static function clearCache() { ExternalCache::flush(); MemoryCache::flush(); }
/** * Generate hierarchical values for using in indexing of hierarchical values with INDEX_ANCESTORS enabled */ private function _genHierarchicalPath($pn_subject_row_id, $ps_field, $t_subject, $pa_options = null) { $vs_key = caMakeCacheKeyFromOptions($pa_options, "{$pn_subject_row_id}/{$ps_field}"); if (MemoryCache::contains($vs_key, 'SearchIndexerHierPaths')) { return MemoryCache::fetch($vs_key, 'SearchIndexerHierPaths'); } $pn_start = caGetOption('INDEX_ANCESTORS_START_AT_LEVEL', $pa_options, 0); $pn_max_levels = caGetOption('INDEX_ANCESTORS_MAX_NUMBER_OF_LEVELS', $pa_options, null); $ps_delimiter = caGetOption('INDEX_ANCESTORS_AS_PATH_WITH_DELIMITER', $pa_options, '; '); // Automagically generate hierarchical paths for preferred labels passed as label table + label field if (is_subclass_of($t_subject, "BaseLabel")) { if (!($t_subject->getPrimaryKey() == $pn_subject_row_id)) { $t_subject->load($pn_subject_row_id); } $pn_subject_row_id = $t_subject->get($t_subject->getSubjectKey()); $t_subject = $t_subject->getSubjectTableInstance(); $ps_field = "preferred_labels.{$ps_field}"; } $va_ids = $t_subject->getHierarchyAncestors($pn_subject_row_id, array('idsOnly' => true, 'includeSelf' => true)); $vs_subject_tablename = $t_subject->tableName(); if (is_array($va_ids) && sizeof($va_ids) > 0) { $qr_hier_res = $t_subject->makeSearchResult($vs_subject_tablename, $va_ids, array('db' => $this->getDb())); $va_hier_values = array(); while ($qr_hier_res->nextHit()) { if ($vs_v = $qr_hier_res->get($vs_subject_tablename . "." . $ps_field)) { $va_hier_values[] = $vs_v; } } $va_hier_values = array_reverse($va_hier_values); if ($pn_start > 0) { $va_hier_values = array_slice($va_hier_values, $pn_start); } if ($pn_max_levels > 0) { $va_hier_values = array_slice($va_hier_values, 0, $pn_max_levels); } if (MemoryCache::itemCountForNamespace('SearchIndexerHierPaths') > 100) { MemoryCache::flush('SearchIndexerHierPaths'); } $va_return = array('values' => $va_hier_values, 'path' => join($ps_delimiter, $va_hier_values)); MemoryCache::save($vs_key, $va_return, 'SearchIndexerHierPaths'); return $va_return; } MemoryCache::save($vs_key, null, 'SearchIndexerHierPaths'); return null; }
/** * Flush whole cache, both in-memory and on-disk. Use with caution! */ public static function flush() { MemoryCache::flush(); ExternalCache::flush(); }