17 require_once SQ_CORE_PACKAGE_PATH.
'/page/page.inc';
18 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
43 $this->_ser_attrs = TRUE;
44 parent::__construct($assetid);
59 protected function _getName($short_name=FALSE, $contextid=NULL)
62 if ($contextid === NULL) {
63 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
67 $values = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'name', $this->
type(), Array($this->
id), $contextid);
68 if (empty($values) === TRUE) {
69 return parent::_getName($short_name, $contextid);
71 return $values[$this->id];
87 $links[SQ_LINK_NOTICE][
'listing_engine'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
106 $initial_path = strtolower($this->
attr(
'name'));
107 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
108 $valid_paths = make_valid_web_paths(Array($initial_path));
109 $good_paths = $GLOBALS[
'SQ_SYSTEM']->am->webPathsInUse($link[
'asset'], $valid_paths, $this->
id, TRUE);
126 if (empty($type))
return $keywords;
127 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($type);
128 $dummy_asset =
new $type();
129 $keywords += $dummy_asset->getAvailableKeywords();
146 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($linkid);
147 switch (strtolower($link[
'value'])) {
148 case 'generate_rss' :
149 return translate(
'listing_engine_asset_link_description');
152 return parent::describeLink($linkid);
184 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
187 if ($this->
attr(
'http_auth') && isset($_SERVER[
'PHP_AUTH_USER'])) {
189 $_REQUEST[
'SQ_ACTION'] =
'login';
191 $_POST[
'SQ_LOGIN_USERNAME'] = $_SERVER[
'PHP_AUTH_USER'];
192 $_POST[
'SQ_LOGIN_PASSWORD'] = $_SERVER[
'PHP_AUTH_PW'];
194 $_POST[
'SQ_LOGIN_KEY'] = $GLOBALS[
'SQ_SYSTEM']->loginKey();
195 $GLOBALS[
'SQ_SYSTEM']->_processGlobalActions();
200 if (!parent::readAccess()) {
203 $GLOBALS[
'SQ_SYSTEM']->paintLogin(translate(
'login'), translate(
'cannot_access_asset', $this->name));
204 $login = ob_get_clean();
207 if ($this->
attr(
'http_auth')) {
208 header(
'WWW-Authenticate: Basic realm="'.$this->name.
'"');
209 header(
'HTTP/1.0 401 Unauthorized');
217 $cm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
218 $rss = $cm->loadFromCache($this->
id, $this->
type(),
'ctx'.$contextid);
220 if ($this->charset) {
221 $charset = $this->charset;
223 $charset = SQ_CONF_DEFAULT_CHARACTER_SET;
227 if ($rss !== FALSE) {
228 $rss = unserialize($rss);
231 $num_assets_as_items = $this->
attr(
'num_assets_as_items');
232 $assets_to_list = Array();
233 $rss_source_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_NOTICE,
'listing_engine', FALSE,
'major',
'generate_rss');
235 if (empty($rss_source_links)) {
236 trigger_error(translate(
'no_listing_engine_assets_linked'), E_USER_WARNING);
239 foreach ($rss_source_links as $links) {
240 $listing_engine = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($links[
'minorid']);
241 $list_of_assets = $listing_engine->getAssetList();
242 $listing_engine->filterAssetList($list_of_assets);
243 $assets_to_list += $list_of_assets;
246 $channel = $this->
attr(
'channel');
247 $image = $this->
attr(
'image');
248 $items = $this->
attr(
'items');
252 if (empty($channel) || empty($items)) {
253 trigger_error(translate(
'no_channel_or_items_found'), E_USER_WARNING);
257 require_once SQ_FUDGE_PATH.
'/rss_feeds/rss_feed_writer.inc';
260 $type = $this->
attr(
'rss_types');
261 $type = explode(
'_', $type);
262 $writer->setTypeVersion($type[0], $type[1]);
264 $new_channel = Array();
265 $rss_type = implode(
'_', $type);
273 if (!$no_errors)
return;
276 $writer->addChannel($new_channel);
281 if (!empty($new_image)) {
284 if (!$no_errors)
return;
286 $writer->addImage($new_image);
292 $new_items = Array();
295 foreach ($assets_to_list as $assetid => $asset_type) {
296 $asset_type = $asset_type[0][
'type_code'];
297 foreach ($items as $type => $keywords) {
298 if (!empty($num_assets_as_items)) {
299 if ($index >= $num_assets_as_items)
break;
302 if (strcasecmp($type, $asset_type) == 0) {
303 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
304 if (!is_null($asset) && ($asset instanceof $asset_type)) {
305 foreach ($keywords as $tag => $keyword) {
308 if (strpos($keyword,
'%') !== FALSE) {
309 $sub_keywords = Array();
310 require_once SQ_FUDGE_PATH.
'/general/text.inc';
311 $sub_keywords = retrieve_keywords_replacements($keyword);
312 $replacements = Array();
313 foreach ($sub_keywords as $key) {
314 $replacements[$key] = $asset->getKeywordReplacement($key);
316 $replacement = replace_keywords($keyword, $replacements);
318 $replacement = $asset->getKeywordReplacement($keyword);
320 if (substr($keyword, 0, 15) ==
'asset_metadata_') {
321 $metadata_keyword = substr($keyword, 15);
323 $mm =& $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
326 $metadata_values = $mm->getMetadataFieldValues($assetid, Array($metadata_keyword));
328 foreach ($metadata_values as $field => $value) {
329 $replacement = $value;
332 if (strpos($tag,
'_') !== FALSE) {
333 $sub_tag = explode(
'_', $tag);
334 $new_items[$index][$sub_tag[0]][
'SUBTAGS'][$sub_tag[1]] = $replacement;
335 }
else if (strpos($tag,
'.') !== FALSE) {
336 $sub_tag = explode(
'.', $tag);
337 $new_items[$index][$sub_tag[0]][
'ATTRIBUTES'][$sub_tag[1]] = $replacement;
339 $new_items[$index][$tag] = $replacement;
349 if (!$no_errors)
return;
350 $writer->addItems($new_items);
351 $rss = $writer->getRSSString(FALSE, $charset);
352 $cm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
353 $r = $cm->saveToCache($this->
id, $this->
type(),
'ctx'.$contextid, serialize($rss));
357 header(
'Content-type: text/xml; charset='.$charset);
428 $new_channel = Array();
429 foreach ($channel as $tag => $value) {
430 if (strpos($tag,
'_') !== FALSE) {
431 $sub_tag = explode(
'_', $tag);
432 if ($sub_tag[0] ==
'link.href') {
433 $link_href_tag = explode(
'.', $sub_tag[0]);
434 $new_channel[$link_href_tag[0]][
'ATTRIBUTES'][$link_href_tag[1]] = $value;
436 $new_channel[$sub_tag[0]][
'SUBTAGS'][$sub_tag[1]] = $value;
438 }
else if (strpos($tag,
'.') !== FALSE) {
439 if ($tag ==
'link.href') {
440 if (assert_valid_assetid($value,
'', TRUE, FALSE)) {
441 $value = $GLOBALS[
'SQ_SYSTEM']->am->getAssetURL($value);
444 $sub_tag = explode(
'.', $tag);
445 $new_channel[$sub_tag[0]][
'ATTRIBUTES'][$sub_tag[1]] = $value;
448 if (in_array($tag, Array(
'updated',
'pubDate',
'lastBuildDate',
'published'))) {
449 $timestamp = strtotime($value);
450 if (($timestamp == -1) ||($timestamp === FALSE)) {
451 $timestamp = mktime($value);
453 if ($rss_type ==
'rss_2.0') {
454 $value = date(
'D, j M Y H:i:s O', $timestamp);
455 }
else if ($rss_type ==
'atom_1.0') {
456 $value = date(
'Y-m-d', $timestamp).
'T'.date(
'H:i:s', $timestamp).
'Z';
459 if ($tag ==
'link') {
460 if (assert_valid_assetid($value,
'', TRUE, FALSE)) {
461 $value = $GLOBALS[
'SQ_SYSTEM']->am->getAssetURL($value);
465 $new_channel[$tag] = $value;
483 $new_image = Array();
484 foreach ($image as $tag => $value) {
485 if (strpos($tag,
'_') !== FALSE) {
486 $sub_tag = explode(
'_', $tag);
487 $new_image[$sub_tag[0]][$sub_tag[1]] = $value;
489 if ($tag ==
'link') {
490 if (assert_valid_assetid($value,
'', TRUE, FALSE)) {
491 $value = $GLOBALS[
'SQ_SYSTEM']->am->getAssetURL($value);
494 $new_image[$tag] = $value;
516 $rss_type = $this->
attr(
'rss_types');
519 $required = Array(
'id',
'updated',
'title',
'author');
522 $required = Array(
'link',
'title',
'rdf:about');
525 $required = Array(
'link',
'title',
'description');
528 foreach ($items as $item) {
529 $keys = array_keys($item);
530 if (in_array(
'category', $keys)) {
531 $temp = $items[
'category'][
'ATTRIBUTUES'];
532 if (!in_array(
'term', array_keys($temp))) {
533 trigger_error(translate(
'required_attr_term_unassigned'), E_USER_WARNING);
537 if ($rss_type ==
'rss_2.0') {
538 if (!in_array(
'title', $keys)) {
539 if (!in_array(
'description', $keys)) {
540 trigger_error(translate(
'required_tag_title_or_description_missing'), E_USER_WARNING);
546 foreach ($required as $req) {
547 if (!in_array($req, $keys)) {
548 trigger_error(
'Required Tag '.$req.
' Is Not Assigned In Items', E_USER_WARNING);
569 if (empty($channel)) {
570 trigger_error(
'Missing Channel Information', E_USER_WARNING);
574 $rss_type = $this->
attr(
'rss_types');
577 $required = Array(
'title',
'link',
'description',
'rdf:about');
580 $required = Array(
'title',
'link',
'description');
583 $required = Array(
'title',
'id',
'updated');
585 foreach ($required as $tag) {
586 if (!in_array($tag, array_keys($channel))) {
587 trigger_error(translate(
'required_attribute').
' "'.$tag.
'" '.translate(
'missing_for_channel'), E_USER_WARNING);
607 trigger_error(translate(
'missing_image_info'), E_USER_WARNING);
611 $rss_type = $this->
attr(
'rss_types');
617 $required = Array(
'title',
'url',
'link');
619 foreach ($required as $tag) {
620 if (!in_array($tag, array_keys($image))) {
621 trigger_error(translate(
'required_attribute').
' "'.$tag.
'" '.translate(
'missing_for_image'), E_USER_WARNING);
641 if (SQ_IN_LIMBO || SQ_IN_BACKEND) {
642 return parent::readAccess($assetids);