function msc_load_elementConfig($die = false) { if (empty($_POST['element'])) { echo 'Please select a shortcode to continue'; die; } $optionID = $_POST['element']; $Element = get_option($_POST['element']); if (empty($Element['_defaultContent'])) { $Element['_defaultContent'] = 'Content Goes Here'; } echo '<input type="hidden" id="shortcodekey" value="' . $Element['_shortcode'] . '" />'; echo '<input type="hidden" id="shortcodetype" value="' . $Element['_shortcodeType'] . '" />'; echo '<input type="hidden" id="defaultContent" value="' . $Element['_defaultContent'] . '" />'; $Groups = array(); if (!empty($Element['_variable'])) { foreach ($Element['_variable'] as $Key => $Var) { if (empty($Element['_isMultiple'][$Key])) { $Groups[$Element['_tabgroup'][$Key]][$Key] = $Var; } else { $Groups[$Element['_group'][$Key]][$Key] = $Var; } } } ?> <div class="wrap poststuff" id="msc_container"> <div id="main"> <?php $groupCount = count($Groups); $contentclass = ''; if ($groupCount == 1) { $contentclass = 'solo'; } ?> <div id="ce-nav" class="<?php echo $contentclass; ?> "> <ul> <?php $first = true; foreach ($Groups as $GroupName => $vars) { $GroupID = sanitize_key($GroupName); $class = ''; if (!empty($Element['_tabgroup'][$GroupID])) { $GroupName = ucwords($Element['_tabgroup'][$GroupID]); } if ($first) { $class = 'class="current"'; } ?> <li <?php echo $class; ?> > <a href="#<?php echo $GroupID; ?> " title="<?php echo $GroupName; ?> "><strong><?php echo $GroupName; ?> </strong></a> </li> <?php $first = false; } ?> </ul> </div> <div id="content" class="<?php echo $contentclass; ?> "> <?php if (empty($Element['_variable'])) { echo 'No configuration nessasary for this plugin, just enjoy it!'; } $isfirst = true; foreach ($Groups as $GroupName => $vars) { $GroupID = sanitize_key($GroupName); $class = ''; if (!empty($Element['_tabgroup'][$GroupID])) { $GroupName = ucwords($Element['_tabgroup'][$GroupID]); } $display = 'none'; if ($isfirst) { $display = 'block'; $isfirst = false; } echo '<div style="display: ' . $display . ';" class="group" id="' . $GroupID . '">'; if ($groupCount == 1) { $GroupName = $Element['_name']; } echo '<h2>' . $GroupName . '</h2>'; echo '<p>'; if (!empty($Element['_variable'][$GroupID])) { echo '<table class="form-table rowGroup group' . $GroupID . '" id="group' . $GroupID . '" ref="' . $GroupID . '">'; } else { echo '<table class="form-table group' . $GroupID . '" id="group' . $GroupID . '" ref="' . $GroupID . '">'; } echo '<tbody>'; foreach ($vars as $key => $var) { if ($Element['_type'][$key] == 'Color Picker') { $enableColorPicker = true; } if (empty($Element['_label'][$key])) { $Element['_label'][$key] = ucwords($Element['_variable'][$key]); } if (!empty($Element['_isMultiple'][$GroupID])) { // go make a multi group if (!isset($isfirst)) { $isfirst = true; } else { $isfirst = false; } if (empty($instance[$var . '_1'])) { $instance[$var . '_1'] = $Element['_variableDefault'][$key]; } $args = array('elementID' => $optionID, 'key' => $key, 'id' => $key, 'name' => $var . '_1', 'default' => $instance[$var . '_1'], 'duplicate' => false); echo msc_attsConfigFields($args); } else { // go make a single group if (empty($instance[$var])) { $instance[$var] = $Element['_variableDefault'][$key]; } if (empty($Element['_variableInfo'][$key])) { $Element['_variableInfo'][$key] = ''; } $args = array('elementID' => $optionID, 'key' => $key, 'id' => $key, 'name' => $var, 'default' => $instance[$var], 'duplicate' => false); echo msc_attsConfigFields($args); } } echo '</tbody>'; echo '</table>'; echo '</p>'; $run = true; $index = 2; while ($run) { if (empty($GroupID) || empty($Element['_variable'][$GroupID])) { break; } if (!empty($instance[$Element['_variable'][$GroupID] . '_' . $index])) { echo msc_alwaysloadaddGroupSet($GroupID, $index, $instance, $optionID); } else { $run = false; } $index++; } if (!empty($Element['_variable'][$GroupID])) { echo '<div class="toolrow" id="tool' . $GroupID . '"><a class="button addRow" href="' . $GroupID . '" ref="' . $optionID . '">Add ' . $GroupName . '</a></div>'; } echo '</div>'; } ?> </div> <div class="clear"></div> </div> <div style="clear:both;"></div> </div> <?php if ($die == true) { return; } die; }
function form($instance) { $Elements = get_option('CE_ELEMENTS'); if (empty($Elements)) { echo 'You don\'t have any elements.'; return; } $cats = array(); $eles = array(); foreach ($Elements as $ID => $Options) { if (!empty($Options['state']) && $Options['elementType'] == 2) { $Cat = strtolower($Options['category']); $cats[$Cat] = $Cat; $eles[$Cat][$ID] = strtolower($Options['name']); } } if (empty($cats)) { echo '<p>You don\'t have any active Widget or Hybrid elements.</p>'; return; } if (!empty($instance['_category']) && !empty($instance['_element'])) { $Element = get_option($instance['_element']); if ($Element['_elementType'] != 2) { unset($instance['_category']); unset($instance['_element']); } } if (!empty($instance['_category']) && !empty($instance['_element'])) { echo "<div id=\"" . $this->get_field_id('_elementSelector') . "\" class=\"elementSelector\">\n"; } echo "<p>\n"; echo "<label for=\"" . $this->get_field_id('_category') . "\">Category:</label>\n"; echo "<select class=\"widefat msc-cat-select\" id=\"" . $this->get_field_id('_category') . "\" ref=\"" . $this->get_field_name('_element') . "|" . $this->get_field_id('_element') . "\" name=\"" . $this->get_field_name('_category') . "\">\n"; echo "<option value=\"\">Select Category</option>\n"; foreach ($cats as $Cat) { $sel = ""; if (!empty($instance['_category'])) { if ($instance['_category'] == $Cat) { $sel = 'selected="selected"'; } } echo "<option value=\"" . $Cat . "\" " . $sel . ">" . ucwords($Cat) . "</option>\n"; } echo "</select>\n"; echo "</p>\n"; echo "<p id=\"ele" . $this->get_field_id('_category') . "\" class=\"elementBox\">\n"; if (!empty($instance['_category'])) { echo "<label for=\"" . $this->get_field_id('_element') . "\">Element:</label>\n"; echo "<select class=\"widefat msc-ele-select\" id=\"" . $this->get_field_id('_element') . "\" name=\"" . $this->get_field_name('_element') . "\">\n"; echo "<option value=\"\">Select Element</option>\n"; foreach ($eles[$instance['_category']] as $ID => $Ele) { $sel = ""; if (!empty($instance['_element'])) { if ($instance['_element'] == $ID) { $sel = 'selected="selected"'; } } echo "<option value=\"" . $ID . "\" " . $sel . ">" . ucwords($Ele) . "</option>\n"; } echo "</select>\n"; echo "<span class=\"fbtn\"><input type=\"submit\" class=\"widget-control-save button loadElementControl-btn\" value=\"Load Element\" /></span>"; } echo "</p>\n"; if (!empty($instance['_category']) && !empty($instance['_element'])) { echo "</div>\n"; echo '<div class="hide-if-no-js show-element-selector-tab"> <a class="show-elements-tab" href="#' . $this->get_field_id('_elementSelector') . '">Show Element Selection</a> </div>'; } if (empty($instance['_category']) || empty($instance['_element'])) { return; } echo "<div id=\"form_" . $this->get_field_id('_element') . "\" class=\"clear scrollbox\">\n"; echo '<h2 class="widgeth2">' . ucwords($eles[$instance['_category']][$instance['_element']]) . '</h2>'; $optionID = $instance['_element']; $Element = get_option($optionID); if (($Element['_elementType'] == 2 || $Element['_elementType'] == 3) && $Element['_widgetTitle'] == 2) { $titleText = ''; if (!empty($instance['_title'])) { $titleText = $instance['_title']; } echo '<p><label>Title<input type="text" value="' . $titleText . '" name="' . $this->get_field_name('_title') . '" id="' . $this->get_field_id('_name') . '" class="widefat"></label></p>'; } $Groups = array(); if (!empty($Element['_variable'])) { foreach ($Element['_variable'] as $Key => $Var) { if (empty($Element['_isMultiple'][$Key])) { $Groups[$Element['_tabgroup'][$Key]][$Key] = $Var; } else { $Groups[$Element['_group'][$Key]][$Key] = $Var; } } } //if(empty($instance)){ if (!empty($Element['_variable'])) { foreach ($Element['_variable'] as $key => $var) { if (!empty($Element['_isMultiple'][$key])) { if ($Element['_isMultiple'][$key]) { $var = $var . '_1'; } } if (!isset($instance[$var])) { $instance[$var] = $Element['_variableDefault'][$key]; } } } //update_option($optionID.'_cfg', $instance); //} if (empty($Element['_variable']) && $Element['_widgetWrap'] == 1 && $Element['_widgetTitle'] == 1) { echo '<p>No configuration nessasary for this plugin, just enjoy it!</p>'; } else { foreach ($Groups as $GroupName => $vars) { $GroupID = sanitize_key($GroupName); if (!empty($Element['_tabgroup'][$GroupID])) { $GroupName = ucwords($Element['_tabgroup'][$GroupID]); } echo '<div class="widget-table" id="header' . $GroupID . '">'; echo '<h2>' . $GroupName . '</h2>'; echo '</div>'; unset($isfirst); echo '<div class="widget-table rowGroup group' . $GroupID . '" id="group' . $GroupID . '" ref="' . $GroupID . '">'; foreach ($vars as $key => $var) { if (!empty($Element['_isMultiple'][$key])) { if (empty($instance[$var . '_1'])) { $instance[$var . '_1'] = $Element['_variableDefault'][$key]; } $args = array('elementID' => $optionID, 'key' => $key, 'id' => $this->get_field_id($key . '_1'), 'name' => $this->get_field_name($var . '_1'), 'default' => $instance[$var . '_1'], 'duplicate' => false); } else { $args = array('elementID' => $optionID, 'key' => $key, 'id' => $this->get_field_id($key), 'name' => $this->get_field_name($var), 'default' => $instance[$var], 'duplicate' => false); } echo msc_attsConfigFields($args); } echo '</div>'; $run = true; $index = 2; while ($run) { if (empty($GroupID) || empty($Element['_variable'][$GroupID])) { break; } if (!empty($instance[$Element['_variable'][$GroupID] . '_' . $index])) { echo $this->addGroup($GroupID, $index, $instance); } else { $run = false; } $index++; } if (!empty($Element['_variable'][$GroupID])) { echo '<div class="toolrow" id="tool' . $GroupID . '" ref="' . $this->get_field_name('__addGroup__') . '"><input type="submit" class="widget-control-save button addRow" value="Add ' . $GroupName . '" ref="' . $GroupID . '"></div>'; } } } if (($Element['_elementType'] == 2 || $Element['_elementType'] == 3) && $Element['_shortcodeType'] == 2) { $contentText = ''; if (!empty($instance['_content'])) { $contentText = $instance['_content']; } echo '<label>Content<textarea name="' . $this->get_field_name('_content') . '" id="' . $this->get_field_id('_content') . '" cols="20" rows="16" class="widefat">' . $contentText . '</textarea></label>'; } echo "</div>\n"; }
function msc_alwaysloadsetuppage() { global $footScripts; $optionID = strtoupper($_GET['page']); $Element = get_option($optionID); if (!empty($_POST)) { if (wp_verify_nonce($_POST['_wpnonce'], 'msc_alwaysloadnounce')) { unset($_POST['_wpnonce']); unset($_POST['_wp_http_referer']); unset($_POST['submit']); update_option($optionID . '_cfg', $_POST); $message = '<div class="update" id="message"><p>Settings Updated.</p></div>'; } } ?> <form action="" method="post"> <?php wp_nonce_field('msc_alwaysloadnounce'); $instance = get_option($optionID . '_cfg'); $Groups = array(); if (!empty($Element['_variable'])) { foreach ($Element['_variable'] as $Key => $Var) { if (empty($Element['_isMultiple'][$Key])) { $Groups[$Element['_tabgroup'][$Key]][$Key] = $Var; } else { $Groups[$Element['_group'][$Key]][$Key] = $Var; } } } if (empty($instance)) { $instance = array(); if (!empty($Element['_variable'])) { foreach ($Element['_variable'] as $key => $var) { if (!empty($Element['_isMultiple'][$key])) { $var = $var . '_1'; } $instance[$var] = $Element['_variableDefault'][$key]; } } if (!empty($Element['_assetLabel'])) { foreach ($Element['_assetLabel'] as $assetKey => $assetLabel) { foreach ($instance as $instanceKey => $instanceVal) { $instance[$instanceKey] = str_replace('{{' . $assetLabel . '}}', $Element['_assetURL'][$assetKey], $instanceVal); } } } //update_option($optionID.'_cfg', $instance); } if (!empty($Groups[0])) { $holder[0] = $Groups[0]; unset($Groups[0]); foreach ($Groups as $key => $Group) { $holder[$key] = $Group; } $Groups = $holder; } ?> <div class="wrap poststuff" id="msc_container"> <div id="header"> <div class="title"> <h2><?php echo $Element['_name']; ?> </h2><sub><?php echo $Element['_description']; ?> </sub> </div> <div class="clear"></div> </div> <?php if (!empty($message)) { ?> <div class="save_bar_tools"> <?php echo $message; ?> </div> <?php } ?> <div id="main"> <div id="ce-nav"> <ul> <?php $first = true; foreach ($Groups as $GroupName => $vars) { $GroupID = sanitize_key($GroupName); $class = ''; if (!empty($Element['_tabgroup'][$GroupID])) { $GroupName = ucwords($Element['_tabgroup'][$GroupID]); } if ($first) { $class = 'class="current"'; } ?> <li <?php echo $class; ?> > <a href="#<?php echo $GroupID; ?> " title="<?php echo $GroupName; ?> "><strong><?php echo $GroupName; ?> </strong></a> </li> <?php $first = false; } ?> </ul> </div> <div id="content"> <?php if (empty($Element['_variable'])) { echo 'No configuration nessasary for this plugin, just enjoy it!'; } $isfirst = true; foreach ($Groups as $GroupName => $vars) { $GroupID = sanitize_key($GroupName); $class = ''; if (!empty($Element['_tabgroup'][$GroupID])) { $GroupName = ucwords($Element['_tabgroup'][$GroupID]); } $display = 'none'; if ($isfirst) { $display = 'block'; $isfirst = false; } echo '<div style="display: ' . $display . ';" class="group" id="' . $GroupID . '">'; echo '<h2>' . $GroupName . '</h2>'; echo '<p>'; if (!empty($Element['_variable'][$GroupID])) { echo '<table class="form-table rowGroup group' . $GroupID . '" id="group' . $GroupID . '" ref="' . $GroupID . '">'; } else { echo '<table class="form-table group' . $GroupID . '" id="group' . $GroupID . '" ref="' . $GroupID . '">'; } echo '<tbody>'; foreach ($vars as $key => $var) { if ($Element['_type'][$key] == 'Color Picker') { $enableColorPicker = true; } if (empty($Element['_label'][$key])) { $Element['_label'][$key] = ucwords($Element['_variable'][$key]); } if (!empty($Element['_isMultiple'][$GroupID])) { // go make a multi group if (!isset($isfirst)) { $isfirst = true; } else { $isfirst = false; } if (empty($instance[$var . '_1'])) { $instance[$var . '_1'] = $Element['_variableDefault'][$key]; } $args = array('elementID' => $optionID, 'key' => $key, 'id' => $key, 'name' => $var . '_1', 'default' => $instance[$var . '_1'], 'duplicate' => false); echo msc_attsConfigFields($args); } else { // go make a single group if (empty($instance[$var])) { $instance[$var] = $Element['_variableDefault'][$key]; } if (empty($Element['_variableInfo'][$key])) { $Element['_variableInfo'][$key] = ''; } $args = array('elementID' => $optionID, 'key' => $key, 'id' => $key, 'name' => $var, 'default' => $instance[$var], 'duplicate' => false); echo msc_attsConfigFields($args); } } echo '</tbody>'; echo '</table>'; echo '</p>'; $run = true; $index = 2; while ($run) { if (empty($GroupID) || empty($Element['_variable'][$GroupID])) { break; } if (!empty($instance[$Element['_variable'][$GroupID] . '_' . $index])) { echo msc_alwaysloadaddGroupSet($GroupID, $index, $instance, $optionID); } else { $run = false; } $index++; } if (!empty($Element['_variable'][$GroupID])) { echo '<div class="toolrow" id="tool' . $GroupID . '"><a class="button addRow" href="' . $GroupID . '" ref="' . $optionID . '">Add ' . $GroupName . '</a></div>'; } echo '</div>'; } ?> </div> <div class="clear"></div> </div> <div class="save_bar_top" style="padding:5px; height: 22px;"> <button type="submit" class="button-primary">Save Changes</button> </div> <div style="clear:both;"></div> </div> </form> <script type="text/javascript"> jQuery(document).ready(function(){ jQuery('#ce-nav li a').click(function(){ jQuery('#ce-nav li').removeClass('current'); jQuery('.group').hide(); jQuery(''+jQuery(this).attr('href')+'').show(); jQuery(this).parent().addClass('current'); return false; }); if(window.location.hash){ var hash = window.location.hash.substring(1); jQuery('.current').removeClass('current'); var vals = hash.split('&'); jQuery('a[href="#'+vals[0]+'"]').parent().addClass('current'); jQuery('#content .group').hide(); jQuery('#'+vals[0]).show(); jQuery('#element_'+vals[1]+' .cs-elementItem.elementMain').addClass('lastEdited'); } <?php if (isset($enableColorPicker)) { echo "jQuery('.miniColors-trigger-fake').remove();"; echo "jQuery('.minicolorPicker').miniColors();"; } ?> }); </script> <script> jQuery('#msc_container').on('click', '.msc_uploader',function() { formfield = jQuery(this).parent().parent().find('input'); tb_show('Select or Upload a File', 'media-upload.php?type=file&post_id=0&TB_iframe=true'); window.send_to_editor = function(html) { if(jQuery('img', html).length){ linkurl = jQuery('img', html).attr('src'); }else{ linkurl = jQuery(html).attr('href'); } jQuery(formfield).val(linkurl); tb_remove(); } return false; }); jQuery('#msc_container').on('click','.remover', function(){ var id = jQuery(this).parent().parent().parent().parent().attr('ref'); jQuery(this).parent().parent().parent().parent().remove(); var count = 1; jQuery('.group'+id).each(function(){ jQuery(this).find('[name]').each(function(){ var name = jQuery(this).attr('name').split('_'); jQuery(this).attr('name', name[0]+'_'+count); }) count++; }); }) jQuery('.addRow').click(function(event){ event.preventDefault(); addGroup(jQuery(this).attr('href'), jQuery(this).attr('ref')); }) function addGroup(id, oID){ number = jQuery('.group'+id).length+1; var ajaxurl = '<?php echo admin_url('admin-ajax.php', 'relative'); ?> '; var data = { action: 'msc_alwaysloadaddgroupSet', group: id, oID: oID, number: number }; jQuery('#mediaPanel').html('<div class="loading">Loading</div>'); jQuery.post(ajaxurl, data, function(response) { jQuery('#tool'+id).before(response); }); } </script> <?php }