Changeset 566668
- Timestamp:
- 07/02/2012 09:03:04 PM (14 years ago)
- Location:
- jazzy-forms/trunk
- Files:
-
- 1 added
- 9 edited
-
back/ctrl-forms.php (modified) (2 diffs)
-
back/tpl-diagnostics.php (modified) (4 diffs)
-
back/tpl-forms.php (modified) (3 diffs)
-
core/Graph.php (modified) (1 diff)
-
core/Log.php (modified) (1 diff)
-
front/ctrl-log.php (added)
-
front/ctrl-shortcode.php (modified) (2 diffs)
-
front/jazzy-forms.js (modified) (4 diffs)
-
front/tmpl-list.php (modified) (2 diffs)
-
jazzy-forms.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
jazzy-forms/trunk/back/ctrl-forms.php
r530820 r566668 42 42 update_option('jzzf_log_level', $_POST['log_level']); 43 43 update_option('jzzf_log_file', $_POST['log_file']); 44 update_option('jzzf_tweak_log_public', $_POST['tweak_log_public']); 44 45 } 45 46 $db_version = jzzf_get_version(); … … 49 50 $log_level = jzzf_log_level(); 50 51 $log_file = jzzf_log_file(); 52 $tweak_log_public = get_option('jzzf_tweak_log_public', false); 51 53 include('tpl-diagnostics.php'); 52 54 return; -
jazzy-forms/trunk/back/tpl-diagnostics.php
r544665 r566668 1 1 <h2>Jazzy Forms diagnostics</h2> 2 <pre>DB version: <?php echo $db_version ?> 2 <pre> 3 <textarea style="width:90%; height:400px;"> 4 DB version: <?php echo $db_version ?> 3 5 4 6 Code version: <?php echo $version ?> … … 7 9 8 10 PHP version: <?php print phpversion() ?> 11 12 Forms: 13 <?php echo htmlentities(json_encode($forms)); ?> 14 15 Plugins: <?php echo htmlentities(json_encode(get_plugins())); ?> 16 </textarea> 9 17 10 18 Browser: <script type="text/javascript"> … … 15 23 navigator.platform + "|" + 16 24 navigator.userAgent);</script> 17 Forms:18 <?php echo htmlentities(json_encode($forms)); ?>19 20 Plugins: <?php echo htmlentities(json_encode(get_plugins())); ?>21 25 22 26 <form method="post" action="#"> … … 29 33 Tweaks: 30 34 <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 31 36 Log file <input type="text" name="log_file" value="<?php esc_attr_e($log_file) ?>"> 32 37 Log 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 211 211 <textarea id="jzzf_element_{{counter}}_title" class="jzzf_element_title">{{title}}</textarea> 212 212 </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> 213 217 </ul> 214 218 </fieldset> … … 223 227 <input type="text" id="jzzf_element_{{counter}}_title" class="jzzf_element_title" value="{{title}}"> 224 228 </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> 225 233 </ul> 226 234 </fieldset> … … 234 242 <label for="jzzf_element_{{counter}}_title">HTML code</label> 235 243 <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}}"> 236 248 </li> 237 249 </ul> -
jazzy-forms/trunk/core/Graph.php
r530820 r566668 1 1 <?php 2 2 3 function jzzf_get_graph($form) { 4 $elements = $form->elements; 3 function jzzf_get_graph($form) { 4 $generator = new Jzzf_Graph_Generator(); 5 return $generator->generate($form); 6 } 7 8 class Jzzf_Graph { 9 public $data; 10 public $types; 11 public $dependencies; 12 public $formulas; 13 public $templates; 14 public $params; 15 public $email; 5 16 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 } 11 26 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 39 class Jzzf_Graph_Generator { 40 private $form; 41 private $graph; 42 43 public function __construct() { 44 $this->graph = new Jzzf_Graph(); 45 } 13 46 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) { 15 58 $id = strtolower($elem->name); 16 59 $type = $elem->type; 17 $t ypes[$id] = $type;60 $this->graph->types[$id] = $type; 18 61 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; 30 119 } 31 120 } 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; 35 145 } 36 146 } 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 } 39 175 } 176 40 177 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 17 17 } 18 18 return sys_get_temp_dir() . '/jazzy-forms.log'; 19 } 20 21 function jzzf_dump_log() { 22 print @file_get_contents(jzzf_log_file()); 23 } 24 25 function jzzf_log_clear() { 26 file_put_contents(jzzf_log_file(), ""); 19 27 } 20 28 -
jazzy-forms/trunk/front/ctrl-shortcode.php
r544665 r566668 66 66 67 67 $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); 69 70 70 71 switch($element->type) { … … 73 74 break; 74 75 case 'f': 75 if(!in_array($element->name, $graph ['formulas'])) {76 if(!in_array($element->name, $graph->formulas)) { 76 77 $element->invalid = true; 77 78 } -
jazzy-forms/trunk/front/jazzy-forms.js
r544665 r566668 145 145 function updating_worker(id) { 146 146 update_dependent(id); 147 if( graph.types[id] != 'f' ||id in just_updated) {147 if(id in just_updated) { 148 148 return; 149 149 } 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 } 151 163 just_updated.push(id); 152 164 } … … 163 175 function evaluate(id) { 164 176 var result; 165 if(!(id in cache) || (graph.types[id] == 'f' && !(id in just_updated))) {177 if(!(id in cache) || !(id in just_updated)) { 166 178 result = evaluation_worker(id); 167 179 cache[id] = result; … … 170 182 } 171 183 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); 172 215 } 173 216 … … 204 247 case 'f': 205 248 return formula(id); 249 case 'm': 250 case 't': 251 case 'h': 252 return template(id); 206 253 } 207 254 return 0; -
jazzy-forms/trunk/front/tmpl-list.php
r530820 r566668 32 32 } 33 33 34 function graph($form, $graph) { extract($graph);?>34 function graph($form, $graph) { ?> 35 35 <script type="text/javascript"> 36 36 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) ?>, 41 42 "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) ?> 44 45 }; 45 46 var jzzf_ajax_url = "<?php esc_attr_e(admin_url('admin-ajax.php')) ?>"; … … 55 56 } 56 57 57 function before($element, $ahead, $first ) { ?>58 function before($element, $ahead, $first, $is_template) { ?> 58 59 <?php if($first) : ?> 59 60 <li class="jzzf_row"> 60 61 <?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 ?>> 62 64 <?php 63 65 } -
jazzy-forms/trunk/jazzy-forms.php
r544665 r566668 36 36 define(JZZF_BACK, JZZF_ROOT . 'back/'); 37 37 define(JZZF_FRONT, JZZF_ROOT . 'front/'); 38 39 require_once(JZZF_CORE . 'Log.php'); 38 40 39 41 function jzzf_get_version() { … … 202 204 } 203 205 204 require_once(JZZF_CORE . 'Log.php'); 206 function jzzf_log_exposure($public=false) { 207 require_once(JZZF_FRONT . 'ctrl-log.php'); 208 jzzf_ctrl_log($public); 209 exit; 210 } 211 212 function jzzf_log_public_exposure() { 213 jzzf_log_exposure(true); 214 } 205 215 206 216 /* register filter hook */ … … 215 225 add_action('wp_ajax_jzzf_email', 'jzzf_email'); 216 226 add_action('wp_ajax_nopriv_jzzf_email', 'jzzf_email'); 227 add_action('wp_ajax_jzzf_log', 'jzzf_log_exposure'); 228 add_action('wp_ajax_nopriv_jzzf_log', 'jzzf_log_public_exposure'); 217 229 218 230 ?>
Note: See TracChangeset
for help on using the changeset viewer.