diff --git a/blog/wp-content/plugins/front-end-editor/admin.php b/blog/wp-content/plugins/front-end-editor/admin.php new file mode 100755 index 0000000..7009bcd --- /dev/null +++ b/blog/wp-content/plugins/front-end-editor/admin.php @@ -0,0 +1,147 @@ +textdomain = 'front-end-editor'; + + $this->args = array('page_title' => __('Front-end Editor', $this->textdomain)); + + $this->boxes = array( + array('fields', __('Fields', $this->textdomain), 'normal'), + array('settings', __('Settings', $this->textdomain), 'side'), + ); + } + + function page_head() { +?> + +options->disabled = $disabled; + + $this->admin_msg(); + } + + function fields_box() { + // Separate fields + $post_fields = $other_fields = array(); + foreach ( FEE_Core::get_fields() as $field => $args ) + if ( 'post' == call_user_func(array($args['class'], 'get_object_type') ) ) + $post_fields[$field] = $args; + else + $other_fields[$field] = $args; + + echo html('p', __('Enable or disable editable fields', $this->textdomain)); + + $tables = self::fields_table(__('Post fields', $this->textdomain), $post_fields); + $tables .= self::fields_table(__('Other fields', $this->textdomain), $other_fields); + + echo $this->form_wrap($tables, '', 'manage_fields'); + } + + private function fields_table($title, $fields) { + $thead = + html('thead', + html('tr', + html('th scope="col" class="check-column"', '') + .html('th scope="col"', $title) + ) + ); + + $tbody = ''; + foreach ( $fields as $field => $args ) + $tbody .= + html('tr', + html('th scope="row" class="check-column"', + $this->input(array( + 'type' => 'checkbox', + 'name' => $field, + 'checked' => ! @in_array($field, $this->options->disabled) + )) + ) + .html('td', $args['title']) + ); + + return html('table class="widefat"', $thead . $tbody); + } + + function settings_handler() { + if ( !isset($_POST['save_settings']) ) + return; + + foreach ( array('rich', 'chunks', 'reset_date', 'highlight', 'tooltip') as $key ) + $this->options->$key = (bool) @$_POST[$key]; + + $this->admin_msg(); + } + + function settings_box() { + $rows = array( + array( + 'desc' => __('Enable the WYSIWYG editor', $this->textdomain), + 'type' => 'checkbox', + 'name' => 'rich', + ), + + array( + 'desc' => __('Edit one paragraph at a time, instead of an entire post', $this->textdomain), + 'type' => 'checkbox', + 'name' => 'chunks', + ), + + array( + 'desc' => __('Reset the post date on each edit', $this->textdomain), + 'type' => 'checkbox', + 'name' => 'reset_date', + ), + + array( + 'desc' => __('Highlight editable elements', $this->textdomain), + 'type' => 'checkbox', + 'name' => 'highlight', + ), + array( + 'desc' => __('Display a tooltip above editable elements', $this->textdomain), + 'type' => 'checkbox', + 'name' => 'tooltip', + ), + ); + + $out = ''; + foreach ( $rows as $row ) + $out .= html('p', $this->input($row)); + + echo $this->form_wrap($out, '', 'save_settings'); + } +} + diff --git a/blog/wp-content/plugins/front-end-editor/core.php b/blog/wp-content/plugins/front-end-editor/core.php new file mode 100644 index 0000000..3cd0fe8 --- /dev/null +++ b/blog/wp-content/plugins/front-end-editor/core.php @@ -0,0 +1,240 @@ +highlight ) + add_action('wp_head', array(__CLASS__, 'highlight')); + } + + static function highlight() { +?> + + $args ) + $field_types[$name] = $args['type']; + + $data = array( + 'save_text' => __('Save', 'front-end-editor'), + 'cancel_text' => __('Cancel', 'front-end-editor'), + 'fields' => $field_types, + 'ajax_url' => admin_url('admin-ajax.php'), + 'spinner' => admin_url('images/loading.gif'), + 'nonce' => wp_create_nonce(self::$nonce), + ); + + $css_dependencies = array(); + $js_dependencies = array('jquery'); + + // qTip + if ( self::$options->tooltip ) { + $data['tooltip'] = array( + 'icon' => $url . 'editor.png', + 'text' => __('Double-click to edit', 'front-end-editor') + ); + + wp_register_script('jquery-qtip', $url . "jquery.qtip$js_dev.js", array(), '1.0-rc3', true); + $js_dependencies[] = 'jquery-qtip'; + } + + // Autosuggest + if ( array_key_exists('terminput', $wrapped) ) { + $js_dependencies[] = 'suggest'; + } + + // Rich Editor + if ( array_key_exists('rich', $wrapped) ) { + $data['nicedit'] = apply_filters('front_end_editor_nicedit', array( + 'iconsPath' => $url . 'nicedit/nicEditorIcons.gif', + 'buttonList' => array( + 'bold', 'italic', 'strikethrough', + 'left','center', 'right', + 'fontFormat', 'fontFamily', 'forecolor', + 'removeformat', + 'ul', 'ol', + 'link', 'image', + 'xhtml' + ) + )); + + wp_register_script('nicedit', $url . "nicedit/nicEdit$js_dev.js", array(), '0.9r23', true); + $js_dependencies[] = 'nicedit'; + } + + // Thickbox + if ( array_key_exists('image', $wrapped) || array_key_exists('thumbnail', $wrapped) ) { + $data['admin_url'] = admin_url(); + + $data['image'] = array( + 'change' => __('Change Image', 'front-end-editor'), + 'revert' => '(' . __('Clear', 'front-end-editor') . ')', + 'tb_close' => get_bloginfo('wpurl') . '/wp-includes/js/thickbox/tb-close.png', + ); + + $css_dependencies[] = 'thickbox'; + $js_dependencies[] = 'thickbox'; + + wp_register_script('livequery', $url . 'livequery.js', array('jquery'), '1.1.0-pre', true); + $js_dependencies[] = 'livequery'; + } + + // Core script + wp_register_style('front-end-editor', $url . "editor$css_dev.css", $css_dependencies, self::$version); + wp_register_script('front-end-editor', $url . "editor$js_dev.js", $js_dependencies, self::$version, true); + +?> + + ucfirst(str_replace('_', ' ', $filter)), + 'type' => 'input', + 'priority' => 11, + 'argc' => 1 + )); + + self::$fields[$filter] = $args; + + return true; + } + + static function make_instances() { + self::$active_fields = self::get_fields(); + foreach ( (array) self::$options->disabled as $name ) + unset(self::$active_fields[$name]); + + foreach ( self::$active_fields as $name => $args ) { + extract($args); + + self::$instances[$name] = new $class($name, $type); + } + } + + static function add_filters() { + foreach ( self::$active_fields as $name => $args ) { + extract($args); + + $instance = self::$instances[$name]; + + add_filter($name, array($instance, 'wrap'), $priority, $argc); + } + } + + static function get_fields() { + return self::$fields; + } + + static function get_args($filter) { + return self::$fields[$filter]; + } + + static function ajax_response() { + // Is user trusted? + check_ajax_referer(self::$nonce, 'nonce'); + + $id = $_POST['item_id']; + $name = $_POST['name']; + $type = $_POST['type']; + $action = $_POST['callback']; + + // Is the current field defined? + if ( ! $instance = self::$instances[$name] ) + die(-1); + + // Does the user have the right to do this? + if ( ! $instance->check($id) || ! $instance->allow($id) ) + die(-1); + + $args = self::get_args($name); + + if ( $action == 'save' ) { + $content = stripslashes_deep($_POST['content']); + $result = $instance->save($id, $content); + $result = @apply_filters($name, $result); + } + elseif ( $action == 'get' ) { + $result = $instance->get($id); + + if ( $type == 'rich' ) + $result = wpautop($result); + } + + die($result); + } +} + +/* +Registers a new editable field + +@param string $filter +@param array $args( + 'class' => string The name of the field handler class (mandatory) + 'title' => string The user-friendly title (optional) + 'type' => string: 'input' | 'textarea' | 'rich' | 'image' (default: input) + 'priority' => integer (default: 11) + 'argc' => integer (default: 1) +) +*/ +function register_fronted_field() { + return FEE_Core::register(func_get_args()); +} + diff --git a/blog/wp-content/plugins/front-end-editor/editor/editor.css b/blog/wp-content/plugins/front-end-editor/editor/editor.css new file mode 100644 index 0000000..780d3de --- /dev/null +++ b/blog/wp-content/plugins/front-end-editor/editor/editor.css @@ -0,0 +1 @@ +.fee-field,.fee-form{margin:0!important;padding:0!important;border-width:0!important;}div.fee-form,textarea.fee-form-content{clear:both!important;width:100%!important;}.fee-form-spinner{border:0!important;width:16px!important;height:16px!important;}div.fee-form button{margin-top:5px;}span.fee-form input{margin-right:5px;}.fee-form button+button{margin-left:5px;}.fee-form button{text-decoration:none!important;line-height:14px!important;font-size:11px!important;vertical-align:middle!important;padding:2px 8px!important;cursor:pointer!important;-moz-border-radius:11px;-khtml-border-radius:11px;-webkit-border-radius:11px;border-radius:11px;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;-khtml-box-sizing:content-box;box-sizing:content-box;}button.fee-form-save{background-color:#23779f;color:#fff;border:1px solid #1c5e7f;font-weight:bold;}.fee-form-save:hover{border:1px solid #000!important;}button.fee-form-cancel{background-color:#fcfcfc;color:#808080;border:1px solid #ddd;}.fee-form-cancel:hover{border:1px solid #666!important;}.nicEdit-selected:focus{outline:none;}.fee-suggest-results{padding:0;margin:0;list-style:none;position:absolute;display:none;z-index:10000;border-width:1px;border-style:solid;}.fee-suggest-results li{padding:2px 5px;white-space:nowrap;text-align:left;}.fee-suggest-match{text-decoration:underline;}.fee-suggest-over{cursor:pointer;}.fee-suggest-results{background-color:#fff;border-color:#808080;}.fee-suggest-results li{color:#101010;}.fee-suggest-match{color:#000;}.fee-suggest-over{background-color:#f0f0b8;}#TB_window #TB_title{background-color:#222;color:#CFCFCF;height:27px;}#fee-img-revert{display:block;float:left;padding:6px 10px 0;}#fee-img-revert:link,#fee-img-revert:active,#fee-img-revert:visited{color:#21759B!important;}#fee-img-revert:hover{color:#D54E21!important;} \ No newline at end of file diff --git a/blog/wp-content/plugins/front-end-editor/editor/editor.dev.css b/blog/wp-content/plugins/front-end-editor/editor/editor.dev.css new file mode 100644 index 0000000..1cc9024 --- /dev/null +++ b/blog/wp-content/plugins/front-end-editor/editor/editor.dev.css @@ -0,0 +1,104 @@ +/* Main */ +.fee-field, .fee-form { + margin: 0 !important; + padding: 0 !important; + border-width: 0 !important; +} +div.fee-form, textarea.fee-form-content { + clear: both !important; + width: 100% !important; +} +.fee-form-spinner { + border: 0 !important; + width: 16px !important; + height: 16px !important; +} + +/* Buttons */ +div.fee-form button {margin-top: 5px} +span.fee-form input {margin-right: 5px} +.fee-form button + button {margin-left: 5px} + +.fee-form button { + text-decoration: none !important; + line-height: 14px !important; + font-size: 11px !important; + vertical-align: middle !important; + padding: 2px 8px !important; + cursor: pointer !important; + -moz-border-radius: 11px; + -khtml-border-radius: 11px; + -webkit-border-radius: 11px; + border-radius: 11px; + -moz-box-sizing: content-box; + -webkit-box-sizing: content-box; + -khtml-box-sizing: content-box; + box-sizing: content-box; +} + +button.fee-form-save { + background-color: #23779f; + color: #fff; + border: 1px solid #1c5e7f; + font-weight: bold; +} + +.fee-form-save:hover { + border: 1px solid #000 !important; +} + +button.fee-form-cancel { + background-color: #fcfcfc; + color: #808080; + border: 1px solid #ddd; +} + +.fee-form-cancel:hover { + border: 1px solid #666 !important; +} + +/* Rich Editor */ +.nicEdit-selected:focus { + outline: none; +} + +/* Suggest */ +.fee-suggest-results { + padding: 0; + margin: 0; + list-style: none; + position: absolute; + display: none; + z-index: 10000; + border-width: 1px; + border-style: solid; +} +.fee-suggest-results li {padding: 2px 5px; white-space: nowrap; text-align: left} +.fee-suggest-match {text-decoration: underline} +.fee-suggest-over {cursor: pointer} + +/* Suggest colors */ +.fee-suggest-results {background-color: #fff; border-color: #808080} +.fee-suggest-results li {color: #101010} +.fee-suggest-match {color: #000} +.fee-suggest-over {background-color: #f0f0b8} + +/* Image */ +#TB_window #TB_title { + background-color: #222; + color: #CFCFCF; + height: 27px; +} + +#fee-img-revert { + display: block; + float: left; + padding: 6px 10px 0; +} +#fee-img-revert:link, #fee-img-revert:active, #fee-img-revert:visited { + color: #21759B !important; +} +#fee-img-revert:hover { + color: #D54E21 !important; +} + diff --git a/blog/wp-content/plugins/front-end-editor/editor/editor.dev.js b/blog/wp-content/plugins/front-end-editor/editor/editor.dev.js new file mode 100644 index 0000000..8778e32 --- /dev/null +++ b/blog/wp-content/plugins/front-end-editor/editor/editor.dev.js @@ -0,0 +1,669 @@ +(function($){ + + if ( FrontEndEditor._loaded ) + return; + FrontEndEditor._loaded = true; + + // http://ejohn.org/blog/simple-javascript-inheritance/ + // Inspired by base2 and Prototype + (function(){ + var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; + + // The base Class implementation (does nothing) + this.Class = function(){}; + + // Create a new Class that inherits from this class + Class.extend = function(prop) { + var _super = this.prototype; + + // Instantiate a base class (but only create the instance, + // don't run the init constructor) + initializing = true; + var prototype = new this(); + initializing = false; + + // Copy the properties over onto the new prototype + for (var name in prop) { + // Check if we're overwriting an existing function + prototype[name] = ( typeof prop[name] == "function" && + typeof _super[name] == "function" && fnTest.test(prop[name]) ) ? + (function(name, fn){ + return function() { + var tmp = this._super; + + // Add a new ._super() method that is the same method + // but on the super-class + this._super = _super[name]; + + // The method only need to be bound temporarily, so we + // remove it when we're done executing + var ret = fn.apply(this, arguments); + this._super = tmp; + + return ret; + }; + })(name, prop[name]) : + prop[name]; + } + + // The dummy class constructor + function Class() { + // All construction is actually done in the init method + if ( !initializing && this.init ) + this.init.apply(this, arguments); + } + + // Populate our constructed prototype object + Class.prototype = prototype; + + // Enforce the constructor to be what we expect + Class.constructor = Class; + + // And make this class extendable + Class.extend = arguments.callee; + + return Class; + }; + })(); + + +// _____Actual code starts here_____ + + + var spinner = $('').attr({ + 'src': FrontEndEditor.data.spinner, + 'class': 'front-editor-spinner' + }); + + var is_overlay = function($el) { + var attr = [$el.attr('id'), $el.attr("class"), $el.attr("rel")]; + + var tokens = ['lightbox', 'thickbox', 'shutter', 'awppost_link']; + + for ( var i in tokens ) + for ( var j in attr ) + if ( attr[j].indexOf(tokens[i]) != -1 ) + return true; + + return false; + }; + + var resume = function() { + if ( FrontEndEditor._trap ) + return; + + var $link = FrontEndEditor._to_click; + + if ( typeof $link == 'undefined' ) + return; + +/* + var ev_reference; + var ev_capture = function(ev) { ev_reference = ev; } + + var onClick = $link.attr('onclick'); + + $link.bind('click', ev_capture); + + if ( typeof onClick == 'function' ) + $link.bind('click', onClick); + + $link.click(); + + $link.unbind('click', ev_capture); + + if ( typeof onClick == 'function' ) + $link.unbind('click', onClick); + + if ( ev_reference.isDefaultPrevented() ) + return; +*/ + + if ( typeof $link.attr('href') != 'undefined' && $link.attr('href') != '#' ) { + if ( $link.attr('target') == '_blank' ) + window.open($link.attr('href')); + else + window.location.href = $link.attr('href'); + } + + delete FrontEndEditor._to_click; + }; + + var fieldTypes = {}; + + fieldTypes['base'] = Class.extend({ + + init: function($el, type, name, id) { + var self = this; + + self.set_el($el); + self.type = type; + self.name = name; + self.id = id; + + self.bind(self.el, 'click', self.click); + self.bind(self.el, 'dblclick', self.dblclick); + }, + + set_el: function($el) { + var self = this; + + self.el = $el; + + // From a > .front-ed > content + // To .front-ed > a > content + var $parent = self.el.parents('a'); + + if ( ! $parent.length ) + return; + + var $link = $parent.clone(true) + .html(self.el.html()); + + var $wrap = self.el.clone(true) + .html($link); + + $parent.replaceWith($wrap); + + self.el = $wrap; + self.switched = true; + }, + + click: function(ev) { +// if ( typeof FrontEndEditor._to_click != 'undefined' ) +// return; + + var $el = $(ev.target).closest('a'); + + if ( ! $el.length ) + return; + + if ( is_overlay($el) ) + return; + + ev.stopImmediatePropagation(); + ev.preventDefault(); + + FrontEndEditor._to_click = $el; + + setTimeout(resume, 300); + }, + + dblclick: function(ev) { + var self = this; + + ev.stopPropagation(); + ev.preventDefault(); + + FrontEndEditor._trap = true; + }, + + get_content: null /* function() */, + set_content: null /* function(content) */, + + ajax_get_handler: null /* function(content) */, + ajax_set_handler: null /* function(content) */, + + ajax_get: function() { + var self = this; + + var data = { + 'nonce': FrontEndEditor.data.nonce, + 'action': 'front-editor', + 'callback': 'get', + 'name': self.name, + 'type': self.type, + 'item_id': self.id + }; + + $.post(FrontEndEditor.data.ajax_url, data, function(response){ + self.ajax_get_handler(response); + }); + }, + + ajax_set: function(content) { + var self = this; + + content = content || self.get_content(); + + var data = { + 'nonce': FrontEndEditor.data.nonce, + 'action': 'front-editor', + 'callback': 'save', + 'name': self.name, + 'type': self.type, + 'item_id': self.id, + 'content': content + }; + + $.post(FrontEndEditor.data.ajax_url, data, function(response){ + self.ajax_set_handler(response); + }); + }, + + // Event utility: this = self + bind: function(element, event, callback) { + var self = this; + + element.bind(event, function(ev) { + callback.call(self, ev); + }); + } + }); + + fieldTypes['image'] = fieldTypes['base'].extend({ + + dblclick: function(ev) { + var self = this; + + self._super(ev); + + self.open_box(); + }, + + open_box: function() { + var self = this; + + tb_show(FrontEndEditor.data.image.change, FrontEndEditor.data.admin_url + + '/media-upload.php?post_id=0&type=image&TB_iframe=true&width=640&editable_image=1'); + + var $revert = $('').text(FrontEndEditor.data.image.revert); + + $revert.click(function(ev){ + self.ajax_set(-1); + }); + + $('#TB_ajaxWindowTitle').after($revert); + $('#TB_closeWindowButton img').attr('src', FrontEndEditor.data.image.tb_close); + + self.bind($('#TB_iframeContent'), 'load', self.replace_button); + }, + + replace_button: function(ev) { + var self = this; + + var $frame = $(ev.target).contents(); + + $('.media-item', $frame).livequery(function(){ + var $item = $(this); + var $button = $('').text(FrontEndEditor.data.image.change); + + $button.click(function(ev){ + self.ajax_set(self.get_content($item)); + }); + + $(this).find(':submit, #go_button').replaceWith($button); + }); + }, + + get_content: function($item) { + var $field; + + // Media library + $field = $item.find('.urlfile'); + if ( $field.length ) + return $field.attr('title'); + + // From URL (embed) + $field = $item.find('#embed-src'); + if ( $field.length ) + return $field.val(); + + // From URL + $field = $item.find('#src'); + if ( $field.length ) + return $field.val(); + + return false; + }, + + ajax_set_handler: function(url) { + var self = this; + + if ( url == -1 ) { + window.location.reload(true); + } else { + self.el.find('img').attr('src', url); + tb_remove(); + } + } + }); + + fieldTypes['thumbnail'] = fieldTypes['image'].extend({ + + replace_button: function(ev) { + var self = this; + + var $frame = $(ev.target).contents(); + + $frame.find('#tab-type_url').remove(); + + self._super(ev); + }, + + get_content: function($item) { + return $item.attr('id').replace('media-item-', ''); + } + }); + + fieldTypes['input'] = fieldTypes['base'].extend({ + + init: function($el, type, name, id) { + var self = this; + + self.spinner = spinner.clone(); + + self._super($el, type, name, id); + }, + + input_tag: '', + + create_input: function() { + var self = this; + + self.input = $(self.input_tag); + + self.input.attr({ + 'id': 'edit_' + self.el.attr('id'), + 'class': 'fee-form-content' + }).prependTo(self.form); + }, + + set_input: function(content) { + var self = this; + + self.input.val(content); + }, + + get_content: function() { + var self = this; + return self.input.val(); + }, + + set_content: function(content) { + var self = this; + + if ( self.switched ) + self.el.find('a').html(content); + else + self.el.html(content); + }, + + ajax_get: function() { + var self = this; + + self.el.hide().after(self.spinner.show()); + + self.create_input(); + + self._super(); + }, + + ajax_set: function() { + var self = this; + + self.el.before(self.spinner.show()); + + self._super(); + }, + + ajax_get_handler: function(content) { + var self = this; + + self.spinner.hide().replaceWith(self.form); + + self.set_input(content); + + self.input.focus(); + }, + + ajax_set_handler: function(content) { + var self = this; + + self.set_content(content); + + self.spinner.hide(); + self.el.show(); + }, + + dblclick: function(ev) { + var self = this; + + self._super(ev); + + self.form_handler(); + }, + + form_handler: function() { + var self = this; + + // Button actions + var form_remove = function(with_spinner) { + FrontEndEditor._trap = false; + + self.form.remove(); + + if ( with_spinner === true ) + self.el.before(self.spinner.show()); + else + self.el.show(); + + self.el.trigger('fee_remove_form'); + }; + + var form_submit = function() { + self.ajax_set(); + form_remove(true); + }; + + // Button markup + self.save_button = $('