| 1 |
<?php |
| 2 |
/** |
| 3 |
* Creates a form in the "Add Media" screen under the new "Photonic" tab. This form lets you insert the gallery shortcode with |
| 4 |
* the right arguments for native WP galleries, Flickr, Google Photos, SmugMug, Zenfolio and Instagram. |
| 5 |
* |
| 6 |
* @package Photonic |
| 7 |
* @subpackage UI |
| 8 |
*/ |
| 9 |
|
| 10 |
global $photonic_alternative_shortcode; |
| 11 |
$shortcode = empty($photonic_alternative_shortcode) ? 'gallery' : $photonic_alternative_shortcode; |
| 12 |
|
| 13 |
$selected_tab = isset($_GET['photonic-tab']) ? esc_attr($_GET['photonic-tab']) : 'default'; |
| 14 |
if (!in_array($selected_tab, array('default', 'flickr', 'google', 'smugmug', 'zenfolio', 'instagram'))) { |
| 15 |
$selected_tab = 'default'; |
| 16 |
} |
| 17 |
|
| 18 |
if (isset($_POST['photonic-submit'])) { |
| 19 |
$shortcode = stripslashes($_POST['photonic-shortcode']); |
| 20 |
media_send_to_editor($shortcode); |
| 21 |
return; |
| 22 |
} |
| 23 |
else if (isset($_POST['photonic-cancel'])) { |
| 24 |
media_send_to_editor(''); |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
?> |
| 29 |
<script type="text/javascript"> |
| 30 |
jQuery(document).ready(function($) { |
| 31 |
window.photonicAdminHtmlEncode = function photonicAdminHtmlEncode(value){ |
| 32 |
return $('<div/>').text(value).html(); |
| 33 |
}; |
| 34 |
|
| 35 |
$('#photonic-shortcode-form input[type="text"], #photonic-shortcode-form select').change(function(event) { |
| 36 |
var comboValues = $('#photonic-shortcode-form').serializeArray(); |
| 37 |
var newValues = []; |
| 38 |
var len = comboValues.length; |
| 39 |
|
| 40 |
$(comboValues).each(function(i, obj) { |
| 41 |
var individual = this; |
| 42 |
if (individual['name'].trim() !== 'photonic-shortcode' && individual['name'].trim() !== 'photonic-submit' && |
| 43 |
individual['name'].trim() !== 'photonic-cancel' && individual['value'].trim() !== '') { |
| 44 |
newValues.push(individual['name'] + "='" + photonicAdminHtmlEncode(decodeURIComponent(individual['value'].trim())) + "'"); |
| 45 |
} |
| 46 |
}); |
| 47 |
|
| 48 |
var shortcode = "[<?php echo $shortcode; ?> type='<?php echo $selected_tab; ?>' "; |
| 49 |
len = newValues.length; |
| 50 |
$(newValues).each(function() { |
| 51 |
shortcode += this + ' '; |
| 52 |
}); |
| 53 |
shortcode += ']'; |
| 54 |
|
| 55 |
$('#photonic-preview').text(shortcode); |
| 56 |
$('#photonic-shortcode').val(shortcode); |
| 57 |
}); |
| 58 |
$('#photonic-shortcode-form select').change(); |
| 59 |
}); |
| 60 |
</script> |
| 61 |
<?php |
| 62 |
require_once(plugin_dir_path(__FILE__).'/../photonic-form.php'); |
| 63 |
|
| 64 |
$tab_list = ''; |
| 65 |
$tab_fields = ''; |
| 66 |
$field_list = array(); |
| 67 |
$prelude = ''; |
| 68 |
foreach ($fields as $tab => $field_group) { |
| 69 |
$tab_list .= "<li><a href='".esc_url(add_query_arg(array('photonic-tab' => $tab)))."' class='".($tab == $selected_tab ? 'current' : '')."'>".esc_attr($field_group['name'])."</a> | </li>"; |
| 70 |
if ($tab == $selected_tab) { |
| 71 |
$field_list = $field_group['fields']; |
| 72 |
$prelude = isset($field_group['prelude']) ? $field_group['prelude'] : ''; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
echo "<form id='photonic-shortcode-form' method='post' action=''>"; |
| 77 |
echo "<ul class='subsubsub'>"; |
| 78 |
if (strlen($tab_list) > 8) { |
| 79 |
$tab_list = substr($tab_list, 0, -8); |
| 80 |
} |
| 81 |
echo $tab_list; |
| 82 |
echo "</ul>"; |
| 83 |
|
| 84 |
if (!empty($prelude)) { |
| 85 |
echo "<p class='prelude'>"; print_r($prelude); echo "</p>"; |
| 86 |
} |
| 87 |
|
| 88 |
echo "<table class='photonic-form'>"; |
| 89 |
foreach ($field_list as $field) { |
| 90 |
echo "<tr>"; |
| 91 |
echo "<th scope='row'>{$field['name']} ".(isset($field['req']) && $field['req'] ? '(*)' : '')." </th>"; |
| 92 |
$alt_id = !empty($field['alt_id']) ? " alt_id='{$field['alt_id']}' " : ''; |
| 93 |
switch ($field['type']) { |
| 94 |
case 'text': |
| 95 |
echo "<td><input type='text' name='{$field['id']}' value='".(isset($field['std']) ? $field['std'] : '')."' $alt_id/></td>"; |
| 96 |
break; |
| 97 |
|
| 98 |
case 'select': |
| 99 |
echo "<td><select name='{$field['id']}' $alt_id>"; |
| 100 |
$default = isset($field['std']) ? $field['std'] : ''; |
| 101 |
foreach ($field['options'] as $option_name => $option_value) { |
| 102 |
if ($option_name == $default) { |
| 103 |
$selected = 'selected'; |
| 104 |
} |
| 105 |
else { |
| 106 |
$selected = ''; |
| 107 |
} |
| 108 |
echo "<option value='$option_name' $selected>".esc_attr($option_value)."</option>"; |
| 109 |
} |
| 110 |
echo "</select></td>"; |
| 111 |
break; |
| 112 |
|
| 113 |
case 'raw': |
| 114 |
echo "<td>".$field['std']."</td>"; |
| 115 |
break; |
| 116 |
} |
| 117 |
echo "<td class='hint'>".(isset($field['hint']) ? $field['hint'] : '')."</td>"; |
| 118 |
echo "</tr>"; |
| 119 |
} |
| 120 |
echo "</table>"; |
| 121 |
|
| 122 |
echo "<div class='preview'>"; |
| 123 |
echo "<script type='text/javascript'></script>"; |
| 124 |
echo "<h4>".esc_html__('Shortcode preview', 'photonic')."</h4>"; |
| 125 |
echo "<pre class='html' id='photonic-preview' name='photonic-preview'></pre>"; |
| 126 |
echo "<input type='hidden' id='photonic-shortcode' name='photonic-shortcode' />"; |
| 127 |
echo "</div>"; |
| 128 |
|
| 129 |
echo "<div class='button-panel'>"; |
| 130 |
echo get_submit_button(esc_html__('Insert into post', 'photonic'), 'primary', 'photonic-submit', false); |
| 131 |
echo get_submit_button(esc_html__('Cancel', 'photonic'), 'delete', 'photonic-cancel', false); |
| 132 |
echo "</div>"; |
| 133 |
echo "</form>"; |
| 134 |
|