Project:Flexifilter
Version:6.x-1.1-rc1
Component:Code - Components
Category:task
Priority:normal
Assigned:Unassigned
Status:needs work

Issue Summary

Attached is a patch that would add several new components:

1) Sequences

2) Storage

Sequences work like this: they replace some given text with a number given by a function. The sequence component itself keeps track of the numbereth time in the sequence: starting at 0, going up by one each time. It then passes that number into a function selected by the user, which had been previously registered through an implementation of hook_flexifilter_sequences. Included in this are basic numbers, lower case letters, and upper case letters.

There are two storage components, a set and a get. The set component sets one variable slot to the current text as run through a set of components set in the settings. The get component gets the variable set previously in one of the variable slots, runs it through a set of components set in the settings, and returns it.

AttachmentSize
flexifilter_components_sequences_and_storage_01.patch5.18 KB

Comments

#1

Status:needs review» needs work

I don't think you totally understand static variables:

<?php
+function flexifilter_component_storage_set($op, $settings, $text) {
+  switch (
$op) {
+    case
'settings':
+      return
flexifilter_storage_slot();
+
+    case
'prepare':
+    case
'process':
+     
$data = flexifilter_invoke_components($settings['components'], $op, $text);
+      static
$_flexifilter_stored_data = array();
?>

<?php
+function flexifilter_component_storage_get($op, $settings, $text) {
+  switch (
$op) {
+    case
'settings':
+     
$form = flexifilter_storage_slot();
+
+    case
'prepare':
+    case
'process':
+      static
$_flexifilter_stored_data = array();
?>

Static variables are just like local variables, only they are persistent across calls to the function. Giving static variables within two different functions the same name does not cause them to be the same variable. Hence, doing a storage get will always be blank, as the storage set was stored in a different variable.

#2

Sequences committed; storage needs work.

#3

It's enough to change the code to:

<?php
function flexifilter_component_storage_set($op, $settings, $text) {
  switch (
$op) {
    case
'settings':
      return
flexifilter_storage_slot();

    case
'prepare':
    case
'process':
     
$data = flexifilter_invoke_components($settings['components'], $op, $text);
     
$stored_data = flexifilter_get_stored_data();
     
$stored_data[$settings['slot']] = $data;
      return
$text;
  }
}

/**
* Component callback.
*/
function flexifilter_component_storage_get($op, $settings, $text) {
  switch (
$op) {
    case
'settings':
     
$form = flexifilter_storage_slot();

    case
'prepare':
    case
'process':
     
$stored_data = flexifilter_get_stored_data();
      if (!isset(
$stored_data[$settings['slot']])) {
       
$stored_data[$settings['slot']] = '';
      }
     
$data = flexifilter_invoke_components($settings['components'], $op, $_flexifilter_stored_data[$settings['slot']]);
      return
$data;
  }
}

function &
flexifilter_get_stored_data() {
  static
$data;
 
  return
$data;
}
?>

#4

Assigned to:cwgordon7» Anonymous
nobody click here