Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
page_asset_builder_management.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_management.inc';
18 
30 {
31 
32 
37  function __construct(&$pm)
38  {
39 
40  $this->Asset_Management($pm);
41 
45  $this->vars['create_type'] = Array(
46  'added' => '0.1',
47  'type' => 'serialise',
48  'default' => Array(),
49  );
50 
51  $this->vars['create_form_customisations'] = Array(
52  'added' => '0.8',
53  'type' => 'serialise',
54  'default' => Array(),
55  );
56 
57  $this->vars['create_status'] = Array(
58  'added' => '0.1',
59  'type' => 'int',
60  'default' => 2,
61  );
62 
63  $this->vars['required_fields'] = Array(
64  'added' => '0.1',
65  'type' => 'serialise',
66  'default' => Array(),
67  );
68 
69  $this->vars['link_value'] = Array(
70  'added' => '0.8',
71  'type' => 'text',
72  'default' => '',
73  );
74 
79  $this->vars['create_location'] = Array(
80  'added' => '0.1',
81  'type' => 'serialise',
82  'default' => Array(),
83  );
84 
85 
86 
97  $this->vars['create_location_optional'] = Array(
98  'added' => '0.1',
99  'type' => 'serialise',
100  'default' => Array(),
101  );
102 
125  $this->vars['create_location_dynamic'] = Array(
126  'added' => '0.7',
127  'type' => 'serialise',
128  'default' => Array(),
129  );
130 
143  $this->vars['create_location_rules'] = Array(
144  'added' => '0.1',
145  'type' => 'serialise',
146  'default' => Array(),
147  );
148 
152  $this->vars['login_invite'] = Array(
153  'added' => '0.1',
154  'type' => 'wysiwyg',
155  'default' => '<p>Sign in using the form below.</p>',
156  'is_contextable' => TRUE,
157  );
158  $this->vars['login_error'] = Array(
159  'added' => '0.1',
160  'type' => 'wysiwyg',
161  'default' => '<p>Incorrect username or password entered. Please try again.</p>',
162  'is_contextable' => TRUE,
163  );
164  $this->vars['create_invite'] = Array(
165  'added' => '0.1',
166  'type' => 'wysiwyg',
167  'default' => '<p>Create an asset using the form below.</p>',
168  'is_contextable' => TRUE,
169  );
170  $this->vars['create_error'] = Array(
171  'added' => '0.1',
172  'type' => 'wysiwyg',
173  'default' => '<p>The new asset was not created. Ensure you have entered all required information and try again.</p>',
174  'is_contextable' => TRUE,
175  );
176 
177  /* Additional (query-fed) create locations must be children of one of these */
178  $this->vars['additional_location_parents'] = Array(
179  'added' => '0.5',
180  'type' => 'serialise',
181  'default' => Array(),
182  );
183 
184  /* Additional (query-fed) create locations will use this link type by default */
185  $this->vars['additional_location_default_link_type'] = Array(
186  'added' => '0.8',
187  'type' => 'selection',
188  'default' => SQ_LINK_TYPE_1,
189  'parameters' => Array(
190  'options' => Array(
191  SQ_LINK_TYPE_1 => 'TYPE_1',
192  SQ_LINK_TYPE_2 => 'TYPE_2',
193  SQ_LINK_TYPE_3 => 'TYPE_3',
194  SQ_LINK_NOTICE => 'NOTICE',
195  ),
196  ),
197  'multiple' => FALSE,
198  'allow_empty' => FALSE,
199  );
200 
201  /* Additional (query-fed) create locations must be of one of these types */
202  $this->vars['additional_location_types'] = Array(
203  'added' => '0.5',
204  'type' => 'serialise',
205  'default' => Array(),
206  );
207 
208  /* Map for connecting runtime data sources with parameters */
209  $this->vars['parameter_map'] = Array(
210  'added' => '0.6',
211  'type' => 'parameter_map',
212  'parameters' => Array(
213  'parameters' => Array(
214  'additional_locations' => 'Additional Create Locations',
215  ),
216  ),
217  'default' => Array(),
218  );
219 
220  $this->vars['allow_public_user'] = Array(
221  'added' => '0.1',
222  'type' => 'boolean',
223  'default' => TRUE,
224  'parameters' => Array(
225  'allow_empty' => FALSE,
226  ),
227  );
228 
229  $this->vars['submit_to_page_url'] = Array(
230  'added' => '0.1',
231  'type' => 'boolean',
232  'default' => FALSE,
233  'parameters' => Array(
234  'allow_empty' => FALSE,
235  ),
236  );
237  $this->vars['require_captcha'] = Array(
238  'type' => 'boolean',
239  'default' => FALSE,
240  'parameters' => Array(
241  'allow_empty' => FALSE,
242  ),
243  );
244  $this->vars['captcha_length'] = Array(
245  'added' => '0.9',
246  'type' => 'int',
247  'default' => 4,
248  );
249  $this->vars['captcha_zoom'] = Array(
250  'added' => '0.9',
251  'type' => 'int',
252  'default' => 1,
253  );
254  $this->vars['captcha_link_text'] = Array(
255  'added' => '0.9',
256  'type' => 'text',
257  'default' => 'Regenerate security key',
258  );
259 
260  $this->vars['captcha_bgcolour'] = Array(
261  'added' => '0.9',
262  'type' => 'colour',
263  'default' => 'FFFFFF',
264  );
265 
266  $this->vars['captcha_textcolour'] = Array(
267  'added' => '0.9',
268  'type' => 'colour',
269  'default' => '000000',
270  );
271 
272  $this->vars['captcha_bordercolour'] = Array(
273  'added' => '0.9',
274  'type' => 'colour',
275  'default' => '000000',
276  );
277 
278  $this->vars['captcha_use_colours'] = Array(
279  'type' => 'boolean',
280  'default' => FALSE,
281  'parameters' => Array(
282  'allow_empty' => FALSE,
283  ),
284  );
285 
286  $this->vars['captcha_usefont'] = Array(
287  'type' => 'boolean',
288  'default' => FALSE,
289  'parameters' => Array(
290  'allow_empty'=> FALSE,
291  ),
292  );
293 
294  $this->vars['captcha_ttf'] = Array(
295  'added' => '0.9',
296  'type' => 'assetid',
297  'default' => '',
298  'description' => 'The asset id of the font file.',
299  );
300 
301  $this->vars['captcha_font_size'] = Array(
302  'added' => '0.9',
303  'type' => 'int',
304  'default' => 20,
305  );
306 
307  $this->vars['captcha_min_angle'] = Array(
308  'added' => '0.9',
309  'type' => 'int',
310  'default' => -20,
311  );
312 
313  $this->vars['captcha_max_angle'] = Array(
314  'added' => '0.9',
315  'type' => 'int',
316  'default' => 20,
317  );
318 
319  $this->vars['captcha_x_start'] = Array(
320  'added' => '0.9',
321  'type' => 'int',
322  'default' => 10,
323  );
324 
325  $this->vars['captcha_min_distance'] = Array(
326  'added' => '0.9',
327  'type' => 'int',
328  'default' => 10,
329  );
330 
331  $this->vars['captcha_max_distance'] = Array(
332  'added' => '0.9',
333  'type' => 'int',
334  'default' => 20,
335  );
336 
337  $this->vars['captcha_width'] = Array(
338  'added' => '0.9',
339  'type' => 'int',
340  'default' => 200,
341  );
342 
343  $this->vars['captcha_height'] = Array(
344  'added' => '0.9',
345  'type' => 'int',
346  'default' => 36,
347  );
348 
349  $this->vars['captcha_arc'] = Array(
350  'type'=> 'boolean',
351  'default'=> FALSE,
352  'parameters'=> Array(
353  'allow_empty'=> FALSE,
354  ),
355  );
356 
357  $this->vars['captcha_arc_colour'] = Array(
358  'added'=> '0.9',
359  'type'=> 'colour',
360  'default'=> 'D20A0A',
361  );
362 
363  $this->vars['captcha_include_uppercase'] = Array(
364  'type'=> 'boolean',
365  'default'=> FALSE,
366  'parameters'=> Array(
367  'allow_empty'=> FALSE,
368  ),
369  );
370 
371  $this->vars['captcha_include_numbers'] = Array(
372  'type' => 'boolean',
373  'default' => FALSE,
374  'parameters' => Array(
375  'allow_empty' => FALSE,
376  ),
377  );
378 
379  $this->vars['provide_accessible_captcha'] = Array(
380  'type' => 'boolean',
381  'default' => FALSE,
382  'parameters' => Array(
383  'allow_empty' => FALSE,
384  ),
385  );
386 
387  $this->vars['layout_to_apply'] = Array(
388  'added' => '0.9',
389  'type' => 'assetid',
390  'default' => 0,
391  );
392  $this->vars['override_layout_to_apply'] = Array(
393  'added' => '0.9',
394  'type' => 'assetid',
395  'default' => 0,
396  );
397 
398  // Mollom Spam Check attributes ///////
399  $this->vars['use_mollom'] = Array(
400  'added' => '0.9',
401  'type' => 'boolean',
402  'default' => FALSE,
403  'parameters' => Array(
404  'allow_empty' => FALSE,
405  ),
406  );
407  $this->vars['mollom_attributes_to_check'] = Array(
408  'added' => '0.9',
409  'type' => 'serialise',
410  'default' => Array(),
411  'description' => 'Asset attributes to check for spam',
412  );
413  $this->vars['mollom_unsure_submission_text'] = Array(
414  'added' => '0.9',
415  'type' => 'text',
416  'default' => 'Please enter the characters in the image to verify your submission',
417  'description' => 'Mollom error message text for unsure submission',
418  );
419  $this->vars['mollom_spam_submission_text'] = Array(
420  'added' => '0.9',
421  'type' => 'text',
422  'default' => 'This submission looks like a spam. Cannot accept this submission',
423  'description' => 'Mollom error message text for spam submission',
424  );
425  $this->vars['mollom_captcha_incorrect_text'] = Array(
426  'added' => '0.9',
427  'type' => 'text',
428  'default' => 'Incorrect security key. Please try again',
429  'description' => 'Mollom error message text for incorrect captcha',
430  );
431  $this->vars['mollom_captcha_regen_link_text'] = Array(
432  'added' => '0.9',
433  'type' => 'text',
434  'default' => 'Regenerate security key',
435  'description' => 'Mollom CAPTCHA regen link text',
436  );
437 
438  }//end constructor
439 
440 
447  function getEventList()
448  {
449  return Array(
450  Array(
451  'event_name' => 'requestKeywords',
452  'broadcast_type_code' => 'content_type',
453  'broadcast_strict_type_code' => FALSE,
454  'options' => Array(
455  'side_of_link' => 'major',
456  'indirect' => TRUE,
457  'is_exclusive' => NULL,
458  'is_dependant' => 1,
459  'value' => '',
460  'link_type' => SQ_LINK_TYPE_2 | SQ_LINK_TYPE_1,
461  ),
462  ),
463  );
464 
465  }//end getEventList()
466 
467 
476  function _upgrade($current_version)
477  {
478  // important upgrades that must be taken care of before create type becomes
479  // a serialise in 0.3
480  if (version_compare($current_version, '0.2', '<=')) {
481  $root_folder = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_folder');
482  $children = $GLOBALS['SQ_SYSTEM']->am->getChildren($root_folder->id, $this->getAssetType(), FALSE);
483  foreach ($children as $assetid => $type) {
484 
485  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid, $type);
486  if (is_null($asset)) continue;
487 
488  if (!$GLOBALS['SQ_SYSTEM']->am->acquireLock($asset->id, 'attributes')) {
489  trigger_localised_error('CMS0025', E_USER_WARNING, '0.2', $asset->name, $asset->id);
490  return FALSE;
491  }
492 
493  $old_create_type = $asset->attr('create_type');
494  $create_type = Array($old_create_type => TRUE);
495  $asset->setAttrValue('create_type', serialize($create_type));
496 
497  if (!$asset->saveAttributes()) {
498  trigger_localised_error('CMS0026', E_USER_WARNING, '0.2');
499  return FALSE;
500  }
501 
502  $GLOBALS['SQ_SYSTEM']->am->releaseLock($asset->id, 'attributes');
503 
504  }
505  }
506 
507 
508  if (!parent::_upgrade($current_version)) return FALSE;
509 
510  if ($current_version == '0.1') {
511  // this upgrade changed the attribute 'create_locations' to include additional
512  // rules that meant the create locations has to be stored in a different format
513 
514  $root_folder = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_folder');
515  $children = $GLOBALS['SQ_SYSTEM']->am->getChildren($root_folder->id, $this->getAssetType(), FALSE);
516  foreach ($children as $assetid => $type) {
517  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid, $type);
518  if (is_null($asset)) continue;
519 
520  if (!$GLOBALS['SQ_SYSTEM']->am->acquireLock($asset->id, 'attributes')) {
521  trigger_localised_error('CMS0025', E_USER_WARNING, '0.1', $asset->name, $asset->id);
522  return FALSE;
523  }
524 
525  // 0.1->0.2 upgrades
526  $new_locations = Array();
527  $old_locations = $asset->attr('create_location_rules');
528 
529  $i = 0;
530  foreach ($old_locations as $rule_text => $locations) {
531  if (empty($rule_text)) continue;
532  $bits = explode(' && ', $rule_text);
533 
534  foreach ($bits as $bit) {
535  list($attr, $value) = explode('==', $bit);
536  $attr = trim($attr, '$');
537  $value = trim($value, " '");
538  $new_locations[$i][$attr]['equals'] = $value;
539  }
540 
541  $new_locations[$i]['_create_locations_'] = array_keys($locations);
542 
543  $i++;
544  }
545 
546  $asset->setAttrValue('create_location_rules', $new_locations);
547 
548  if (!$asset->saveAttributes()) {
549  trigger_localised_error('CMS0026', E_USER_WARNING, '0.1');
550  return FALSE;
551  }
552  $GLOBALS['SQ_SYSTEM']->am->releaseLock($asset->id, 'attributes');
553  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
554  }//end foreach
555 
556  pre_echo('ASSET BUILDER UPGRADE COMPLETE - VERSION 0.1');
557  }//end if version 0.1 upgrade
558 
559  if ($current_version == '0.2') {
560  // this update changed the way create types are stored, to allow for the creation
561  // of multiple asset types
562  pre_echo('STARTING ASSET BUILDER UPGRADE - VERSION 0.2');
563 
564  $root_folder = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_folder');
565  $children = $GLOBALS['SQ_SYSTEM']->am->getChildren($root_folder->id, $this->getAssetType(), FALSE);
566  foreach ($children as $assetid => $type) {
567  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid, $type);
568  if (is_null($asset)) continue;
569 
570  if (!$GLOBALS['SQ_SYSTEM']->am->acquireLock($asset->id, 'attributes')) {
571  trigger_localised_error('CMS0025', E_USER_WARNING, '0.2', $asset->name, $asset->id);
572  return FALSE;
573  }
574 
575  $create_locs = $asset->attr('create_location_rules');
576  $create_locs = Array($old_create_type => $create_locs);
577 
578  $asset->setAttrValue('create_location_rules', $create_locs);
579 
580  $required_fields = $asset->attr('required_fields');
581  $required_fields = Array($old_create_type => $required_fields);
582 
583  $asset->setAttrValue('required_fields', $required_fields);
584  if (!$asset->saveAttributes()) {
585  trigger_localised_error('CMS0026', E_USER_WARNING, '0.2');
586  return FALSE;
587  }
588  $GLOBALS['SQ_SYSTEM']->am->releaseLock($asset->id, 'attributes');
589  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
590  }
591  $this->_upgrade03To04();
592  pre_echo('ASSET BUILDER UPGRADE COMPLETE - VERSION 0.2');
593  }//end if version 0.2 upgrade
594 
595  if ($current_version == '0.3') {
596  pre_echo('STARTING ASSET BUILDER UPGRADE - VERSION 0.3');
597  $this->_upgrade03To04();
598  pre_echo('ASSET BUILDER UPGRADE COMPLETE - VERSION 0.3');
599  }
600  return TRUE;
601 
602  }//end _upgrade()
603 
604 
611  function _upgrade03To04()
612  {
613  // The create locations regime was radically overhauled between versions 0.3 and 0.4
614  // to add more functions and more flexibility
615 
616  $root_folder = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_folder');
617  $children = $GLOBALS['SQ_SYSTEM']->am->getChildren($root_folder->id, $this->getAssetType(), FALSE);
618  foreach ($children as $assetid => $type) {
619  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid, $type);
620  if (is_null($asset)) continue;
621 
622 
623  if (!$GLOBALS['SQ_SYSTEM']->am->acquireLock($asset->id, 'attributes')) {
624  trigger_localised_error('CMS0025', E_USER_WARNING, '0.3', $asset->name, $asset->id);
625  return FALSE;
626  }
627 
628  $old_link_type = $asset->attr('create_link_type');
629 
630  // convert the fixed create locations by adding the link types
631  $old_create_locations = $asset->attr('create_location');
632  if (!Array($old_create_locations)) {
633  $old_create_locations = Array(0 => $old_create_locations);
634  }
635  $fixed_create_locations = Array();
636  foreach ($old_create_locations as $assetid => $null) {
637  $fixed_create_locations[$assetid] = $old_link_type;
638  }
639  $asset->setAttrValue('create_location', $fixed_create_locations);
640 
641  // convert the selectable (optional) create locations by creating a set of the old ones
642  if ($asset->attr('create_location_optional')) {
643  $old_input_style = ($asset->attr('create_location_type') == 'select') ? 'dropdown' : 'radio';
644  $old_selectable_locations = array_values($asset->attr('create_location_optional'));
645  if (!is_array($old_selectable_locations)) {
646  $old_selectable_locations = Array($old_selectable_locations);
647  }
648  $old_allow_multiple = $asset->attr('create_location_multiple') ? 1 : 0;
649  $selectable_locations_set_details = Array();
650  $location_details = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($old_selectable_locations);
651  $selectable_locations_set_details['locations'] = Array();
652  foreach ($old_selectable_locations as $assetid) {
653  $selectable_locations_set_details['locations'][$assetid] = $location_details[$assetid]['name'];
654  }
655  echo "\n\n Allow Multiple is $old_allow_multiple\n\n";
656  $selectable_locations_set_details['allow_multiple'] = $old_allow_multiple;
657  $selectable_locations_set_details['allow_empty'] = 0;
658  $selectable_locations_set_details['link_type'] = $old_link_type;
659  $selectable_locations_set_details['input_style'] = $old_input_style;
660  $asset->setAttrValue('create_location_optional', Array('First Selectable Location' => $selectable_locations_set_details));
661  }
662 
663  // convert the create location rules into the new format
664  $old_rules = $asset->attr('create_location_rules');
665  $create_location_rules = Array();
666 
667  foreach ($old_rules as $create_type => $type_rules) {
668  $create_location_rules[$create_type] = Array();
669  foreach ($type_rules as $i => $rule_details) {
670  $new_rule = Array(
671  'attributes' => Array(),
672  'comparators' => Array(),
673  'values' => Array(),
674  'locations' => Array(),
675  );
676  foreach ($rule_details as $attr_name => $conditions) {
677  if ($attr_name == '_create_locations_') continue;
678  foreach ($conditions as $comparator => $value) {
679  $new_rule['attributes'][] = $attr_name;
680  $new_rule['comparators'][] = $comparator;
681  $new_rule['values'][] = $value;
682  }
683  }
684  if (is_array($rule_details['_create_locations_'])) {
685  foreach ($rule_details['_create_locations_'] as $assetid) {
686  $new_rule['locations'][] = $assetid;
687  $new_rule['link_types'][] = $old_link_type;
688  }
689  } else if ($rule_details['_create_locations_']) {
690  $new_rule['locations'][$rule_details['_create_locations_']] = $old_link_type;
691  }
692  $create_location_rules[$create_type][] = $new_rule;
693  }
694  }
695  $asset->setAttrValue('create_location_rules', $create_location_rules);
696 
697  if (!$asset->saveAttributes()) {
698  trigger_localised_error('CMS0027', E_USER_WARNING, '0.3');
699  return FALSE;
700  }
701 
702  // change the %create_location% keyword in bodycopies to the keyword for our new set
703  $content_assetids = $GLOBALS['SQ_SYSTEM']->am->getChildren($asset->id, 'content_type_wysiwyg');
704  foreach (array_keys($content_assetids) as $assetid) {
705  $content_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
706  if (!$GLOBALS['SQ_SYSTEM']->am->acquireLock($content_asset->id, 'attributes')) {
707  trigger_localised_error('CMS0025', E_USER_WARNING, '0.3', $content_asset->name, $content_asset->id);
708  return FALSE;
709  }
710  $html = $content_asset->attr('html');
711  $html = str_replace('%create_location%', '%first_selectable_location_field%', $html);
712  $content_asset->setAttrValue('html', $html);
713  $content_asset->saveAttributes();
714  $content_asset->_updated();
715  $GLOBALS['SQ_SYSTEM']->am->releaseLock($content_asset->id, 'attributes');
716  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($content_asset);
717  }
718 
719  // regenerate the content files of the bodycopy containers so that they notice
720  $container_assetids = $GLOBALS['SQ_SYSTEM']->am->getChildren($asset->id, 'bodycopy_container', FALSE);
721  foreach (array_keys($container_assetids) as $assetid) {
722  $container_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
723  if (!$GLOBALS['SQ_SYSTEM']->am->acquireLock($container_asset->id, 'attributes')) {
724  trigger_localised_error('CMS0025', E_USER_WARNING, '0.3', $container_asset->name, $container_asset->id);
725  return FALSE;
726  }
727  $container_asset->saveSystemVersion();
728  $GLOBALS['SQ_SYSTEM']->am->releaseLock($container_asset->id, 'attributes');
729  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($container_asset);
730  }
731 
732  $GLOBALS['SQ_SYSTEM']->am->releaseLock($asset->id, 'attributes');
733  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
734 
735  if (!$asset->saveAttributes()) {
736  trigger_localised_error('CMS0027', E_USER_WARNING, '0.3');
737  return FALSE;
738  }
739 
740  $asset->_updated();
741  }//end foreach
742 
743  // get rid of the old attributes
744  $this->_deleteAttribute('create_location_multiple');
745  $this->_deleteAttribute('create_location_type');
746  $this->_deleteAttribute('create_link_type');
747 
748  }//end _upgrade03To04()
749 
750 
751 }//end class
752 
753 ?>