| 1 |
<?php |
| 2 |
/* Finding the path to the wp-admin folder */ |
| 3 |
$iswin = preg_match('/:\\\/', dirname(__file__)); |
| 4 |
$slash = ($iswin) ? "\\" : "/"; |
| 5 |
|
| 6 |
$wp_path = preg_split('/(?=((\\\|\/)wp-content)).*/', dirname(__file__)); |
| 7 |
$wp_path = (isset($wp_path[0]) && $wp_path[0] != "") ? $wp_path[0] : $_SERVER["DOCUMENT_ROOT"]; |
| 8 |
|
| 9 |
/** Load WordPress Administration Bootstrap */ |
| 10 |
require_once($wp_path . $slash . 'wp-load.php'); |
| 11 |
require_once($wp_path . $slash . 'wp-admin' . $slash . 'admin.php'); |
| 12 |
|
| 13 |
|
| 14 |
// check for rights |
| 15 |
if ( !is_user_logged_in() || !current_user_can('edit_posts') ) |
| 16 |
wp_die(__( "You are not allowed to be here", 'post-snippets' )); |
| 17 |
|
| 18 |
?> |
| 19 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 20 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
| 21 |
<head> |
| 22 |
<title>Post Snippets</title> |
| 23 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| 24 |
<script language="javascript" type="text/javascript" src="<?php echo get_option('siteurl') ?>/wp-includes/js/tinymce/tiny_mce_popup.js"></script> |
| 25 |
<script language="javascript" type="text/javascript" src="<?php echo get_option('siteurl') ?>/wp-includes/js/tinymce/utils/mctabs.js"></script> |
| 26 |
<script language="javascript" type="text/javascript" src="<?php echo get_option('siteurl') ?>/wp-includes/js/tinymce/utils/form_utils.js"></script> |
| 27 |
<script language="javascript" type="text/javascript"> |
| 28 |
function init() { |
| 29 |
tinyMCEPopup.resizeToInnerSize(); |
| 30 |
} |
| 31 |
|
| 32 |
function createSnippet(theSnippet) { |
| 33 |
} |
| 34 |
|
| 35 |
function createShortcode(shortcodeTag, shortcodeAtts) { |
| 36 |
theSnippet = "[" + shortcodeTag; |
| 37 |
for (x in shortcodeAtts) |
| 38 |
{ |
| 39 |
theSnippet += ' ' + shortcodeAtts[x] + '="{' + shortcodeAtts[x] + '}"'; |
| 40 |
} |
| 41 |
theSnippet += "]"; |
| 42 |
return theSnippet; |
| 43 |
} |
| 44 |
|
| 45 |
function insertSnippet() { |
| 46 |
|
| 47 |
var insertString; |
| 48 |
|
| 49 |
<?php |
| 50 |
$snippets = get_option($post_snippets->plugin_options); |
| 51 |
for ($i = 0; $i < count($snippets); $i++) { ?> |
| 52 |
var panel<?php echo $i; ?> = document.getElementById('ps_panel<?php echo $i; ?>'); |
| 53 |
<?php } ?> |
| 54 |
|
| 55 |
var rss = document.getElementById('ps_panel0'); |
| 56 |
|
| 57 |
<?php |
| 58 |
$snippets = get_option($post_snippets->plugin_options); |
| 59 |
for ($i = 0; $i < count($snippets); $i++) { |
| 60 |
// Make it js safe |
| 61 |
$theString = str_replace('"','\"',str_replace(Chr(13), '', str_replace(Chr(10), '', str_replace('<', '\x3C', str_replace('>', '\x3E', $snippets[$i]['snippet']))))); |
| 62 |
// \x3C and \x3E |
| 63 |
?> |
| 64 |
|
| 65 |
if (panel<?php echo $i; ?>.className.indexOf('current') != -1) { |
| 66 |
<?php |
| 67 |
if ($snippets[$i]['shortcode']) { |
| 68 |
$var_arr = explode(",",$snippets[$i]['vars']); |
| 69 |
$theVariables = ""; |
| 70 |
if (!empty($var_arr[0])) { |
| 71 |
for ($j = 0; $j < count($var_arr); $j++) { |
| 72 |
$theVariables = $theVariables . "'" . $var_arr[$j] . "'"; |
| 73 |
if ( $j < (count($var_arr) -1) ) |
| 74 |
$theVariables = $theVariables . ", "; |
| 75 |
|
| 76 |
} |
| 77 |
} |
| 78 |
echo "var variables" . $i ." = new Array(".$theVariables.");"; ?> |
| 79 |
insertString = createShortcode("<?php echo $snippets[$i]['title']; ?>", variables<?php echo $i; ?>); |
| 80 |
<?php }else{ ?> |
| 81 |
insertString = "<?php echo $theString; ?>"; |
| 82 |
<?php } ?> |
| 83 |
<?php |
| 84 |
$var_arr = explode(",",$snippets[$i]['vars']); |
| 85 |
if (!empty($var_arr[0])) { |
| 86 |
for ($j = 0; $j < count($var_arr); $j++) { ?> |
| 87 |
var var_<?php echo $i; ?>_<?php echo $j; ?> = document.getElementById('var_<?php echo $i; ?>_<?php echo $j; ?>').value; |
| 88 |
insertString = insertString.replace(/\{<?php echo $var_arr[$j]; ?>\}/g, var_<?php echo $i; ?>_<?php echo $j; ?>); |
| 89 |
<?php } } ?> |
| 90 |
} |
| 91 |
<?php } ?> |
| 92 |
|
| 93 |
|
| 94 |
if(window.tinyMCE) { |
| 95 |
//window.tinyMCE.execInstanceCommand('content', 'mceInsertContent', false, insertString); |
| 96 |
tinyMCEPopup.execCommand("mceBeginUndoLevel"); |
| 97 |
tinyMCEPopup.execCommand('mceInsertContent', false, insertString); |
| 98 |
tinyMCEPopup.execCommand("mceEndUndoLevel"); |
| 99 |
//Peforms a clean up of the current editor HTML. |
| 100 |
//tinyMCEPopup.editor.execCommand('mceCleanup'); |
| 101 |
//Repaints the editor. Sometimes the browser has graphic glitches. |
| 102 |
tinyMCEPopup.editor.execCommand('mceRepaint'); |
| 103 |
tinyMCEPopup.close(); |
| 104 |
} |
| 105 |
return; |
| 106 |
} |
| 107 |
</script> |
| 108 |
<base target="_self" /> |
| 109 |
</head> |
| 110 |
<body id="link" onload="tinyMCEPopup.executeOnLoad('init();');document.body.style.display='';" style="display: none"> |
| 111 |
<!-- <form onsubmit="insertLink();return false;" action="#"> --> |
| 112 |
<form name="post_snippets" action="#"> |
| 113 |
|
| 114 |
<div class="tabs"> |
| 115 |
<ul> |
| 116 |
<?php |
| 117 |
$snippets = get_option($post_snippets->plugin_options); |
| 118 |
for ($i = 0; $i < count($snippets); $i++) { ?> |
| 119 |
<li id="ps_tab<?php echo $i; ?>"<?php if ($i == 0) {?> class="current"><?php } ?><span><a href="javascript:mcTabs.displayTab('ps_tab<?php echo $i; ?>','ps_panel<?php echo $i; ?>');" onmousedown="return false;"><?php echo $snippets[$i]['title']; ?></a></span></li> |
| 120 |
<?php } ?> |
| 121 |
</ul> |
| 122 |
</div> |
| 123 |
|
| 124 |
<div class="panel_wrapper" style="overflow:auto;"> |
| 125 |
<?php |
| 126 |
$snippets = get_option($post_snippets->plugin_options); |
| 127 |
for ($i = 0; $i < count($snippets); $i++) { ?> |
| 128 |
<div id="ps_panel<?php echo $i; ?>" class="panel<?php if ($i == 0) {?> current<?php } ?>"> |
| 129 |
<br /> |
| 130 |
<table border="0" cellpadding="4" cellspacing="0"> |
| 131 |
<?php |
| 132 |
$var_arr = explode(",",$snippets[$i]['vars']); |
| 133 |
if (!empty($var_arr[0])) { |
| 134 |
for ($j = 0; $j < count($var_arr); $j++) { ?> |
| 135 |
<tr> |
| 136 |
<td nowrap="nowrap"><label for="var_<?php echo $i; ?>_<?php echo $j; ?>"><?php echo($var_arr[$j]);?>:</label></td> |
| 137 |
<td><input type="text" id="var_<?php echo $i; ?>_<?php echo $j; ?>" name="var_<?php echo $i; ?>_<?php echo $j; ?>" style="width: 190px" /> |
| 138 |
</td> |
| 139 |
</tr> |
| 140 |
<?php } } ?> |
| 141 |
</table> |
| 142 |
</div> |
| 143 |
<?php } ?> |
| 144 |
</div> |
| 145 |
|
| 146 |
<div class="mceActionPanel"> |
| 147 |
<div style="float: left"> |
| 148 |
<input type="button" id="cancel" name="cancel" value="<?php _e( 'Cancel', 'post-snippets' ); ?>" onclick="tinyMCEPopup.close();" /> |
| 149 |
</div> |
| 150 |
|
| 151 |
<div style="float: right"> |
| 152 |
<input type="submit" id="insert" name="insert" value="<?php _e( 'Insert', 'post-snippets' ); ?>" onclick="insertSnippet();" /> |
| 153 |
</div> |
| 154 |
</div> |
| 155 |
</form> |
| 156 |
</body> |
| 157 |
</html> |