/**
  * Performs a search (for use with REST-style services)
  * NOTE: This method cannot be used via the SOAP services since
  * Zend_Service can't put DOMDocument objects in SOAP responses
  *
  * @param string $type can be one of: "ca_objects", "ca_entities", "ca_places", "ca_occurrences", "ca_collections", "ca_list_items", "ca_object_representations", "ca_storage_locations", "ca_movements", "ca_loans", "ca_tours", "ca_tour_stops"
  * @param string $query the search query
  * @param array $additional_bundles associated array which defines the additional data to get. It must be an array of
  *	"bundle name" => "option array" mappings, e.g.
  *
  *	array(
  *		"ca_objects.status" => array("convertCodesToDisplayText" => 1)
  *	)
  *
  *	For a list of available options @see ItemInfo::get().
  * @return DOMDocument
  * @throws SoapFault
  */
 public function queryRest($type, $query, $additional_bundles)
 {
     if (!($ps_class = $this->mapTypeToSearchClassName($type))) {
         throw new SoapFault("Server", "Invalid type [{$type}]");
     }
     require_once __CA_LIB_DIR__ . "/ca/Search/{$ps_class}.php";
     require_once __CA_MODELS_DIR__ . "/{$type}.php";
     $vo_search = new $ps_class();
     $t_instance = new $type();
     $vo_result = $vo_search->search($query);
     $vo_dom = new DOMDocument('1.0', 'utf-8');
     $vo_root = $vo_dom->createElement('CaSearchResult');
     $vo_dom->appendChild($vo_root);
     while ($vo_result->nextHit()) {
         // create element representing row
         $vo_item = $vo_dom->createElement($type);
         $vo_item->setAttribute($t_instance->primaryKey(), $vo_result->get($t_instance->primaryKey()));
         $vo_root->appendChild($vo_item);
         // add display label
         if (is_array($va_display_labels = $vo_result->getDisplayLabels())) {
             $vo_display_label = $vo_dom->createElement("displayLabel", caEscapeForXML(array_pop($va_display_labels)));
             $vo_item->appendChild($vo_display_label);
         }
         // add idno
         if ($vs_idno = $vo_result->get("idno")) {
             $vo_idno = $vo_dom->createElement("idno", htmlspecialchars($vs_idno));
             $vo_item->appendChild($vo_idno);
         }
         if (is_array($additional_bundles)) {
             foreach ($additional_bundles as $vs_bundle => $va_options) {
                 if ($this->_isBadBundle($vs_bundle)) {
                     continue;
                 }
                 $vo_bundle = $vo_dom->createElement($vs_bundle, htmlspecialchars($vo_result->get($vs_bundle, $va_options)));
                 $vo_item->appendChild($vo_bundle);
             }
         }
     }
     return $vo_dom;
 }
示例#2
0
 /**
  * Character data callback
  *
  * @param resource $parser xml parser
  * @param string $data character data
  * @return void
  */
 protected function _cbCharacterData($parser, $data)
 {
     $data = trim($data);
     if (strlen($data)) {
         $this->_prev = self::PREV_WAS_TEXT;
         if ($this->_options["wordwrapCData"]) {
             $pad = $this->_getPaddingStr();
             $data = wordwrap($data, $this->_options["wordwrapCData"], $this->_options["outputEOL"] . $pad, false);
         }
         fwrite($this->_output, caEscapeForXML($data));
     }
 }
示例#3
0
?>
]]></name>
		<description><![CDATA[<?php 
print $t_set->getAttributesForDisplay("description");
?>
]]></description>
	</setInfo>
	<setImages>
<?php 
if (sizeof($va_items)) {
    foreach ($va_items as $vn_item_id => $va_item) {
        $vs_large_image = caEscapeForXML($va_item['representation_url']);
        $vs_thumbnail_image = '';
        $vs_maker = '';
        $vs_credit = '';
        $vs_title = caEscapeForXML($va_item['label']['name']);
        ?>
			<image large="<?php 
        print $vs_large_image;
        ?>
" thumbnail="<?php 
        print $vs_thumbnail_image;
        ?>
" title="<?php 
        print $vs_title;
        ?>
" maker="<?php 
        print $vs_maker;
        ?>
" credit="<?php 
        print $vs_credit;
示例#4
0
 /**
  * Get a field value of the table row that is represented by this object.
  *
  * @param string $ps_field field name
  * @param array $pa_options options array; can be omitted.
  * It should be an associative array of boolean (except one of the options) flags. In case that some of the options are not set, they are treated as 'false'.
  * Possible options (keys) are:
  * 		BINARY: return field value as is
  * 		FILTER_HTML_SPECIAL_CHARS: convert all applicable chars to their html entities
  * 		DONT_PROCESS_GLOSSARY_TAGS: ?
  * 		CONVERT_HTML_BREAKS: similar to nl2br()
  * 		convertLineBreaks: same as CONVERT_HTML_BREAKS
  * 		getDirectDate: return raw date value from database if $ps_field adresses a date field, otherwise the value will be parsed using the TimeExpressionParser::getText() method
  * 		getDirectTime: return raw time value from database if $ps_field adresses a time field, otherwise the value will be parsed using the TimeExpressionParser::getText() method
  * 		TIMECODE_FORMAT: set return format for fields representing time ranges possible (string) values: COLON_DELIMITED, HOURS_MINUTES_SECONDS, RAW; data will be passed through floatval() by default
  * 		QUOTE: set return value into quotes
  * 		URL_ENCODE: value will be passed through urlencode()
  * 		ESCAPE_FOR_XML: convert <, >, &, ' and " characters for XML use
  * 		DONT_STRIP_SLASHES: if set to true, return value will not be passed through stripslashes()
  * 		template: formatting string to use for returned value; ^<fieldname> placeholder is used to represent field value in template
  * 		returnAsArray: if true, fields that can return multiple values [currently only <table_name>.children.<field>] will return values in an indexed array; default is false
  * 		returnAllLocales:
  * 		delimiter: if set, value is used as delimiter when fields that can return multiple fields are returned as strings; default is a single space
  * 		convertCodesToDisplayText: if set, id values refering to foreign keys are returned as preferred label text in the current locale
  * 		returnURL: if set then url is returned for media, otherwise an HTML tag for display is returned
  * 		dateFormat: format to return created or lastModified dates in. Valid values are iso8601 or text
  *		checkAccess = array of access values to filter results by; if defined only items with the specified access code(s) are returned. Only supported for table that have an "access" field.
  *		sort = optional field to sort returned values on. The field specifiers are fields with or without table name specified.	 
  *		sort_direction = direction to sort results by, either 'asc' for ascending order or 'desc' for descending order; default is 'asc'	 
  */
 public function get($ps_field, $pa_options = null)
 {
     if (!$ps_field) {
         return null;
     }
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     $vb_return_as_array = caGetOption('returnAsArray', $pa_options, false);
     $vb_return_with_structure = caGetOption('returnWithStructure', $pa_options, false);
     $vb_return_all_locales = caGetOption('returnAllLocales', $pa_options, false);
     $vs_delimiter = caGetOption('delimiter', $pa_options, ' ');
     if (($vb_return_with_structure || $vb_return_all_locales) && !$vb_return_as_array) {
         $vb_return_as_array = true;
     }
     $vn_row_id = $this->getPrimaryKey();
     if ($vb_return_as_array && $vb_return_as_array) {
         $vn_locale_id = $this->hasField('locale_id') ? $this->get('locale_id') : null;
     }
     $va_tmp = explode('.', $ps_field);
     if (sizeof($va_tmp) > 1) {
         if ($va_tmp[0] === $this->tableName()) {
             //
             // Return created on or last modified
             //
             if (in_array($va_tmp[1], array('created', 'lastModified'))) {
                 if ($vb_return_as_array) {
                     return $va_tmp[1] == 'lastModified' ? $this->getLastChangeTimestamp() : $this->getCreationTimestamp();
                 } else {
                     $va_data = $va_tmp[1] == 'lastModified' ? $this->getLastChangeTimestamp() : $this->getCreationTimestamp();
                     $vs_subfield = isset($va_tmp[2]) && isset($va_data[$va_tmp[2]]) ? $va_tmp[2] : 'timestamp';
                     $vm_val = $va_data[$vs_subfield];
                     if ($vs_subfield == 'timestamp') {
                         $o_tep = new TimeExpressionParser();
                         $o_tep->setUnixTimestamps($vm_val, $vm_val);
                         $vm_val = $o_tep->getText($pa_options);
                     }
                     return $vm_val;
                 }
             }
             //
             // Generalized get
             //
             $va_field_info = $this->getFieldInfo($va_tmp[1]);
             switch (sizeof($va_tmp)) {
                 case 2:
                     // support <table_name>.<field_name> syntax
                     $ps_field = $va_tmp[1];
                     break;
                 default:
                     // > 2 elements
                     // media field?
                     if ($va_field_info['FIELD_TYPE'] === FT_MEDIA && !isset($pa_options['returnAsArray']) && !$pa_options['returnAsArray']) {
                         $o_media_settings = new MediaProcessingSettings($va_tmp[0], $va_tmp[1]);
                         $va_versions = $o_media_settings->getMediaTypeVersions('*');
                         $vs_version = $va_tmp[2];
                         if (!isset($va_versions[$vs_version])) {
                             $va_available_versions = array_keys($va_versions);
                             $vs_version = $va_tmp[2] = array_shift($va_available_versions);
                         }
                         if (isset($va_tmp[3])) {
                             return $this->getMediaInfo($va_tmp[1], $vs_version, 'width');
                         } else {
                             if (isset($pa_options['returnURL']) && $pa_options['returnURL']) {
                                 return $this->getMediaUrl($va_tmp[1], $vs_version, $pa_options);
                             } else {
                                 return $this->getMediaTag($va_tmp[1], $vs_version, $pa_options);
                             }
                         }
                     }
                     if ($va_tmp[1] == 'parent' && $this->isHierarchical() && ($vn_parent_id = $this->get($this->getProperty('HIERARCHY_PARENT_ID_FLD')))) {
                         $t_instance = $this->getAppDatamodel()->getInstanceByTableNum($this->tableNum());
                         if (!$t_instance->load($vn_parent_id)) {
                             return $vb_return_as_array ? array() : null;
                         } else {
                             unset($va_tmp[1]);
                             $va_tmp = array_values($va_tmp);
                             if ($vb_return_as_array) {
                                 if ($vb_return_all_locales) {
                                     return array($vn_row_id => array($vn_locale_id => array($t_instance->get(join('.', $va_tmp)))));
                                 } else {
                                     return array($vn_row_id => $t_instance->get(join('.', $va_tmp)));
                                 }
                             } else {
                                 return $t_instance->get(join('.', $va_tmp));
                             }
                         }
                     } else {
                         if ($va_tmp[1] == 'children' && $this->isHierarchical()) {
                             $vb_check_access = is_array($pa_options['checkAccess']) && $this->hasField('access');
                             $va_sort = isset($pa_options['sort']) ? $pa_options['sort'] : null;
                             if (!is_array($va_sort) && $va_sort) {
                                 $va_sort = array($va_sort);
                             }
                             if (!is_array($va_sort)) {
                                 $va_sort = array();
                             }
                             $vs_sort_direction = isset($pa_options['sort_direction']) && in_array(strtolower($pa_options['sort_direction']), array('asc', 'desc')) ? strtolower($pa_options['sort_direction']) : 'asc';
                             unset($va_tmp[1]);
                             // remove 'children' from field path
                             $va_tmp = array_values($va_tmp);
                             $vs_childless_path = join('.', $va_tmp);
                             $va_data = array();
                             $va_children_ids = $this->getHierarchyChildren(null, array('idsOnly' => true));
                             if (is_array($va_children_ids) && sizeof($va_children_ids)) {
                                 $t_instance = $this->getAppDatamodel()->getInstanceByTableNum($this->tableNum());
                                 if ($va_tmp[1] == $this->primaryKey() && !$vs_sort) {
                                     foreach ($va_children_ids as $vn_child_id) {
                                         $va_data[$vn_child_id] = $vn_child_id;
                                     }
                                 } else {
                                     if (method_exists($this, "makeSearchResult")) {
                                         // Use SearchResult lazy loading when available
                                         $vs_table = $this->tableName();
                                         $vs_pk = $vs_table . '.' . $this->primaryKey();
                                         $qr_children = $this->makeSearchResult($this->tableName(), $va_children_ids);
                                         while ($qr_children->nextHit()) {
                                             if ($vb_check_access && !in_array($qr_children->get("{$vs_table}.access"), $pa_options['checkAccess'])) {
                                                 continue;
                                             }
                                             $vn_child_id = $qr_children->get($vs_pk);
                                             $vs_sort_key = '';
                                             foreach ($va_sort as $vs_sort) {
                                                 $vs_sort_key .= $vs_sort ? $qr_children->get($vs_sort) : 0;
                                             }
                                             if (!is_array($va_data[$vs_sort_key])) {
                                                 $va_data[$vs_sort_key] = array();
                                             }
                                             if ($vb_return_as_array) {
                                                 $va_data[$vs_sort_key][$vn_child_id] = array_shift($qr_children->get($vs_childless_path, array_merge($pa_options, array('returnAsArray' => $vb_return_as_array, 'returnAllLocales' => $vb_return_all_locales))));
                                             } else {
                                                 $va_data[$vs_sort_key][$vn_child_id] = $qr_children->get($vs_childless_path, array_merge($pa_options, array('returnAsArray' => false, 'returnAllLocales' => false)));
                                             }
                                         }
                                         ksort($va_data);
                                         if ($vs_sort_direction && $vs_sort_direction == 'desc') {
                                             $va_data = array_reverse($va_data);
                                         }
                                         $va_sorted_data = array();
                                         foreach ($va_data as $vs_sort_key => $va_items) {
                                             foreach ($va_items as $vs_k => $vs_v) {
                                                 $va_sorted_data[] = $vs_v;
                                             }
                                         }
                                         $va_data = $va_sorted_data;
                                     } else {
                                         // Fall-back to loading records row-by-row (slow)
                                         foreach ($va_children_ids as $vn_child_id) {
                                             if ($t_instance->load($vn_child_id)) {
                                                 if ($vb_check_access && !in_array($t_instance->get("access"), $pa_options['checkAccess'])) {
                                                     continue;
                                                 }
                                                 $vs_sort_key = $vs_sort ? $t_instance->get($vs_sort) : 0;
                                                 if (!is_array($va_data[$vs_sort_key])) {
                                                     $va_data[$vs_sort_key] = array();
                                                 }
                                                 if ($vb_return_as_array) {
                                                     $va_data[$vs_sort_key][$vn_child_id] = array_shift($t_instance->get($vs_childless_path, array_merge($pa_options, array('returnAsArray' => $vb_return_as_array, 'returnAllLocales' => $vb_return_all_locales))));
                                                 } else {
                                                     $va_data[$vs_sort_key][$vn_child_id] = $t_instance->get($vs_childless_path, array_merge($pa_options, array('returnAsArray' => false, 'returnAllLocales' => false)));
                                                 }
                                             }
                                         }
                                         ksort($va_data);
                                         if ($vs_sort_direction && $vs_sort_direction == 'desc') {
                                             $va_data = array_reverse($va_data);
                                         }
                                         $va_sorted_data = array();
                                         foreach ($va_data as $vs_sort_key => $va_items) {
                                             foreach ($va_items as $vs_k => $vs_v) {
                                                 $va_sorted_data[] = $vs_v;
                                             }
                                         }
                                         $va_data = $va_sorted_data;
                                     }
                                 }
                             }
                             if ($vb_return_as_array) {
                                 return $va_data;
                             } else {
                                 return join($vs_delimiter, $va_data);
                             }
                         }
                     }
                     break;
             }
         } else {
             $va_rels = $this->getRelatedItems($va_tmp[0]);
             $va_vals = array();
             if (is_array($va_rels)) {
                 foreach ($va_rels as $va_rel_item) {
                     if (isset($va_rel_item[$va_tmp[1]])) {
                         $va_vals[] = $va_rel_item[$va_tmp[1]];
                     }
                 }
                 return $vb_return_as_array ? $va_vals : join($vs_delimiter, $va_vals);
             }
             // can't pull fields from other tables!
             return $vb_return_as_array ? array() : null;
         }
     }
     if (isset($pa_options["BINARY"]) && $pa_options["BINARY"]) {
         return $this->_FIELD_VALUES[$ps_field];
     }
     if (array_key_exists($ps_field, $this->FIELDS)) {
         $ps_field_type = $this->getFieldInfo($ps_field, "FIELD_TYPE");
         if ($this->getFieldInfo($ps_field, 'IS_LIFESPAN')) {
             $pa_options['isLifespan'] = true;
         }
         switch ($ps_field_type) {
             case FT_BIT:
                 $vs_prop = isset($this->_FIELD_VALUES[$ps_field]) ? $this->_FIELD_VALUES[$ps_field] : "";
                 if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText']) {
                     $vs_prop = (bool) $vs_prop ? _t('yes') : _t('no');
                 }
                 return $vs_prop;
                 break;
             case FT_TEXT:
             case FT_NUMBER:
             case FT_PASSWORD:
                 $vs_prop = isset($this->_FIELD_VALUES[$ps_field]) ? $this->_FIELD_VALUES[$ps_field] : null;
                 if (isset($pa_options["FILTER_HTML_SPECIAL_CHARS"]) && $pa_options["FILTER_HTML_SPECIAL_CHARS"]) {
                     $vs_prop = htmlentities(html_entity_decode($vs_prop));
                 }
                 //
                 // Convert foreign keys and choice list values to display text is needed
                 //
                 if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && ($vs_list_code = $this->getFieldInfo($ps_field, "LIST_CODE"))) {
                     $t_list = new ca_lists();
                     $vs_prop = $t_list->getItemFromListForDisplayByItemID($vs_list_code, $vs_prop);
                 } else {
                     if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && ($vs_list_code = $this->getFieldInfo($ps_field, "LIST"))) {
                         $t_list = new ca_lists();
                         if (!($vs_tmp = $t_list->getItemFromListForDisplayByItemValue($vs_list_code, $vs_prop))) {
                             if ($vs_tmp = $this->getChoiceListValue($ps_field, $vs_prop)) {
                                 $vs_prop = $vs_tmp;
                             }
                         } else {
                             $vs_prop = $vs_tmp;
                         }
                     } else {
                         if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && $ps_field === 'locale_id' && (int) $vs_prop > 0) {
                             $t_locale = new ca_locales($vs_prop);
                             $vs_prop = $t_locale->getName();
                         } else {
                             if (isset($pa_options['convertCodesToDisplayText']) && $pa_options['convertCodesToDisplayText'] && is_array($va_list = $this->getFieldInfo($ps_field, "BOUNDS_CHOICE_LIST"))) {
                                 foreach ($va_list as $vs_option => $vs_value) {
                                     if ($vs_value == $vs_prop) {
                                         $vs_prop = $vs_option;
                                         break;
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if (isset($pa_options["CONVERT_HTML_BREAKS"]) && $pa_options["CONVERT_HTML_BREAKS"] || isset($pa_options["convertLineBreaks"]) && $pa_options["convertLineBreaks"]) {
                     $vs_prop = caConvertLineBreaks($vs_prop);
                 }
                 break;
             case FT_DATETIME:
             case FT_TIMESTAMP:
             case FT_HISTORIC_DATETIME:
             case FT_HISTORIC_DATE:
             case FT_DATE:
                 $vn_timestamp = isset($this->_FIELD_VALUES[$ps_field]) ? $this->_FIELD_VALUES[$ps_field] : 0;
                 if ($vb_return_with_structure) {
                     $vs_prop = array('start' => $this->_FIELD_VALUES[$ps_field], 'end' => $this->_FIELD_VALUES[$ps_field]);
                 } elseif (caGetOption('GET_DIRECT_DATE', $pa_options, false) || caGetOption('getDirectDate', $pa_options, false) || caGetOption('rawDate', $pa_options, false)) {
                     $vs_prop = $this->_FIELD_VALUES[$ps_field];
                 } elseif (isset($pa_options['sortable']) && $pa_options['sortable']) {
                     $vs_prop = $vn_timestamp . "/" . $vn_timestamp;
                 } else {
                     $o_tep = new TimeExpressionParser();
                     if ($ps_field_type == FT_HISTORIC_DATETIME || $ps_field_type == FT_HISTORIC_DATE) {
                         $o_tep->setHistoricTimestamps($vn_timestamp, $vn_timestamp);
                     } else {
                         $o_tep->setUnixTimestamps($vn_timestamp, $vn_timestamp);
                     }
                     if ($ps_field_type == FT_DATE || $ps_field_type == FT_HISTORIC_DATE) {
                         $vs_prop = $o_tep->getText(array_merge(array('timeOmit' => true), $pa_options));
                     } else {
                         $vs_prop = $o_tep->getText($pa_options);
                     }
                 }
                 break;
             case FT_TIME:
                 if ($vb_return_with_structure) {
                     $vs_prop = array('start' => $this->_FIELD_VALUES[$ps_field], 'end' => $this->_FIELD_VALUES[$ps_field]);
                 } elseif (caGetOption('GET_DIRECT_TIME', $pa_options, false) || caGetOption('getDirectTime', $pa_options, false) || caGetOption('rawTime', $pa_options, false)) {
                     $vs_prop = $this->_FIELD_VALUES[$ps_field];
                 } else {
                     $o_tep = new TimeExpressionParser();
                     $vn_timestamp = isset($this->_FIELD_VALUES[$ps_field]) ? $this->_FIELD_VALUES[$ps_field] : 0;
                     $o_tep->setTimes($vn_timestamp, $vn_timestamp);
                     $vs_prop = $o_tep->getText($pa_options);
                 }
                 break;
             case FT_DATERANGE:
             case FT_HISTORIC_DATERANGE:
                 $vs_start_field_name = $this->getFieldInfo($ps_field, "START");
                 $vs_end_field_name = $this->getFieldInfo($ps_field, "END");
                 $vn_start_date = isset($this->_FIELD_VALUES[$vs_start_field_name]) ? $this->_FIELD_VALUES[$vs_start_field_name] : null;
                 $vn_end_date = isset($this->_FIELD_VALUES[$vs_end_field_name]) ? $this->_FIELD_VALUES[$vs_end_field_name] : null;
                 if ($vb_return_with_structure) {
                     $vs_prop = array('start' => $vn_start_date, 'end' => $vn_end_date);
                 } elseif (!caGetOption('GET_DIRECT_DATE', $pa_options, false) && !caGetOption('getDirectDate', $pa_options, false) && !caGetOption('rawDate', $pa_options, false)) {
                     $o_tep = new TimeExpressionParser();
                     if ($ps_field_type == FT_HISTORIC_DATERANGE) {
                         $o_tep->setHistoricTimestamps($vn_start_date, $vn_end_date);
                     } else {
                         $o_tep->setUnixTimestamps($vn_start_date, $vn_end_date);
                     }
                     $vs_prop = $o_tep->getText($pa_options);
                 } elseif (isset($pa_options['sortable']) && $pa_options['sortable']) {
                     $vs_prop = $vn_start_date;
                     //."/".$vn_timestamp;
                 } else {
                     $vs_prop = $vn_start_date;
                     //array($vn_start_date, $vn_end_date);
                 }
                 break;
             case FT_TIMERANGE:
                 $vs_start_field_name = $this->getFieldInfo($ps_field, "START");
                 $vs_end_field_name = $this->getFieldInfo($ps_field, "END");
                 $vn_start_date = isset($this->_FIELD_VALUES[$vs_start_field_name]) ? $this->_FIELD_VALUES[$vs_start_field_name] : null;
                 $vn_end_date = isset($this->_FIELD_VALUES[$vs_end_field_name]) ? $this->_FIELD_VALUES[$vs_end_field_name] : null;
                 if ($vb_return_with_structure) {
                     $vs_prop = array('start' => $vn_start_date, 'end' => $vn_end_date);
                 } elseif (!caGetOption('GET_DIRECT_TIME', $pa_options, false) && !caGetOption('getDirectTime', $pa_options, false) && !caGetOption('rawTime', $pa_options, false)) {
                     $o_tep = new TimeExpressionParser();
                     $o_tep->setTimes($vn_start_date, $vn_end_date);
                     $vs_prop = $o_tep->getText($pa_options);
                 } else {
                     $vs_prop = array($vn_start_date, $vn_end_date);
                 }
                 break;
             case FT_TIMECODE:
                 $o_tp = new TimecodeParser();
                 $o_tp->setParsedValueInSeconds($this->_FIELD_VALUES[$ps_field]);
                 $vs_prop = $o_tp->getText(isset($pa_options["TIMECODE_FORMAT"]) ? $pa_options["TIMECODE_FORMAT"] : null);
                 break;
             case FT_MEDIA:
             case FT_FILE:
                 if ($vb_return_with_structure || $pa_options["USE_MEDIA_FIELD_VALUES"]) {
                     if (isset($pa_options["USE_MEDIA_FIELD_VALUES"]) && $pa_options["USE_MEDIA_FIELD_VALUES"]) {
                         $vs_prop = $this->_FIELD_VALUES[$ps_field];
                     } else {
                         $vs_prop = isset($this->_SET_FILES[$ps_field]['tmp_name']) && $this->_SET_FILES[$ps_field]['tmp_name'] ? $this->_SET_FILES[$ps_field]['tmp_name'] : $this->_FIELD_VALUES[$ps_field];
                     }
                 } else {
                     $va_versions = $this->getMediaVersions($ps_field);
                     $vs_tag = $this->getMediaTag($ps_field, array_shift($va_versions));
                     if ($vb_return_as_array) {
                         return array($vs_tag);
                     } else {
                         return $vs_tag;
                     }
                 }
                 break;
             case FT_VARS:
                 $vs_prop = isset($this->_FIELD_VALUES[$ps_field]) && $this->_FIELD_VALUES[$ps_field] ? $this->_FIELD_VALUES[$ps_field] : null;
                 break;
         }
         if (isset($pa_options["QUOTE"]) && $pa_options["QUOTE"]) {
             $vs_prop = $this->quote($ps_field, $vs_prop);
         }
     } else {
         $this->postError(710, _t("'%1' does not exist in this object", $ps_field), "BaseModel->get()");
         return $vb_return_as_array ? array() : null;
     }
     if (isset($pa_options["URL_ENCODE"]) && $pa_options["URL_ENCODE"]) {
         $vs_prop = urlEncode($vs_prop);
     }
     if (isset($pa_options["ESCAPE_FOR_XML"]) && $pa_options["ESCAPE_FOR_XML"]) {
         $vs_prop = caEscapeForXML($vs_prop);
     }
     if (!(isset($pa_options["DONT_STRIP_SLASHES"]) && $pa_options["DONT_STRIP_SLASHES"])) {
         if (is_string($vs_prop)) {
             $vs_prop = stripSlashes($vs_prop);
         }
     }
     if (isset($pa_options["template"]) && $pa_options["template"]) {
         $vs_template_with_substitution = str_replace("^" . $ps_field, $vs_prop, $pa_options["template"]);
         $vs_prop = str_replace("^" . $this->tableName() . "." . $ps_field, $vs_prop, $vs_template_with_substitution);
     }
     if ($vb_return_as_array) {
         if ($vb_return_all_locales) {
             return array($vn_row_id => array($vn_locale_id => array($vs_prop)));
         } else {
             return array($vn_row_id => $vs_prop);
         }
     } else {
         return $vs_prop;
     }
 }
示例#5
0
 /**
  * Get the value of a field in the current row.
  * Possible keys in the options array:
  * binary, unserialize, convertHTMLBreaks, urlEncode, filterHTMLSpecialCharacters, escapeForXML, stripSlashes
  *
  * @param string $ps_field field name
  * @param array $pa_options associative array of options, keys are names of the options, values are boolean.
  * @return mixed
  */
 function get($ps_field, $pa_options = null)
 {
     $va_field = isset(DbResult::$s_field_info_cache[$ps_field]) ? DbResult::$s_field_info_cache[$ps_field] : $this->getFieldInfo($ps_field);
     if (!isset($this->opa_current_row[$va_field["field"]])) {
         return null;
     }
     $vs_val = isset($this->opa_current_row[$va_field["field"]]) ? $this->opa_current_row[$va_field["field"]] : null;
     if (isset($pa_options["binary"]) && $pa_options["binary"]) {
         return $vs_val;
     }
     if (isset($pa_options["unserialize"]) && $pa_options["unserialize"]) {
         if (!isset($this->opa_unserialized_cache[$va_field["field"]]) || !($vm_data = $this->opa_unserialized_cache[$va_field["field"]])) {
             $vm_data = caUnserializeForDatabase($vs_val);
             $this->opa_unserialized_cache[$va_field["field"]] =& $vm_data;
         }
         return $vm_data;
     }
     if (isset($pa_options["convertHTMLBreaks"]) && $pa_options["convertHTMLBreaks"]) {
         # check for tags before converting breaks
         preg_match_all("/<[A-Za-z0-9]+/", $vs_val, $va_tags);
         $va_ok_tags = array("<b", "<i", "<u", "<strong", "<em", "<strike", "<sub", "<sup", "<a", "<img", "<span");
         $vb_convert_breaks = true;
         foreach ($va_tags[0] as $vs_tag) {
             if (!in_array($vs_tag, $va_ok_tags)) {
                 $vb_convert_breaks = false;
                 break;
             }
         }
         if ($vb_convert_breaks) {
             $vs_val = preg_replace("/(\n|\r\n){2}/", "<p/>", $vs_val);
             $vs_val = ereg_replace("\n", "<br/>", $vs_val);
         }
     }
     if (isset($pa_options["urlEncode"]) && $pa_options["urlEncode"]) {
         $vs_val = urlEncode($vs_val);
     }
     if (isset($pa_options["filterHTMLSpecialCharacters"]) && $pa_options["filterHTMLSpecialCharacters"]) {
         $vs_val = htmlentities(html_entity_decode($vs_val));
     }
     if (isset($pa_options["escapeForXML"]) && $pa_options["escapeForXML"]) {
         $vs_val = caEscapeForXML($vs_val);
     }
     if (get_magic_quotes_gpc() || $pa_options["stripSlashes"]) {
         $vs_val = stripSlashes($vs_val);
     }
     return $vs_val;
 }
示例#6
0
 private function processItem($pa_item, $po_parent)
 {
     if (!$po_parent instanceof DOMNode) {
         return false;
     }
     //caDebug($pa_item,"Data passed to XML item processor");
     $vs_element = $pa_item['element'];
     $vs_text = isset($pa_item['text']) ? $pa_item['text'] : null;
     $this->log(_t("XML export formatter: Processing element or attribute '%1' with text '%2' and parent element '%3' ...", $vs_element, $vs_text, $po_parent->nodeName));
     $vs_first = substr($vs_element, 0, 1);
     if ($vs_first == "@") {
         // attribute
         // attributes are only valid for DOMElement, not for DOMDocument
         if (!$po_parent instanceof DOMElement) {
             return false;
         }
         $vs_rest = substr($vs_element, 1);
         $po_parent->setAttribute($vs_rest, $vs_text);
         $vo_new_element = $po_parent;
         // attributes shouldn't have children, but still ...
     } else {
         // element
         $vs_escaped_text = trim(caEscapeForXML($vs_text));
         if (strlen($vs_text) > 0) {
             if ($vs_escaped_text != $vs_text) {
                 // sth was escaped by caEscapeForXML -> wrap in CDATA
                 $vo_new_element = $this->opo_dom->createElement($vs_element);
                 $vo_new_element->appendChild(new DOMCdataSection($vs_text));
             } else {
                 // add text as-is using DOMDocument
                 $vo_new_element = $this->opo_dom->createElement($vs_element, $vs_text);
             }
         } else {
             $vo_new_element = $this->opo_dom->createElement($vs_element);
         }
         $po_parent->appendChild($vo_new_element);
     }
     if (is_array($pa_item['children'])) {
         foreach ($pa_item['children'] as $va_child) {
             if (!empty($va_child)) {
                 $this->processItem($va_child, $vo_new_element);
             }
         }
     }
 }
示例#7
0
 public function flushContentBuffer()
 {
     /* build Solr xml indexing format for each core */
     $va_post_xml = array();
     foreach (WLPlugSearchEngineSolr::$s_doc_content_buffer as $vs_key => $va_doc_content_buffer) {
         $va_key = explode('/', $vs_key);
         $va_post_xml[$va_key[0]] .= "\t<doc>\n";
         foreach ($va_doc_content_buffer as $vs_field_name => $va_field_content) {
             $va_acc = array();
             foreach ($va_field_content as $vs_field_content) {
                 if (is_array($vs_field_content)) {
                     foreach ($vs_field_content as $vs_field_content_element) {
                         $va_post_xml[$va_key[0]] .= "\t\t" . '<field name="';
                         $va_post_xml[$va_key[0]] .= $vs_field_name;
                         $va_post_xml[$va_key[0]] .= '"><![CDATA[';
                         $va_post_xml[$va_key[0]] .= caEscapeForXML($vs_field_content_element);
                         $va_post_xml[$va_key[0]] .= ']]></field>' . "\n";
                     }
                 } else {
                     $va_acc[] = $vs_field_content;
                 }
             }
             if (sizeof($va_acc)) {
                 $va_post_xml[$va_key[0]] .= "\t\t" . '<field name="';
                 $va_post_xml[$va_key[0]] .= $vs_field_name;
                 $va_post_xml[$va_key[0]] .= '"><![CDATA[';
                 $va_post_xml[$va_key[0]] .= caEscapeForXML(join("\n", $va_acc));
                 $va_post_xml[$va_key[0]] .= ']]></field>' . "\n";
             }
         }
         if (!isset($va_doc_content_buffer[$va_key[0] . "." . $va_key[1]])) {
             /* add pk */
             $va_post_xml[$va_key[0]] .= "\t\t" . '<field name="' . $va_key[0] . "." . $va_key[1] . '">' . $va_key[2] . '</field>' . "\n";
         }
         $va_post_xml[$va_key[0]] .= "\t</doc>\n";
         // Output created on and modified on timestamps
         $qr_res = $this->opo_db->query("\t\n\t\t\t\t\t\t\t\tSELECT ccl.log_id, ccl.log_datetime, ccl.changetype, ccl.user_id\n\t\t\t\t\t\t\t\tFROM ca_change_log ccl\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t(ccl.logged_table_num = ?) AND (ccl.logged_row_id = ?)\n\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t(ccl.changetype <> 'D')\n\t\t\t\t", $this->opo_datamodel->getTableNum($va_key[0]), (int) $va_key[2]);
         while ($qr_res->nextRow()) {
             $va_post_xml[$va_key[0]] .= "\t<doc>\n";
             // We "fake" the <table>.<primary key> value here to be the log_id of the change log entry to ensure that the log entry
             // document has a different unique key than the entry for the actual record. If we didn't do this then we'd overwrite
             // the indexing for the record itself with indexing for successful log entries. Since the SearchEngine is looking for
             // just the primary key, sans table name, it's ok to do this hack.
             $va_post_xml[$va_key[0]] .= "\t\t" . '<field name="' . $va_key[0] . "." . $va_key[1] . '">' . $qr_res->get('log_id') . '</field>' . "\n";
             $va_post_xml[$va_key[0]] .= "\t\t" . '<field name="' . $va_key[1] . '">' . $va_key[2] . '</field>' . "\n";
             if ($qr_res->get('changetype') == 'I') {
                 $va_post_xml[$va_key[0]] .= "\t\t" . '<field name="created"';
                 $va_post_xml[$va_key[0]] .= '><![CDATA[';
                 $va_post_xml[$va_key[0]] .= date("c", $qr_res->get('log_datetime')) . 'Z';
                 $va_post_xml[$va_key[0]] .= ']]></field>' . "\n";
                 $va_post_xml[$va_key[0]] .= "\t\t" . '<field name="created_user_id"><![CDATA[' . $qr_res->get('user_id') . ']]></field>' . "\n";
             } else {
                 $va_post_xml[$va_key[0]] .= "\t\t" . '<field name="modified"';
                 $va_post_xml[$va_key[0]] .= '><![CDATA[';
                 $va_post_xml[$va_key[0]] .= date("c", $qr_res->get('log_datetime')) . 'Z';
                 $va_post_xml[$va_key[0]] .= ']]></field>' . "\n";
                 $va_post_xml[$va_key[0]] .= "\t\t" . '<field name="modified_user_id"><![CDATA[' . $qr_res->get('user_id') . ']]></field>' . "\n";
             }
             $va_post_xml[$va_key[0]] .= "\t</doc>\n";
         }
     }
     /* No delete of the old stuff needed. If the pk (defined as uniqueKey) already exists, it is automatically updated */
     /* send data */
     try {
         $vo_http_client = new Zend_Http_Client();
         foreach ($va_post_xml as $vs_core => $vs_post_xml) {
             $vo_http_client->setUri($this->ops_search_solr_url . "/" . $vs_core . "/update");
             $vo_http_client->setRawData($x = "<add>{$vs_post_xml}</add>")->setEncType('text/xml')->request('POST');
             try {
                 $vo_http_response = $vo_http_client->request();
                 if ($o_resp = new SimpleXMLElement($vo_http_response->getBody())) {
                     $va_status = $o_resp->xpath("/response/lst/int[@name='status']");
                     $vn_status = (int) $va_status[0];
                     if ($vn_status > 0) {
                         caLogEvent('ERR', _t('Indexing failed for %1: status %2, msg %3', $vs_core, $vn_status, $o_resp->asXML()), 'Solr->flushContentBuffer()');
                     } else {
                         /* commit */
                         try {
                             $vs_post_xml = '<commit />';
                             $vo_http_client->setRawData($vs_post_xml)->setEncType('text/xml')->request('POST');
                             $vo_http_response = $vo_http_client->request();
                             if ($o_resp = new SimpleXMLElement($vo_http_response->getBody())) {
                                 $va_status = $o_resp->xpath("/response/lst/int[@name='status']");
                                 $vn_status = (int) $va_status[0];
                                 if ($vn_status > 0) {
                                     caLogEvent('ERR', _t('Indexing commit failed for %1: status %2, msg %3', $vs_core, $vn_status, $o_resp->asXML()), 'Solr->flushContentBuffer()');
                                 }
                             } else {
                                 caLogEvent('ERR', _t('Indexing commit failed for %1: invalid response from SOLR %2', $vs_core, $vo_http_response->getBody()), 'Solr->flushContentBuffer()');
                             }
                         } catch (Exception $e) {
                             // Commit error
                             caLogEvent('ERR', _t('Indexing commit failed: %1; response was %2', $e->getMessage(), $vo_http_response->getBody()), 'Solr->flushContentBuffer()');
                         }
                     }
                 } else {
                     caLogEvent('ERR', _t('Indexing failed for %1: invalid response from SOLR %2', $vs_core, $vo_http_response->getBody()), 'Solr->flushContentBuffer()');
                 }
             } catch (Exception $e) {
                 // Indexing error
                 caLogEvent('ERR', _t('Indexing failed for %1: %2; response was %3', $vs_core, $e->getMessage(), $vo_http_response->getBody()), 'Solr->flushContentBuffer()');
             }
         }
     } catch (Exception $e) {
         caLogEvent('ERR', _t('Could not connect to SOLR server: %1', $e->getMessage()), 'Solr->flushContentBuffer()');
     }
     /* clean up */
     unset($vo_http_client);
     unset($vs_post_xml);
     $this->opa_doc_content_buffer = array();
     WLPlugSearchEngineSolr::$s_doc_content_buffer = array();
 }
 public function getDisplaysAsXML()
 {
     $t_display = new ca_bundle_displays();
     /** @var Datamodel $o_dm */
     $o_dm = Datamodel::load();
     $this->opt_locale = new ca_locales();
     $va_displays = $t_display->getBundleDisplays();
     $vs_buf = "<displays>\n";
     foreach ($va_displays as $vn_i => $va_display_by_locale) {
         $va_locales = array_keys($va_display_by_locale);
         $va_info = $va_display_by_locale[$va_locales[0]];
         if (!$t_display->load($va_info['display_id'])) {
             continue;
         }
         $vs_buf .= "\t<display code='" . ($va_info['display_code'] && preg_match('!^[A-Za-z0-9_]+$!', $va_info['display_code']) ? $va_info['display_code'] : 'display_' . $va_info['display_id']) . "' type='" . $o_dm->getTableName($va_info['table_num']) . "' system='" . $t_display->get('is_system') . "'>\n";
         $vs_buf .= "\t\t<labels>\n";
         foreach ($va_display_by_locale as $vn_locale_id => $va_display_info) {
             if (strlen($this->opt_locale->localeIDToCode($vn_locale_id)) > 0) {
                 $vs_buf .= "\t\t\t<label locale='" . $this->opt_locale->localeIDToCode($vn_locale_id) . "'><name>" . caEscapeForXML($va_display_info['name']) . "</name></label>\n";
             }
         }
         $vs_buf .= "\t\t</labels>\n";
         $va_settings = $t_display->getSettings();
         if (sizeof($va_settings) > 0) {
             $vs_buf .= "\t\t<settings>\n";
             foreach ($va_settings as $vs_setting => $vm_val) {
                 if (is_array($vm_val)) {
                     foreach ($vm_val as $vn_i => $vn_val) {
                         $vs_buf .= "\t\t\t<setting name='{$vs_setting}'><![CDATA[" . $vn_val . "]]></setting>\n";
                     }
                 } else {
                     $vs_buf .= "\t\t\t<setting name='{$vs_setting}'><![CDATA[" . $vm_val . "]]></setting>\n";
                 }
             }
             $vs_buf .= "\t\t</settings>\n";
         }
         // User and group access
         $va_users = $t_display->getUsers();
         if (sizeof($va_users) > 0) {
             $vs_buf .= "\t\t<userAccess>\n";
             foreach ($va_users as $va_user_info) {
                 $vs_buf .= "\t\t\t<permission user='******' access='" . $this->_convertUserGroupAccessToString(intval($va_user_info['access'])) . "'/>\n";
             }
             $vs_buf .= "\t\t</userAccess>\n";
         }
         $va_groups = $t_display->getUserGroups();
         if (sizeof($va_groups) > 0) {
             $vs_buf .= "\t\t<groupAccess>\n";
             foreach ($va_groups as $va_group_info) {
                 $vs_buf .= "\t\t\t<permission group='" . $va_group_info["code"] . "' access='" . $this->_convertUserGroupAccessToString(intval($va_group_info['access'])) . "'/>\n";
             }
             $vs_buf .= "\t\t</groupAccess>\n";
         }
         $va_placements = $t_display->getPlacements();
         $vs_buf .= "<bundlePlacements>\n";
         foreach ($va_placements as $vn_placement_id => $va_placement_info) {
             $vs_buf .= "\t\t<placement code='" . preg_replace("![^A-Za-z0-9_]+!", "_", $va_placement_info['bundle_name']) . "'><bundle>" . $va_placement_info['bundle_name'] . "</bundle>\n";
             $va_settings = caUnserializeForDatabase($va_placement_info['settings']);
             if (is_array($va_settings)) {
                 $vs_buf .= "<settings>\n";
                 foreach ($va_settings as $vs_setting => $vm_value) {
                     switch ($vs_setting) {
                         case 'label':
                             if (is_array($vm_value)) {
                                 foreach ($vm_value as $vn_locale_id => $vm_locale_specific_value) {
                                     if (preg_match("/^[a-z]{2,3}\\_[A-Z]{2,3}\$/", $vn_locale_id)) {
                                         // locale code
                                         $vs_locale_code = $vn_locale_id;
                                     } else {
                                         if (!($vs_locale_code = $this->opt_locale->localeIDToCode($vn_locale_id))) {
                                             $vs_locale_code = 'en_US';
                                         }
                                     }
                                     $vs_buf .= "<setting name='label' locale='" . $vs_locale_code . "'>" . caEscapeForXML($vm_locale_specific_value) . "</setting>\n";
                                 }
                             }
                             break;
                         case 'restrict_to_relationship_types':
                             if (is_array($vm_value)) {
                                 foreach ($vm_value as $vn_val) {
                                     $t_rel_type = new ca_relationship_types($vn_val);
                                     if ($t_rel_type->getPrimaryKey()) {
                                         $vs_value = $t_rel_type->get('type_code');
                                         $vs_buf .= "\t\t\t\t<setting name='{$vs_setting}'><![CDATA[" . $vs_value . "]]></setting>\n";
                                     }
                                 }
                             }
                             break;
                         case 'restrict_to_types':
                             if (is_array($vm_value)) {
                                 foreach ($vm_value as $vn_val) {
                                     $t_item = new ca_list_items($vn_val);
                                     if ($t_item->getPrimaryKey()) {
                                         $vs_value = $t_item->get('idno');
                                         $vs_buf .= "\t\t\t\t<setting name='{$vs_setting}'><![CDATA[" . $vs_value . "]]></setting>\n";
                                     }
                                 }
                             }
                             break;
                         default:
                             if (is_array($vm_value)) {
                                 foreach ($vm_value as $vn_i => $vn_val) {
                                     $vs_buf .= "\t\t\t\t<setting name='{$vs_setting}'><![CDATA[" . $vn_val . "]]></setting>\n";
                                 }
                             } else {
                                 $vs_buf .= "\t\t\t\t<setting name='{$vs_setting}'><![CDATA[" . $vm_value . "]]></setting>\n";
                             }
                             break;
                     }
                 }
                 $vs_buf .= "</settings>\n";
             }
             $vs_buf .= "\t\t</placement>\n";
         }
         $vs_buf .= "</bundlePlacements>\n";
         $vs_buf .= "\t</display>\n";
     }
     $vs_buf .= "</displays>\n";
     return $vs_buf;
 }
 public function getDisplaysAsXML($pa_options = null)
 {
     $t_display = new ca_bundle_displays();
     $o_dm = Datamodel::load();
     $this->opt_locale = new ca_locales();
     $va_displays = $t_display->getBundleDisplays();
     $vs_buf = "<displays>\n";
     foreach ($va_displays as $vn_i => $va_display_by_locale) {
         $va_locales = array_keys($va_display_by_locale);
         $va_info = $va_display_by_locale[$va_locales[0]];
         if (!$t_display->load($va_info['display_id'])) {
             continue;
         }
         $vs_buf .= "\t<display code='" . ($va_info['display_code'] && preg_match('!^[A-Za-z0-9_]+$!', $va_info['display_code']) ? $va_info['display_code'] : 'display_' . $va_info['display_id']) . "' type='" . $o_dm->getTableName($va_info['table_num']) . "' system='" . $t_display->get('is_system') . "'>\n";
         $vs_buf .= "\t\t<labels>\n";
         foreach ($va_display_by_locale as $vn_locale_id => $va_display_info) {
             if (strlen($this->opt_locale->localeIDToCode($vn_locale_id)) > 0) {
                 $vs_buf .= "\t\t\t<label locale='" . $this->opt_locale->localeIDToCode($vn_locale_id) . "'><name>" . caEscapeForXML($va_display_info['name']) . "</name></label>\n";
             }
         }
         $vs_buf .= "\t\t</labels>\n";
         $va_placements = $t_display->getPlacements();
         //print_R(($va_placements));
         $vs_buf .= "<bundlePlacements>\n";
         foreach ($va_placements as $vn_placement_id => $va_placement_info) {
             $vs_buf .= "\t\t<placement code='" . preg_replace("![^A-Za-z0-9_]+!", "_", $va_placement_info['bundle_name']) . "'><bundle>" . $va_placement_info['bundle_name'] . "</bundle>\n";
             $va_settings = caUnserializeForDatabase($va_placement_info['settings']);
             if (is_array($va_settings)) {
                 $vs_buf .= "<settings>\n";
                 foreach ($va_settings as $vs_setting => $vm_value) {
                     switch ($vs_setting) {
                         case 'label':
                             //restrict_to_relationship_types
                             if (is_array($vm_value)) {
                                 foreach ($vm_value as $vn_locale_id => $vm_locale_specific_value) {
                                     $vs_buf .= "<setting name='label' locale='" . $this->opt_locale->localeIDToCode($vn_locale_id) . "'>" . caEscapeForXML($vm_locale_specific_value) . "</setting>\n";
                                 }
                             }
                             break;
                         default:
                             if (is_array($vm_value)) {
                                 foreach ($vm_value as $vn_i => $vn_val) {
                                     $vs_buf .= "\t\t\t\t<setting name='{$vs_setting}'>" . caEscapeForXML($vn_val) . "</setting>\n";
                                 }
                             } else {
                                 $vs_buf .= "\t\t\t\t<setting name='{$vs_setting}'>" . caEscapeForXML($vm_value) . "</setting>\n";
                             }
                             break;
                     }
                 }
                 $vs_buf .= "</settings>\n";
             }
             $vs_buf .= "\t\t</placement>\n";
         }
         $vs_buf .= "</bundlePlacements>\n";
         $vs_buf .= "\t</display>\n";
     }
     $vs_buf .= "</displays>\n";
     //print_R($va_displays);
     return $vs_buf;
 }
示例#10
0
 private static function _makeList($pa_list, $pn_indent = 0)
 {
     $vs_locale = 'en_US';
     $vn_ident = $pn_indent ? str_repeat("\t", $pn_indent) : '';
     $vs_buf = '';
     foreach ($pa_list as $vn_i => $va_item) {
         $vs_label = caEscapeForXML($va_item['value']);
         $vs_label_proc = preg_replace("![^A-Za-z0-9]+!", "_", $vs_label);
         $vs_buf .= "{$vn_ident}<item idno=\"{$vs_label_proc}\" enabled=\"1\" default=\"0\">\n{$vn_ident}\t<labels>\n{$vn_ident}\t\t<label locale=\"{$vs_locale}\" preferred=\"1\">\n{$vn_ident}\t\t\t<name_singular>{$vs_label}</name_singular>\n{$vn_ident}\t\t\t<name_plural>{$vs_label}</name_plural>\n{$vn_ident}\t\t</label>\n{$vn_ident}\t</labels>" . (is_array($va_item['subitems']) && sizeof($va_item['subitems']) ? "{$vn_ident}\t<items>\n{$vn_indent}" . CLITools::_makeList($va_item['subitems'], $pn_indent + 2) . "{$vn_ident}\t</items>" : '') . "\n{$vn_ident}</item>\n";
     }
     return $vs_buf;
 }
示例#11
0
 /**
  * Sets value of one of the fields listed in XMPParser::$opa_fields above. The field values are used to
  * populate an RDF-format XML document embedded in the image file when written out to disk.
  *
  * @param string $ps_field The name of a field, as listed in XMPParser::$opa_fields
  * @param mixed $ps_value The value of the field
  * @return bool True on success, false on error
  */
 public function set($ps_field, $ps_value)
 {
     if (!isset($this->opa_fields[$ps_field])) {
         return false;
     }
     // bad field
     $ps_value = caEscapeForXML($ps_value);
     $this->opa_isset[$ps_field] = true;
     switch ($ps_field) {
         case 'Format':
             $this->o_rdf_desc[0]->addAttribute('dc:format', $ps_value, "http://purl.org/dc/elements/1.1/");
             break;
         case 'DateCreated':
             $this->o_rdf_desc[0]->addAttribute('photoshop:DateCreated', $ps_value, "http://ns.adobe.com/photoshop/1.0/");
             break;
         case 'DescriptionWriter':
             $this->o_rdf_desc[0]->addAttribute('photoshop:CaptionWriter', $ps_value, "http://ns.adobe.com/photoshop/1.0/");
             break;
         case 'RightsURL':
             $this->o_rdf_desc[0]->addAttribute('xmpRights:WebStatement', $ps_value, "http://ns.adobe.com/xap/1.0/rights/");
             break;
         case 'CopyrightStatus':
             if (!is_null($ps_value)) {
                 $vs_value = (bool) $ps_value ? "True" : "False";
                 $this->o_rdf_desc[0]->addAttribute('xmpRights:Marked', $vs_value, "http://ns.adobe.com/xap/1.0/rights/");
             }
             break;
         case 'Title':
             $o_node = $this->o_rdf_desc[0]->addChild("dc:title", '', "http://purl.org/dc/elements/1.1/");
             $o_node = $o_node->addChild("rdf:Alt", '', "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
             $o_node = $o_node->addChild("rdf:li", $ps_value, "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
             $o_node->addAttribute('xml:lang', 'x-default', 'http://www.w3.org/XML/1998/namespace');
             break;
         case 'Description':
             $o_node = $this->o_rdf_desc[0]->addChild("dc:description", '', "http://purl.org/dc/elements/1.1/");
             $o_node = $o_node->addChild("rdf:Alt", '', "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
             $o_node = $o_node->addChild("rdf:li", $ps_value, "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
             $o_node->addAttribute('xml:lang', 'x-default', 'http://www.w3.org/XML/1998/namespace');
             break;
         case 'Rights':
             $o_node = $this->o_rdf_desc[0]->addChild("dc:rights", '', "http://purl.org/dc/elements/1.1/");
             $o_node = $o_node->addChild("rdf:Alt", '', "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
             $o_node = $o_node->addChild("rdf:li", $ps_value, "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
             $o_node->addAttribute('xml:lang', 'x-default', 'http://www.w3.org/XML/1998/namespace');
             break;
         case 'Creator':
             $o_node = $this->o_rdf_desc[0]->addChild("dc:creator", '', "http://purl.org/dc/elements/1.1/");
             $o_node = $o_node->addChild("rdf:Alt", '', "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
             $o_node = $o_node->addChild("rdf:li", $ps_value, "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
             $o_node->addAttribute('xml:lang', 'x-default', 'http://www.w3.org/XML/1998/namespace');
             break;
         case 'Subjects':
             $o_node = $this->o_rdf_desc[0]->addChild("dc:subject", '', "http://purl.org/dc/elements/1.1/");
             $o_node = $o_node->addChild("rdf:Alt", '', "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
             $o_node = $o_node->addChild("rdf:li", $ps_value, "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
             $o_node->addAttribute('xml:lang', 'x-default', 'http://www.w3.org/XML/1998/namespace');
             break;
         case 'CreatorAddress':
         case 'CreatorCity':
         case 'CreatorStateRegion':
         case 'CreatorPostalCode':
         case 'CreatorCountry':
         case 'CreatorPhone':
         case 'CreatorEmail':
         case 'CreatorWebsite':
             if (!$this->o_creator) {
                 if (!($this->o_creator = $this->opo_metadata->xpath('//Iptc4xmpCore:CreatorContactInfo'))) {
                     $this->o_creator = $this->o_rdf_desc[0]->addChild("Iptc4xmpCore:CreatorContactInfo", '', "http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/");
                 }
             }
             switch ($ps_field) {
                 case 'CreatorAddress':
                     $this->o_creator[0]->addAttribute('Iptc4xmpCore:CiAdrExtadr', $ps_value, "http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/");
                     break;
                 case 'CreatorCity':
                     $this->o_creator[0]->addAttribute('Iptc4xmpCore:CiAdrCity', $ps_value, "http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/");
                     break;
                 case 'CreatorStateRegion':
                     $this->o_creator[0]->addAttribute('Iptc4xmpCore:CiAdrRegion', $ps_value, "http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/");
                     break;
                 case 'CreatorPostalCode':
                     $this->o_creator[0]->addAttribute('Iptc4xmpCore:CiAdrPcode', $ps_value, "http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/");
                     break;
                 case 'CreatorCountry':
                     $this->o_creator[0]->addAttribute('Iptc4xmpCore:CiAdrCtry', $ps_value, "http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/");
                     break;
                 case 'CreatorPhone':
                     $this->o_creator[0]->addAttribute('Iptc4xmpCore:CiTelWork', $ps_value, "http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/");
                     break;
                 case 'CreatorEmail':
                     $this->o_creator[0]->addAttribute('Iptc4xmpCore:CiEmailWork', $ps_value, "http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/");
                     break;
                 case 'CreatorWebsite':
                     $this->o_creator[0]->addAttribute('Iptc4xmpCore:CiUrlWork', $ps_value, "http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/");
                     break;
             }
             break;
     }
     return true;
 }
示例#12
0
 private function processItem($pa_item, $po_parent)
 {
     if (!$po_parent instanceof DOMNode) {
         return false;
     }
     //caDebug($pa_item,"Data passed to XML item processor");
     $vs_element = $pa_item['element'];
     $vs_text = isset($pa_item['text']) ? $pa_item['text'] : null;
     $vs_first = substr($vs_element, 0, 1);
     if ($vs_first == "@") {
         // attribute
         // attributes are only valid for DOMElement, not for DOMDocument
         if (!$po_parent instanceof DOMElement) {
             return false;
         }
         $vs_rest = substr($vs_element, 1);
         $po_parent->setAttribute($vs_rest, $vs_text);
     } else {
         // element
         $vs_text = trim(caEscapeForXML($vs_text));
         if (strlen($vs_text) > 0) {
             $vo_new_element = $this->opo_dom->createElement($vs_element, $vs_text);
         } else {
             $vo_new_element = $this->opo_dom->createElement($vs_element);
         }
         $po_parent->appendChild($vo_new_element);
     }
     if (is_array($pa_item['children'])) {
         foreach ($pa_item['children'] as $va_child) {
             if (!empty($va_child)) {
                 $this->processItem($va_child, $vo_new_element);
             }
         }
     }
 }
示例#13
0
	<setImages>
<?php 
if (sizeof($va_items)) {
    if (!($va_display_flds = $this->request->config->getList('ca_objects_set_slideshow_display_attributes'))) {
        $va_display_flds = array('ca_objects.preferred_labels.name');
    }
    foreach ($va_items as $vn_item_id => $va_item) {
        $t_object = new ca_objects($va_item['row_id']);
        $va_display_values = array();
        foreach ($va_display_flds as $vs_display_fld) {
            if ($vs_val = trim($t_object->get($vs_display_fld))) {
                $va_display_values[] = $vs_val;
            }
        }
        $vs_large_image = caEscapeForXML($va_item['representation_url']);
        $vs_title = caEscapeForXML(join("\n", $va_display_values));
        ?>
			<image large="<?php 
        print $vs_large_image;
        ?>
" title="<?php 
        print $vs_title;
        ?>
" item_id="<?php 
        print $va_item['object_id'];
        ?>
"/>
<?php 
    }
}
?>