Changeset 709089
- Timestamp:
- 05/07/2013 07:26:27 AM (13 years ago)
- Location:
- cross-network-posts/trunk
- Files:
-
- 1 added
- 3 deleted
- 3 edited
-
cnp-ajax.js (modified) (2 diffs)
-
cnp-get-blogs.php (deleted)
-
cnp-includes.php (modified) (1 diff)
-
cnp.php (modified) (6 diffs)
-
cnp_ajax_processor.php (deleted)
-
cnp_build_shortcut.php (deleted)
-
options.php (added)
Legend:
- Unmodified
- Added
- Removed
-
cross-network-posts/trunk/cnp-ajax.js
r707623 r709089 9 9 $('.cnp-posts').hide(); 10 10 } 11 }); 12 13 $('.cnp-use-schortcode').on('click', function(){ 14 var content = $('.cnp-shortcode').text(); 15 console.log(content); 16 if($('textarea.wp-editor-area').css('display') == 'none'){ 17 tinyMCE.execCommand('mceInsertContent',false,'\r\n' + content); 18 } else { 19 $('textarea.wp-editor-area').append('\r\n' + content); 20 } 21 window.parent.tb_remove() 11 22 }); 12 23 … … 29 40 30 41 $.ajax({ 42 response: 'ajax-response', 31 43 type: "POST", 32 44 url: ajaxurl, 33 data: { type: _type, blogid: _blogid, postid: _postid, catid: _catid, excerpt: _excerpt, titlelink: _titlelink, numberofposts: _numberofposts, header: _header } 34 }).done(function(data){ 35 $('.cnp-shortcode').text(data); 45 data: {action: 'getshortcode', type: _type, blogid: _blogid, postid: _postid, catid: _catid, excerpt: _excerpt, titlelink: _titlelink, numberofposts: _numberofposts, header: _header } 46 }).done(function(r){ 47 var res = wpAjax.parseAjaxResponse(r,this.response); 48 var shortcode = ''; 49 $.each(res.responses, function() { 50 if(this.what == 'cnp_get_shortcode'){ 51 shortcode += this.data; 52 } 53 if(this.errors){ 54 shortcode = "Something went wrong"; 55 } 56 }); 57 $('.cnp-shortcode').text(shortcode); 36 58 }); 37 59 }); -
cross-network-posts/trunk/cnp-includes.php
r707623 r709089 5 5 //set constructor and execute enqueing 6 6 function __construct(){ 7 add_action('wp_ajax_cnp_getshortcode', 'cnp_get_shortcode'); 8 } 9 10 function cnp_get_shortcode(){ 11 if(isset($_POST['type'])){ 12 $type = $_POST['type']; 13 }else{ 14 die("No type"); 15 } 16 17 if(isset($_POST['blogid'])){ 18 $blogid = $_POST['blogid']; 19 }else{ 20 die("No blog ID"); 21 } 22 23 24 $shortcode = "[cnp blogid=".$blogid; 25 if($type=='post'){ 26 if(isset($_POST['postid'])){ 27 $post_ID = $_POST['postid']; 28 $shortcode .= ", postid=".$post_ID; 29 }else{ 30 die("Content empty"); 31 } 32 } 33 if($type=='category'){ 34 if(isset($_POST['catid'])){ 35 $cat_ID = $_POST['catid']; 36 $shortcode .= ", catid=".$cat_ID; 37 }else{ 38 die("Content empty"); 39 } 40 } 41 42 if(isset($_POST['excerpt'])){ 43 $shortcode .= ", excerpt=".$_POST['excerpt']; 44 } 45 46 if(isset($_POST['header']) && $_POST['header'] != ""){ 47 $shortcode .= ", header=".$_POST['header']; 48 } 49 50 if(isset($_POST['numberofposts']) && $_POST['numberofposts'] != ""){ 51 $shortcode .= ", numberofposts=".$_POST['numberofposts']; 52 } 53 54 if(isset($_POST['titlelink'])){ 55 $shortcode .= ", titlelink=".$_POST['titlelink']; 56 } 57 58 $shortcode .= "]"; 59 return $shortcode; 7 60 } 8 61 -
cross-network-posts/trunk/cnp.php
r707623 r709089 2 2 /* 3 3 Plugin Name: Cross-network posts 4 Plugin URI: http://wordpress.org/extend/plugins/c np/4 Plugin URI: http://wordpress.org/extend/plugins/cross-network-posts/ 5 5 Description: Gets a post or category that is within another website on the same Wordpress network. Use as shortcode: [cnp blogid=1 postid=1]. More info on attributes on plugin page. 6 6 Version: 1.02 … … 10 10 if ( ! is_multisite() ) 11 11 wp_die( __( 'Multisite support is not enabled.' ) ); 12 13 //http://wakeusup.com/2011/11/how-to-create-plugin-options-page-in-wordpress/ 14 if(!class_exists('cnp_plugin_options')): 15 // DEFINE PLUGIN ID 16 define('CNPPLUGINOPTIONS_ID', 'cnppluginoptions'); 17 // DEFINE PLUGIN NICK 18 define('CNPPLUGINOPTIONS_NICK', 'CNP options'); 19 20 class cnp_plugin_options 21 { 22 /** function/method 23 * Usage: hooking the plugin options/settings 24 * Arg(0): null 25 * Return: void 26 */ 27 public static function register() 28 { 29 register_setting(CNPPLUGINOPTIONS_ID.'_options', 'cnp_builder'); 30 register_setting(CNPPLUGINOPTIONS_ID.'_options', 'cnp_author_restriction'); 31 register_setting(CNPPLUGINOPTIONS_ID.'_options', 'cnp_plugin_link'); 32 } 33 /** function/method 34 * Usage: hooking (registering) the plugin menu 35 * Arg(0): null 36 * Return: void 37 */ 38 public static function menu() 39 { 40 // Create menu tab 41 add_options_page(CNPPLUGINOPTIONS_NICK.' Plugin Options', CNPPLUGINOPTIONS_NICK, 'manage_options', CNPPLUGINOPTIONS_ID.'_options', array('cnp_plugin_options', 'options_page')); 42 } 43 /** function/method 44 * Usage: show options/settings form page 45 * Arg(0): null 46 * Return: void 47 */ 48 public static function options_page() 49 { 50 if (!current_user_can('manage_options')) 51 { 52 wp_die( __('You do not have sufficient permissions to access this page.') ); 53 } 54 55 $plugin_id = CNPPLUGINOPTIONS_ID; 56 // display options page 57 include(plugin_dir_path(__FILE__).'/options.php'); 58 } 59 /** function/method 60 * Usage: filtering the content 61 * Arg(1): string 62 * Return: string 63 */ 64 public static function cnp_show_builder() 65 { 66 if(get_option('cnp_builder')){ 67 return false; 68 }else{ 69 return true; 70 } 71 } 72 public static function cnp_author_restriction(){ 73 if(get_option('cnp_author_restriction')){ 74 return true; 75 }else{ 76 return false; 77 } 78 } 79 public static function cnp_plugin_link(){ 80 if(get_option('cnp_plugin_link')){ 81 return true; 82 }else{ 83 return false; 84 } 85 } 86 } 87 if(is_admin()){ 88 add_action('admin_init', array('cnp_plugin_options', 'register')); 89 add_action('admin_menu', array('cnp_plugin_options', 'menu')); 90 } 91 endif; 12 92 13 93 include(plugin_dir_path(__FILE__).'/cnp-includes.php'); … … 15 95 //enqueue javascript 16 96 add_action( 'admin_enqueue_scripts', 'cnp_enqueue' ); 17 function localize_vars() { 97 98 /*function localize_vars() { 18 99 return array( 19 100 'SiteUrl' => get_bloginfo('url'), 20 ' AjaxUrl' => admin_url('admin-ajax.php')101 'MyAjax' => plugin_dir_url( __FILE__ ) . 'cnp_ajax_processor.php' 21 102 ); 22 } 103 }*/ 23 104 function cnp_enqueue($hook) { 24 105 wp_enqueue_script('cnp_ajax', plugins_url('cnp-ajax.js', __FILE__), array('jquery'), '1.0.0'); 25 wp_localize_script( 'cnp_ajax', 'cnp_build_shortcut', localize_vars()); 26 } 27 106 wp_localize_script( 'cnp_ajax', 'cnp_build_shortcut',''); 107 } 108 109 //add ajax call back 110 add_action('wp_ajax_getshortcode', 'ajax_get_shortcode'); 111 112 function ajax_get_shortcode(){ 113 function cnp_get_shortcode(){ 114 if(isset($_POST['type'])){ 115 $type = $_POST['type']; 116 }else{ 117 die("No type"); 118 } 119 120 if(isset($_POST['blogid'])){ 121 $blogid = $_POST['blogid']; 122 }else{ 123 die("No blog ID"); 124 } 125 126 127 $shortcode = "[cnp blogid=".$blogid; 128 if($type=='post'){ 129 if(isset($_POST['postid'])){ 130 $post_ID = $_POST['postid']; 131 $shortcode .= ", postid=".$post_ID; 132 }else{ 133 die("Content empty"); 134 } 135 } 136 if($type=='category'){ 137 if(isset($_POST['catid'])){ 138 $cat_ID = $_POST['catid']; 139 $shortcode .= ", catid=".$cat_ID; 140 }else{ 141 die("Content empty"); 142 } 143 } 144 145 if(isset($_POST['excerpt'])){ 146 $shortcode .= ", excerpt=".$_POST['excerpt']; 147 } 148 149 if(isset($_POST['header']) && $_POST['header'] != ""){ 150 $shortcode .= ", header=".$_POST['header']; 151 } 152 153 if(isset($_POST['numberofposts']) && $_POST['numberofposts'] != ""){ 154 $shortcode .= ", numberofposts=".$_POST['numberofposts']; 155 } 156 157 if(isset($_POST['titlelink'])){ 158 $shortcode .= ", titlelink=".$_POST['titlelink']; 159 } 160 161 $shortcode .= "]"; 162 return $shortcode; 163 } 164 165 $response = array( 166 'what' => 'cnp_get_shortcode', 167 'data' => cnp_get_shortcode() 168 ); 169 170 $xmlResponse = new WP_Ajax_Response($response); 171 $xmlResponse->send(); 172 } 28 173 29 174 //do something with the shortcode … … 116 261 ob_end_clean(); 117 262 263 //show some credits 264 $credit = ""; 265 if(cnp_plugin_options::cnp_plugin_link()){ 266 $credit = "<!--<a href='http://wordpress.org/extend/plugins/cross-network-posts/' title='Thanks to CNP: Cross Network Posts plugin for Wordpress'>Thanks to CNP: Cross Network Posts plugin for Wordpress</a>-->"; 267 } 268 269 $output_string .= $credit; 270 118 271 //return output 119 272 return $output_string; … … 129 282 //credits for this piece of code go to http://themergency.com/adding-custom-buttons-to-the-wordpress-content-editor-part-1/ 130 283 //add a button to the content editor, next to the media button 131 //this button will show a popup that contains inline content 132 add_action('media_buttons_context', 'add_my_custom_button'); 133 134 //add some content to the bottom of the page 135 //This will be shown in the inline modal 136 add_action('admin_footer', 'add_cnp_inline_popup_content'); 284 if(cnp_plugin_options::cnp_show_builder()){ 285 //this button will show a popup that contains inline content 286 add_action('media_buttons_context', 'add_my_custom_button'); 287 //add some content to the bottom of the page 288 //This will be shown in the inline modal 289 add_action('admin_footer', 'add_cnp_inline_popup_content'); 290 } 137 291 138 292 //action to add a custom button to the content editor … … 217 371 <h3>The shortcode is:</h3> 218 372 <div class="cnp-shortcode"></div> 373 <input type="button" value="Place shortcode" class="cnp-use-schortcode"/> 219 374 </fieldset> 220 375 </form>
Note: See TracChangeset
for help on using the changeset viewer.