Plugin Directory

Changeset 566668


Ignore:
Timestamp:
07/02/2012 09:03:04 PM (14 years ago)
Author:
jazzigor
Message:

Updating trunk to v0.9.9

Location:
jazzy-forms/trunk
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • jazzy-forms/trunk/back/ctrl-forms.php

    r530820 r566668  
    4242        update_option('jzzf_log_level', $_POST['log_level']);
    4343        update_option('jzzf_log_file', $_POST['log_file']);
     44        update_option('jzzf_tweak_log_public', $_POST['tweak_log_public']);
    4445    }
    4546    $db_version = jzzf_get_version();
     
    4950    $log_level = jzzf_log_level();
    5051    $log_file = jzzf_log_file();
     52    $tweak_log_public = get_option('jzzf_tweak_log_public', false);
    5153    include('tpl-diagnostics.php');
    5254    return;
  • jazzy-forms/trunk/back/tpl-diagnostics.php

    r544665 r566668  
    11<h2>Jazzy Forms diagnostics</h2>
    2 <pre>DB version: <?php echo $db_version ?>
     2<pre>
     3<textarea style="width:90%; height:400px;">
     4DB version: <?php echo $db_version ?>
    35
    46Code version: <?php echo $version ?>
     
    79
    810PHP version: <?php print phpversion() ?>
     11
     12Forms:
     13<?php echo htmlentities(json_encode($forms)); ?>
     14
     15Plugins: <?php echo htmlentities(json_encode(get_plugins())); ?>
     16</textarea>
    917
    1018Browser: <script type="text/javascript">
     
    1523    navigator.platform + "|" +
    1624    navigator.userAgent);</script>
    17 Forms:
    18 <?php echo htmlentities(json_encode($forms)); ?>
    19 
    20 Plugins: <?php echo htmlentities(json_encode(get_plugins())); ?>
    2125
    2226<form method="post" action="#">
     
    2933Tweaks:
    3034<input type="checkbox" name="tweak_suppress_email"<?php if($tweak_suppress_email): ?> checked="checked" <?php endif ?> value="1"> Suppress email
     35<input type="checkbox" name="tweak_log_public"<?php if($tweak_log_public): ?> checked="checked" <?php endif ?> value="1"> Public log exposure
    3136Log file    <input type="text" name="log_file" value="<?php esc_attr_e($log_file) ?>">
    3237Log level   <input type="text" name="log_level" value="<?php esc_attr_e($log_level) ?>"> (0: off, 10-50: debug-critical)
  • jazzy-forms/trunk/back/tpl-forms.php

    r530820 r566668  
    211211                <textarea id="jzzf_element_{{counter}}_title" class="jzzf_element_title">{{title}}</textarea>
    212212            </li>
     213            <li>
     214                <label for="jzzf_element_{{counter}}_name">ID</label>
     215                <input type="text" id="jzzf_element_{{counter}}_name" class="jzzf_element_name" value="{{name}}">
     216            </li>
    213217        </ul>
    214218    </fieldset>
     
    223227                <input type="text" id="jzzf_element_{{counter}}_title" class="jzzf_element_title" value="{{title}}">
    224228            </li>
     229            <li>
     230                <label for="jzzf_element_{{counter}}_name">ID</label>
     231                <input type="text" id="jzzf_element_{{counter}}_name" class="jzzf_element_name" value="{{name}}">
     232            </li>
    225233        </ul>
    226234    </fieldset>
     
    234242                <label for="jzzf_element_{{counter}}_title">HTML code</label>
    235243                <textarea id="jzzf_element_{{counter}}_title" class="jzzf_element_title">{{title}}</textarea>
     244            </li>
     245            <li>
     246                <label for="jzzf_element_{{counter}}_name">ID</label>
     247                <input type="text" id="jzzf_element_{{counter}}_name" class="jzzf_element_name" value="{{name}}">
    236248            </li>
    237249        </ul>
  • jazzy-forms/trunk/core/Graph.php

    r530820 r566668  
    11<?php
    22
    3 function jzzf_get_graph($form) {
    4     $elements = $form->elements;
     3function jzzf_get_graph($form) {   
     4    $generator = new Jzzf_Graph_Generator();
     5    return $generator->generate($form);
     6}
     7
     8class Jzzf_Graph {
     9    public $data;
     10    public $types;
     11    public $dependencies;
     12    public $formulas;
     13    public $templates;
     14    public $params;
     15    public $email;
    516   
    6     $data = array();
    7     $types = array();
    8     $dependencies = array();
    9     $formulas = array();
    10     $params = array();
     17    public function __construct() {
     18        $this->data = array();
     19        $this->types = array();
     20        $this->dependencies = array();
     21        $this->formulas = array();
     22        $this->templates = array();
     23        $this->params = array();
     24        $this->email = array();
     25    }
    1126   
    12     $param_keys = array_flip(array('prefix', 'postfix', 'fixed', 'decimals', "zeros", "thousands", "point"));
     27    public function to_array() {
     28        return array(
     29            "data" => $this->data,
     30            "types" => $this->types,
     31            "dependencies" => $this->dependencies,
     32            "formulas" => $this->formulas,
     33            "params" => $this->params,
     34            "email" => $this->email
     35        );
     36    }
     37}
     38
     39class Jzzf_Graph_Generator {
     40    private $form;
     41    private $graph;
     42
     43    public function __construct() {
     44        $this->graph = new Jzzf_Graph();
     45    }
    1346   
    14     foreach($elements as $elem) {
     47    public function generate($form) {
     48        $this->form = $form;
     49
     50        foreach($form->elements as $elem) {
     51            $this->process_element($elem);
     52        }
     53        $this->graph->email = $this->get_email_formulas();
     54        return $this->graph;
     55    }
     56   
     57    function process_element($elem) {
    1558        $id = strtolower($elem->name);
    1659        $type = $elem->type;
    17         $types[$id] = $type;
     60        $this->graph->types[$id] = $type;
    1861        if($type == "f") {
    19             $formula = null;
    20             try {
    21                 $formula = jzzf_parse($elem->formula);
    22             } catch(Exception $e) {
    23                
    24             }
    25             if($formula) {
    26                 $formulas[$id] = $formula;
    27                 $deps = jzzf_get_dependencies($formula);
    28                 foreach($deps as $dep) {
    29                     $dependencies[$dep][] = $id;
     62            $this->process_output_element($id, $elem);
     63        } elseif($this->is_template($type)) {
     64            $this->process_template_element($id, $elem);
     65        } elseif($values = $this->get_values($elem)) {
     66            $this->graph->data[$id] = $values;
     67        }
     68    }
     69   
     70    function process_output_element($id, $elem) {
     71        $param_keys = array_flip(array('prefix', 'postfix', 'fixed', 'decimals', "zeros", "thousands", "point"));
     72       
     73        try {
     74            $formula = jzzf_parse($elem->formula);
     75        } catch(Exception $e) {
     76            return;
     77        }
     78        $this->graph->formulas[$id] = $formula;
     79        $deps = $this->get_dependencies($formula);
     80        $this->add_dependencies($deps, $id);
     81        $this->graph->params[$id] = array_intersect_key((array) $elem, $param_keys);       
     82    }
     83
     84    function process_template_element($id, $elem) {
     85        $parsed = jzzf_parse_template($elem->title);
     86        if(!$parsed || (count($parsed)==1 && !is_array($parsed[0]))) {
     87            return;
     88        }
     89        $this->graph->templates[$id] = $parsed;
     90        $deps = $this->get_template_dependencies($parsed);
     91        $this->add_dependencies($deps, $id);       
     92    }
     93   
     94    function is_template($type) {
     95        return in_array($type, array('m', 't', 'h'));
     96    }
     97   
     98    function get_email_formulas() {
     99        $formulas = null;
     100        if(property_exists($this->form, 'email') && is_object($this->form->email)) {
     101            $email = $this->form->email;
     102            $formulas = jzzf_formulas_from_template($email->to, 'to') +
     103                jzzf_formulas_from_template($email->from, 'form') +
     104                jzzf_formulas_from_template($email->cc, 'cc') +
     105                jzzf_formulas_from_template($email->bcc, 'bcc') +
     106                jzzf_formulas_from_template($email->subject, 'subject') +
     107                jzzf_formulas_from_template($email->message, 'message');
     108        }
     109        return $formulas;
     110    }
     111   
     112    function get_dependencies($formula) {
     113        $deps = array();
     114        foreach($formula as $token) {
     115            if($token[0] == 'v') {
     116                $id = $token[1];
     117                if(!in_array($id, $deps)) {
     118                    $deps[] = $id;
    30119                }
    31120            }
    32             $params[$id] = array_intersect_key((array) $elem, $param_keys);
    33         } elseif($values = jzzf_get_values($elem)) {
    34             $data[$id] = $values;
     121        }
     122        return $deps;
     123    }
     124
     125    function get_template_dependencies($template) {
     126        $dependencies = array();
     127       
     128        foreach($template as $chunk) {
     129            if(jzzf_chunk_is_formula($chunk)) {
     130                $deps = $this->get_dependencies($chunk);
     131                foreach($deps as $dep) {
     132                    if(!in_array($dep, $dependencies)) {
     133                        $dependencies[] = $dep;
     134                    }
     135                }
     136            }
     137        }
     138       
     139        return $dependencies;
     140    }
     141   
     142    function add_dependencies($dependencies, $id) {
     143        foreach($dependencies as $dep) {
     144            $this->graph->dependencies[$dep][] = $id;
    35145        }
    36146    }
    37     $email = jzzf_get_email_formulas($form);
    38     return compact('data', 'types', 'dependencies', 'formulas', 'params', 'email');
     147   
     148    function get_values($element) {
     149        $values = null;
     150        switch($element->type) {
     151            case 'n':
     152                if($val = $element->value) {
     153                    $values = $val;
     154                }
     155                break;
     156            case 'c':
     157                $val = $element->value ? $element->value : 1;
     158                $val2 = $element->value2 ? $element->value2 : 0;
     159                $values = array($val2, $val);
     160                break;
     161            case 'r':
     162            case 'd':
     163                $values = array();
     164                foreach($element->options as $opt) {
     165                    if($opt->value) {
     166                        $values[] = $opt->value;
     167                    } else {
     168                        $values[] = 0;
     169                    }
     170                }
     171                break;
     172        }
     173        return $values;
     174    }
    39175}
     176   
    40177
    41 function jzzf_get_email_formulas($form) {
    42     $formulas = null;
    43     if(property_exists($form, 'email') && is_object($form->email)) {
    44         $email = $form->email;
    45         $formulas = jzzf_formulas_from_template($email->to, 'to') +
    46             jzzf_formulas_from_template($email->from, 'form') +
    47             jzzf_formulas_from_template($email->cc, 'cc') +
    48             jzzf_formulas_from_template($email->bcc, 'bcc') +
    49             jzzf_formulas_from_template($email->subject, 'subject') +
    50             jzzf_formulas_from_template($email->message, 'message');
    51     }
    52     return $formulas;
    53 }
    54 
    55 function jzzf_get_dependencies($formula) {
    56     $deps = array();
    57     foreach($formula as $token) {
    58         if($token[0] == 'v') {
    59             $id = $token[1];
    60             if(!in_array($id, $deps)) {
    61                 $deps[] = $id;
    62             }
    63         }
    64     }
    65     return $deps;
    66 }
    67 
    68 function jzzf_get_values($element) {
    69     $values = null;
    70     switch($element->type) {
    71         case 'n':
    72             if($val = $element->value) {
    73                 $values = $val;
    74             }
    75             break;
    76         case 'c':
    77             $val = $element->value ? $element->value : 1;
    78             $val2 = $element->value2 ? $element->value2 : 0;
    79             $values = array($val2, $val);
    80             break;
    81         case 'r':
    82         case 'd':
    83             $values = array();
    84             foreach($element->options as $opt) {
    85                 if($opt->value) {
    86                     $values[] = $opt->value;
    87                 } else {
    88                     $values[] = 0;
    89                 }
    90             }
    91             break;
    92     }
    93     return $values;
    94 }
  • jazzy-forms/trunk/core/Log.php

    r544665 r566668  
    1717    }
    1818    return sys_get_temp_dir() . '/jazzy-forms.log';
     19}
     20
     21function jzzf_dump_log() {
     22    print @file_get_contents(jzzf_log_file());
     23}
     24
     25function jzzf_log_clear() {
     26    file_put_contents(jzzf_log_file(), "");   
    1927}
    2028
  • jazzy-forms/trunk/front/ctrl-shortcode.php

    r544665 r566668  
    6666       
    6767        $element->classes = jzzf_get_classes($element, $ahead);
    68         $tpl->before($element, $ahead, ($element->break || $idx==0));
     68        $is_template = in_array($element->type, array("m", "t", "h"));
     69        $tpl->before($element, $ahead, ($element->break || $idx==0), $is_template);
    6970       
    7071        switch($element->type) {
     
    7374                break;
    7475            case 'f':
    75                 if(!in_array($element->name, $graph['formulas'])) {
     76                if(!in_array($element->name, $graph->formulas)) {
    7677                    $element->invalid = true;
    7778                }
  • jazzy-forms/trunk/front/jazzy-forms.js

    r544665 r566668  
    145145    function updating_worker(id) {
    146146        update_dependent(id);
    147         if(graph.types[id] != 'f' || id in just_updated) {
     147        if(id in just_updated) {
    148148            return;
    149149        }
    150         element(id).val(sanitize_result(evaluate(id), id));
     150        var value = evaluate(id);
     151        switch(graph.types[id]) {
     152            case 'f':
     153                element(id).val(sanitize_result(value, id));
     154                break;
     155            case 'm':
     156                element(id).html(value);
     157                break;
     158            case 't':
     159            case 'h':
     160                element(id).text(value);
     161                break;
     162        }
    151163        just_updated.push(id);       
    152164    }
     
    163175    function evaluate(id) {
    164176        var result;
    165         if(!(id in cache) || (graph.types[id] == 'f' && !(id in just_updated))) {
     177        if(!(id in cache) || !(id in just_updated)) {
    166178            result = evaluation_worker(id);
    167179            cache[id] = result;
     
    170182        }
    171183        return result;
     184    }
     185   
     186    function template(id) {
     187        var result = '';
     188        var chunks = graph.templates[id];
     189        for(var i=0; i<chunks.length; i++) {
     190            var chunk = chunks[i];
     191            if(typeof chunk == 'object') {
     192                if(is_formatted_variable(chunk)) {
     193                    result += evaluate_formatted_variable(chunk);
     194                } else {
     195                    result += evaluate_formula(chunk);
     196                }
     197            } else {
     198                result += chunk;
     199            }
     200        }
     201        return result;
     202    }
     203   
     204    function is_formatted_variable(formula) {
     205        if(formula && formula.length == 1 && formula[0][0] == 'v') {
     206            return graph.types[formula[0][1]] == 'f';
     207        } else {
     208            return false;
     209        }
     210    }
     211   
     212    function evaluate_formatted_variable(formula) {
     213        var id = formula[0][1];
     214        return sanitize_result(evaluate(id), id);
    172215    }
    173216   
     
    204247            case 'f':
    205248                return formula(id);
     249            case 'm':
     250            case 't':
     251            case 'h':
     252                return template(id);
    206253        }
    207254        return 0;
  • jazzy-forms/trunk/front/tmpl-list.php

    r530820 r566668  
    3232    }
    3333   
    34     function graph($form, $graph) { extract($graph); ?>
     34    function graph($form, $graph) { ?>
    3535    <script type="text/javascript">
    3636        var jzzf_graph_<?php echo $form->id ?> = {
    37             "data": <?php echo json_encode($data) ?>,
    38             "types": <?php echo json_encode($types) ?>,
    39             "dependencies": <?php echo json_encode($dependencies) ?>,
    40             "formulas": <?php echo json_encode($formulas) ?>,
     37            "data": <?php echo json_encode($graph->data) ?>,
     38            "types": <?php echo json_encode($graph->types) ?>,
     39            "dependencies": <?php echo json_encode($graph->dependencies) ?>,
     40            "formulas": <?php echo json_encode($graph->formulas) ?>,
     41            "templates": <?php echo json_encode($graph->templates) ?>,
    4142            "form": <?php echo json_encode($form) ?>,
    42             "params": <?php echo json_encode($params) ?>,
    43             "email": <?php echo json_encode($email) ?>
     43            "params": <?php echo json_encode($graph->params) ?>,
     44            "email": <?php echo json_encode($graph->email) ?>
    4445        };
    4546        var jzzf_ajax_url = "<?php esc_attr_e(admin_url('admin-ajax.php'))  ?>";
     
    5556    }
    5657   
    57     function before($element, $ahead, $first) { ?>
     58    function before($element, $ahead, $first, $is_template) { ?>
    5859    <?php if($first) : ?>
    5960  <li class="jzzf_row">
    6061    <?php endif ?>
    61   <div class="<?php echo $element->classes ?>" <?php if($element->visible===0): ?> style="display:none;"<?php endif ?>>
     62  <div class="<?php echo $element->classes ?>" <?php if($element->visible===0): ?> style="display:none;"<?php endif ?><?php
     63  if($is_template): ?> id="<?php $this->id($element) ?>"<?php endif ?>>
    6264<?php
    6365    }
  • jazzy-forms/trunk/jazzy-forms.php

    r544665 r566668  
    3636define(JZZF_BACK, JZZF_ROOT . 'back/');
    3737define(JZZF_FRONT, JZZF_ROOT . 'front/');
     38
     39require_once(JZZF_CORE . 'Log.php');
    3840
    3941function jzzf_get_version() {
     
    202204}
    203205
    204 require_once(JZZF_CORE . 'Log.php');
     206function jzzf_log_exposure($public=false) {
     207    require_once(JZZF_FRONT . 'ctrl-log.php');
     208    jzzf_ctrl_log($public);
     209    exit;
     210}
     211
     212function jzzf_log_public_exposure() {
     213    jzzf_log_exposure(true);
     214}
    205215
    206216/* register filter hook */
     
    215225add_action('wp_ajax_jzzf_email', 'jzzf_email');
    216226add_action('wp_ajax_nopriv_jzzf_email', 'jzzf_email');
     227add_action('wp_ajax_jzzf_log', 'jzzf_log_exposure');
     228add_action('wp_ajax_nopriv_jzzf_log', 'jzzf_log_public_exposure');
    217229
    218230?>
Note: See TracChangeset for help on using the changeset viewer.