Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
funnelback_manager_edit_fns.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
18 
31 {
32 
33 
40  function __construct($assetid=0)
41  {
42  parent::__construct($assetid);
43  unset($this->static_screens['settings']);
44  unset($this->static_screens['preview']);
45  unset($this->static_screens['lookupValues']);
46  unset($this->static_screens['metadata']);
47  unset($this->static_screens['metadataSchemas']);
48  unset($this->static_screens['workflow']);
49  unset($this->static_screens['tagging']);
50  unset($this->static_screens['dependants']);
51  unset($this->static_screens['linking']);
52  unset($this->static_screens['roles']);
53  unset($this->static_screens['permissions']);
54  unset($this->static_screens['layouts']);
55 
56  }//end constructor
57 
58 
68  function indexingOn(&$owner, $prefix)
69  {
70  return $owner->attr('indexing');
71 
72  }//end indexingOn()
73 
74 
85  function paintIndexing(&$asset, &$o, $prefix)
86  {
87  $wa = $asset->writeAccess('attributes');
88  $indexing = $asset->attr('indexing');
89  $options = Array('0'=>translate('disabled'),'1'=>translate('enabled'));
90  if ($wa) {
91  combo_box($prefix.'_indexing', $options, FALSE, (($indexing) ? '1' : '0'));
92  } else {
93  echo (($indexing) ? translate('enabled') : translate('disabled'));
94  }//end if
95 
96  return TRUE;
97 
98  }//end paintIndexing()
99 
100 
111  function processIndexing(&$asset, &$o, $prefix)
112  {
113  $status = FALSE;
114  $wa = $asset->writeAccess('attributes');
115  $choice = array_get_index($_POST, $prefix.'_indexing', FALSE);
116  if ($wa) {
117  if ($choice == '1') {
118  $asset->setAttrValue('indexing', TRUE);
119 
120  if ($asset->checkInstalled() === FALSE) {
121  log_dump('Funnelback is enabled, but the binaries are not installed');
122  }
123  } else {
124  $asset->setAttrValue('indexing', FALSE);
125  }//end if
126 
127  $status = $asset->saveAttributes();
128  }//end if
129 
130  return $status;
131 
132  }//end processIndexing()
133 
134 
145  function paintRebuildCache(&$asset, &$o, $prefix)
146  {
147  $wa = $asset->writeAccess('attributes');
148  if ($wa) {
149  asset_finder($prefix.'_rebuild_root_node', 0);
150 
151  $o->closeField();
152  $o->openField(translate('system_wide'));
153 
154  check_box($prefix.'_rebuild_all_system', 1);
155  echo translate('funnelback_rebuild_whole_system');
156  }//end if
157 
158  return TRUE;
159 
160  }//end paintRebuildCache()
161 
162 
173  function processRebuildCache(&$asset, &$o, $prefix)
174  {
175  $status = FALSE;
176  $wa = $asset->writeAccess('attributes');
177  if ($wa) {
178  $node_info = array_get_index($_POST, $prefix.'_rebuild_root_node', Array());
179  $all_system = array_get_index($_POST, $prefix.'_rebuild_all_system', 0);
180  $root_node = array_get_index($node_info, 'assetid', 0);
181 
182  if (!empty($all_system)) {
183  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
184  $running_vars = Array('root_assetid' => Array());
185  $hh->queueHipo('hipo_job_funnelback_rebuild_cache', $running_vars, '', SQ_PACKAGES_PATH.'/funnelback/hipo_jobs');
186  } else if (!empty($root_node) && $GLOBALS['SQ_SYSTEM']->am->assetExists($root_node)) {
187  // Indexing by a root node
188  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
189  $running_vars = Array('root_assetid' => Array($root_node));
190  $hh->queueHipo('hipo_job_funnelback_rebuild_cache', $running_vars, '', SQ_PACKAGES_PATH.'/funnelback/hipo_jobs');
191  }//end if
192 
193  return TRUE;
194  }//end if
195 
196  return $status;
197 
198  }//end processRebuildCache()
199 
200 
201 // --- INDEXER SCREEN FUNCTIONS --- //
202 
203 
214  function paintReindexing(&$asset, &$o, $prefix)
215  {
216  $wa = $asset->writeAccess('attributes');
217  if ($wa) {
218  if ($this->indexingOn($asset, $prefix)) {
219  $collections = $asset->getCollections();
220  ksort($collections);
221  foreach ($collections as $collection_id => $collection_data) {
222  $name = array_get_index($collection_data, 'name', '');
223  $valid = array_get_index($collection_data, 'valid', TRUE);
224  if (empty($name)) continue;
225  check_box($prefix.'_reindex_collection[]', $collection_id);
226  echo $name.'<br />';
227  }//end foreach
228 
229  $o->closeField();
230  $o->openField(translate('system_wide'));
231 
232  check_box($prefix.'_reindex_all_system', 1);
233  echo translate('funnelback_index_whole_system');
234  } else {
235  echo translate('funnelback_indexing_not_enabled');
236  }//end if
237  }//end if
238 
239  return TRUE;
240 
241  }//end paintReindexing()
242 
243 
254  function processReindexing(&$asset, &$o, $prefix)
255  {
256  $wa = $asset->writeAccess('attributes');
257  if ($wa) {
258  $collections = array_get_index($_POST, $prefix.'_reindex_collection', Array());
259  $all_system = array_get_index($_POST, $prefix.'_reindex_all_system', 0);
260  $reindex = FALSE;
261 
262  if (!empty($all_system)) {
263  // Indexing the whole system
264  $collections = Array();
265  $reindex = TRUE;
266  } else if (!empty($collections)) {
267  // Indexing by a root node
268  $reindex = TRUE;
269  }//end if
270 
271  if ($reindex) {
272  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
273  $running_vars = Array('collections' => $collections);
274  $hh->queueHipo('hipo_job_funnelback_reindex', $running_vars, '', SQ_PACKAGES_PATH.'/funnelback/hipo_jobs');
275  return TRUE;
276  }//end if
277  }//end if
278 
279  return FALSE;
280 
281  }//end processReindexing()
282 
283 
284 // --- COLLECTION SCREEN FUNCTIONS --- //
285 
286 
297  function paintNewCollection(&$asset, &$o, $prefix)
298  {
299  $wa = $asset->writeAccess('attributes');
300 
301  if ($wa) {
302  // New collection
303  $js = 'onChange="javascript:funnelbackDisableURL(this);"';
304  $o->openField(translate('funnelback_collection_id'), '', translate('funnelback_collection_id_note'));
305  text_box($prefix.'_new_collection');
306  $o->closeField();
307  $o->openField(translate('funnelback_collection_name'), '', translate('funnelback_collection_name_note'));
308  text_box($prefix.'_new_collection_name');
309  $o->closeField();
310  $o->openField(translate('funnelback_collection_type'));
311  combo_box($prefix.'_new_collection_type', $asset->_getCollectionTypes(), FALSE, 'web', 0, $js);
312  $o->closeField();
313  }//end if
314 
315  return TRUE;
316 
317  }//end paintNewCollection()
318 
319 
330  function processNewCollection(&$asset, &$o, $prefix)
331  {
332  $saved = FALSE;
333  $wa = $asset->writeAccess('attributes');
334 
335  if ($wa) {
336  $new_collection = array_get_index($_POST, $prefix.'_new_collection', '');
337  $new_collection_name = array_get_index($_POST, $prefix.'_new_collection_name', '');
338  $new_collection_type = array_get_index($_POST, $prefix.'_new_collection_type', 'web');
339  $collections = $asset->getCollections();
340  $new_collection = str_replace(' ', '_', $new_collection);
341  if (!empty($new_collection) && !isset($collections[$new_collection])) {
342  $collections[$new_collection] = Array(
343  'name' => $new_collection_name,
344  'type' => $new_collection_type,
345  'asset' => 0,
346  );
347  $asset->setAttrValue('collections', $collections);
348  $saved = $asset->saveAttributes();
349  $coll_path = $asset->getCollectionDataPath($new_collection);
350  $config_files = $asset->getCollectionConfigFiles($new_collection);
351  foreach ($config_files as $type => $config) {
352  $asset->createCollectionConfig($config, $type);
353  }//end foreach
354  }//end if
355  }//end if
356 
357  return $saved;
358 
359  }//end processNewCollection()
360 
361 
372  function paintCollections(&$asset, &$o, $prefix)
373  {
374  $wa = $asset->writeAccess('attributes');
375  $collections = $asset->getCollections();
376  $collection_id = array_get_index($_POST, $prefix.'_edit_collection', '');
377  hidden_field($prefix.'_edit_collection', $collection_id);
378  ?>
379  <table class="sq-backend-table" style="width:100%">
380  <tr>
381  <?php if ($wa) { ?><td class="sq-backend-table-header"><?php echo translate('edit'); ?></td><?php } ?>
382  <td class="sq-backend-table-header" width="20%"><?php echo translate('funnelback_collection_id'); ?></td>
383  <td class="sq-backend-table-header" width="50%"><?php echo translate('funnelback_collection_name'); ?></td>
384  <td class="sq-backend-table-header" width="20%"><?php echo translate('funnelback_collection_type'); ?></td>
385  <td class="sq-backend-table-header" width="20%"><?php echo translate('valid_question'); ?></td>
386  <?php if ($wa) { ?><td class="sq-backend-table-header"><?php echo translate('delete'); ?>?</td><?php } ?>
387  </tr>
388  <?php
389  if (!empty($collections)) {
390  foreach ($collections as $coll_id => $collection_info) {
391  if ($collection_id == $coll_id) {
392  $class = 'sq-table-row alt';
393  } else {
394  $class = 'sq-table-row';
395  }//end if
396  echo '<tr class="'.$class.'"><td>';
397  if ($wa) {
398  $img = '<a href="#" onclick="document.getElementById(\''.$prefix.'_edit_collection\').value = \''.$coll_id.'\'; document.main_form.submit(); return false;"><img src="'.sq_web_path('lib').'/web/images/icons/edit_mode.png" width="15" height="15" border="0" /></a>';
399  echo '<p>'.$img.'</p>';
400  echo '</td><td>';
401  }//end if
402  echo $coll_id;
403  echo '</td><td>';
404  echo array_get_index($collection_info, 'name', '');
405  echo '</td><td>';
406  $current_type = array_get_index($collection_info, 'type', 'web');
407  $types = $asset->_getCollectionTypes();
408  echo array_get_index($types, $current_type, $types['web']);
409  echo '</td><td>';
410  if (array_get_index($collection_info, 'valid', FALSE) && $this->_checkCollection($collections, $coll_id)) {
411  $icon = 'tick';
412  } else {
413  $icon = 'cross';
414  }//end if
415  echo '<img src="'.sq_web_path('lib').'/web/images/'.$icon.'.gif" border="0" />';
416  if ($wa) {
417  echo '</td><td>';
418  check_box($prefix.'_delete[]', $coll_id);
419  }//end if
420  echo '</td></tr>';
421  }//end foreach
422  } else {
423  $cols = ($wa) ? '6' : '4';
424  echo '<tr><td align="center" colspan="'.$cols.'">'.translate('funnelback_no_collection').'</td></tr>';
425  }//end if
426  ?>
427  </table>
428  <?php
429 
430  return TRUE;
431 
432  }//end paintCollections()
433 
434 
445  function processCollections(&$asset, &$o, $prefix)
446  {
447  $status = FALSE;
448  $wa = $asset->writeAccess('attributes');
449  $collections = $asset->getCollections();
450  $delete_collection = array_get_index($_POST, $prefix.'_delete', Array());
451  if ($wa) {
452  if (!empty($delete_collection)) {
453  foreach($delete_collection as $del_collection) {
454  if (isset($collections[$del_collection])) {
455  // Get the collection data path
456  $coll_path = $asset->getCollectionDataPath($del_collection);
457  if (is_dir($coll_path)) {
458  require_once SQ_FUDGE_PATH.'/general/file_system.inc';
459  delete_directory($coll_path);
460  }//end if
461 
462  // 'Delete' the collection
463  unset($collections[$del_collection]);
464  }//end if
465  }//end foreach
466  $asset->setAttrValue('collections', $collections);
467  $status = $asset->saveAttributes();
468  }//end if
469  }//end if
470 
471  return $status;
472 
473  }//end processCollections()
474 
475 
486  function paintSelectedCollection(&$asset, &$o, $prefix)
487  {
488  $wa = $asset->writeAccess('attributes');
489  $collections = $asset->getCollections();
490  $collection_id = array_get_index($_POST, $prefix.'_edit_collection', NULL);
491 
492  if ($wa) {
493  if (!empty($collection_id) && isset($collections[$collection_id])) {
494  $current_type = array_get_index($collections[$collection_id], 'type', 'web');
495  $current_name = array_get_index($collections[$collection_id], 'name', '');
496  $current_assetid = array_get_index($collections[$collection_id], 'asset', Array());
497  $current_url = array_get_index($collections[$collection_id], 'url', Array());
498  $o->openField(translate('funnelback_collection_name'));
499  hidden_field($prefix.'_edit_collection_id', $collection_id);
500  text_box($prefix.'_edit_collection_name', $current_name);
501  $o->closeField();
502  switch ($current_type) {
503  case 'meta':
504  $o->openField(translate('funnelback_collections'));
505  $all_collections = $asset->getCollections();
506  $selected_collections = array_get_index($collections[$collection_id], 'collections', Array());
507  unset($all_collections[$collection_id]);
508  ?>
509  <table class="sq-backend-table" style="width:70%">
510  <tr>
511  <td class="sq-backend-table-header" width="80%">
512  <?php echo translate('funnelback_collection_name'); ?>
513  </td>
514  <td class="sq-backend-table-header"><?php echo translate('please_select'); ?>?</td>
515  </tr>
516  <?php
517  foreach ($all_collections as $each_collection_id => $each_collection) {
518  $selected = (in_array($each_collection_id, $selected_collections)) ? TRUE : FALSE;
519  $name = array_get_index($each_collection, 'name', '');
520  if (empty($name)) continue;
521  echo '<tr><td>';
522  echo $name;
523  echo '</td><td>';
524  check_box($prefix.'_edit_collection_meta_collections[]', $each_collection_id, $selected);
525  echo '</td></tr>';
526  }//end foreach
527  ?>
528  </table>
529  <?php
530  $o->closeField();
531  break;
532 
533  default:
534  $o->openField(translate('funnelback_collection_source'));
535  asset_finder($prefix.'_edit_collection_source', $current_assetid);
536  $o->closeField();
537  $o->openField(translate('funnelback_collection_url'));
538  $urls = Array();
539  if (!empty($current_assetid)) {
540  $current_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($current_assetid, '', TRUE);
541  if (!is_null($current_asset)) {
542  $possible_urls = $current_asset->getURLs();
543  foreach ($possible_urls as $possible_url) {
544  $http = array_get_index($possible_url, 'http', FALSE);
545  $https = array_get_index($possible_url, 'https', FALSE);
546  $purl = array_get_index($possible_url, 'url', '');
547 
548  if ($http && !empty($purl)) {
549  $urls[] = 'http://'.$purl;
550  }
551  if ($https && !empty($purl)) {
552  $urls[] = 'https://'.$purl;
553  }
554  }//end foreach
555  }//end if
556  }//end if
557 
558  if (empty($urls)) {
559  echo translate('funnelback_collection_no_url');
560  } else {
561  foreach ($urls as $url) {
562  check_box($prefix.'_edit_collection_url[]', $url, ((in_array($url, $current_url)) ? TRUE : FALSE));
563  echo ' '.htmlspecialchars($url).'<br />';
564  }//end foreach
565  }//end if
566  $o->closeField();
567  }//end switch
568  }//end if
569  }//end if
570 
571  return TRUE;
572 
573  }//end paintSelectedCollection()
574 
575 
586  function processSelectedCollection(&$asset, &$o, $prefix)
587  {
588  $status = FALSE;
589  $changed = FALSE;
590  $wa = $asset->writeAccess('attributes');
591  $collections = $asset->getCollections();
592  $collection_id = array_get_index($_POST, $prefix.'_edit_collection_id', NULL);
593 
594  if ($wa) {
595  if (!empty($collection_id) && isset($collections[$collection_id])) {
596  $name = array_get_index($_POST, $prefix.'_edit_collection_name', '');
597  $source = array_get_index($_POST, $prefix.'_edit_collection_source', '');
598  $url = array_get_index($_POST, $prefix.'_edit_collection_url', Array());
599  $current_type = array_get_index($collections[$collection_id], 'type', 'web');
600  if ($current_type == 'meta') {
601  $meta_collections = array_get_index($_POST, $prefix.'_edit_collection_meta_collections', Array());
602  $collections[$collection_id]['valid'] = FALSE;
603  $collections[$collection_id]['collections'] = $meta_collections;
604  // Create the meta collection
605  $index_paths = Array();
606  foreach ($meta_collections as $meta_collection) {
607  $meta_collection_data_path = $asset->getCollectionDataPath($meta_collection, 'idx');
608  if (!empty($meta_collection_data_path) && is_dir($meta_collection_data_path)) {
609  $index_paths[] = $meta_collection_data_path.'/'.$meta_collection;
610  }//end if
611  }//end foreach
612  $data_path = $asset->getCollectionDataPath($collection_id, 'idx');
613  // Create the meta collection
614  // No indexing is needed as the other collections it uses, should handle indexing themselves
615  $create_status = file_put_contents($data_path.'/'.$collection_id.'.sdinfo', implode("\n", $index_paths));
616  if ($create_status !== FALSE && !empty($index_paths)) {
617  $collections[$collection_id]['valid'] = TRUE;
618  }//end if
619  $changed = TRUE;
620  }//end if
621  if (!empty($name)) {
622  $collections[$collection_id]['name'] = $name;
623  $changed = TRUE;
624  }//end if
625  if (!empty($source)) {
626  $source_assetid = array_get_index($source, 'assetid', 0);
627  if (!empty($source_assetid)) {
628  $source_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($source_assetid);
629  if (!empty($source_asset)) {
630  $asset_url = $source_asset->getURL();
631  $unrestricted_asset = strpos($asset_url, '/__data/') !== FALSE ||
632  (SQ_CONF_STATIC_ROOT_URL && strpos($asset_url, SQ_CONF_STATIC_ROOT_URL.'/') !== FALSE);
633  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($source_asset);
634 
635  if ($unrestricted_asset) {
636  trigger_localised_error('FNB0015', E_USER_WARNING);
637  return FALSE;
638  }
639  $collections[$collection_id]['asset'] = $source_assetid;
640  $changed = TRUE;
641  }//end if
642  }//end if
643  }//end if
644  if ($current_type == 'web') {
645  $collections[$collection_id]['url'] = $url;
646  if (empty($url) || empty($collections[$collection_id]['asset'])) {
647  $collections[$collection_id]['valid'] = FALSE;
648  }//end if
649  $changed = TRUE;
650  }//end if
651 
652  if ($changed) {
653  // First check, and make valid if an assetid/url are set correctly
654  $collections = $this->_checkCollection($collections);
655  $asset->setAttrValue('collections', $collections);
656  $status = $asset->saveAttributes();
657  }//end if
658  }//end if
659  }//end if
660 
661  return $status;
662 
663  }//end processSelectedCollection()
664 
665 
666 // --- THESAURUS SCREEN FUNCTIONS --- //
667 
668 
679  function paintThesaurusChooser(&$asset, &$o, $prefix)
680  {
681  $wa = $asset->writeAccess('attributes');
682  $collections = $asset->getCollections();
683  $collection_selecter = Array();
684  $current_choice = array_get_index($_POST, $prefix.'_choose_thesaurus', '');
685  foreach ($collections as $id => $collection) {
686  $collection_selecter[$id] = array_get_index($collection, 'name', '');
687  }//end foreach
688  ksort($collection_selecter);
689 
690  if ($wa) {
691  if (!empty($collection_selecter)) {
692  echo combo_box($prefix.'_choose_thesaurus', $collection_selecter, FALSE, $current_choice);
693  } else {
694  echo translate('funnelback_no_collection_to_proceed');
695  }//end if
696  }//end if
697 
698  return TRUE;
699 
700  }//end paintThesaurusChooser()
701 
702 
713  function processThesaurusChooser(&$asset, &$o, $prefix)
714  {
715  // I don't do anything ;)
716 
717  return TRUE;
718 
719  }//end processThesaurusChooser()
720 
721 
732  function paintThesaurus(&$asset, &$o, $prefix)
733  {
734  $wa = $asset->writeAccess('attributes');
735  $collections = $asset->getCollections();
736  $current_choice = array_get_index($_POST, $prefix.'_choose_thesaurus', '');
737  hidden_field($prefix.'_chosen_thesaurus', $current_choice);
738  $thesaurus_types = Array('term'=>translate('fb_term_term'), 'whole'=>translate('fb_whole'), 'regex'=>translate('fb_regex'));
739  if ($wa && !empty($current_choice) && isset($collections[$current_choice])) {
740  $thesaurus_config = $asset->getCollectionDataPath($current_choice, 'conf').'/synonyms.cfg';
741  $config = $asset->readConfiguration($thesaurus_config);
742  ?>
743  <table class="sq-backend-table">
744  <tr>
745  <td class="sq-backend-table-header"><?php echo translate('fb_query'); ?></td>
746  <td class="sq-backend-table-header"><?php echo translate('fb_term'); ?></td>
747  <td class="sq-backend-table-header"><?php echo translate('fb_replacement'); ?></td>
748  <td class="sq-backend-table-header"><?php echo translate('delete'); ?></td>
749  </tr>
750  <?php
751  // Current thesaurus
752  $count = 1;
753  foreach ($config as $line) {
754  echo '<tr><td>';
755  echo combo_box($prefix.'_thesaurus_query['.$count.']', $thesaurus_types, FALSE, $line['query']);
756  echo '</td><td>';
757  echo text_box($prefix.'_thesaurus_term['.$count.']', $line['term'], 30);
758  echo '</td><td>';
759  echo text_box($prefix.'_thesaurus_expansion['.$count.']', $line['expansion'], 30);
760  echo '</td><td>';
761  echo check_box($prefix.'_thesaurus_delete['.$count.']', '1');
762  echo '</td></tr>';
763  $count++;
764  }//end foreach
765 
766  // Add new ones
767  for ($i=$count; $i<=($count+1); $i++) {
768  echo '<tr><td>';
769  echo combo_box($prefix.'_thesaurus_query['.$i.']', $thesaurus_types);
770  echo '</td><td>';
771  echo text_box($prefix.'_thesaurus_term['.$i.']', '', 30);
772  echo '</td><td>';
773  echo text_box($prefix.'_thesaurus_expansion['.$i.']', '', 30);
774  echo '</td><td>';
775  echo check_box($prefix.'_thesaurus_delete['.$i.']', '1');
776  echo '</td></tr>';
777  }//end for
778  ?>
779  </table>
780  <?php
781  } else if (!empty($current_choice) && !isset($collections[$current_choice])) {
782  echo translate('funnelback_missing_collection', $current_choice);
783  }//end if
784 
785  return TRUE;
786 
787  }//end paintThesaurus()
788 
789 
800  function processThesaurus(&$asset, &$o, $prefix)
801  {
802  $status = FALSE;
803  $wa = $asset->writeAccess('attributes');
804  if (!$wa) return $status;
805 
806  $collection = array_get_index($_POST, $prefix.'_chosen_thesaurus', '');
807  if (empty($collection)) return $status;
808 
809  // Grab all the terms, expansions etc.
810  $query = array_get_index($_POST, $prefix.'_thesaurus_query', Array());
811  $term = array_get_index($_POST, $prefix.'_thesaurus_term', Array());
812  $expansion = array_get_index($_POST, $prefix.'_thesaurus_expansion', Array());
813  $delete = array_get_index($_POST, $prefix.'_thesaurus_delete', Array());
814 
815  if (empty($query) || (count($query) != count($term) && count($query) != count($expansion))) {
816  return $status;
817  }//end if
818 
819  $data = Array();
820  foreach ($query as $id => $each_query) {
821  if (!isset($delete[$id]) || $delete[$id] != '1') {
822  $query_type = '+';
823  if ($each_query == 'term') {
824  $query_type = '%';
825  } else if ($each_query == 'regex') {
826  $query_type = '~';
827  }//end if
828  $data[] = Array('query'=>$query_type, 'term'=>$term[$id], 'expansion'=>$expansion[$id]);
829  }//end if
830  }//end foreach
831 
832  $config = $asset->getCollectionDataPath($collection, 'conf').'/synonyms.cfg';
833  $asset->writeConfiguration($config, $data);
834 
835  return $status;
836 
837  }//end processThesaurus()
838 
839 
840 // --- FEATURE PAGES SCREEN FUNCTIONS --- //
841 
842 
853  function paintFeaturePageChooser(&$asset, &$o, $prefix)
854  {
855  $wa = $asset->writeAccess('attributes');
856  $collections = $asset->getCollections();
857  $collection_selecter = Array();
858  $current_choice = array_get_index($_POST, $prefix.'_edit_feature_page', '');
859  foreach ($collections as $id => $collection) {
860  $collection_selecter[$id] = array_get_index($collection, 'name', '');
861  }//end foreach
862  ksort($collection_selecter);
863 
864  if ($wa) {
865  if (!empty($collection_selecter)) {
866  echo combo_box($prefix.'_edit_feature_page', $collection_selecter, FALSE, $current_choice);
867  } else {
868  echo translate('funnelback_no_collection_to_proceed');
869  }//end if
870  }//end if
871 
872  return TRUE;
873 
874  }//end paintFeaturePageChooser()
875 
876 
887  function processFeaturePageChooser(&$asset, &$o, $prefix)
888  {
889  $wa = $asset->writeAccess('attributes');
890  $collection_id = array_get_index($_POST, $prefix.'_edit_feature_page', '');
891  if ($wa) {
892  $current_feature_pages = $asset->attr('feature_pages');
893  if (!empty($collection_id) && !isset($current_feature_pages[$collection_id])) {
894  $current_feature_pages[$collection_id] = Array(
895  Array(
896  'query' => 'substring',
897  'trigger' => '',
898  'assetid' => 0,
899  'url' => '',
900  'valid' => FALSE,
901  ),
902  );
903  $asset->setAttrValue('feature_pages', $current_feature_pages);
904  return $asset->saveAttributes();
905  }//end if
906  }//end if
907 
908  return TRUE;
909 
910  }//end processFeaturePageChooser()
911 
912 
923  function paintFeaturePage(&$asset, &$o, $prefix)
924  {
925  $wa = $asset->writeAccess('attributes');
926  $collections = $asset->getCollections();
927  $config = $asset->attr('feature_pages');
928  $collection_id = array_get_index($_POST, $prefix.'_edit_feature_page', '');
929  $line_id = array_get_index($_POST, $prefix.'_edit_feature_page_line', '');
930  hidden_field($prefix.'_edit_feature_page_collection_id', $collection_id);
931  hidden_field($prefix.'_edit_feature_page_line', $line_id);
932  if (!empty($collection_id)) {
933  $collection_name = array_get_index(array_get_index($collections, $collection_id, Array()), 'name', '');
934  echo translate('funnelback_editing_collection', $collection_name);
935  ?>
936  <table class="sq-backend-table">
937  <tr>
938  <?php if ($wa) { ?><td class="sq-backend-table-header"><?php echo translate('edit'); ?></td><?php } ?>
939  <td class="sq-backend-table-header"><?php echo translate('fb_trigger'); ?></td>
940  <td class="sq-backend-table-header"><?php echo translate('valid_question'); ?></td>
941  <td class="sq-backend-table-header"><?php echo translate('url'); ?></td>
942  <?php if ($wa) { ?><td class="sq-backend-table-header"><?php echo translate('delete'); ?>?</td><?php } ?>
943  </tr>
944  <?php
945  if (isset($config[$collection_id])) {
946  // Current feature pages
947  foreach ($config[$collection_id] as $index => $feature_page) {
948  $feature_trigger = array_get_index($feature_page, 'trigger', '');
949  $feature_url = array_get_index($feature_page, 'url', '');
950  if ($index == $line_id) {
951  $class = 'sq-table-row alt';
952  } else {
953  $class = 'sq-table-row';
954  }//end if
955  echo '<tr class="'.$class.'"><td>';
956  if ($wa) {
957  $img = '<a href="#" onclick="document.getElementById(\''.$prefix.'_edit_feature_page_line\').value = \''.$index.'\'; document.getElementById(\''.$prefix.'_edit_selected_feature_page_changed\').value = \'0\'; document.main_form.submit(); return false;"><img src="'.sq_web_path('lib').'/web/images/icons/edit_mode.png" width="15" height="15" border="0" /></a>';
958  echo '<p>'.$img.'</p>';
959  echo '</td><td>';
960  }//end if
961  echo $feature_trigger;
962  echo '</td><td>';
963  if (array_get_index($feature_page, 'valid', FALSE)) {
964  $icon = 'tick';
965  } else {
966  $icon = 'cross';
967  }//end if
968  echo '<img src="'.sq_web_path('lib').'/web/images/'.$icon.'.gif" border="0" />';
969  echo '</td><td width="50%">';
970  echo htmlspecialchars($feature_url, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
971  echo '</td><td>';
972  echo check_box($prefix.'_feature_delete['.$index.']', '1');
973  echo '</td></tr>';
974  }//end foreach
975  }//end if
976  ?>
977  </table>
978  <?php
979 
980  if ($wa) {
981  echo int_text_box($prefix.'_add_new', 0, FALSE, 5, 0, 10);
982  echo ' '.translate('funnelback_add_new_feature_page');
983  }//end if
984  } else {
985  echo translate('funnelback_no_collection_selected');
986  }//end if
987 
988  return TRUE;
989 
990  }//end paintFeaturePage()
991 
992 
1003  function processFeaturePage(&$asset, &$o, $prefix)
1004  {
1005  $status = FALSE;
1006  $wa = $asset->writeAccess('attributes');
1007  if ($wa) {
1008  $collection_id = array_get_index($_POST, $prefix.'_edit_feature_page_collection_id', '');
1009  $feature_pages = $asset->attr('feature_pages');
1010  if (!empty($collection_id) && isset($feature_pages[$collection_id])) {
1011  $feature_delete = array_get_index($_POST, $prefix.'_feature_delete', Array());
1012  $new_feature = Array();
1013  $changed = FALSE;
1014  foreach ($feature_pages[$collection_id] as $index => $current_settings) {
1015  if (isset($feature_delete[$index]) && $feature_delete[$index] == '1') {
1016  unset($feature_pages[$collection_id][$index]);
1017  $changed = TRUE;
1018  } else {
1019  $new_feature[] = $current_settings;
1020  }//end if
1021  }//end foreach
1022 
1023  $add_new = array_get_index($_POST, $prefix.'_add_new', 0);
1024  if (!empty($add_new)) {
1025  $changed = TRUE;
1026  for ($i=0; $i<$add_new; $i++) {
1027  $new_feature[] = Array('query'=>'substring','trigger'=>'','url'=>'','assetid'=>0,'valid'=>FALSE);
1028  }//end for
1029  }//end if
1030 
1031  if ($changed) {
1032  $feature_pages[$collection_id] = $new_feature;
1033  $asset->setAttrValue('feature_pages', $feature_pages);
1034  $status = $asset->saveAttributes();
1035  $this->_writeFeaturePagesConfiguration($asset, $collection_id, $new_feature);
1036  }//end if
1037  }//end if
1038  }//end if
1039 
1040  return $status;
1041 
1042  }//end processFeaturePage()
1043 
1044 
1055  function paintSelectedFeaturePage(&$asset, &$o, $prefix)
1056  {
1057  $changed = '0';
1058  $wa = $asset->writeAccess('attributes');
1059  $feature_queries = Array(
1060  'term' => translate('fb_term_term'),
1061  'exact' => translate('fb_exact'),
1062  'regex' => translate('fb_regex'),
1063  'substring' => translate('fb_substring'),
1064  );
1065  if ($wa) {
1066  $config = $asset->attr('feature_pages');
1067  $collection_id = array_get_index($_POST, $prefix.'_edit_feature_page_collection_id', '');
1068  $line_id = array_get_index($_POST, $prefix.'_edit_feature_page_line', '');
1069  if ($collection_id != '' && $line_id != '') {
1070  if (isset($config[$collection_id][$line_id])) {
1071  $changed = '1';
1072  $line_data = $config[$collection_id][$line_id];
1073  $o->closeField();
1074  $o->openField(translate('fb_query'));
1075  $query = array_get_index($line_data, 'query', 'substring');
1076  echo combo_box($prefix.'_edit_selected_feature_page_query', $feature_queries, FALSE, $query);
1077  $o->closeField();
1078  $o->openField(translate('fb_trigger'));
1079  $trigger = array_get_index($line_data, 'trigger', '');
1080  echo text_box($prefix.'_edit_selected_feature_page_trigger', $trigger, 25);
1081  $o->closeField();
1082  $o->openField(translate('fb_title'));
1083  $title = array_get_index($line_data, 'title', '');
1084  echo text_box($prefix.'_edit_selected_feature_page_title', $title, 25);
1085  $o->closeField();
1086  $o->openField(translate('fb_desc'));
1087  $desc = array_get_index($line_data, 'desc', '');
1088  echo text_area($prefix.'_edit_selected_feature_page_desc', $desc, 22, 3);
1089  $o->closeField();
1090  $o->openField(translate('asset'));
1091  $assetid = array_get_index($line_data, 'assetid', 0);
1092  echo asset_finder($prefix.'_edit_selected_feature_page_assetid', $assetid, Array('page'=>'D','site'=>'D'));
1093  $o->closeField();
1094  $o->openField(translate('url'));
1095  $url = array_get_index($line_data, 'url', '');
1096  if ($GLOBALS['SQ_SYSTEM']->am->assetExists($assetid)) {
1097  $asset_urls = Array();
1098  $raw_urls = $GLOBALS['SQ_SYSTEM']->am->getURLs($assetid);
1099  foreach ($raw_urls as $raw_url) {
1100  $base_url = array_get_index($raw_url, 'url', '');
1101  $http = array_get_index($raw_url, 'http', 0);
1102  $https = array_get_index($raw_url, 'https', 0);
1103  if ($http) {
1104  $new_url = 'http://'.$base_url;
1105  $asset_urls[$new_url] = $new_url;
1106  }//end if
1107  if ($https) {
1108  $new_url = 'https://'.$base_url;
1109  $asset_urls[$new_url] = $new_url;
1110  }//end if
1111  }//end foreach
1112  echo combo_box($prefix.'_edit_selected_feature_page_url', $asset_urls, FALSE, $url);
1113  }//end if
1114  }//end if
1115  }//end if
1116  }//end if
1117  hidden_field($prefix.'_edit_selected_feature_page_changed', $changed);
1118 
1119  return TRUE;
1120 
1121  }//end paintSelectedFeaturePage()
1122 
1123 
1134  function processSelectedFeaturePage(&$asset, &$o, $prefix)
1135  {
1136  $status = FALSE;
1137  $wa = $asset->writeAccess('attributes');
1138  if ($wa) {
1139  $config = $asset->attr('feature_pages');
1140  $collection_id = array_get_index($_POST, $prefix.'_edit_feature_page', '');
1141  $line_id = array_get_index($_POST, $prefix.'_edit_feature_page_line', '');
1142  if ($collection_id != '' && $line_id != '') {
1143  if (isset($config[$collection_id][$line_id])) {
1144  $changed = array_get_index($_POST, $prefix.'_edit_selected_feature_page_changed', '0');
1145  $query = array_get_index($_POST, $prefix.'_edit_selected_feature_page_query', 'substring');
1146  $trigger = array_get_index($_POST, $prefix.'_edit_selected_feature_page_trigger', '');
1147  $title = array_get_index($_POST, $prefix.'_edit_selected_feature_page_title', '');
1148  $desc = array_get_index($_POST, $prefix.'_edit_selected_feature_page_desc', '');
1149  $asset_info = array_get_index($_POST, $prefix.'_edit_selected_feature_page_assetid', Array());
1150  $assetid = array_get_index($asset_info, 'assetid', 0);
1151  if (!empty($assetid)) {
1152  $asset_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($assetid, Array(), TRUE, 'type_code');
1153  if (isset($asset_info[$assetid])) {
1154  $asset_type = $asset_info[$assetid];
1155  if (!($GLOBALS['SQ_SYSTEM']->am->isTypeDecendant($asset_type, 'page') || $GLOBALS['SQ_SYSTEM']->am->isTypeDecendant($asset_type, 'site'))) {
1156  $assetid = 0;
1157  }//end if
1158  } else {
1159  $assetid = 0;
1160  }//end if
1161  }//end if
1162  $url = array_get_index($_POST, $prefix.'_edit_selected_feature_page_url', '');
1163  $edit_feature = Array('query'=>$query,'trigger'=>$trigger,'assetid'=>$assetid,'url'=>$url,'valid'=>FALSE);
1164  if (!empty($title)) $edit_feature['title'] = $title;
1165  if (!empty($desc)) $edit_feature['desc'] = $desc;
1166 
1167  // Check the feature page is valid
1168  if ($GLOBALS['SQ_SYSTEM']->am->assetExists($assetid)) {
1169  $asset_urls = Array();
1170  $raw_urls = $GLOBALS['SQ_SYSTEM']->am->getURLs($assetid);
1171  foreach ($raw_urls as $raw_url) {
1172  $base_url = array_get_index($raw_url, 'url', '');
1173  $http = array_get_index($raw_url, 'http', 0);
1174  $https = array_get_index($raw_url, 'https', 0);
1175  if ($http) {
1176  $new_url = 'http://'.$base_url;
1177  $asset_urls[$new_url] = $new_url;
1178  }//end if
1179  if ($https) {
1180  $new_url = 'https://'.$base_url;
1181  $asset_urls[$new_url] = $new_url;
1182  }//end if
1183  }//end foreach
1184  if (in_array($url, $asset_urls)) {
1185  $edit_feature['valid'] = TRUE;
1186  } else {
1187  $edit_feature['url'] = '';
1188  }//end if
1189  }//end if
1190 
1191  if ($changed == '1') {
1192  $config[$collection_id][$line_id] = $edit_feature;
1193  $asset->setAttrValue('feature_pages', $config);
1194  $status = $asset->saveAttributes();
1195  $this->_writeFeaturePagesConfiguration($asset, $collection_id, $config[$collection_id]);
1196  }//end if
1197  }//end if
1198  }//end if
1199  }//end if
1200 
1201  return $status;
1202 
1203  }//end processSelectedFeaturePage()
1204 
1205 
1206 // --- FLUSTER (CONTEXTUAL NAVIGATION) SCREEN FUNCTIONS --- //
1207 
1208 
1219  function paintFlusterChooser(&$asset, &$o, $prefix)
1220  {
1221  $wa = $asset->writeAccess('attributes');
1222  $collections = $asset->getCollections();
1223  $collection_selecter = Array();
1224  $current_choice = array_get_index($_POST, $prefix.'_edit_fluster', '');
1225  foreach ($collections as $id => $collection) {
1226  $collection_selecter[$id] = array_get_index($collection, 'name', '');
1227  }//end foreach
1228  ksort($collection_selecter);
1229 
1230  if ($wa) {
1231  if (!empty($collection_selecter)) {
1232  echo combo_box($prefix.'_edit_fluster', $collection_selecter, FALSE, $current_choice);
1233  } else {
1234  echo translate('funnelback_no_collection_to_proceed');
1235  }//end if
1236  }//end if
1237 
1238  return TRUE;
1239 
1240  }//end paintFlusterChooser()
1241 
1242 
1253  function processFlusterChooser(&$asset, &$o, $prefix)
1254  {
1255  // I do nothing ;)
1256 
1257  return TRUE;
1258 
1259  }//end processFlusterChooser()
1260 
1261 
1272  function paintFluster(&$asset, &$o, $prefix)
1273  {
1274  $wa = $asset->writeAccess('attributes');
1275  $collections = $asset->getCollections();
1276  $collection_id = array_get_index($_POST, $prefix.'_edit_fluster', '');
1277  if ($wa && !empty($collection_id) && isset($collections[$collection_id])) {
1278  $coll_conf_path = $asset->getCollectionDataPath($collection_id, 'conf');
1279  $fluster_config = $coll_conf_path.'/contextual_navigation.cfg';
1280  $asset->createCollectionConfig($fluster_config, 'fluster');
1281  $config = $asset->readConfiguration($fluster_config, 'fluster');
1282  $multi_opts = Array('cannot_end_with', 'kill_list');
1283  $bool_opts = Array('categorise_clusters','enable_fluster');
1284  hidden_field($prefix.'_fluster_collection_id', $collection_id);
1285  foreach ($config as $switch => $parameter) {
1286  $name = str_replace('.', '_', $switch);
1287  $o->closeField();
1288  $o->openField(ucwords(str_replace('_', ' ', $name)));
1289 
1290  // Do not enable this flag as this we control ourselves
1291  if ($switch == 'enable_fluster') continue;
1292 
1293  if (in_array($switch, $multi_opts)) {
1294  // Multi-options available
1295  hidden_field($prefix.'_fluster_multi_opts[]', $switch);
1296  require_once SQ_ATTRIBUTES_PATH.'/option_list/option_list.inc';
1297  $opts = new Asset_Attribute_Option_List();
1298  $opts->_edit_params['allow_reorder'] = FALSE;
1299  $opts->delimiter = ',';
1300  $opts->value = $parameter;
1301  $opts->paint($prefix.'_fluster_opt_'.$name);
1302  } else if (in_array($switch, $bool_opts)) {
1303  // Boolean options
1304  $options = Array('true' => translate('true'), 'false' => translate('false'));
1305  if (!array_key_exists($parameter, $options)) $parameter = 'false';
1306  hidden_field($prefix.'_fluster_opts[]', $switch);
1307  combo_box($prefix.'_fluster_opt_'.$name, $options, FALSE, $parameter);
1308  } else {
1309  hidden_field($prefix.'_fluster_opts[]', $switch);
1310  text_box($prefix.'_fluster_opt_'.$name, $parameter);
1311  }//end if
1312  }//end foreach
1313  } else {
1314  echo translate('funnelback_no_collection_selected');
1315  }//end if
1316 
1317  return TRUE;
1318 
1319  }//end paintFluster()
1320 
1321 
1332  function processFluster(&$asset, &$o, $prefix)
1333  {
1334  $status = FALSE;
1335  $wa = $asset->writeAccess('attributes');
1336  if ($wa) {
1337  $collection_id = array_get_index($_POST, $prefix.'_fluster_collection_id', '');
1338  if (!empty($collection_id)) {
1339  $coll_conf_path = $asset->getCollectionDataPath($collection_id, 'conf');
1340  $fluster_config = $coll_conf_path.'/contextual_navigation.cfg';
1341  $data = Array();
1342  $options = array_get_index($_POST, $prefix.'_fluster_opts', Array());
1343  $multi_options = array_get_index($_POST, $prefix.'_fluster_multi_opts', Array());
1344  foreach ($options as $opt_name) {
1345  $name = str_replace('.', '_', $opt_name);
1346  $data[$opt_name] = array_get_index($_POST, $prefix.'_fluster_opt_'.$name, '');
1347  }//end foreach
1348  foreach ($multi_options as $opt_name) {
1349  $name = str_replace('.', '_', $opt_name);
1350  require_once SQ_ATTRIBUTES_PATH.'/option_list/option_list.inc';
1351  $opts = new Asset_Attribute_Option_List();
1352  $opts->_edit_params['allow_reorder'] = FALSE;
1353  $opts->delimiter = ',';
1354  $opts->process($prefix.'_fluster_opt_'.$name);
1355  $data[$opt_name] = $opts->value;
1356  }//end foreach
1357 
1358  // Saving the file
1359  if (!empty($data)) {
1360  $status = $asset->writeConfiguration($fluster_config, $data, 'fluster');
1361  }//end if
1362  }//end if
1363  }//end if
1364 
1365  return $status;
1366 
1367  }//end processFluster()
1368 
1369 
1370 // --- METADATA SCREEN FUNCTIONS --- //
1371 
1372 
1383  function paintMetamapChooser(&$asset, &$o, $prefix)
1384  {
1385  $wa = $asset->writeAccess('attributes');
1386  $collections = $asset->getCollections();
1387  $collection_selecter = Array();
1388  $current_choice = array_get_index($_POST, $prefix.'_edit_metadata', '');
1389  foreach ($collections as $id => $collection) {
1390  $collection_selecter[$id] = array_get_index($collection, 'name', '');
1391  }//end foreach
1392  ksort($collection_selecter);
1393 
1394  if ($wa) {
1395  if (!empty($collection_selecter)) {
1396  echo combo_box($prefix.'_edit_metadata', $collection_selecter, FALSE, $current_choice);
1397  } else {
1398  echo translate('funnelback_no_collection_to_proceed');
1399  }//end if
1400  }//end if
1401 
1402  return TRUE;
1403 
1404  }//end paintMetamapChooser()
1405 
1406 
1417  function processMetamapChooser(&$asset, &$o, $prefix)
1418  {
1419  // I do nothing ;)
1420 
1421  return TRUE;
1422 
1423  }//end processMetamapChooser()
1424 
1425 
1436  function paintMetamap(&$asset, &$o, $prefix)
1437  {
1438  $wa = $asset->writeAccess('attributes');
1439  $collections = $asset->getCollections();
1440  $collection_id = array_get_index($_POST, $prefix.'_edit_metadata', '');
1441  if ($wa && !empty($collection_id) && isset($collections[$collection_id])) {
1442  $coll_conf_path = $asset->getCollectionDataPath($collection_id, 'conf');
1443  $metadata_config = $coll_conf_path.'/metamap.cfg';
1444  $metamap_config = $asset->attr('metamap');
1445  $config = array_get_index($metamap_config, $collection_id, Array());
1446  if (empty($config)) {
1447  if (!file_exists($metadata_config)) {
1448  // Config does not exist create from funnelback install
1449  $asset->createCollectionConfig($metadata_config, 'metadata');
1450  }//end if
1451  $config = $asset->readConfiguration($metadata_config, 'metadata', ',');
1452  }//end if
1453  if (!empty($config)) {
1454  // Set the current collection, so if collection picker changes, we do not save this config to a different collection
1455  hidden_field($prefix.'_metamap_collection_id', $collection_id);
1456  ?>
1457  <table class="sq-backend-table">
1458  <tr>
1459  <td class="sq-backend-table-header" width="15%"><?php echo translate('funnelback_mclass'); ?></td>
1460  <td class="sq-backend-table-header" width="15%"><?php echo translate('funnelback_word_logic'); ?></td>
1461  <td class="sq-backend-table-header" width="15%"><?php echo translate('funnelback_flag'); ?></td>
1462  <td class="sq-backend-table-header" width="60%"><?php echo translate('funnelback_tag_name'); ?></td>
1463  <td class="sq-backend-table-header" width="5%"><?php echo translate('delete'); ?></td>
1464  </tr>
1465  <tr>
1466  <td class="sq-backend-table-row"><?php echo translate('fb_mclass', 'S'); ?></td>
1467  <td class="sq-backend-table-row" colspan="5"><?php echo translate('funnelback_reserved_class'); ?></td>
1468  </tr>
1469  <?php
1470  $alias_options = $asset->getMetadataAliases();
1471  $flag_options = Array(0=>translate('fb_noindex'),1=>translate('fb_index'));
1472  $word_logic_options = Array(
1473  0 => translate('fb_logic_exclude'),
1474  1 => translate('fb_logic_include_any'),
1475  2 => translate('fb_logic_include_all'),
1476  );
1477 
1478  if (isset($alias_options['S'])) unset($alias_options['S']);
1479 
1480  $alias_word_logic = Array();
1481  $metadata_class_count = 0;
1482  foreach ($config as $line) {
1483  $alias = array_get_index($line, 'alias', '');
1484  $content = array_get_index($line, 'content', '');
1485  $metatag = array_get_index($line, 'metatag', '');
1486  $word_logic = array_get_index($line, 'word_logic', 2);
1487  $system = array_get_index($line, 'system', FALSE);
1488 
1489 
1490  // This alias is reserved for Squiz authtentication keys, and for this reason
1491  // the keys represented by 'S' will be shown as reserved
1492  if ($alias == 'S') {
1493  continue;
1494  }//end if
1495 
1496  echo '<tr>';
1497  echo '<td class="sq-table-row">';
1498  if ($system) {
1499  echo $alias_options[$alias];
1500  hidden_field($prefix.'_metamap_alias[]', $alias);
1501  } else {
1502  combo_box($prefix.'_metamap_alias[]', $alias_options, FALSE, $alias);
1503  }//end if
1504  echo '</td>';
1505  echo '<td class="sq-table-row">';
1506  if (!isset($alias_word_logic[$alias])) {
1507  combo_box($prefix.'_metamap_word_logic[]', $word_logic_options, FALSE, $word_logic);
1508  $alias_word_logic[$alias] = $word_logic;
1509  } else {
1510  echo $word_logic_options[$alias_word_logic[$alias]];
1511  hidden_field($prefix.'_metamap_word_logic[]', $alias_word_logic[$alias]);
1512  }
1513  echo '</td>';
1514  echo '<td class="sq-table-row">';
1515  if ($system) {
1516  echo $flag_options[$content];
1517  hidden_field($prefix.'_metamap_content[]', $content);
1518  } else {
1519  combo_box($prefix.'_metamap_content[]', $flag_options, FALSE, $content);
1520  }//end if
1521  echo '</td>';
1522  echo '<td class="sq-table-row">';
1523  if ($system) {
1524  echo $metatag;
1525  hidden_field($prefix.'_metamap_metatag[]', $metatag);
1526  } else {
1527  text_box($prefix.'_metamap_metatag[]', $metatag, 30);
1528  }//end if
1529  hidden_field($prefix.'_metamap_system[]', (string) $system);
1530  echo '</td>';
1531  echo '<td class="sq-table-row">';
1532  if ($system) {
1533  hidden_field($prefix.'_metamap_delete['.$metadata_class_count.']', '0');
1534  } else {
1535  check_box($prefix.'_metamap_delete['.$metadata_class_count.']', '1');
1536  }//end if
1537  echo '</td>';
1538  echo '</tr>';
1539 
1540  $metadata_class_count++;
1541  }//end foreach
1542 
1543  // Add new entries
1544  for ($i=0; $i<2; $i++) {
1545  echo '<tr>';
1546  echo '<td class="sq-table-row">';
1547  combo_box($prefix.'_metamap_alias[]', $alias_options, FALSE, '');
1548  echo '</td>';
1549  echo '<td class="sq-table-row">';
1550  combo_box($prefix.'_metamap_word_logic[]', $word_logic_options, FALSE, 2);
1551  echo '</td>';
1552  echo '<td class="sq-table-row">';
1553  combo_box($prefix.'_metamap_content[]', $flag_options, FALSE, 0);
1554  echo '</td>';
1555  echo '<td class="sq-table-row">';
1556  text_box($prefix.'_metamap_metatag[]', '', 30);
1557  hidden_field($prefix.'_metamap_system[]', '0');
1558  echo '</td>';
1559  echo '<td class="sq-table-row">';
1560  check_box($prefix.'_metamap_delete['.($metadata_class_count+$i).']', '0');
1561  echo '</td>';
1562  echo '</tr>';
1563  }//end for
1564  } else {
1565  echo translate('funnelback_no_collection_selected');
1566  }//end if
1567  } else {
1568  echo translate('funnelback_no_collection_selected');
1569  }//end if
1570 
1571  return TRUE;
1572 
1573  }//end paintMetamap()
1574 
1575 
1586  function processMetamap(&$asset, &$o, $prefix)
1587  {
1588  $status = FALSE;
1589  $wa = $asset->writeAccess('attributes');
1590  if ($wa) {
1591  $collection_id = array_get_index($_POST, $prefix.'_metamap_collection_id', '');
1592  if (!empty($collection_id)) {
1593  $coll_conf_path = $asset->getCollectionDataPath($collection_id, 'conf');
1594  $metamap_config = $coll_conf_path.'/metamap.cfg';
1595  $data = Array();
1596  $alias = array_get_index($_POST, $prefix.'_metamap_alias', Array());
1597  $content = array_get_index($_POST, $prefix.'_metamap_content', Array());
1598  $metatags = array_get_index($_POST, $prefix.'_metamap_metatag', Array());
1599  $word_logic = array_get_index($_POST, $prefix.'_metamap_word_logic', Array());
1600  $system = array_get_index($_POST, $prefix.'_metamap_system', Array());
1601  $delete = array_get_index($_POST, $prefix.'_metamap_delete', Array());
1602  $metamap_word_logic = Array();
1603 
1604  foreach ($alias as $index => $mclass) {
1605  $metadata_class = $mclass;
1606  $metadata_index = array_get_index($content, $index, 0);
1607  $metadata_metag = array_get_index($metatags, $index, '');
1608  $metadata_system = array_get_index($system, $index, FALSE);
1609  $metadata_delete = array_get_index($delete, $index, '0');
1610 
1611  // Once the word logic for the particular metadata class is set,
1612  // use same value for other metadata in same class
1613  if (isset($metamap_word_logic[$mclass])) {
1614  $metadata_word_logic = $metamap_word_logic[$mclass];
1615  } else {
1616  $metadata_word_logic = array_get_index($word_logic, $index, 2);
1617  $metamap_word_logic[$mclass] = $metadata_word_logic;
1618  }
1619 
1620  if (!empty($metadata_metag) && !(!$metadata_system && $metadata_delete)) {
1621  $data[] = Array(
1622  'alias' => $metadata_class,
1623  'content' => $metadata_index,
1624  'metatag' => $metadata_metag,
1625  'word_logic' => $metadata_word_logic,
1626  'system' => $metadata_system,
1627  );
1628  }//end if
1629  }//end foreach
1630 
1631  // Saving the attribute/file
1632  if (!empty($data)) {
1633  // Save
1634  $config = $asset->attr('metamap');
1635  $config[$collection_id] = $data;
1636  $asset->setAttrValue('metamap', $config);
1637  $status = $asset->saveAttributes();
1638  if ($status) {
1639  $status = $asset->writeConfiguration($metamap_config, $data, 'metadata', ',');
1640  }//end if
1641  }//end if
1642  }//end if
1643  }//end if
1644 
1645  return $status;
1646 
1647  }//end processMetamap()
1648 
1649 
1650 // --- OTHER MISCELLANEOUS FUNCTION --- //
1651 
1652 
1663  function paintPassword(&$asset, &$o, $prefix)
1664  {
1665  $wa = $asset->writeAccess('attributes');
1666 
1667  require_once SQ_ATTRIBUTES_PATH.'/password/password.inc';
1668  $password_field = new Asset_Attribute_Password();
1669  $password_field->paint($prefix, !$wa);
1670 
1671  return TRUE;
1672 
1673  }//end paintPassword()
1674 
1675 
1686  function processPassword(&$asset, &$o, $prefix)
1687  {
1688  $status = FALSE;
1689  $wa = $asset->writeAccess('attributes');
1690  if ($wa) {
1691  require_once SQ_ATTRIBUTES_PATH.'/password/password.inc';
1692  $password_field = new Asset_Attribute_Password();
1693  $result = $password_field->process($prefix);
1694  if ($result !== FALSE && $password_field->processed == TRUE) {
1695  $asset->setAttrValue('password', $password_field->value);
1696  $status = $asset->saveAttributes();
1697  }//end if
1698 
1699  // Regardless of whether a password was entered or not, verify against the user
1700  // This only warns the user, it is up to them to change it!
1701  $user = $asset->attr('user');
1702  if (!empty($user)) {
1703  $user_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($user, '', TRUE);
1704  if (!is_null($user_asset)) {
1705  if (!$user_asset->comparePassword($asset->attr('password'))) {
1706  trigger_localised_error('FNB0014', E_USER_WARNING);
1707  return FALSE;
1708  }//end if
1709 
1710  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($user_asset, TRUE);
1711  }//end if
1712  }//end if
1713  }//end if
1714 
1715  return $status;
1716 
1717  }//end processPassword()
1718 
1719 
1720 // --- ASSET EXCLUSIONS SCREEN FUNCTIONS --- //
1721 
1722 
1733  function paintExcludeAssetid(&$asset, &$o, $prefix)
1734  {
1735  $wa = $asset->writeAccess('attributes');
1736  $exclusions = array_get_index($asset->attr('global_exclude'), 'assetid', Array());
1737  if ($wa) {
1738  multiple_asset_finder($prefix.'_global_assetid_exclusions', $exclusions);
1739  } else {
1740  if (empty($exclusions)) {
1741  echo translate('funnelback_no_assets');
1742  } else {
1743  ?><ul style="margin:1px 15px;"><?php
1744  foreach ($exclusions as $assetid) {
1745  echo '<li>'.get_asset_tag_line($assetid).'</li>';
1746  }
1747  ?></ul><?php
1748  }//end if
1749  }//end if
1750 
1751  return TRUE;
1752 
1753  }//end paintExcludeAssetid()
1754 
1755 
1766  function processExcludeAssetid(&$asset, &$o, $prefix)
1767  {
1768  $wa = $asset->writeAccess('attributes');
1769  $exclusions = $asset->attr('global_exclude');
1770  $user_set = array_get_index($_POST, $prefix.'_global_assetid_exclusions', Array());
1771 
1772  if ($wa) {
1773  $global_assetid_exclude = Array();
1774  foreach ($user_set as $asset_info) {
1775  $assetid = array_get_index($asset_info, 'assetid', 0);
1776  if (empty($assetid)) continue;
1777  $global_assetid_exclude[] = $assetid;
1778  }//end foreach
1779  $exclusions['assetid'] = $global_assetid_exclude;
1780  $asset->setAttrValue('global_exclude', $exclusions);
1781  }//end if
1782 
1783  return TRUE;
1784 
1785  }//end processExcludeAssetid()
1786 
1787 
1798  function paintExcludeAssetType(&$asset, &$o, $prefix)
1799  {
1800  $wa = $asset->writeAccess('attributes');
1801  $exclusions = array_get_index($asset->attr('global_exclude'), 'type', Array());
1802  if ($wa) {
1803  asset_type_chooser($prefix.'_global_type_exclusions', TRUE, $exclusions);
1804  } else {
1805  // print the read-only version
1806  if (empty($exclusions)) {
1807  echo '<p class="sq-backend-warning">'.translate('funnelback_no_asset_types_selected').'</p>';
1808  } else {
1809  $type_names = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($exclusions, 'name');
1810  ?><ul style="margin:1px 15px;"><?php
1811  foreach ($exclusions as $type) {
1812  echo '<li>';
1813  echo get_asset_type_icon($type);
1814  echo $type_names[$type];
1815  echo '</li>';
1816  }
1817  ?></ul><?php
1818  }//end if
1819  }//end if
1820 
1821  return TRUE;
1822 
1823  }//end paintExcludeAssetType()
1824 
1825 
1836  function processExcludeAssetType(&$asset, &$o, $prefix)
1837  {
1838  $wa = $asset->writeAccess('attributes');
1839  $exclusions = $asset->attr('global_exclude');
1840  $user_set = array_get_index($_POST, $prefix.'_global_type_exclusions', Array());
1841 
1842  if ($wa) {
1843  $types = Array();
1844  foreach ($user_set as $type_code) {
1845  if (empty($type_code)) continue;
1846  $types[] = $type_code;
1847  }//end foreach
1848  $exclusions['type'] = $types;
1849  $asset->setAttrValue('global_exclude', $exclusions);
1850  }//end if
1851 
1852  return TRUE;
1853 
1854  }//end processExcludeAssetType()
1855 
1856 
1867  function paintExcludeTreeNode(&$asset, &$o, $prefix)
1868  {
1869  $wa = $asset->writeAccess('attributes');
1870  $exclusions = array_get_index($asset->attr('global_exclude'), 'tree', Array());
1871  if ($wa) {
1872  multiple_asset_finder($prefix.'_global_tree_exclusions', $exclusions);
1873  } else {
1874  if (empty($exclusions)) {
1875  echo translate('funnelback_no_root_nodes');
1876  } else {
1877  ?><ul style="margin:1px 15px;"><?php
1878  foreach ($exclusions as $assetid) {
1879  echo '<li>'.get_asset_tag_line($assetid).'</li>';
1880  }
1881  ?></ul><?php
1882  }//end if
1883  }//end if
1884 
1885  return TRUE;
1886 
1887  }//end paintExcludeTreeNode()
1888 
1889 
1900  function processExcludeTreeNode(&$asset, &$o, $prefix)
1901  {
1902  $wa = $asset->writeAccess('attributes');
1903  $exclusions = $asset->attr('global_exclude');
1904  $user_set = array_get_index($_POST, $prefix.'_global_tree_exclusions', Array());
1905 
1906  if ($wa) {
1907  $global_tree_exclude = Array();
1908  foreach ($user_set as $asset_info) {
1909  $assetid = array_get_index($asset_info, 'assetid', 0);
1910  if (empty($assetid)) continue;
1911  $global_tree_exclude[] = $assetid;
1912  }//end foreach
1913  $exclusions['tree'] = $global_tree_exclude;
1914  $asset->setAttrValue('global_exclude', $exclusions);
1915  }//end if
1916 
1917  return TRUE;
1918 
1919  }//end processExcludeTreeNode()
1920 
1921 
1922 // --- PRIVATE FUNCTIONS --- //
1923 
1924 
1934  function _checkCollection($collections, $collection_id='')
1935  {
1936  foreach ($collections as $coll_id => $coll_info) {
1937  // If we are targeting a particular collection, skip over other collections
1938  if (!empty($collection_id) && $collection_id != $coll_id) {
1939  continue;
1940  }//end if
1941 
1942  // Go through the asset for this collection looking for a possible match
1943  $assetid = array_get_index($coll_info, 'asset', 0);
1944  $collection_url = array_get_index($coll_info, 'url', Array());
1945  if (!empty($assetid)) {
1946  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
1947  if (!is_null($asset)) {
1948  $poss_urls = $asset->getURLs();
1949  foreach ($poss_urls as $poss_url) {
1950  $http = array_get_index($poss_url, 'http', FALSE);
1951  $https = array_get_index($poss_url, 'https', FALSE);
1952  $burl = array_get_index($poss_url, 'url', '');
1953  if ($http && !empty($burl)) {
1954  $url_to_check = 'http://'.$burl;
1955  // If $url_to_check and url from the collection are the same, then this collection_id is valid
1956  if (in_array($url_to_check, $collection_url)) {
1957  $collections[$coll_id]['valid'] = TRUE;
1958  }//end if
1959  }//end if
1960  if ($https && !empty($burl)) {
1961  $url_to_check = 'https://'.$burl;
1962  // If $url_to_check and url from the collection are the same, then this collection_id is valid
1963  if (in_array($url_to_check, $collection_url)) {
1964  $collections[$coll_id]['valid'] = TRUE;
1965  }//end if
1966  }//end if
1967  }//end foreach
1968  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($coll_asset, TRUE);
1969  }//end if
1970  }//end if
1971  }//end foreach
1972 
1973  if (!empty($collection_id)) {
1974  // Targetting a specific collection
1975  if (isset($collections[$collection_id]) && array_get_index($collections[$collection_id], 'valid', FALSE)) {
1976  return TRUE;
1977  } else {
1978  return FALSE;
1979  }//end if
1980  } else {
1981  // Not targetting a specific collection, return all collections
1982  return $collections;
1983  }//end if
1984 
1985  }//end _checkCollection()
1986 
1987 
1996  function _getCollectionDefault($type='web')
1997  {
1998  $default = Array(
1999  'name' => '',
2000  'settings' => Array(),
2001  'type' => $type,
2002  );
2003  switch ($type) {
2004  case 'meta':
2005  $default['collections'] = Array();
2006  break;
2007  default:
2008  }//end switch
2009 
2010  return $default;
2011 
2012  }//end _getCollectionDefault()
2013 
2014 
2027  function _writeFeaturePagesConfiguration(&$asset, $collection, $data)
2028  {
2029  $validData = Array();
2030 
2031  foreach ($data as $line) {
2032  $trigger = array_get_index($line, 'trigger', '');
2033  $url = array_get_index($line, 'url', '');
2034  $valid = array_get_index($line, 'valid', FALSE);
2035  if ($trigger != '' && $url != '' && $valid === TRUE) {
2036  // Found a valid line
2037  $validData[] = $line;
2038  }//end if
2039  }//end foreach
2040 
2041  $configFile = $asset->getCollectionDataPath($collection, 'conf').'/best_bets.cfg';
2042  $asset->writeConfiguration($configFile, $validData, 'feature', '==');
2043 
2044  }//end _writeFeaturePagesConfiguration()
2045 
2046 
2047 }//end class
2048 ?>