snip_id = (int)$_REQUEST['sppl_snip_id']; } else { $this->snip_id = 0; } //Save Snip if(isset($_POST['saveSuppleSnip'])){ $ret = $this->saveSnip(); if($ret){ $this->snip_id = $ret; } } //Load up Snip defaults $this->showSnipsForm(); $this->showFieldsTable(); } function saveSnip(){ global $wpdb; check_admin_referer( 'update-supplesnips'); $d['snip_name'] = $_POST['sppl_snip_name']; if(!$this->checkName($d['snip_name'])){ $this->message = 'Invalid snip name...use numbers, letters, and underscore only.'; $this->msgclass= 'error'; return false; } $d['auto_add'] = (int)$_POST['sppl_auto_add']; $d['snip'] = $_POST['sppl_snip']; $d['css'] = $_POST['sppl_css']; $d['lists'] = $_POST['sppl_lists']; if(get_magic_quotes_gpc()){ $d['snip'] = stripslashes($d['snip']); $d['css'] = stripslashes($d['css']); $d['lists'] = stripslashes($d['lists']); } if($this->snip_id == 0){ $nametest = $wpdb->get_var($wpdb->prepare('SELECT snip_name FROM ' .SUPPLESNIPSTABLE.' WHERE snip_name = %s',$d['snip_name'])); if($nametest){ $this->message = "

Duplicate Snip name: ".$d['snip_name']. " - Snip not added.

"; return false; } if($wpdb->insert(SUPPLESNIPSTABLE,$d)){ $insert_id = $wpdb->insert_id; $this->message = "Snip Added -> ".$d['snip_name']; return $insert_id; } else { $this->message = "

FAILED...field failed to insert:

".$d['field_name']; } }else{ $where['snip_id'] = $this->snip_id; $wpdb->update( SUPPLESNIPSTABLE, $d, $where); $this->message = "Snip updated: ".$d['snip_name'].""; } } function checkName($text) { $regex = "/^([A-Za-z0-9_]+)$/"; if (preg_match($regex, $text)) { return TRUE; } else { return FALSE; } } /** * Displays the Add/Edit form for HTML Snips * * Snips let you build complex HTML templates for * displaying your field data within a post * */ function showSnipsForm(){ global $wpdb; $snipsDDL = $this->getSnipsDDL($this->snip_id); if($this->snip_id){ $snipOptions = $wpdb->get_row($wpdb->prepare('SELECT * FROM '.SUPPLESNIPSTABLE.' WHERE snip_id = %d',$this->snip_id), ARRAY_A); if($snipOptions){ if(get_magic_quotes_gpc()){ $snipOptions['snip'] = stripslashes($snipOptions['snip']); $snipOptions['css'] = stripslashes($snipOptions['css']); $snipOptions['lists'] = stripslashes($snipOptions['lists']); } } } ?>
">

Supple Forms -> HTML Snips Editor

message){ echo '

'.$this->message.'

'; } ?>

Add/Edit HTML Snips

 
Select Snip to edit: 
Snip name: '/>
  1. Used in shortcodes to display snip: [supple snip='']
  2. Use letters, numbers, and underscore ( _ ) only
Auto-add to posts:
Not implemented at this time.
disabled> No auto-add
disabled> Add before content
disabled> Add to end of content
Not implemented at this time...
List of values: HTML snippet

1) Use standard HTML to format your display
2) Show field values with tags like: [my_field]
CSS: Enter as normal CSS for use with classes/IDs in your snips:
Multi-value fields formats:
Format multi-value fields as lists by entering formats from below. Place each format on a new line, and enter formats in order for each multi-value field used in snip.
Enter only one format to use same for all multi-value fields.

Formats:

  • ol - will turn values for a field into an ordered list
  • ul - unordered list
  • br - new line
  • ", " (without the quotation marks) - will separate items with comma and space
  • any other delimiter - only 'ol', 'ul', and 'br' will be transformed into tags
 

<new>"; $query = $wpdb->get_results("SELECT snip_id, snip_name FROM " .SUPPLESNIPSTABLE." ORDER BY snip_name;"); if($query){ foreach($query as $row){ if($selected_snip == $row->snip_id){$sel = "selected='selected'";}else{$sel = "";} $ret .= ""; } } $ret =""; return $ret; } function showFieldsTable(){ $fldTable = $this->getTableOfFields(); echo "

Table of your fields for reference:

Field values can be inserted into your snippet with a short code like [field_name]. Example:

<div>I live in [my_city].</div>

Renders: I live in St. Louis."; echo $fldTable; } //Get a table of the created fields function getTableOfFields() { global $wpdb; $sql = "SELECT * FROM ".SUPPLEFIELDSTABLE." ORDER BY form_id, seq"; $query = $wpdb->get_results($wpdb->prepare($sql, $form_id)); if($this->options['use_custom_fields'] == 0 ){ $ct = 'Generated'; $b = true; } if($query){ foreach($query as $row) { if($b){ $gen = $row->status == 1 ? "generated" : "not generated"; $gen = "".$gen.""; if(!$row->status){$this->ungeneratedfields++;} } $multi = $row->multi_val == 0 ? 'No' : 'Yes'; $nbr = $row->numeric_field == 0 ? 'No' : 'Yes'; $def = $row->default_val ? $row->default_val : ' '; $ret .= "".$row->seq ." - " .$row->field_name."" ."".$row->label."" ."".$this->getControlType($row->type)."" ."".$nbr."" ."".$multi."" ."".$def."" .$gen." "; } } return ' '.$ct.' '.$ret.'
Field name Label Type Nbr Multi-value Default value
'; } function getControlType($type) { switch ($type) { case 0: return "Textbox"; break; case 1: return "Multi-line"; break; case 2: return "Dropdown List"; break; case 3: return "Radio buttons"; break; case 4: return "Checkboxes"; break; case 5: return "Date Picker"; break; case 6: return "Hidden"; break; } } } if ( !function_exists('wp_nonce_field') ) { function bwbsppl_nonce_field($action = -1) { return; } $bwbsppl_plugin_nonce = -1; } else { function bwbsppl_nonce_field($action = -1) { return wp_nonce_field($action); } } ?>