| 1 |
<?php |
| 2 |
function wp_insert_get_control($type = 'text', $returnHTML = false, $name = '', $id='', $value = '', $label = '', $info = '', $data = null, $class = '', $useParagraph = true, $dummy = '') { |
| 3 |
$control = array( |
| 4 |
'html' => '', |
| 5 |
'javascript' => '' |
| 6 |
); |
| 7 |
if($useParagraph) { $control['html'] .= '<p>'; } |
| 8 |
switch($type) { |
| 9 |
case 'hidden': |
| 10 |
if($value == '') { $value = 0; } |
| 11 |
if($class == '') { $class = 'input widefat'; } |
| 12 |
if($label != '') { $control['html'] .= '<label for="'.$id.'">'.$label.' '.$value.'</label><br />'; } |
| 13 |
$control['html'] .= '<input type="hidden" id="'.$id.'" name="'.$name.'" value="'.$value.'" class="'.$class.'" />'; |
| 14 |
break; |
| 15 |
case 'text': |
| 16 |
if($class == '') { $class = 'input widefat'; } |
| 17 |
if($label != '') { $control['html'] .= '<label for="'.$id.'">'.$label.'</label><br />'; } |
| 18 |
$control['html'] .= '<input type="text" id="'.$id.'" name="'.$name.'" value="'.$value.'" class="'.$class.'" />'; |
| 19 |
break; |
| 20 |
case 'checkbox': |
| 21 |
if($class == '') { $class = 'input'; } |
| 22 |
$control['html'] .= '<input type="checkbox" id="'.$id.'" name="'.$name.'" value="1" class="'.$class.'" '.checked($value, 1, false).' />'; |
| 23 |
if($label != '') { $control['html'] .= ' <label for="'.$id.'">'.$label.'</label>'; } |
| 24 |
break; |
| 25 |
case 'select': |
| 26 |
if($class == '') { $class = 'input widefat'; } |
| 27 |
if($label != '') { $control['html'] .= '<label for="'.$id.'">'.$label.'</label><br />'; } |
| 28 |
$control['html'] .= '<select id="'.$id.'" name="'.$name.'" class="'.$class.'">'; |
| 29 |
if($data) { |
| 30 |
foreach($data as $option) { |
| 31 |
$control['html'] .= '<option value='.(($option['value'] == '')?$option['text']:$option['value']).' '.selected($value, (($option['value'] == '')?$option['text']:$option['value']), false).'>'.$option['text'].'</option>'; |
| 32 |
} |
| 33 |
} |
| 34 |
$control['html'] .= '</select>'; |
| 35 |
break; |
| 36 |
case 'textarea': |
| 37 |
if($class == '') { $class = 'input widefat'; } |
| 38 |
if($label != '') { $control['html'] .= '<label for="'.$id.'">'.$label.'</label><br />'; } |
| 39 |
$control['html'] .= '<textarea id="'.$id.'" name="'.$name.'" class="'.$class.'">'.$value.'</textarea>'; |
| 40 |
break; |
| 41 |
case 'upload': |
| 42 |
if($class == '') { $class = 'input widefat'; } |
| 43 |
if($label != '') { $control['html'] .= '<label for="'.$id.'">'.$label.'</label><br />'; } |
| 44 |
$control['html'] .= '<input type="text" id="'.$id.'" name="'.$name.'" value="'.$value.'" class="'.$class.'" style="width: 74%;" />'; |
| 45 |
$control['html'] .= '<input type="button" value="Upload Image" class="wp_insert_uploader_button" id="upload_image_button" style="width: 25%;" />'; |
| 46 |
break; |
| 47 |
case 'nicedit': |
| 48 |
if($class == '') { $class = 'input widefat'; } |
| 49 |
if($label != '') { $control['html'] .= '<label for="'.$id.'">'.$label.'</label><br />'; } |
| 50 |
$control['html'] .= '<textarea id="'.$id.'" name="'.$name.'" class="'.$class.'" cols="100" style="height: 250px;">'.$value.'</textarea>'; |
| 51 |
$control['javascript'] .= 'new nicEditor({maxHeight : 400, buttonList : ["fontSize","bold","italic","underline","left","center","right","justify","strikeThrough","subscript","superscript","indent","outdent","hr","image","forecolor","bgcolor","link","unlink","fontSize","fontFormat","xhtml"]} ).panelInstance("'.$id.'");'; |
| 52 |
break; |
| 53 |
case 'tz-checkbox': |
| 54 |
if($class == '') { $class = 'input betterCheckbox'; } |
| 55 |
if($label != '') { $control['html'] .= '<label for="'.$id.'">'.$label.'</label><br />'; } |
| 56 |
$control['html'] .= '<input type="checkbox" id="'.$id.'" name="'.$name.'" class="'.$class.'" value="1" '.checked($value, 1, false).' />'; |
| 57 |
$control['javascript'] .= 'jQuery("#'.$id.'").tzCheckbox({labels: ["Active", "Inactive"]});'; |
| 58 |
break; |
| 59 |
case 'ip-checkbox': |
| 60 |
if($class == '') { $class = 'input iphoneCheckbox'; } |
| 61 |
if($label != '') { $control['html'] .= '<label for="'.$id.'">'.$label.'</label><br />'; } |
| 62 |
$control['html'] .= '<input type="checkbox" id="'.$id.'" name="'.$name.'" class="'.$class.'" value="1" '.checked($value, 1, false).' />'; |
| 63 |
$control['javascript'] .= 'jQuery("#'.$id.'").iphoneStyle({checkedLabel: "Hide Ads", uncheckedLabel: "Show Ads", resizeContainer: false, resizeHandle: false});'; |
| 64 |
break; |
| 65 |
case 'popup': |
| 66 |
if($class == '') { $class = 'input narrowfat'; } |
| 67 |
if($label != '') { $control['html'] .= '<label for="'.$id.'">'.$label.'</label><br />'; } |
| 68 |
$control['html'] .= '<input type="text" id="'.$id.'" name="'.$name.'" value="'.$value.'" class="'.$class.'" />'; |
| 69 |
$control['html'] .= '<a id="'.$id.'_button" href="#"><img style="width: 16px; height: 16px; margin: 0 0 -3px 5px;" src="'.WP_INSERT_URL.'/includes/common/images/pointer.png" /></a>'; |
| 70 |
if($data) { |
| 71 |
$control['javascript'] .= 'jQuery("#'.$id.'_button").click(function() {'; |
| 72 |
$control['javascript'] .= 'jQuery.colorbox({overlayClose: false, scrolling: false, transition: "elastic", innerWidth: "577px", innerHeight: "402px", iframe: true, href: "'.WP_INSERT_URL.'/includes/common/popups/'.$data['type'].'.php?data="+escape(jQuery("#'.$id.'").val())+"&target='.$id.'"});'; |
| 73 |
$control['javascript'] .= 'return false;'; |
| 74 |
$control['javascript'] .= '});'; |
| 75 |
} |
| 76 |
break; |
| 77 |
} |
| 78 |
if($info != '') { |
| 79 |
$control['html'] .= '<small style="float: right;">'.$info.'</small>'; |
| 80 |
} |
| 81 |
if($useParagraph) { $control['html'] .= '</p>'; } |
| 82 |
if($info != '') { |
| 83 |
$control['html'] .= '<div class="clear"></div>'; |
| 84 |
} |
| 85 |
|
| 86 |
if($returnHTML) { |
| 87 |
return $control['html']; |
| 88 |
} else { |
| 89 |
return $control; |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
function wp_insert_get_vtabs($id, $args) { |
| 94 |
$control = array( |
| 95 |
'html' => '', |
| 96 |
'javascript' => '' |
| 97 |
); |
| 98 |
$control['html'] .= '<div id="'.$id.'">'; |
| 99 |
$control['html'] .= '<div>'; |
| 100 |
$control['html'] .= '<ul>'; |
| 101 |
foreach($args as $tab) { |
| 102 |
$control['html'] .= '<li><a href="#'.str_replace(array(' ', '-'), '_', strtolower($tab['title'])).'">'.$tab['title'].'</a></li>'; |
| 103 |
} |
| 104 |
$control['html'] .= '</ul>'; |
| 105 |
$control['html'] .= '</div>'; |
| 106 |
$control['html'] .= '<div>'; |
| 107 |
foreach($args as $tab) { |
| 108 |
$control['html'] .= '<div id="#'.str_replace(array(' ', '-'), '_', strtolower($tab['title'])).'">'.$tab['content'].'</div>'; |
| 109 |
} |
| 110 |
$control['html'] .= '</div>'; |
| 111 |
$control['html'] .= '</div>'; |
| 112 |
$control['javascript'] .= 'jQuery("#'.$id.'").jVertTabs({equalHeights: false});'; |
| 113 |
return $control; |
| 114 |
} |
| 115 |
|
| 116 |
function wp_insert_get_table($args) { |
| 117 |
$output = '<table'.(($args['id'] != '')?' id="'.$args['id'].'"':'').(($args['class'] != '')?' class="'.$args['class'].'"':'').(($args['style'] != '')?' style="'.$args['style'].'"':'').'>'; |
| 118 |
foreach($args['rows'] as $row) { |
| 119 |
$output .= '<tr'.(($row['id'] != '')?' id="'.$row['id'].'"':'').(($row['class'] != '')?' class="'.$row['class'].'"':'').(($row['style'] != '')?' style="'.$row['style'].'"':'').'>'; |
| 120 |
foreach($row['cells'] as $cell) { |
| 121 |
if($cell['type'] == '') { $cell['type'] = 'td'; } |
| 122 |
$output .= '<'.$cell['type'].(($cell['colspan'] != '')?' colspan="'.$cell['colspan'].'"':'').(($cell['id'] != '')?' id="'.$cell['id'].'"':'').(($cell['class'] != '')?' class="'.$cell['class'].'"':'').(($cell['style'] != '')?' style="'.$cell['style'].'"':'').'>'; |
| 123 |
$output .= $cell['content']; |
| 124 |
$output .= '</'.$cell['type'].'>'; |
| 125 |
} |
| 126 |
$output .= '</tr>'; |
| 127 |
} |
| 128 |
$output .= '</table>'; |
| 129 |
return $output; |
| 130 |
} |
| 131 |
|
| 132 |
function wp_insert_get_script_tag($content) { |
| 133 |
$script = ''; |
| 134 |
if(is_array($content)) { |
| 135 |
foreach($content as $control) { |
| 136 |
$script .= $control['javascript']; |
| 137 |
} |
| 138 |
} else { |
| 139 |
$script = $content; |
| 140 |
} |
| 141 |
$output = '<script type="text/javascript">'; |
| 142 |
$output .= 'jQuery(document).ready(function(){'.$script.'});'; |
| 143 |
$output .= '</script>'; |
| 144 |
return $output; |
| 145 |
} |
| 146 |
?> |