/**
  * Sets and saves form element settings, taking parameters off of the request as needed. Does an update()
  * on the ca_search_forms instance to save settings to the database
  */
 public function setSettingsFromHTMLForm($po_request, $pa_options = null)
 {
     $va_locales = ca_locales::getLocaleList(array('sort_field' => '', 'sort_order' => 'asc', 'index_by_code' => true, 'available_for_cataloguing_only' => true));
     $va_available_settings = $this->getAvailableSettings();
     $this->o_instance->setMode(ACCESS_WRITE);
     $va_values = array();
     $vs_id_prefix = caGetOption('id', $pa_options, 'setting');
     $vs_placement_code = caGetOption('placement_code', $pa_options, '');
     foreach (array_keys($va_available_settings) as $vs_setting) {
         $va_properties = $va_available_settings[$vs_setting];
         if (isset($va_properties['takesLocale']) && $va_properties['takesLocale']) {
             foreach ($va_locales as $vs_locale => $va_locale_info) {
                 $va_values[$vs_setting][$va_locale_info['locale_id']] = $po_request->getParameter("{$vs_placement_code}{$vs_id_prefix}{$vs_setting}_{$vs_locale}", pString);
             }
         } else {
             if (isset($va_properties['useRelationshipTypeList']) && $va_properties['useRelationshipTypeList'] && $va_properties['height'] > 1 || isset($va_properties['useList']) && $va_properties['useList'] && $va_properties['height'] > 1 || isset($va_properties['showLists']) && $va_properties['showLists'] && $va_properties['height'] > 1 || isset($va_properties['showVocabularies']) && $va_properties['showVocabularies'] && $va_properties['height'] > 1) {
                 $va_values[$vs_setting] = $po_request->getParameter("{$vs_placement_code}{$vs_id_prefix}{$vs_setting}", pArray);
             } else {
                 $va_values = array($vs_setting => $po_request->getParameter("{$vs_placement_code}{$vs_id_prefix}{$vs_setting}", pString));
             }
         }
         foreach ($va_values as $vs_setting_key => $vs_value) {
             $this->setSetting($vs_setting, $vs_value);
         }
     }
     return true;
 }
 /**
  * 
  * 
  * @param string $ps_source MySQL URL
  * @param array $pa_options
  * @return bool
  */
 public function read($ps_source, $pa_options = null)
 {
     parent::read($ps_source, $pa_options);
     # mysql://username:password@localhost/database?table=tablename
     # or limit the query using
     # mysql://username:password@localhost/database?table=tablename&limit=100&offset=10
     $va_url = parse_url($ps_source);
     try {
         $vs_db = substr($va_url['path'], 1);
         $this->opo_handle = new Db(null, array("username" => $va_url['user'], "password" => $va_url['pass'], "host" => $va_url['host'], "database" => $vs_db, "type" => 'mysql'));
         $this->opn_current_row = 0;
         parse_str($va_url['query'], $va_path);
         $this->ops_table = $va_path['table'];
         if (!$this->ops_table) {
             return false;
         }
         $vn_limit = caGetOption('limit', $va_path, 0, array('castTo' => 'int'));
         $vn_offset = caGetOption('offset', $va_path, 0, array('castTo' => 'int'));
         $vs_limit = $vn_limit ? " LIMIT " . ($vn_offset ? "{$vn_offset}, {$vn_limit}" : $vn_limit) : "";
         $this->opo_rows = $this->opo_handle->query("SELECT * FROM {$this->ops_table}{$vs_limit}");
     } catch (Exception $e) {
         return false;
     }
     return true;
 }
 public function processExport($pa_data, $pa_options = array())
 {
     if (!caGetOption('singleRecord', $pa_options, true)) {
         throw new Exception("The ExifTool exporter does not support exporting multiple records");
     }
     $o_rdf = $this->getDom()->createElementNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdf:RDF');
     $this->getDom()->appendChild($o_rdf);
     $o_desc = $this->getDom()->createElement('rdf:Description');
     $o_rdf->appendChild($o_desc);
     // add full range of exiftool namespaces
     foreach ($this->opa_namespaces as $vs_ns_key => $vs_ns_url) {
         $o_desc->setAttributeNS('http://www.w3.org/2000/xmlns/', $vs_ns_key, $vs_ns_url);
     }
     $o_desc->setAttribute('et:toolkit', 'CollectiveAccess ExifTool Exporter');
     $this->log("ExifTool export formatter: Now processing export tree ...");
     foreach ($pa_data as $va_element) {
         if (!isset($va_element['element']) || !$va_element['element'] || !isset($va_element['text']) || !$va_element['text']) {
             $this->log("ExifTool export formatter: Skipped row because either element or text was empty. Element in tree was:");
             $this->log(print_r($va_element, true));
             continue;
         }
         $o_element = $this->getDom()->createElement($va_element['element'], $va_element['text']);
         $o_desc->appendChild($o_element);
     }
     $this->log("ExifTool export formatter: Done processing export tree ...");
     return $this->getDom()->saveXML();
 }
 /**
  *
  *
  * @param string $ps_cache_key
  * @param array $pa_options Options include:
  *		removeDeletedItems = remove any items in the cache that are currently marked as deleted [Default=true]
  *
  * @return bool
  */
 public function load($ps_cache_key, $pa_options = null)
 {
     if (ExternalCache::contains($ps_cache_key, 'Browse')) {
         $this->opa_browse = ExternalCache::fetch($ps_cache_key, 'Browse');
         $this->ops_cache_key = $ps_cache_key;
         if (caGetOption('removeDeletedItems', $pa_options, true)) {
             $o_dm = Datamodel::load();
             if (($t_instance = $o_dm->getInstanceByTableNum($this->opa_browse['params']['table_num'], true)) && $t_instance->hasField('deleted')) {
                 // check if there are any deleted items in the cache
                 if (is_array($va_ids = $this->opa_browse['results']) && sizeof($va_ids)) {
                     $vs_pk = $t_instance->primaryKey();
                     $qr_deleted = $t_instance->getDb()->query($x = "\n\t\t\t\t\t\t\tSELECT {$vs_pk} FROM " . $t_instance->tableName() . " WHERE {$vs_pk} IN (?) AND deleted = 1\n\t\t\t\t\t\t", array($va_ids));
                     if ($qr_deleted->numRows() > 0) {
                         $va_deleted_ids = $qr_deleted->getAllFieldValues($vs_pk);
                         foreach ($va_deleted_ids as $vn_deleted_id) {
                             if (($vn_i = array_search($vn_deleted_id, $va_ids)) !== false) {
                                 unset($va_ids[$vn_i]);
                             }
                         }
                         $this->opa_browse['results'] = array_values($va_ids);
                     }
                 }
             }
         }
         return true;
     }
     return false;
 }
 /**
  * Options:
  * 		rawDate - if true, returns date as an array of start and end historic timestames
  *		sortable - if true a language-independent sortable representation is returned.
  *		getDirectDate - get underlying historic timestamp (floatval)
  */
 public function getDisplayValue($pa_options = null)
 {
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     if (isset($pa_options['rawDate']) && $pa_options['rawDate']) {
         return array(0 => $this->opn_start_date, 1 => $this->opn_end_date, 'start' => $this->opn_start_date, 'end' => $this->opn_end_date);
     }
     if (caGetOption('GET_DIRECT_DATE', $pa_options, false) || caGetOption('getDirectDate', $pa_options, false)) {
         return $this->opn_start_date;
     }
     if (isset($pa_options['sortable']) && $pa_options['sortable']) {
         if (!$this->opn_start_date || !$this->opn_end_date) {
             return null;
         }
         return $this->opn_start_date . '/' . $this->opn_end_date;
     }
     $o_config = Configuration::load();
     $o_date_config = Configuration::load($o_config->get('datetime_config'));
     if ($o_date_config->get('dateFormat') == 'original') {
         return $this->ops_text_value;
     } else {
         $t_element = new ca_metadata_elements($this->getElementID());
         $va_settings = $this->getSettingValuesFromElementArray($t_element->getFieldValuesArray(), array('isLifespan'));
         $o_tep = new TimeExpressionParser();
         $o_tep->setHistoricTimestamps($this->opn_start_date, $this->opn_end_date);
         return $o_tep->getText(array_merge(array('isLifespan' => $va_settings['isLifespan']), $pa_options));
         //$this->ops_text_value;
     }
 }
 public function dispatchLoopShutdown()
 {
     //
     // Force output to be sent - we need the client to have the page before
     // we start flushing progress bar updates
     //
     $app = AppController::getInstance();
     $req = $app->getRequest();
     $resp = $app->getResponse();
     $resp->sendResponse();
     $resp->clearContent();
     //
     // Do batch processing
     //
     if ($req->isLoggedIn()) {
         set_time_limit(3600 * 24);
         // if it takes more than 24 hours we're in trouble
         if (isset($_FILES['sourceFile']['tmp_name']) && $_FILES['sourceFile']['tmp_name']) {
             $vs_input = $_FILES['sourceFile']['tmp_name'];
         } elseif (!($vs_input = $req->getParameter('sourceUrl', pString))) {
             $vs_input = $req->getParameter('sourceText', pString);
         }
         $vs_file_input = caGetOption('fileInput', $this->opa_options, null);
         $vs_base_import_dir = $req->config->get('batch_media_import_root_directory');
         $vs_file_import_directory = caGetOption('fileImportPath', $this->opa_options, null);
         if ($vs_file_input === 'import' && is_dir($vs_base_import_dir . '/' . $vs_file_import_directory)) {
             // grab files from import directory
             $vs_input = $vs_base_import_dir . '/' . $vs_file_import_directory;
         }
         $va_errors = BatchProcessor::importMetadata($req, $vs_input, $req->getParameter('importer_id', pInteger), $req->getParameter('inputFormat', pString), array_merge($this->opa_options, array('progressCallback' => 'caIncrementBatchMetadataImportProgress', 'reportCallback' => 'caUpdateBatchMetadataImportResultsReport')));
     }
 }
Exemple #7
0
 /**
  * Generate maps output in specified format
  *
  * @param array $pa_viz_settings Array of visualization settings taken from visualization.conf
  * @param string $ps_format Specifies format to generate output in. Currently only 'HTML' is supported.
  * @param array $pa_options Array of options to use when rendering output. Supported options are:
  *		width =
  *		height =
  *		mapType - type of map to render; valid values are 'ROADMAP', 'SATELLITE', 'HYBRID', 'TERRAIN'; if not specified 'google_maps_default_type' setting in app.conf is used; if that is not set default is 'SATELLITE'
  *		showNavigationControls - if true, navigation controls are displayed; default is to use 'google_maps_show_navigation_controls' setting in app.conf
  *		showScaleControls -  if true, scale controls are displayed; default is to use 'google_maps_show_scale_controls' setting in app.conf
  *		showMapTypeControls -  if true, map type controls are displayed; default is to use 'google_maps_show_map_type_controls' setting in app.conf
  *		minZoomLevel - Minimum zoom level to allow; leave null if you don't want to enforce a limit
  *		maxZoomLevel - Maximum zoom level to allow; leave null if you don't want to enforce a limit
  *		zoomLevel - Zoom map to specified level rather than fitting all markers into view; leave null if you don't want to specify a zoom level. IF this option is set minZoomLevel and maxZoomLevel will be ignored.
  *		pathColor - 
  *		pathWeight -
  *		pathOpacity - 
  *		request = current request; required for generation of editor links
  */
 public function render($pa_viz_settings, $ps_format = 'HTML', $pa_options = null)
 {
     if (!($vo_data = $this->getData())) {
         return null;
     }
     $po_request = isset($pa_options['request']) && $pa_options['request'] ? $pa_options['request'] : null;
     list($vs_width, $vs_height) = $this->_parseDimensions(caGetOption('width', $pa_options, 500), caGetOption('height', $pa_options, 500));
     $o_map = new GeographicMap($vs_width, $vs_height, $pa_options['id']);
     $this->opn_num_items_rendered = 0;
     foreach ($pa_viz_settings['sources'] as $vs_source_code => $va_source_info) {
         $vs_color = $va_source_info['color'];
         if (method_exists($vo_data, "seek")) {
             $vo_data->seek(0);
         }
         $va_opts = array('renderLabelAsLink' => false, 'request' => $po_request, 'color' => $vs_color);
         $va_opts['labelTemplate'] = $va_source_info['display']['title_template'];
         if (isset($va_source_info['display']['ajax_content_url']) && $va_source_info['display']['ajax_content_url']) {
             $va_opts['ajaxContentUrl'] = $va_source_info['display']['ajax_content_url'];
         } else {
             $va_opts['contentTemplate'] = $va_source_info['display']['description_template'];
         }
         $va_ret = $o_map->mapFrom($vo_data, $va_source_info['data'], $va_opts);
         if (is_array($va_ret) && isset($va_ret['items'])) {
             $this->opn_num_items_rendered += (int) $va_ret['items'];
         }
     }
     return $o_map->render($ps_format, $pa_options);
 }
 public function __call($ps_function, $pa_args)
 {
     $ps_function = strtolower($ps_function);
     if (!($va_form_info = $this->_checkForm($ps_function))) {
         return;
     }
     $this->view->setVar('t_subject', $t_subject = $this->pt_subject);
     $va_tags = $this->view->getTagList($va_form_info['view']);
     foreach ($va_tags as $vs_tag) {
         if (in_array($vs_tag, array('form', '/form', 'submit', 'reset'))) {
             continue;
         }
         $va_parse = caParseTagOptions($vs_tag);
         $vs_tag_proc = $va_parse['tag'];
         $va_opts = $va_parse['options'];
         if (($vs_default_value = caGetOption('default', $va_opts, null)) || ($vs_default_value = caGetOption($vs_tag_proc, $va_default_form_values, null))) {
             $va_default_form_values[$vs_tag_proc] = $vs_default_value;
             unset($va_opts['default']);
         }
         $vs_tag_val = null;
         switch (strtolower($vs_tag_proc)) {
             case 'submit':
                 $this->view->setVar($vs_tag, "<a href='#' class='caContributeFormSubmit'>" . (isset($va_opts['label']) && $va_opts['label'] ? $va_opts['label'] : _t('Submit')) . "</a>");
                 break;
             case 'reset':
                 $this->view->setVar($vs_tag, "<a href='#' class='caContributeFormReset'>" . (isset($va_opts['label']) && $va_opts['label'] ? $va_opts['label'] : _t('Reset')) . "</a>");
                 $vs_script = "<script type='text/javascript'>\n\tjQuery('.caContributeFormSubmit').bind('click', function() {\n\t\tjQuery('#caContribute').submit();\n\t\treturn false;\n\t});\n\tjQuery('.caContributeFormReset').bind('click', function() {\n\t\tjQuery('#caContribute').find('input[type!=\"hidden\"],textarea').val('');\n\t\tjQuery('#caContribute').find('select.caContributeBoolean').val('AND');\n\t\tjQuery('#caContribute').find('select').prop('selectedIndex', 0);\n\t\treturn false;\n\t});\n\tjQuery(document).ready(function() {\n\t\tvar f, defaultValues = " . json_encode($va_default_form_values) . ", defaultBooleans = " . json_encode($va_default_form_booleans) . ";\n\t\tfor (f in defaultValues) {\n\t\t\tvar f_proc = f + '[]';\n\t\t\tjQuery('input[name=\"' + f_proc+ '\"], textarea[name=\"' + f_proc+ '\"], select[name=\"' + f_proc+ '\"]').each(function(k, v) {\n\t\t\t\tif (defaultValues[f][k]) { jQuery(v).val(defaultValues[f][k]); } \n\t\t\t});\n\t\t}\n\t\tfor (f in defaultBooleans) {\n\t\t\tvar f_proc = f + '[]';\n\t\t\tjQuery('select[name=\"' + f_proc+ '\"].caContributeBoolean').each(function(k, v) {\n\t\t\t\tif (defaultBooleans[f][k]) { jQuery(v).val(defaultBooleans[f][k]); }\n\t\t\t});\n\t\t}\n\t});\n</script>\n";
                 break;
             default:
                 if (preg_match("!^(.*):label\$!", $vs_tag_proc, $va_matches)) {
                     $this->view->setVar($vs_tag, $vs_tag_val = $t_subject->getDisplayLabel($va_matches[1]));
                 } else {
                     $va_opts['asArrayElement'] = true;
                     if ($vs_tag_val = $t_subject->htmlFormElementForSimpleForm($this->request, $vs_tag_proc, $va_opts)) {
                         $this->view->setVar($vs_tag, $vs_tag_val);
                     }
                     $va_tmp = explode('.', $vs_tag_proc);
                     if (($t_element = ca_metadata_elements::getInstance($va_tmp[1])) && $t_element->get('datatype') == 0) {
                         if (is_array($va_elements = $t_element->getElementsInSet())) {
                             foreach ($va_elements as $va_element) {
                                 if ($va_element['datatype'] > 0) {
                                     $va_form_elements[] = $va_tmp[0] . '.' . $va_tmp[1] . '.' . $va_element['element_code'];
                                 }
                             }
                         }
                         break;
                     }
                 }
                 if ($vs_tag_val) {
                     $va_form_elements[] = $vs_tag_proc;
                 }
                 break;
         }
     }
     $this->view->setVar("form", caFormTag($this->request, "Send", 'caContribute', null, 'post', 'multipart/form-data', '_top', array('disableUnsavedChangesWarning' => true)));
     $this->view->setVar("/form", $vs_script . caHTMLHiddenInput("_contributeFormName", array("value" => $ps_function)) . caHTMLHiddenInput("_formElements", array("value" => join(';', $va_form_elements))) . caHTMLHiddenInput("_contribute", array("value" => 1)) . "</form>");
     $this->render($va_form_info['view']);
 }
 /**
  * Returns HTML bundle for picking representations to attach to an object-* relationship
  *
  * @param object $po_request The current request
  * @param $ps_form_name The name of the HTML form this bundle will be part of
  *
  * @return string HTML for bundle
  */
 public function getRepresentationChooserHTMLFormBundle($po_request, $ps_form_name, $ps_placement_code, $pa_bundle_settings, $pa_options = null)
 {
     $o_view = new View($po_request, $po_request->getViewsDirectoryPath() . '/bundles/');
     $o_view->setVar('lookup_urls', caJSONLookupServiceUrl($po_request, $this->getAppDatamodel()->getTableName($this->get('table_num'))));
     $o_view->setVar('t_subject', $this);
     $vn_object_id = $this->getLeftTableName() == 'ca_objects' ? $this->get($this->getLeftTableFieldName()) : $this->get($this->getRightTableFieldName());
     $o_view->setVar('t_object', $t_object = new ca_objects($vn_object_id));
     $o_view->setVar('id_prefix', $ps_form_name);
     $o_view->setVar('placement_code', $ps_placement_code);
     $o_view->setVar('element_code', caGetOption(array('elementCode', 'element_code'), $pa_bundle_settings, null));
     $o_view->setVar('settings', $pa_bundle_settings);
     return $o_view->render('ca_object_representation_chooser_html.php');
 }
 /**
  * 
  * 
  * @param string $ps_source
  * @param array $pa_options Options include
  *		dataset = number of worksheet to read [Default=0]
  * @return bool
  */
 public function read($ps_source, $pa_options = null)
 {
     parent::read($ps_source, $pa_options);
     try {
         $this->opo_handle = PHPExcel_IOFactory::load($ps_source);
         $this->opo_handle->setActiveSheetIndex(caGetOption('dataset', $pa_options, 0));
         $o_sheet = $this->opo_handle->getActiveSheet();
         $this->opo_rows = $o_sheet->getRowIterator();
         $this->opn_current_row = 0;
     } catch (Exception $e) {
         return false;
     }
     return true;
 }
 /**
  * Returns value suitable for display
  *
  * @param $pa_options array Options are:
  *		returnAsDecimal = return duration in seconds as decimal number
  *
  * @return mixed Values as string or decimal
  */
 public function getDisplayValue($pa_options = null)
 {
     if (caGetOption('returnAsDecimal', $pa_options, false)) {
         return (double) $this->opn_duration;
     }
     if (!strlen($this->opn_duration)) {
         return '';
     }
     $o_tcp = new TimecodeParser();
     $o_tcp->setParsedValueInSeconds($this->opn_duration);
     $o_config = Configuration::load();
     if (!($vs_format = $o_config->get('timecode_output_format'))) {
         $vs_format = 'HOURS_MINUTES_SECONDS';
     }
     return $o_tcp->getText($vs_format);
 }
 /**
  * @param $ps_plugin_code string Code of plugin to use for rendering. If omitted the first available plugin is used.
  */
 public function __construct($ps_plugin_code = null)
 {
     $this->renderer = null;
     $va_available_plugins = PDFRenderer::getAvailablePDFRendererPlugins();
     if ($ps_plugin_code && in_array($ps_plugin_code, $va_available_plugins)) {
         $this->renderer = $this->getPDFRendererPlugin($ps_plugin_code);
     }
     if (!$this->renderer) {
         foreach ($va_available_plugins as $vs_plugin_code) {
             if ($o_renderer = $this->getPDFRendererPlugin($vs_plugin_code)) {
                 $va_status = $o_renderer->checkStatus();
                 if (caGetOption('available', $va_status, false)) {
                     $this->renderer = $o_renderer;
                     break;
                 }
             }
         }
     }
 }
Exemple #13
0
 /**
  *
  */
 public function __construct($po_request, $pm_path = null, $ps_character_encoding = 'UTF8', $pa_options = null)
 {
     parent::__construct();
     $this->opo_request = $po_request;
     $this->opa_view_paths = array();
     $this->opa_view_vars = array();
     $this->opo_appconfig = Configuration::load();
     $this->ops_character_encoding = $ps_character_encoding;
     if (!$pm_path) {
         $pm_path = array();
     }
     $vs_suffix = null;
     if (!is_array($pm_path)) {
         $pm_path = array($pm_path);
     }
     foreach ($pm_path as $ps_path) {
         // Preserve any path suffix after "views"
         // Eg. if path is /web/myinstall/themes/mytheme/views/bundles then we want to retain "/bundles" on the default path
         $va_suffix_bits = array();
         $va_tmp = array_reverse(explode("/", $ps_path));
         foreach ($va_tmp as $vs_path_element) {
             if ($vs_path_element == 'views') {
                 break;
             }
             array_push($va_suffix_bits, $vs_path_element);
         }
         if ($vs_suffix = join("/", $va_suffix_bits)) {
             $vs_suffix = '/' . $vs_suffix;
             break;
         }
     }
     if (caGetOption('includeDefaultThemePath', $pa_options, true)) {
         $vs_default_theme_path = $po_request->getDefaultThemeDirectoryPath() . '/views' . $vs_suffix;
         if (!in_array($vs_default_theme_path, $pm_path) && !in_array($vs_default_theme_path . '/', $pm_path)) {
             array_unshift($pm_path, $vs_default_theme_path);
         }
     }
     if (sizeof($pm_path) > 0) {
         $this->setViewPath($pm_path);
     }
 }
 /**
  * Options:
  * 		rawDate - if true, returns date as an array of start and end historic timestames
  *		sortable - if true a language-independent sortable representation is returned.
  *		getDirectDate - get underlying historic timestamp (floatval)
  */
 public function getDisplayValue($pa_options = null)
 {
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     if (isset($pa_options['rawDate']) && $pa_options['rawDate']) {
         return array(0 => $this->opn_start_date, 1 => $this->opn_end_date, 'start' => $this->opn_start_date, 'end' => $this->opn_end_date);
     }
     if (caGetOption('GET_DIRECT_DATE', $pa_options, false) || caGetOption('getDirectDate', $pa_options, false)) {
         return $this->opn_start_date;
     }
     if (isset($pa_options['sortable']) && $pa_options['sortable']) {
         if (!$this->opn_start_date || !$this->opn_end_date) {
             return null;
         }
         return $this->opn_start_date . '/' . $this->opn_end_date;
     }
     $o_date_config = Configuration::load(__CA_CONF_DIR__ . '/datetime.conf');
     $vs_date_format = $o_date_config->get('dateFormat');
     $vs_cache_key = md5($vs_date_format . $this->opn_start_date . $this->opn_end_date);
     // pull from cache
     if (isset(DateRangeAttributeValue::$s_date_cache[$vs_cache_key])) {
         return DateRangeAttributeValue::$s_date_cache[$vs_cache_key];
     }
     // if neither start nor end date are set, the setHistoricTimestamps() call below will
     // fail and the TEP will return the text for whatever happened to be parsed previously
     // so we have to init() before trying
     DateRangeAttributeValue::$o_tep->init();
     if ($vs_date_format == 'original') {
         return DateRangeAttributeValue::$s_date_cache[$vs_cache_key] = $this->ops_text_value;
     } else {
         if (!is_array($va_settings = MemoryCache::fetch($this->getElementID(), 'ElementSettings'))) {
             $t_element = new ca_metadata_elements($this->getElementID());
             $va_settings = MemoryCache::fetch($this->getElementID(), 'ElementSettings');
         }
         DateRangeAttributeValue::$o_tep->setHistoricTimestamps($this->opn_start_date, $this->opn_end_date);
         return DateRangeAttributeValue::$s_date_cache[$vs_cache_key] = DateRangeAttributeValue::$o_tep->getText(array_merge(array('isLifespan' => $va_settings['isLifespan']), $pa_options));
         //$this->ops_text_value;
     }
 }
 public function processExport($pa_data, $pa_options = array())
 {
     $pb_single_record = caGetOption('singleRecord', $pa_options);
     //$pb_rdf_mode = caGetOption('rdfMode', $pa_options);
     $pb_strip_cdata = (bool) caGetOption('stripCDATA', $pa_options['settings'], false);
     //caDebug($pa_data,"Data to build XML from");
     $this->log("XML export formatter: Now processing export tree ...");
     // XML exports should usually have only one top-level element (i.e. one root).
     if (sizeof($pa_data) != 1) {
         return false;
     }
     $this->processItem(array_pop($pa_data), $this->opo_dom);
     $this->log(_t("XML export formatter: Done processing export tree ..."));
     // when dealing with a record set export, we don't want <?xml tags in front of each record
     // that way we can simply dump a sequence of records in a file and have well-formed XML as result
     $vs_return = $pb_single_record ? $this->opo_dom->saveXML() : $this->opo_dom->saveXML($this->opo_dom->firstChild);
     if ($pb_strip_cdata) {
         $vs_return = str_replace('<![CDATA[', '', $vs_return);
         $vs_return = str_replace(']]>', '', $vs_return);
     }
     return $vs_return;
 }
 /**
  *
  */
 public function refine(&$pa_destination_data, $pa_group, $pa_item, $pa_source_data, $pa_options = null)
 {
     $o_log = isset($pa_options['log']) && is_object($pa_options['log']) ? $pa_options['log'] : null;
     $t_mapping = caGetOption('mapping', $pa_options, null);
     if ($t_mapping) {
         $o_dm = Datamodel::load();
         if ($t_mapping->get('table_num') != $o_dm->getTableNum('ca_places')) {
             if ($o_log) {
                 $o_log->logError(_t("placeHierarchyBuilder refinery may only be used in imports to ca_places"));
             }
             return null;
         }
     }
     $va_group_dest = explode(".", $pa_group['destination']);
     $vs_terminal = array_pop($va_group_dest);
     $pm_value = $pa_source_data[$pa_item['source']];
     $vn_parent_id = null;
     // Set place parents
     if ($va_parents = $pa_item['settings']['placeHierarchyBuilder_parents']) {
         $vn_parent_id = caProcessRefineryParents('placeHierarchyBuilderRefinery', 'ca_places', $va_parents, $pa_source_data, $pa_item, null, array_merge($pa_options, array('hierarchy_id' => $pa_item['settings']['placeHierarchyBuilder_hierarchy'])));
     }
     return $vn_parent_id;
 }
if (is_array($va_facets) && sizeof($va_facets)) {
    $vb_refine = true;
    $vn_col_span = 3;
    $vn_col_span_sm = 6;
    $vn_col_span_xs = 6;
}
if ($vn_start < $qr_res->numHits()) {
    $vn_c = 0;
    $qr_res->seek($vn_start);
    if ($vs_table != 'ca_objects') {
        $va_ids = array();
        while ($qr_res->nextHit() && $vn_c < $vn_hits_per_block) {
            $va_ids[] = $qr_res->get($vs_pk);
            $vn_c++;
        }
        $va_images = caGetDisplayImagesForAuthorityItems($vs_table, $va_ids, array('version' => 'squarethumb', 'relationshipTypes' => caGetOption('selectMediaUsingRelationshipTypes', $va_options, null), 'checkAccess' => $va_access_values));
        $vn_c = 0;
        $qr_res->seek($vn_start);
    }
    $vs_add_to_lightbox_msg = addslashes(_t('Add to lightbox'));
    while ($qr_res->nextHit() && $vn_c < $vn_hits_per_block) {
        $vn_id = $qr_res->get("{$vs_table}.{$vs_pk}");
        if ($qr_res->get('ca_objects.dates.dates_value')) {
            $vn_date = ", " . $qr_res->get('ca_objects.dates.dates_value');
        } else {
            $vn_date = "";
        }
        if ($qr_res->get('ca_entities.preferred_labels')) {
            $vs_entity_detail_link = "<p>" . $qr_res->get("ca_entities.preferred_labels", array('delimiter' => ', ')) . $vn_date . "</p>";
        } elseif ($qr_res->get('ca_occurrences.preferred_labels')) {
            $vs_entity_detail_link = "<p>" . $qr_res->get("ca_occurrences.preferred_labels", array('delimiter' => ', ')) . $vn_date . "</p>";
/**
 * Try to match given (partial) hierarchy path to a single subject in getty linked data AAT service
 * @param array $pa_hierarchy_path
 * @param int $pn_threshold
 * @param array $pa_options
 * 		removeParensFromLabels = Remove parens from labels for search and string comparison. This can improve results in specific cases.
 * @return bool|string
 */
function caMatchAAT($pa_hierarchy_path, $pn_threshold = 180, $pa_options = array())
{
    $vs_cache_key = md5(print_r($pa_hierarchy_path, true));
    if (MemoryCache::contains($vs_cache_key, 'AATMatches')) {
        return MemoryCache::fetch($vs_cache_key, 'AATMatches');
    }
    if (!is_array($pa_hierarchy_path)) {
        return false;
    }
    $pb_remove_parens_from_labels = caGetOption('removeParensFromLabels', $pa_options, false);
    // search the bottom-most component (the actual term)
    $vs_bot = trim(array_pop($pa_hierarchy_path));
    if ($pb_remove_parens_from_labels) {
        $vs_lookup = trim(preg_replace("/\\([\\p{L}\\-\\_\\s]+\\)/", '', $vs_bot));
    } else {
        $vs_lookup = $vs_bot;
    }
    $o_service = new WLPlugInformationServiceAAT();
    $va_hits = $o_service->lookup(array(), $vs_lookup, array('phrase' => true, 'raw' => true, 'limit' => 2000));
    if (!is_array($va_hits)) {
        return false;
    }
    $vn_best_distance = 0;
    $vn_pick = -1;
    foreach ($va_hits as $vn_i => $va_hit) {
        if (stripos($va_hit['TermPrefLabel']['value'], $vs_lookup) !== false) {
            // only consider terms that match what we searched
            // calculate similarity as a number by comparing both the term and the parent string
            $vs_label_with_parens = $va_hit['TermPrefLabel']['value'];
            $vs_label_without_parens = trim(preg_replace("/\\([\\p{L}\\s]+\\)/", '', $vs_label_with_parens));
            $va_label_percentages = array();
            // we try every combination with and without parens on both sides
            // unfortunately this code gets rather ugly because getting the similarity
            // as percentage is only possible by passing a reference parameter :-(
            similar_text($vs_label_with_parens, $vs_bot, $vn_label_percent);
            $va_label_percentages[] = $vn_label_percent;
            similar_text($vs_label_with_parens, $vs_lookup, $vn_label_percent);
            $va_label_percentages[] = $vn_label_percent;
            similar_text($vs_label_without_parens, $vs_bot, $vn_label_percent);
            $va_label_percentages[] = $vn_label_percent;
            similar_text($vs_label_without_parens, $vs_lookup, $vn_label_percent);
            $va_label_percentages[] = $vn_label_percent;
            // similarity to parent path
            similar_text($va_hit['ParentsFull']['value'], join(' ', array_reverse($pa_hierarchy_path)), $vn_parent_percent);
            // it's a weighted sum because the term label is more important than the exact path
            $vn_tmp = 2 * max($va_label_percentages) + $vn_parent_percent;
            //var_dump($va_hit); var_dump($vn_tmp);
            if ($vn_tmp > $vn_best_distance) {
                $vn_best_distance = $vn_tmp;
                $vn_pick = $vn_i;
            }
        }
    }
    if ($vn_pick >= 0 && $vn_best_distance > $pn_threshold) {
        $va_pick = $va_hits[$vn_pick];
        MemoryCache::save($vs_cache_key, $va_pick['ID']['value'], 'AATMatches');
        return $va_pick['ID']['value'];
    }
    return false;
}
                    $vs_style = "style='clear:left;'";
                    $i = 1;
                }
                print "<a href='#' class='facetLink facet{$vs_facet_code}' onclick='caUIBrowsePanel.showBrowsePanel(\"{$vs_facet_code}\"); \$(\".facetLink\").removeClass(\"active\"); \$(\".facet{$vs_facet_code}\").addClass(\"active\");' " . $vs_style . ">" . $va_facet_info['label_plural'] . caNavIcon($this->request, __CA_NAV_BUTTON_ADD__) . "</a>";
            }
            ?>
					<div style='clear:both;width:100%;'></div>
					</div><!-- end refineBrowse -->
<?php 
        }
        print "</div><!-- end browseControls -->";
        $vn_x = 0;
        print "<div class='blueDivide'></div>";
        print "<div id='browseCriteria'><span class='criteriaHeading'>" . _t("You browsed for: ") . "</span>";
        foreach ($va_criteria as $vs_facet_name => $va_row_ids) {
            $vs_facet_label = caGetOption('label_singular', $va_info_for_facets[$vs_facet_name], "???");
            $vn_x++;
            $vn_row_c = 0;
            foreach ($va_row_ids as $vn_row_id => $vs_label) {
                print "<div class='criteriaLink'>{$vs_facet_label}: {$vs_label}" . caNavLink($this->request, 'x', 'close', $this->request->getModulePath(), $this->request->getController(), 'removeCriteria', array('facet' => $vs_facet_name, 'id' => urlencode($vn_row_id))) . "</div>\n";
                $vn_row_c++;
            }
        }
        print caNavLink($this->request, _t('start over'), 'startOver', $this->request->getModulePath(), $this->request->getController(), 'clearCriteria', array());
        print "</div><!-- end browseCriteria -->\n";
        print "<div class='blueDivide'></div>";
    } else {
        if (sizeof($va_facets)) {
            print "<div id='facetList'>";
            print "<div class='startBrowsingBy'>" . _t("Browse by") . "</div>";
            $va_available_facets = $this->getVar('available_facets');
 *
 * This source code is free and modifiable under the terms of 
 * GNU General Public License. (http://www.gnu.org/copyleft/gpl.html). See
 * the "license.txt" file for details, or visit the CollectiveAccess web site at
 * http://www.CollectiveAccess.org
 *
 * ----------------------------------------------------------------------
 */
$vs_id_prefix = $this->getVar('placement_code') . $this->getVar('id_prefix');
$t_subject = $this->getVar('t_subject');
// the object-to-whatever relationship
$t_object = $this->getVar('t_object');
// the object
$va_settings = $this->getVar('settings');
$va_reps = $t_object->getRepresentations();
$vb_read_only = (bool) caGetOption('readonly', $va_settings, false);
if ($vs_element_code = $this->getVar('element_code')) {
    if (!is_array($va_selected_rep_ids = $t_subject->get($x = $t_subject->tableName() . "." . $vs_element_code, array('returnAsArray' => true, 'idsOnly' => true)))) {
        $va_selected_rep_ids = array();
    }
    ?>

	<div class="caObjectRepresentationChooserContainer" id="<?php 
    print $vs_id_prefix;
    ?>
">
<?php 
    foreach ($va_reps as $va_rep) {
        $va_attributes = array('value' => $va_rep['representation_id']);
        if (in_array($va_rep['representation_id'], $va_selected_rep_ids)) {
            $va_attributes['checked'] = 1;
// array of browse criteria
$vs_key = $this->getVar('key');
// cache key for current browse
$va_access_values = $this->getVar('access_values');
// list of access values for this user
$vs_view = $this->getVar('view');
$vs_browse_type = $this->getVar('browse_type');
$o_browse = $this->getVar('browse');
$vn_facet_display_length_initial = 7;
$vn_facet_display_length_maximum = 60;
if (is_array($va_facets) && sizeof($va_facets)) {
    print "<div id='bMorePanel'><!-- long lists of facets are loaded here --></div>";
    print "<div id='bRefine'>";
    print "<H3>" . _t("Filter by") . "</H3>";
    foreach ($va_facets as $vs_facet_name => $va_facet_info) {
        if ((caGetOption('deferred_load', $va_facet_info, false) || $va_facet_info["group_mode"] == 'hierarchical') && $o_browse->getFacet($vs_facet_name)) {
            print "<H5>" . $va_facet_info['label_singular'] . "</H5>";
            ?>
					<script type="text/javascript">
						jQuery(document).ready(function() {
							jQuery("#bHierarchyList_<?php 
            print $vs_facet_name;
            ?>
").load("<?php 
            print caNavUrl($this->request, '*', '*', 'getFacetHierarchyLevel', array('facet' => $vs_facet_name, 'browseType' => $vs_browse_type, 'key' => $vs_key, 'linkTo' => 'morePanel'));
            ?>
");
						});
					</script>
					<div id='bHierarchyList_<?php 
            print $vs_facet_name;
',
			interstitialPrimaryTable: '<?php 
    print $t_instance->tableName();
    ?>
',
			interstitialPrimaryID: <?php 
    print (int) $t_instance->getPrimaryKey();
    ?>
,
			
			minRepeats: <?php 
    print caGetOption('minRelationshipsPerRow', $va_settings, 0);
    ?>
,
			maxRepeats: <?php 
    print caGetOption('maxRelationshipsPerRow', $va_settings, 65535);
    ?>
		});
<?php 
} else {
    ?>
	
		caUI.initChecklistBundle('#<?php 
    print $vs_id_prefix . $t_item->tableNum() . '_rel';
    ?>
', {
			fieldNamePrefix: '<?php 
    print $vs_id_prefix;
    ?>
_',
			templateValues: ['item_id'],
 /**
  * 
  * 
  * @param string $ps_spec
  * @param array $pa_options
  * @return mixed
  */
 public function get($ps_spec, $pa_options = null)
 {
     $vb_return_as_array = caGetOption('returnAsArray', $pa_options, false);
     $vs_delimiter = caGetOption('delimiter', $pa_options, ';');
     //$ps_spec = str_replace("/", "", $ps_spec);
     if ($this->opb_tag_names_as_case_insensitive) {
         $ps_spec = strtolower($ps_spec);
     }
     if (is_array($this->opa_row_buf) && $ps_spec && isset($this->opa_row_buf[$ps_spec])) {
         if ($vb_return_as_array) {
             return $this->opa_row_buf[$ps_spec];
         } else {
             return join($vs_delimiter, $this->opa_row_buf[$ps_spec]);
         }
     }
     return null;
 }
Exemple #24
0
    /** 
     * Perform lookup on TGN-based data service
     *
     * @param array $pa_settings Plugin settings values
     * @param string $ps_search The expression with which to query the remote data service
     * @param array $pa_options Lookup options
     * 			phrase => send a lucene phrase search instead of keywords
     * 			raw => return raw, unprocessed results from getty service
     * @return array
     */
    public function lookup($pa_settings, $ps_search, $pa_options = null)
    {
        if (!is_array($pa_options)) {
            $pa_options = array();
        }
        $va_service_conf = $this->opo_linked_data_conf->get('tgn');
        $vs_search_field = isset($va_service_conf['search_text']) && $va_service_conf['search_text'] ? 'luc:text' : 'luc:term';
        $pb_phrase = (bool) caGetOption('phrase', $pa_options, false);
        $pb_raw = (bool) caGetOption('raw', $pa_options, false);
        $pn_limit = (int) caGetOption('limit', $pa_options, $va_service_conf['result_limit'] ? $va_service_conf['result_limit'] : 50);
        /**
         * Contrary to what the Getty documentation says the terms seem to get combined by OR, not AND, so if you pass
         * "Coney Island" you get all kinds of Islands, just not the one you're looking for. It's in there somewhere but
         * the order field might prevent it from showing up within the limit. So we do our own little piece of "query rewriting" here.
         */
        if (is_numeric($ps_search)) {
            $vs_search = $ps_search;
        } elseif (isURL($ps_search)) {
            $vs_search = str_replace('http://vocab.getty.edu/tgn/', '', $ps_search);
        } elseif ($pb_phrase) {
            $vs_search = '\\"' . $ps_search . '\\"';
        } else {
            $va_search = preg_split('/[\\s]+/', $ps_search);
            $vs_search = join(' AND ', $va_search);
        }
        $vs_query = urlencode('SELECT ?ID ?TermPrefLabel ?Parents ?Type ?ParentsFull{
			?ID a skos:Concept; ' . $vs_search_field . ' "' . $vs_search . '"; skos:inScheme tgn: ;
			gvp:prefLabelGVP [xl:literalForm ?TermPrefLabel].
  			{?ID gvp:parentStringAbbrev ?Parents}
  			{?ID gvp:parentStringAbbrev ?ParentsFull}
  			{?ID gvp:displayOrder ?Order}
  			{?ID gvp:placeTypePreferred [gvp:prefLabelGVP [xl:literalForm ?Type]]}
		} ORDER BY ASC(?Order)
		LIMIT ' . $pn_limit);
        $va_results = parent::queryGetty($vs_query);
        if (!is_array($va_results)) {
            return false;
        }
        if ($pb_raw) {
            return $va_results;
        }
        $va_return = array();
        foreach ($va_results as $va_values) {
            $vs_id = '';
            if (preg_match("/[a-z]{3,4}\\/[0-9]+\$/", $va_values['ID']['value'], $va_matches)) {
                $vs_id = str_replace('/', ':', $va_matches[0]);
            }
            $vs_label = '[' . str_replace('tgn:', '', $vs_id) . '] ' . $va_values['TermPrefLabel']['value'] . "; " . $va_values['Parents']['value'] . " (" . $va_values['Type']['value'] . ")";
            $va_return['results'][] = array('label' => htmlentities(str_replace(', ... World', '', $vs_label)), 'url' => $va_values['ID']['value'], 'idno' => $vs_id);
        }
        return $va_return;
    }
Exemple #25
0
/**
 * 
 */
function caProcessBottomLineTemplate($po_request, $pa_placement, $pr_res, $pa_options = null)
{
    global $g_ui_units_pref, $g_ui_locale;
    if (!isset($pa_placement['settings']['bottom_line']) || !$pa_placement['settings']['bottom_line']) {
        return null;
    }
    if (!$pr_res) {
        return null;
    }
    $vs_template = $pa_placement['settings']['bottom_line'];
    $vs_bundle_name = $pa_placement['bundle_name'];
    $pn_page_start = caGetOption('pageStart', $pa_options, 0);
    $pn_page_end = caGetOption('pageEnd', $pa_options, $pr_res->numHits());
    if (($vn_current_index = $pr_res->currentIndex()) < 0) {
        $vn_current_index = 0;
    }
    $pr_res->seek(0);
    $o_dm = Datamodel::load();
    $va_tmp = explode(".", $vs_bundle_name);
    if (!($t_instance = $o_dm->getInstanceByTableName($va_tmp[0], true))) {
        return null;
    }
    if (!method_exists($t_instance, "_getElementDatatype") || is_null($vn_datatype = $t_instance->_getElementDatatype($va_tmp[1]))) {
        return null;
    }
    if (!($vs_user_currency = $po_request->user ? $po_request->user->getPreference('currency') : 'USD')) {
        $vs_user_currency = 'USD';
    }
    // Parse out tags and optional sub-elements from template
    //		we have to pull each sub-element separately
    //
    //		Ex. 	^SUM:valuation = sum of "valuation" sub-element
    //				^SUM = sum of primary value in non-container element
    if (!preg_match("!(\\^[A-Z]+[\\:]{0,1}[A-Za-z0-9\\_\\-]*)!", $vs_template, $va_tags)) {
        return $vs_template;
    }
    $va_tags_to_process = array();
    $va_subelements_to_process = array();
    if ($vn_datatype == 0) {
        // container
        foreach ($va_tags as $vs_raw_tag) {
            $va_tmp = explode(":", $vs_raw_tag);
            $vs_tag = $va_tmp[0];
            if (sizeof($va_tmp) == 2) {
                $vs_subelement = $va_tmp[1];
            } else {
                continue;
            }
            $va_tags_to_process[$vs_raw_tag] = true;
            $va_subelements_to_process["{$vs_bundle_name}.{$vs_subelement}"] = $t_instance->_getElementDatatype($vs_subelement);
        }
    } else {
        $va_tmp = explode(".", $vs_bundle_name);
        if (sizeof($va_tmp) == 2) {
            $vs_bundle_name .= "." . array_pop($va_tmp);
        }
        $va_subelements_to_process = array($vs_bundle_name => $vn_datatype);
    }
    $vn_c = 0;
    $vn_page_len = 0;
    $vb_has_timecode = false;
    $vn_min = $vn_max = null;
    $vn_page_min = $vn_page_max = null;
    $va_tag_values = array();
    while ($pr_res->nextHit()) {
        foreach ($va_subelements_to_process as $vs_subelement => $vn_subelement_datatype) {
            if (!is_array($va_tag_values[$vs_subelement])) {
                $va_tag_values[$vs_subelement]['SUM'] = 0;
                $va_tag_values[$vs_subelement]['PAGESUM'] = 0;
                $va_tag_values[$vs_subelement]['MIN'] = null;
                $va_tag_values[$vs_subelement]['PAGEMIN'] = null;
                $va_tag_values[$vs_subelement]['MAX'] = null;
                $va_tag_values[$vs_subelement]['PAGEMAX'] = null;
                $va_tag_values[$vs_subelement]['AVG'] = 0;
                $va_tag_values[$vs_subelement]['PAGEAVG'] = 0;
            }
            switch ($vn_subelement_datatype) {
                case 2:
                    // date range
                    $vs_value = $pr_res->get($vs_subelement);
                    break;
                case 6:
                    // currency
                    $va_values = $pr_res->get($vs_subelement, array('returnAsDecimalWithCurrencySpecifier' => true, 'returnAsArray' => true));
                    if (is_array($va_values)) {
                        foreach ($va_values as $vs_value) {
                            $vn_value = (double) caConvertCurrencyValue($vs_value, $vs_user_currency, array('numericValue' => true));
                            $va_tag_values[$vs_subelement]['SUM'] += $vn_value;
                            if (is_null($va_tag_values[$vs_subelement]['MIN']) || $vn_value < $va_tag_values[$vs_subelement]['MIN']) {
                                $va_tag_values[$vs_subelement]['MIN'] = $vn_value;
                            }
                            if (is_null($va_tag_values[$vs_subelement]['MAX']) || $vn_value > $va_tag_values[$vs_subelement]['MAX']) {
                                $va_tag_values[$vs_subelement]['MAX'] = $vn_value;
                            }
                            if ($vn_c >= $pn_page_start && $vn_c <= $pn_page_end) {
                                $va_tag_values[$vs_subelement]['PAGESUM'] += $vn_value;
                                if (is_null($va_tag_values[$vs_subelement]['PAGEMIN']) || $vn_value < $va_tag_values[$vs_subelement]['PAGEMIN']) {
                                    $va_tag_values[$vs_subelement]['PAGEMIN'] = $vn_value;
                                }
                                if (is_null($va_tag_values[$vs_subelement]['PAGEMAX']) || $vn_value > $va_tag_values[$vs_subelement]['PAGEMAX']) {
                                    $va_tag_values[$vs_subelement]['PAGEMAX'] = $vn_value;
                                }
                                $vn_page_len++;
                            }
                        }
                    }
                    break;
                case 8:
                    // length
                // length
                case 9:
                    // weight
                    $va_values = $pr_res->get($vs_subelement, array('returnAsDecimalMetric' => true, 'returnAsArray' => true));
                    if (is_array($va_values)) {
                        foreach ($va_values as $vs_value) {
                            $vn_value = (double) $vs_value;
                            $va_tag_values[$vs_subelement]['SUM'] += $vn_value;
                            if (is_null($va_tag_values[$vs_subelement]['MIN']) || $vn_value < $va_tag_values[$vs_subelement]['MIN']) {
                                $va_tag_values[$vs_subelement]['MIN'] = $vn_value;
                            }
                            if (is_null($va_tag_values[$vs_subelement]['MAX']) || $vn_value > $va_tag_values[$vs_subelement]['MAX']) {
                                $va_tag_values[$vs_subelement]['MAX'] = $vn_value;
                            }
                            if ($vn_c >= $pn_page_start && $vn_c <= $pn_page_end) {
                                $va_tag_values[$vs_subelement]['PAGESUM'] += $vn_value;
                                if (is_null($va_tag_values[$vs_subelement]['PAGEMIN']) || $vn_value < $va_tag_values[$vs_subelement]['PAGEMIN']) {
                                    $va_tag_values[$vs_subelement]['PAGEMIN'] = $vn_value;
                                }
                                if (is_null($va_tag_values[$vs_subelement]['PAGEMAX']) || $vn_value > $va_tag_values[$vs_subelement]['PAGEMAX']) {
                                    $va_tag_values[$vs_subelement]['PAGEMAX'] = $vn_value;
                                }
                                $vn_page_len++;
                            }
                        }
                    }
                    break;
                case 10:
                    // timecode
                    $va_values = $pr_res->get($vs_subelement, array('returnAsDecimal' => true, 'returnAsArray' => true));
                    if (is_array($va_values)) {
                        foreach ($va_values as $vn_value) {
                            $va_tag_values[$vs_subelement]['SUM'] += $vn_value;
                            if (is_null($vn_min) || $vn_value < $vn_min) {
                                $vn_min = $vn_value;
                            }
                            if (is_null($vn_max) || $vn_value > $vn_max) {
                                $vn_max = $vn_value;
                            }
                            if ($vn_c >= $pn_page_start && $vn_c <= $pn_page_end) {
                                $va_tag_values[$vs_subelement]['PAGESUM'] += $vn_value;
                                if (is_null($vn_page_min) || $vn_value < $vn_page_min) {
                                    $vn_page_min = $vn_value;
                                }
                                if (is_null($vn_page_max) || $vn_value > $vn_page_max) {
                                    $vn_page_max = $vn_value;
                                }
                                $vn_page_len++;
                            }
                        }
                    }
                    $vb_has_timecode = true;
                    break;
                case 11:
                    // integer
                // integer
                case 12:
                    // numeric (decimal)
                // numeric (decimal)
                default:
                    $va_values = $pr_res->get($vs_subelement, array('returnAsArray' => true));
                    if (is_array($va_values)) {
                        foreach ($va_values as $vs_value) {
                            $vn_value = (double) $vs_value;
                            $va_tag_values[$vs_subelement]['SUM'] += $vn_value;
                            if (is_null($vn_min) || $vn_value < $vn_min) {
                                $vn_min = $vn_value;
                            }
                            if (is_null($vn_max) || $vn_value > $vn_max) {
                                $vn_max = $vn_value;
                            }
                            if ($vn_c >= $pn_page_start && $vn_c <= $pn_page_end) {
                                $va_tag_values[$vs_subelement]['PAGESUM'] += $vn_value;
                                if (is_null($vn_page_min) || $vn_value < $vn_page_min) {
                                    $vn_page_min = $vn_value;
                                }
                                if (is_null($vn_page_max) || $vn_value > $vn_page_max) {
                                    $vn_page_max = $vn_value;
                                }
                                $vn_page_len++;
                            }
                        }
                    }
                    break;
                default:
                    break 2;
            }
        }
        $vn_c++;
    }
    if ($vb_has_timecode) {
        $o_tcp = new TimecodeParser();
        $o_config = Configuration::load();
        if (!($vs_timecode_format = $o_config->get('timecode_output_format'))) {
            $vs_timecode_format = 'HOURS_MINUTES_SECONDS';
        }
    }
    // Post processing
    foreach ($va_subelements_to_process as $vs_subelement => $vn_subelement_datatype) {
        switch ($vn_subelement_datatype) {
            case 6:
                // currency
                $va_tag_values[$vs_subelement]['PAGEAVG'] = $vn_page_len > 0 ? sprintf("%1.2f", $va_tag_values[$vs_subelement]['PAGESUM'] / $vn_page_len) : 0;
                $va_tag_values[$vs_subelement]['AVG'] = $vn_c > 0 ? sprintf("%1.2f", $va_tag_values[$vs_subelement]['SUM'] / $vn_c) : "0.00";
                foreach ($va_tag_values[$vs_subelement] as $vs_tag => $vn_val) {
                    $va_tag_values[$vs_subelement][$vs_tag] = "{$vs_user_currency} " . $va_tag_values[$vs_subelement][$vs_tag];
                }
                break;
            case 8:
                // length
                $va_tag_values[$vs_subelement]['PAGEAVG'] = $vn_page_len > 0 ? sprintf("%1.2f", $va_tag_values[$vs_subelement]['PAGESUM'] / $vn_page_len) : 0;
                $va_tag_values[$vs_subelement]['AVG'] = $vn_c > 0 ? sprintf("%1.2f", $va_tag_values[$vs_subelement]['SUM'] / $vn_c) : "0.00";
                foreach ($va_tag_values[$vs_subelement] as $vs_tag => $vn_val) {
                    $vo_measurement = new Zend_Measure_Length((double) $vn_val, 'METER', $g_ui_locale);
                    $va_tag_values[$vs_subelement][$vs_tag] = $vo_measurement->convertTo($g_ui_units_pref == 'metric' ? Zend_Measure_Length::METER : Zend_Measure_Length::FEET, 4);
                }
                break;
            case 9:
                // weight
                $va_tag_values[$vs_subelement]['PAGEAVG'] = $vn_page_len > 0 ? sprintf("%1.2f", $va_tag_values[$vs_subelement]['PAGESUM'] / $vn_page_len) : 0;
                $va_tag_values[$vs_subelement]['AVG'] = $vn_c > 0 ? sprintf("%1.2f", $va_tag_values[$vs_subelement]['SUM'] / $vn_c) : "0.00";
                foreach ($va_tag_values[$vs_subelement] as $vs_tag => $vn_val) {
                    $vo_measurement = new Zend_Measure_Length((double) $vn_val, 'KILOGRAM', $g_ui_locale);
                    $va_tag_values[$vs_subelement][$vs_tag] = $vo_measurement->convertTo($g_ui_units_pref == 'metric' ? Zend_Measure_Weight::KILOGRAM : Zend_Measure_Weight::POUND, 4);
                }
                break;
            case 10:
                // timecode
                $va_tag_values[$vs_subelement]['PAGEAVG'] = $vn_page_len > 0 ? sprintf("%1.2f", $va_tag_values[$vs_subelement]['PAGESUM'] / $vn_page_len) : 0;
                $va_tag_values[$vs_subelement]['AVG'] = $vn_c > 0 ? sprintf("%1.2f", $va_tag_values[$vs_subelement]['SUM'] / $vn_c) : 0;
                foreach ($va_tag_values[$vs_subelement] as $vs_tag => $vn_val) {
                    if (!$vb_has_timecode) {
                        $va_tag_values[$vs_subelement][$vs_tag] = '';
                        continue;
                    }
                    $o_tcp->setParsedValueInSeconds($vn_val);
                    $va_tag_values[$vs_subelement][$vs_tag] = $o_tcp->getText($vs_timecode_format);
                }
                break;
            case 11:
                // integer
                foreach ($va_tag_values[$vs_subelement] as $vs_tag => $vn_val) {
                    $va_tag_values[$vs_subelement][$vs_tag] = (int) $va_tag_values[$vs_subelement][$vs_tag];
                }
                break;
            case 12:
                // numeric (decimal)
                foreach ($va_tag_values[$vs_subelement] as $vs_tag => $vn_val) {
                    $va_tag_values[$vs_subelement][$vs_tag] = (double) $va_tag_values[$vs_subelement][$vs_tag];
                }
                break;
        }
    }
    // Restore current position of search result
    $pr_res->seek($vn_current_index);
    foreach ($va_tag_values as $vs_subelement => $va_tag_data) {
        foreach ($va_tag_data as $vs_tag => $vs_tag_value) {
            if ($vs_subelement == $vs_bundle_name) {
                $vs_template = str_replace("^{$vs_tag}", $vs_tag_value, $vs_template);
            } else {
                $va_tmp = explode(".", $vs_subelement);
                $vs_template = str_replace("^{$vs_tag}:" . array_pop($va_tmp), $vs_tag_value, $vs_template);
            }
        }
    }
    return $vs_template;
}
Exemple #26
0
 /**
  * Check if record with primary key id or idno exists. Will check box, giving preference to primary key id unless the 'idOnly' option is set
  * in which case it will only consider primary key ids. If the 'idnoOnly' option is set and the model supports idno's then only idno's will
  * be considered
  *
  * @param mixed $pm_id Numeric primary key id or alphanumeric idno to search for.
  * @param array $pa_options Options include:
  *		idOnly = Only consider primary key ids. [Default is false]
  *		idnoOnly = Only consider idnos. [Default is false]
  *		transaction = Transaction to use. [Default is no transaction]
  * @return bool
  */
 public static function exists($pm_id, $pa_options = null)
 {
     $o_dm = Datamodel::load();
     $o_trans = caGetOption('transaction', $pa_option, null);
     if (is_numeric($pm_id) && $pm_id > 0) {
         $vn_c = self::find([$o_dm->primaryKey(get_called_class()) => $pm_id], ['returnAs' => 'count', 'transaction' => $o_trans]);
         if ($vn_c > 0) {
             return true;
         }
     }
     if (!caGetOption('idOnly', $pa_options, false) && ($vs_idno_fld = $o_dm->getTableProperty(get_called_class(), 'ID_NUMBERING_ID_FIELD'))) {
         $vn_c = self::find([$vs_idno_fld => $pm_id], ['returnAs' => 'count', 'transaction' => $o_trans]);
         if ($vn_c > 0) {
             return true;
         }
     }
     return false;
 }
Exemple #27
0
 /**
  * Generate timeline data feed
  *
  * @param array $pa_viz_settings Array of visualization settings taken from visualization.conf
  * @param array $pa_options Array of options to use when rendering output. Supported options are:
  *		NONE
  */
 public function getDataForVisualization($pa_viz_settings, $pa_options = null)
 {
     $va_data = array("headline" => isset($pa_viz_settings['display']['headline']) ? $pa_viz_settings['display']['headline'] : '', "type" => "default", "text" => isset($pa_viz_settings['display']['introduction']) ? $pa_viz_settings['display']['introduction'] : '', "asset" => array("media" => "", "credit" => "", "caption" => ""));
     $po_request = caGetOption('request', $pa_options, null);
     $qr_res = $this->getData();
     $vs_table_name = $qr_res->tableName();
     $vs_pk = $qr_res->primaryKey();
     $vn_c = 0;
     $va_results = array();
     while ($qr_res->nextHit()) {
         foreach ($pa_viz_settings['sources'] as $vs_source_name => $va_source) {
             $vs_dates = $qr_res->get($va_source['data'], array('sortable' => true, 'returnAsArray' => false, 'delimiter' => ';'));
             $va_dates = explode(";", $vs_dates);
             $va_date_list = explode("/", $va_dates[0]);
             if (!$va_date_list[0] || !$va_date_list[1]) {
                 continue;
             }
             $va_timeline_dates = caGetDateRangeForTimelineJS($va_date_list);
             $vn_row_id = $qr_res->get("{$vs_table_name}.{$vs_pk}");
             $vs_title = $qr_res->getWithTemplate($va_source['display']['title_template']);
             $va_data['date'][] = array("startDate" => $va_timeline_dates['start'], "endDate" => $va_timeline_dates['end'], "headline" => $po_request ? caEditorLink($po_request, $vs_title, '', $vs_table_name, $vn_row_id) : $vs_title, "text" => $qr_res->getWithTemplate($va_source['display']['description_template']), "tag" => $vs_tag, "classname" => "", "asset" => array("media" => $qr_res->getWithTemplate($va_source['display']['image'], array('returnURL' => true)), "thumbnail" => $qr_res->getWithTemplate($va_source['display']['icon'], array('returnURL' => true)), "credit" => $qr_res->getWithTemplate($va_source['display']['credit_template']), "caption" => $qr_res->getWithTemplate($va_source['display']['caption_template'])));
         }
         $vn_c++;
         if ($vn_c > 2000) {
             break;
         }
     }
     return json_encode(array('timeline' => $va_data));
 }
Exemple #28
0
 /**
  * Generate timeline data feed
  *
  * @param array $pa_viz_settings Array of visualization settings taken from visualization.conf
  * @param array $pa_options Array of options to use when rendering output. Supported options are:
  *		NONE
  */
 public function getDataForVisualization($pa_viz_settings, $pa_options = null)
 {
     $po_request = caGetOption('request', $pa_options, null);
     $qr_res = $this->getData();
     $vs_table_name = $qr_res->tableName();
     $vs_pk = $qr_res->primaryKey();
     $va_default_colors = array("#a7797e", "#dc4671", "#ab22b4", "#0650be", "#685dcd", "#6c5ace", "#7f34bd", "#6b95b4", "#56b5bc", "#41b895", "#008f4c", "#d09a24");
     $va_default_colors_lighter = array("#c7999e", "#fc6691", "#cb42d4", "#2670de", "#887ded", "#8c7aee", "#9f54dd", "#8bb5d4", "#76d5dc", "#61d8b5", "#20af6c", "#f0ba44");
     $va_default_colors_darker = array("#87595e", "#bc2651", "#8b0294", "#06309e", "#483dad", "#4c3aae", "#5f14bd", "#4b7594", "#36959c", "#219875", "#006f2c", "#b07a04");
     $va_default_colors_num = count($va_default_colors);
     $vn_c = 0;
     while ($qr_res->nextHit()) {
         foreach ($pa_viz_settings['sources'] as $vs_source_name => $va_source) {
             $vn_event_num = 1;
             $vs_dates = $qr_res->get($va_source['data'], array('sortable' => true, 'returnAsArray' => false, 'delimiter' => ';'));
             $vs_display_date = $qr_res->get($va_source['data']);
             $va_dates = explode(";", $vs_dates);
             if ($vs_dates !== "") {
                 $va_date_list = explode("/", $va_dates[0]);
                 if (!$va_date_list[0] || !$va_date_list[1]) {
                     continue;
                 }
                 $va_calendar_dates = caGetDateRangeForCalendar($va_date_list);
                 $vn_row_id = $qr_res->get("{$vs_table_name}.{$vs_pk}");
                 $data = array("start" => $va_calendar_dates['start_iso'], "end" => $va_calendar_dates['end_iso'], "display_date" => $vs_display_date, "url" => $po_request ? caEditorUrl($po_request, $vs_table_name, $vn_row_id) : "#", "description" => $qr_res->getWithTemplate($va_source['display']['description_template']), "title" => $qr_res->getWithTemplate($va_source['display']['title_template']), "color" => "darkblue", "textColor" => "white");
                 $data["color"] = $va_default_colors[$vn_c % $va_default_colors_num];
                 if ($va_calendar_dates["start"]["hours"] === "00" && $va_calendar_dates["end"]["hours"] === "23" && $va_calendar_dates["start"]["minutes"] === "00" && $va_calendar_dates["end"]["minutes"] === "59") {
                     $data["allDay"] = true;
                 }
                 $va_data[] = $data;
                 if (isset($va_source["before"])) {
                     $start_date = new DateTime($va_calendar_dates['start_iso']);
                     $data = array("start" => $start_date->modify($va_source["before"])->format('c'), "end" => $va_calendar_dates['start_iso'], "display_date" => $start_date->format('d-m-Y'), "url" => $po_request ? caEditorUrl($po_request, $vs_table_name, $vn_row_id) : "#", "description" => $qr_res->getWithTemplate($va_source['display_before']['description_template']), "title" => $qr_res->getWithTemplate($va_source['display_before']['title_template']), "color" => "darkblue", "textColor" => "white", "allDay" => true);
                     $data["color"] = $va_default_colors_lighter[$vn_c % $va_default_colors_num];
                     $va_data[] = $data;
                 }
                 if (isset($va_source["after"])) {
                     $start_date = new DateTime($va_calendar_dates['end_iso']);
                     $data = array("start" => $start_date->modify("+1 days")->setTime(0, 0)->format('c'), "end" => $start_date->modify($va_source["after"])->format('c'), "display_date" => $start_date->format('d-m-Y'), "url" => $po_request ? caEditorUrl($po_request, $vs_table_name, $vn_row_id) : "#", "description" => $qr_res->getWithTemplate($va_source['display_after']['description_template']), "title" => $qr_res->getWithTemplate($va_source['display_after']['title_template']), "color" => "darkblue", "textColor" => "white", "allDay" => true);
                     $data["color"] = $va_default_colors_darker[$vn_c % $va_default_colors_num];
                     $va_data[] = $data;
                 }
             }
             $vn_event_num++;
         }
         $vn_c++;
         if ($vn_c > 2000) {
             break;
         }
     }
     return json_encode($va_data);
 }
Exemple #29
0
 /**
  * Establishes a connection to the database
  *
  * @param mixed $po_caller representation of the caller, usually a Db() object
  * @param array $pa_options array containing options like host, username, password
  * @return bool success state
  */
 public function connect($po_caller, $pa_options)
 {
     global $g_connect;
     if (!is_array($g_connect)) {
         $g_connect = array();
     }
     $vs_db_connection_key = $pa_options["host"] . '/' . $pa_options["database"];
     if (!($vb_unique_connection = caGetOption('uniqueConnection', $pa_options, false)) && isset($g_connect[$vs_db_connection_key]) && is_resource($g_connect[$vs_db_connection_key])) {
         $this->opr_db = $g_connect[$vs_db_connection_key];
         return true;
     }
     if (!function_exists("mysql_connect")) {
         die(_t("Your PHP installation lacks MySQL support. Please add it and retry..."));
         exit;
     }
     if (!$vb_unique_connection && ($vb_persistent_connections = caGetOption('persistentConnections', $pa_options, false))) {
         $this->opr_db = @mysql_pconnect($pa_options["host"], $pa_options["username"], $pa_options["password"]);
     } else {
         $this->opr_db = @mysql_connect($pa_options["host"], $pa_options["username"], $pa_options["password"], true);
     }
     if (!$this->opr_db) {
         $po_caller->postError(200, mysql_error(), "Db->mysql->connect()");
         return false;
     }
     if (!mysql_select_db($pa_options["database"], $this->opr_db)) {
         $po_caller->postError(201, mysql_error($this->opr_db), "Db->mysql->connect()");
         return false;
     }
     mysql_query('SET NAMES \'utf8\'', $this->opr_db);
     mysql_query('SET character_set_results = NULL', $this->opr_db);
     if (!$vb_unique_connection) {
         $g_connect[$vs_db_connection_key] = $this->opr_db;
     }
     return true;
 }
Exemple #30
0
    public function htmlTag($ps_url, $pa_properties, $pa_options = null, $pa_volume_info = null)
    {
        if (!is_array($pa_options)) {
            $pa_options = array();
        }
        foreach (array('name', 'show_controls', 'url', 'text_only', 'viewer_width', 'viewer_height', 'id', 'poster_frame_url', 'viewer_parameters', 'viewer_base_url', 'width', 'height', 'vspace', 'hspace', 'alt', 'title', 'usemap', 'align', 'border', 'class', 'style') as $vs_k) {
            if (!isset($pa_options[$vs_k])) {
                $pa_options[$vs_k] = null;
            }
        }
        switch ($pa_properties["mimetype"]) {
            # ------------------------------------------------
            case 'audio/x-realaudio':
                $vs_name = $pa_options["name"] ? $pa_options["name"] : "prm";
                $vb_show_controls = isset($pa_options["show_controls"]) && $pa_options["show_controls"] ? 1 : 0;
                if ($pa_options["text_only"]) {
                    return "<a href='" . (isset($pa_options["url"]) ? $pa_options["url"] : $ps_url) . "'>" . ($pa_options["text_only"] ? $pa_options["text_only"] : "View Realmedia") . "</a>";
                } else {
                    ob_start();
                    ?>
					<table border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td>
								<object id="<?php 
                    print $vs_name;
                    ?>
" width="<?php 
                    print $pa_properties["width"];
                    ?>
" height="<?php 
                    print $pa_properties["height"];
                    ?>
" classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA">
									<param name="controls" value="ImageWindow">
		<?php 
                    if ($vb_show_controls) {
                        ?>
									<param name="console" value="<?php 
                        print $vs_name;
                        ?>
_controls">
		<?php 
                    }
                    ?>
									<param name="autostart" value="true">
									<param name="type" value="audio/x-pn-realaudio-plugin">
									<param name="autogotourl" value="false">
									<param name="src" value="<?php 
                    print isset($pa_options["url"]) ? $pa_options["url"] : $ps_url;
                    ?>
">

									<embed name="<?php 
                    print $vs_name;
                    ?>
" src="<?php 
                    print isset($pa_options["url"]) ? $pa_options["url"] : $ps_url;
                    ?>
" width="<?php 
                    print $pa_properties["width"];
                    ?>
" height="<?php 
                    print $pa_properties["height"];
                    ?>
"
										controls="ImageWindow" nojava="false"
										showdisplay="0" showstatusbar="1" autostart="true" type="audio/x-pn-realaudio-plugin">
									</embed>
								</object>
							</td>
						</tr>
<?php 
                    if ($vb_show_controls) {
                        ?>
						<tr>
							<td>
								<object id="<?php 
                        print $vs_name;
                        ?>
_controls" width="<?php 
                        print $pa_properties["width"];
                        ?>
" height="32" classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA">
									<param name="controls" value="ControlPanel">
									<param name="type" value="audio/x-pn-realaudio-plugin">
									<param name="src" value="<?php 
                        print isset($pa_options["url"]) ? $pa_options["url"] : $ps_url;
                        ?>
">

									<embed name="id_<?php 
                        print $vs_name;
                        ?>
_controls" src="<?php 
                        print isset($pa_options["url"]) ? $pa_options["url"] : $ps_url;
                        ?>
" width="<?php 
                        print $pa_properties["width"];
                        ?>
" height="32"
										console="Clip1" controls="ControlPanel" type="audio/x-pn-realaudio-plugin">
									</embed>
								</object>
							</td>
						</tr>
<?php 
                    }
                    ?>
					</table>
<?php 
                    return ob_get_clean();
                }
                break;
                # ------------------------------------------------
            # ------------------------------------------------
            case 'video/x-ms-asf':
            case 'video/x-ms-wmv':
                $vs_name = $pa_options["name"] ? $pa_options["name"] : "pwmv";
                $vb_show_controls = isset($pa_options["show_controls"]) && $pa_options["show_controls"] ? "1" : "0";
                ob_start();
                if (isset($pa_options["text_only"]) && $pa_options["text_only"]) {
                    return "<a href='" . (isset($pa_options["url"]) ? $pa_options["url"] : $ps_url) . "'>" . ($pa_options["text_only"] ? $pa_options["text_only"] : "View WindowsMedia") . "</a>";
                } else {
                    ?>
					<table border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td>
								<object id="<?php 
                    print $vs_name;
                    ?>
"
									standby="Loading Microsoft Windows Media Player components..."
									type="application/x-oleobject"
									width="<?php 
                    print $pa_properties["width"];
                    ?>
" height="<?php 
                    print $pa_properties["height"] + ($vb_show_controls == 'true' ? 45 : 0);
                    ?>
"
									codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715"
									classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95">
									<param name="ShowControls" value="<?php 
                    print $vb_show_controls;
                    ?>
">
									<param name="ShowAudioControls" value="<?php 
                    print $vb_show_controls;
                    ?>
">
									<param name="ShowPositionControls" value="<?php 
                    print $vb_show_controls;
                    ?>
">
									<param name="ShowTracker" value="<?php 
                    print $vb_show_controls;
                    ?>
">
									<param name="ShowStatusBar" value="<?php 
                    print $vb_show_controls;
                    ?>
">
									<param name="ShowDisplay" value="<?php 
                    print $vb_show_controls;
                    ?>
">
									<param name="AnimationatStart" value="0">
									<param name="AutoStart" value="1">
									<param name="FileName" value="<?php 
                    print isset($pa_options["url"]) ? $pa_options["url"] : $ps_url;
                    ?>
">
									<param name="AllowChangeDisplaySize" value="1">
									<param name="DisplaySize" value="0">

									<embed  src="<?php 
                    print isset($pa_options["url"]) ? $pa_options["url"] : $ps_url;
                    ?>
"
										name="<?php 
                    print $vs_name;
                    ?>
"
										id="<?php 
                    print $vs_name;
                    ?>
"
										width="<?php 
                    print $pa_properties["width"];
                    ?>
" height="<?php 
                    print $pa_properties["height"] + ($vb_show_controls == 'true' ? 45 : 0);
                    ?>
"
										AutoStart="1"
										AnimationatStart="0"
										ShowControls="<?php 
                    print $vb_show_controls;
                    ?>
"
										ShowAudioControls="<?php 
                    print $vb_show_controls;
                    ?>
"
										ShowPositionControls="<?php 
                    print $vb_show_controls;
                    ?>
"
										ShowStatusBar="<?php 
                    print $vb_show_controls;
                    ?>
"
										ShowTracker="<?php 
                    print $vb_show_controls;
                    ?>
"
										ShowDisplay="<?php 
                    print $vb_show_controls;
                    ?>
"
										AllowChangeDisplaySize="1"
										DisplaySize="0"
										TYPE="application/x-mplayer2"
										PLUGINSPAGE="http://www.microsoft.com/isapi/redir.dll?prd=windows&sbp=mediaplayer&ar=Media&sba=Plugin&">
									</embed>
								</object>
							</td>
						</tr>
					</table>
<?php 
                    return ob_get_clean();
                }
                # ------------------------------------------------
            # ------------------------------------------------
            case 'video/quicktime':
                $vs_name = $pa_options["name"] ? $pa_options["name"] : "qplayer";
                $vn_width = $pa_options["viewer_width"] ? $pa_options["viewer_width"] : $pa_properties["width"];
                $vn_height = $pa_options["viewer_height"] ? $pa_options["viewer_height"] : $pa_properties["height"];
                ob_start();
                if ($pa_options["text_only"]) {
                    return "<a href='{$ps_url}'>" . ($pa_options["text_only"] ? $pa_options["text_only"] : "View QuickTime") . "</a>";
                } else {
                    ?>
					<table border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td>
								<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
									width="<?php 
                    print $vn_width;
                    ?>
" height="<?php 
                    print $vn_height + 16;
                    ?>
"
 									codebase="http://www.apple.com/qtactivex/qtplugin.cab">
									<param name="src" VALUE="<?php 
                    print $ps_url;
                    ?>
">
									<param name="autoplay" VALUE="true">
									<param name="controller" VALUE="true">

									<embed  src="<?php 
                    print $ps_url;
                    ?>
"
										name="id_<?php 
                    print $vs_name;
                    ?>
"
										width="<?php 
                    print $vn_width;
                    ?>
" height="<?php 
                    print $vn_height + 16;
                    ?>
"
										autoplay="true" controller="true" kioskmode="true"
										pluginspage="http://www.apple.com/quicktime/download/"
										type="video/quicktime"
									>
									</embed>
								</object>
							</td>
						</tr>
					</table>
<?php 
                    return ob_get_clean();
                }
                break;
                # ------------------------------------------------
            # ------------------------------------------------
            case "video/x-flv":
            case 'video/mpeg':
            case 'audio/mpeg':
            case 'video/mp4':
                $vs_id = $pa_options["id"] ? $pa_options["id"] : "mp4_player";
                $vs_poster_frame_url = $pa_options["poster_frame_url"];
                $vs_flash_vars = $pa_options["viewer_parameters"];
                $viewer_base_url = $pa_options["viewer_base_url"];
                $vn_width = $pa_options["viewer_width"] ? $pa_options["viewer_width"] : $pa_properties["width"];
                $vn_height = $pa_options["viewer_height"] ? $pa_options["viewer_height"] : $pa_properties["height"];
                $va_captions = caGetOption("captions", $pa_options, array(), array('castTo' => 'array'));
                ob_start();
                $vs_config = 'config={"playlist":[{"url":"' . $vs_poster_frame_url . '", "scaling": "fit"}, {"url": "' . $ps_url . '","autoPlay":false,"autoBuffering":true, "scaling": "fit"}]};';
                $vb_is_rtmp = false;
                if ($vb_is_rtmp = substr($ps_url, 0, 7) === 'rtmp://') {
                    //  && (isset($pa_options['always_use_flash']) && $pa_options['always_use_flash'])) {
                    $pa_options['always_use_flash'] = true;
                    switch ($pa_properties["mimetype"]) {
                        case "video/x-flv":
                            $vs_type = 'flv';
                            break;
                        case 'audio/mpeg':
                            $vs_type = 'mp3';
                            break;
                        case 'video/mpeg':
                        case 'video/mp4':
                        default:
                            $vs_type = 'mp4';
                            break;
                    }
                    if ($vb_is_rtmp) {
                        $va_volume_info = isset($pa_volume_info['accessUsingMirror']) && (bool) $pa_volume_info['accessUsingMirror'] ? $pa_volume_info['mirrors'][$pa_volume_info['accessUsingMirror']] : $pa_volume_info;
                        $va_tmp = explode('/', $ps_url);
                        $va_filename = explode('.', array_pop($va_tmp));
                        $vs_ext = $va_filename[1];
                        $vs_stub = (isset($va_volume_info['accessProtocol']) ? $va_volume_info['accessProtocol'] : $va_volume_info['protocol']) . '://' . (isset($va_volume_info['accessHostname']) ? $va_volume_info['accessHostname'] : $va_volume_info['hostname']) . (isset($va_volume_info['accessUrlPath']) ? $va_volume_info['accessUrlPath'] : $va_volume_info['urlPath']);
                        $vs_file_path = str_replace($vs_stub, '', $ps_url);
                        $vs_file_path = preg_replace('!\\.' . $vs_ext . '$!', '', $vs_file_path);
                        $vs_config = '{ "playlist":[ {"url": "' . $va_volume_info['rtmpContentPath'] . $vs_file_path . '", "provider": "streaming_server"} ], "plugins" : { "streaming_server" : { "url": "flowplayer.rtmp-3.2.3.swf", "netConnectionUrl": "' . (isset($va_volume_info['accessProtocol']) ? $va_volume_info['accessProtocol'] : $va_volume_info['protocol']) . '://' . (isset($va_volume_info['accessHostname']) ? $va_volume_info['accessHostname'] : $va_volume_info['hostname']) . $va_volume_info['rtmpMediaPrefix'] . '" } } }';
                    }
                    ?>
				<div id="<?php 
                    print $vs_id;
                    ?>
" style="width: <?php 
                    print $vn_width;
                    ?>
px; height: <?php 
                    print $vn_height;
                    ?>
px;"> </div>
				<script type="text/javascript">
					flowplayer("<?php 
                    print $vs_id;
                    ?>
", "<?php 
                    print $viewer_base_url;
                    ?>
/viewers/apps/flowplayer-3.2.7.swf", <?php 
                    print $vs_config;
                    ?>
);
				</script>
<?php 
                } else {
                    ?>
			<!-- Begin VideoJS -->
			 <video id="<?php 
                    print $vs_id;
                    ?>
" class="video-js vjs-default-skin"  
				  controls preload="auto" width="<?php 
                    print $vn_width;
                    ?>
" height="<?php 
                    print $vn_height;
                    ?>
"  
				  poster="<?php 
                    print $vs_poster_frame_url;
                    ?>
"  
				  data-setup='{}'>  
				 <source src="<?php 
                    print $ps_url;
                    ?>
" type='video/mp4' />  
<?php 
                    if (is_array($va_captions)) {
                        foreach ($va_captions as $vn_locale_id => $va_caption_track) {
                            print "<track kind=\"captions\" src=\"" . $va_caption_track['url'] . "\" srclang=\"" . $va_caption_track["locale_code"] . "\" label=\"" . $va_caption_track['locale'] . "\">\n";
                        }
                    }
                    ?>
				</video>
			<script type="text/javascript">
				_V_.players["<?php 
                    print $vs_id;
                    ?>
"] = undefined;	// make sure VideoJS doesn't think it has already loaded the viewer
				jQuery("#<?php 
                    print $vs_id;
                    ?>
").attr('width', jQuery('#<?php 
                    print $vs_id;
                    ?>
:parent').width()).attr('height', jQuery('#<?php 
                    print $vs_id;
                    ?>
:parent').height());
				_V_("<?php 
                    print $vs_id;
                    ?>
", {}, function() {});
			</script>
			<!-- End VideoJS -->
<?php 
                }
                ?>

<?php 
                return ob_get_clean();
                break;
                # ------------------------------------------------
            # ------------------------------------------------
            case 'video/ogg':
                $vs_id = $pa_options["id"] ? $pa_options["id"] : "mp4_player";
                $vs_poster_frame_url = $pa_options["poster_frame_url"];
                $vn_width = $pa_options["viewer_width"] ? $pa_options["viewer_width"] : $pa_properties["width"];
                $vn_height = $pa_options["viewer_height"] ? $pa_options["viewer_height"] : $pa_properties["height"];
                return "<video id='{$vs_id}' src='{$ps_url}' width='{$vn_width}' height='{$vn_height}' controls='1'></video>";
                break;
                # ------------------------------------------------
            # ------------------------------------------------
            case 'video/x-matroska':
                $vs_id = $pa_options["id"] ? $pa_options["id"] : "mp4_player";
                $vs_poster_frame_url = $pa_options["poster_frame_url"];
                $vn_width = $pa_options["viewer_width"] ? $pa_options["viewer_width"] : $pa_properties["width"];
                $vn_height = $pa_options["viewer_height"] ? $pa_options["viewer_height"] : $pa_properties["height"];
                return "<video id='{$vs_id}' src='{$ps_url}' width='{$vn_width}' height='{$vn_height}' controls='1'></video>";
                break;
                # ------------------------------------------------
            # ------------------------------------------------
            case 'application/x-shockwave-flash':
                $vs_name = $pa_options["name"] ? $pa_options["name"] : "swfplayer";
                #
                # We allow forcing of width and height for Flash media
                #
                # If you set a width or height, the Flash media will be scaled so it is as large as it
                # can be without exceeding either dimension
                if (isset($pa_options["width"]) || isset($pa_options["height"])) {
                    $vn_ratio = 1;
                    $vn_w_ratio = 0;
                    if ($pa_options["width"] > 0) {
                        $vn_ratio = $vn_w_ratio = $pa_options["width"] / $pa_properties["width"];
                    }
                    if ($pa_options["height"] > 0) {
                        $vn_h_ratio = $pa_options["height"] / $pa_properties["height"];
                        if ($vn_h_ratio < $vn_w_ratio || !$vn_w_ratio) {
                            $vn_ratio = $vn_h_ratio;
                        }
                    }
                    $pa_options["width"] = intval($pa_properties["width"] * $vn_ratio);
                    $pa_options["height"] = intval($pa_properties["height"] * $vn_ratio);
                }
                ob_start();
                if ($pa_options["text_only"]) {
                    return "<a href='{$ps_url}'>" . ($pa_options["text_only"] ? $pa_options["text_only"] : "View Flash") . "</a>";
                } else {
                    ?>

			<div id="<?php 
                    print $vs_name;
                    ?>
">
				<h1><?php 
                    print _t('You must have the Flash Plug-in version 9.0.124 or better installed to play video and audio in CollectiveAccess');
                    ?>
</h1>
				<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
			</div>
			<script type="text/javascript">
				jQuery(document).ready(function() { swfobject.embedSWF("<?php 
                    print $ps_url;
                    ?>
", "<?php 
                    print $vs_name;
                    ?>
", "<?php 
                    print isset($pa_options["width"]) ? $pa_options["width"] : $pa_properties["width"];
                    ?>
", "<?php 
                    print isset($pa_options["height"]) ? $pa_options["height"] : $pa_properties["height"];
                    ?>
", "9.0.124", "swf/expressInstall.swf", {}, {'allowscriptaccess': 'always', 'allowfullscreen' : 'true', 'allowNetworking' : 'all'}); });
			</script>
<?php 
                    return ob_get_clean();
                }
                break;
                # ------------------------------------------------
            # ------------------------------------------------
            case 'image/jpeg':
            case 'image/gif':
                if (!is_array($pa_options)) {
                    $pa_options = array();
                }
                if (!is_array($pa_properties)) {
                    $pa_properties = array();
                }
                return caHTMLImage($ps_url, array_merge($pa_options, $pa_properties));
                break;
                # ------------------------------------------------
        }
    }