Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
page_rss_feed_edit_fns.inc
1 <?php
16 require_once SQ_CORE_PACKAGE_PATH.'/page/page_edit_fns.inc';
29 {
30 
31 
36  function __construct()
37  {
38  parent::__construct();
39 
40  }//end constructor
41 
42 
53  function paintLisitngChooser(&$asset, &$o, $prefix)
54  {
55  $current_rss_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_NOTICE, 'listing_engine', FALSE, 'major', 'generate_rss');
56  $rss_links = Array();
57  foreach ($current_rss_links as $i => $link) {
58  $rss_links[$link['minorid']] = $link['minor_type_code'];
59  }
60  $wa = $asset->writeAccess('attributes');
61  if ($wa) {
62  multiple_asset_finder($prefix.'_listing_engines', array_keys($rss_links), Array('listing_engine' => 'D'));
63  return TRUE;
64  } else {
65  $infos = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(array_keys($rss_links));
66  ?>
67  <table class="sq-backend-table">
68  <tr>
69  <td class="sq-backend-table-header"><?php echo translate('asset') ?></td>
70  <td class="sq-backend-table-header"><?php echo translate('type') ?></td>
71  </tr>
72  <?php
73  foreach ($infos as $assetid => $info) {
74  ?>
75  <tr>
76  <td class="sq-backend-table-cell"><?php echo get_asset_tag_line($assetid) ?></td>
77  <td class="sq-backend-table-cell"><?php echo $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($info['type_code'], 'name') ?></td>
78  </tr>
79  <?php
80  }
81  ?>
82  </table>
83  <?php
84  return FALSE;
85  }
86 
87  }//end paintLisitngChooser()
88 
89 
100  function processLisitngChooser(&$asset, &$o, $prefix)
101  {
102  if (isset($_POST[$prefix.'_listing_engines'])) {
103  $listings = $_POST[$prefix.'_listing_engines'];
104  $listing_ids = Array();
105  foreach ($listings as $listing) {
106  if (!empty($listing['assetid'])) {
107  $listing_ids[] = $listing['assetid'];
108  }
109  }
110  $links = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_NOTICE, 'listing_engine', FALSE, 'major', 'generate_rss');
111  $existing_list_ids = Array();
112  foreach ($links as $link) {
113  if (!in_array($link['minorid'], $listing_ids)) {
114  $asset->deleteLink($link['linkid']);
115  } else {
116  $existing_list_ids[] = $link['minorid'];
117  }
118  }
119  foreach ($listing_ids as $listing_id) {
120  if (!in_array($listing_id, $existing_list_ids)) {
121  $listing_engine = $GLOBALS['SQ_SYSTEM']->am->getAsset($listing_id);
122  $id = $asset->createLink($listing_engine, SQ_LINK_NOTICE, 'generate_rss');
123  }
124  }
125  }
126 
127  }//end processLisitngChooser()
128 
129 
140  function paintKeywords(&$asset, &$o, $prefix)
141  {
142  $types = Array();
143  $rss_source_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_NOTICE, 'listing_engine', FALSE, 'major', 'generate_rss');
144  if (!empty($rss_source_links)) {
145  $keywords = Array();
146  foreach ($rss_source_links as $links) {
147  $listing_engine = $GLOBALS['SQ_SYSTEM']->am->getAsset($links['minorid']);
148  $attribute_types = array_keys($listing_engine->attr('types'));
149  if (!empty($attribute_types)) {
150  foreach ($attribute_types as $type) {
151  if (!isset($keywords[$type])) {
152  $keywords[$type] = $asset->_getAvailableKeywordsOfType($type);
153  }
154  $types[$type] = $type;
155  }
156  }
157  }
158  $types['select'] = translate('select_asset_type');
159  $wa = $asset->writeAccess('attributes');
160  if ($wa) {
161  $type = null;
162  $tag = null;
163  if (isset($_POST['asset_type']) && ($_POST['asset_type'] != 'select')) {
164  $type = $_POST['asset_type'];
165  }
166  if (isset($_POST[$prefix.'_tag']) && !empty($_POST[$prefix.'_tag'])) {
167  $tag = $_POST[$prefix.'_tag'];
168  $type = null;
169  }
170 
171  ?>
172  <table class="sq-backend-table">
173  <tr>
174  <td> <?php echo translate('choose_asset_type');?></td>
175  <td>
176  <?php
177  combo_box('asset_type', $types, FALSE, !empty($type)? $type: 'select');
178  ?>
179  </td>
180  <td>&nbsp;</td>
181  </tr>
182  <?php
183  if (!empty($type)) {
184  $keywords['select'] = translate('select_keyword');
185  $keyword = null;
186  $tag = null;
187  if (isset($_POST[$prefix.'_keyword']) && ($_POST[$prefix.'_keyword'] != 'select')) {
188  $keyword = $_POST[$prefix.'_keyword'];
189  }
190  if (empty($tag)) {
191  ?>
192  <tr>
193  <td><?php echo translate('choose_or_enter_keyword');?></td>
194  <td>
195  <?php
196  combo_box($prefix.'_keyword', $keywords[$type], FALSE, !empty($keyword)? $keyword: 'select');
197  ?>
198  </td>
199  <td>
200  <?php
201  text_box($prefix.'_keyword_text', '');
202  ?>
203  </td>
204  </tr>
205  <?php
206  $type = $asset->attr('rss_types');
207  $tags = Array();
208  if ($type == 'rss_1.0') {
209  $tags = Array('title', 'description', 'link', 'rdf:about');
210  } else if ($type == 'rss_2.0') {
211  $tags = Array('title', 'description', 'link', 'pubDate', 'category', 'author', 'comments', 'guid', 'enclosure.url', 'enclosure.length', 'enclosure.type');
212  } else {
213  // it is of type ATOM 1.0
214  // Refer http://www.atomenabled.org/developers/syndication/#requiredEntryElements
215  $tags = Array('id', 'title', 'updated', 'author_name', 'author_email', 'author_uri', 'content', 'link.rel', 'link.href', 'summary', 'category.term', 'contributor_name', 'contributor_email', 'contributor_uri', 'source_id', 'source_title', 'source_updated', 'source_rights', 'rights');
216  }
217  foreach ($tags as $key => $val) {
218  $tags[$val] = strpos($val, '_') !== FALSE? str_replace('_', ' ', $val): (strpos($val, '.') !== FALSE? str_replace('.', ' ', $val).' = ':$val);
219  unset($tags[$key]);
220  }
221  ?>
222  <tr>
223  <td><?php echo translate('choose_tag');?></td>
224  <td>
225  <?php
226  combo_box($prefix.'_tag', $tags, FALSE, !empty($tag)? $tag: '');
227  ?>
228  </td>
229  <td>&nbsp;</td>
230  </tr>
231  <?php
232  }//end if tag is not empty
233  }//end if type is not empty
234  ?>
235  </table>
236  <?php
237  return TRUE;
238  }//end if write access
239  } else {
240  echo 'No Listing Engine Assets Have Been Selected To Generate The RSS';
241  }
242  return FALSE;
243 
244  }//end paintKeywords()
245 
246 
257  function processKeywords(&$asset, &$o, $prefix)
258  {
259  if (isset($_POST[$prefix.'_tag']) && !empty($_POST[$prefix.'_tag'])) {
260  $type = $_POST['asset_type'];
261  if ($type != 'select') {
262  $tag = $_POST[$prefix.'_tag'];
263  $keyword = null;
264  if (empty($_POST[$prefix.'_keyword_text'])) {
265  $keyword = $_POST[$prefix.'_keyword'];
266  } else {
267  $keyword = $_POST[$prefix.'_keyword_text'];
268  }
269  $items = $asset->attr('items');
270  $items[$type][$tag] = $keyword;
271  $asset->setAttrValue('items', $items);
272  return TRUE;
273  }
274  }
275  return FALSE;
276 
277  }//end processKeywords()
278 
279 
290  function paintSelectedKeywords(&$asset, &$o, $prefix)
291  {
292  $items = $asset->attr('items');
293  $wa = $asset->writeAccess('attributes');
294  if (!empty($items)) {
295  ?>
296  <table class="sq-backend-table">
297  <tr>
298  <th><?php echo translate('asset_type');?></th>
299  <th><?php echo translate('keyword');?></th>
300  <th><?php echo translate('tag_represented');?></th>
301  <?php
302  if ($wa) {
303  ?>
304  <th><?php echo translate('delete_question');?></th>
305  <?php
306  }
307  ?>
308  </tr>
309  <?php
310  foreach ($items as $type => $info) {
311  foreach ($info as $tag => $keyword) {
312  ?>
313  <tr>
314  <td><?php echo $type;?></td>
315  <td><?php echo $keyword; ?></td>
316  <td><?php echo $tag; ?></td>
317  <?php
318  if ($wa) {
319  ?>
320  <td><?php check_box('delete_tag['.$type.']['.$tag.']', $keyword);?></td>
321  <?php
322  }
323  ?>
324  </tr>
325  <?php
326  }
327  }
328  ?>
329  </table>
330  <?php
331  }//end if where items is not empty
332  if ($wa) return TRUE;
333  return FALSE;
334 
335  }//end paintSelectedKeywords()
336 
337 
348  function processSelectedKeywords(&$asset, &$o, $prefix)
349  {
350  if (isset($_POST['delete_tag'])) {
351  $selected_items = $asset->attr('items');
352  $deleted = $_POST['delete_tag'];
353  foreach ($deleted as $type => $info) {
354  foreach ($info as $tag => $keyword) {
355  unset($selected_items[$type][$tag]);
356  }
357  }
358  // if there are no keywords and tags for a particular asset type then unset the asset type from the items array
359  // you dont want to have a key in an array with an empty value.. no !! never.. unless i want a messy interface
360  foreach ($selected_items as $key => $value) {
361  if (empty($value)) unset($selected_items[$key]);
362  }
363  $asset->setAttrValue('items', $selected_items);
364  return TRUE;
365  }
366  return FALSE;
367 
368  }//end processSelectedKeywords()
369 
370 
381  function paintChannelImage(&$asset, &$o, $prefix)
382  {
383  $modes = Array('add_channel', 'add_image');
384  foreach ($modes as $mode) {
385  $tags = Array();
386  $required = Array();
387  $type = $asset->attr('rss_types');
388  switch ($mode) {
389  case 'add_channel':
390  if ($type == 'rss_1.0') {
391  $tags = Array('title', 'link', 'description', 'rdf:about');
392  $required = $tags;
393  } else if ($type == 'rss_2.0') {
394  $required = Array('title', 'link', 'description');
395  $tags = Array('title', 'link', 'description', 'pubDate', 'lastBuildDate', 'language', 'copyright', 'webMaster', 'managingEditor', 'category', 'generator', 'ttl');
396  } else {
397  // type is ATOM 1.0
398  // Refer http://www.atomenabled.org/developers/syndication/#requiredFeedElements
399  $required = Array('id', 'title', 'updated');
400  $recommended = Array('author_name', 'author_email', 'author_uri', 'link.rel', 'link.href');
401  $optional = Array('category.term', 'contributor_name', 'icon', 'logo', 'rights', 'subtitle');
402  $tags = array_merge($required, $recommended, $optional);
403  }
404  break;
405  case 'add_image':
406  if ($type == 'rss_1.0') {
407  $tags = Array('title', 'url', 'link');
408  $required = Array('title', 'url', 'link');
409  } else if ($type == 'rss_2.0') {
410  $tags = Array('title', 'description', 'url', 'width', 'height', 'link');
411  $required = Array('title', 'url', 'link');
412  } else {
413  // ATOM 1.0
414  $tags = Array('icon');
415  $required = Array('icon');
416  }
417  break;
418  }
419  $attr = substr($mode, strlen('add_'));
420  $attr_val = $asset->attr($attr);
421  $wa = $asset->writeAccess('attributes');
422  $i = 0;
423  if (!empty($attr_val) || ($wa)) {
424  echo '<br /><b>'.translate($attr.'_info').'</b>';
425  ?>
426  <table class="sq-backend-table" width="100%">
427  <tr>
428  <th><?php echo translate('tag');?></th>
429  <th><?php echo translate('value');?></th>
430  <?php
431  if (($wa) && (in_array('link', $tags) || in_array('link.href', $tags))) {
432  ?>
433  <th><?php echo translate('link_text_value');?></th>
434  <?php
435  }
436  ?>
437  <th><?php echo translate('required');?></th>
438  </tr>
439  <?php
440  foreach ($tags as $tag) {
441  ?>
442  <tr>
443  <td><?php echo $tag; ?></td>
444  <td>
445  <?php
446  if ($wa) {
447  // if the tag is not a link then just use the value normally
448  // else check if the value is a valid asset id and if yes then print the asset finder with the assetid
449  // else just print the value normally in a text box
450  if (($tag != 'link') && ($tag !== 'link.href')) {
451  text_box($attr.'['.$tag.']', isset($attr_val[$tag])? $attr_val[$tag]: '', 30);
452  if (($wa) && (in_array('link', $tags) || in_array('link.href', $tags))) {
453  ?>
454  </td>
455  <td>&nbsp;
456  <?php
457  }
458  } else {
459  $id = 0;
460  $url = null;
461  if (isset($attr_val[$tag])) {
462  if (assert_valid_assetid($attr_val[$tag], '', TRUE, FALSE)) {
463  $id = $attr_val[$tag];
464  } else {
465  $url = $attr_val[$tag];
466  }
467  }
468  asset_finder($attr.'['.$tag.']', $id);
469  ?>
470  </td>
471  <td><?php text_box($attr.'['.$tag.'_text]', $url);
472  }
473  } else {
474  // if the tag is not a link then just use the value normally
475  // else check if the value is a valid asset id and if yes then print the asset's url
476  // else just print the value normally
477  if (($tag != 'link') && ($tag !== 'link.href')) {
478  echo isset($attr_val[$tag])? $attr_val[$tag]: '&nbsp;';
479  } else if (isset($attr_val[$tag])) {
480  if (assert_valid_assetid($attr_val[$tag], '', TRUE, FALSE)) {
481  $value = $GLOBALS['SQ_SYSTEM']->am->getAssetURL($attr_val[$tag]);
482  echo $value;
483  } else {
484  echo $attr_val[$tag];
485  }
486  } else {
487  echo '&nbsp;';
488  }
489  }
490  ?>
491  </td>
492  <td>
493  <?php
494  // if the current tag is a required tag or not
495  if (!empty($required)) {
496  if (in_array($tag, $required)) {
497  echo 'Yes';
498  } else {
499  echo 'No';
500  }
501  }
502  ?></td>
503  </tr>
504  <?php
505  }//end foreach of tags
506  ?>
507  </table>
508  <?php
509  }//end if write access or attribute value is not empty
510  }//end foreach of modes
511 
512  }//end paintChannelImage()
513 
514 
525  function processChannelImage(&$asset, &$o, $prefix)
526  {
527  $modes = Array('add_channel', 'add_image');
528  foreach ($modes as $mode) {
529  $attr = substr($mode, strlen('add_'));
530  if (isset($_POST[$attr])) {
531  $attr_val = $_POST[$attr];
532  $new_val = Array();
533  foreach ($attr_val as $tag => $value) {
534  if ($tag == 'link_text') continue;
535  if (!empty($value)) {
536  if (in_array($tag, Array('link', 'link.href'))) {
537  // if there is a text value for the link then it is taken
538  // else the asset id is taken and its url is stored
539  if (!empty($attr_val['link_text'])) {
540  $value = $attr_val['link_text'];
541  } else {
542  if (empty($value['assetid'])) continue;
543  $value = $value['assetid'];
544  }
545  }
546  $new_val[$tag] = $value;
547  }
548  }
549  $asset->setAttrValue($attr, $new_val);
550  }
551  }
552  return TRUE;
553 
554  }//end processChannelImage()
555 
556 
566  function ifWriteAccess(&$asset, $prefix)
567  {
568  $wa = $asset->writeAccess('attributes');
569  if ($wa) return TRUE;
570  return FALSE;
571 
572  }//end ifWriteAccess()
573 
574 
584  function ItemsNotEmpty(&$asset, $prefix)
585  {
586  $items = $asset->attr('items');
587  if (!empty($items)) return TRUE;
588  return FALSE;
589 
590  }//end ItemsNotEmpty()
591 
592 
593 }//end class
594 ?>