Changeset 1017974
- Timestamp:
- 11/01/2014 05:42:03 PM (11 years ago)
- Location:
- wpcreo
- Files:
-
- 7 added
- 3 edited
-
tags/1.1 (added)
-
tags/1.1/WPCREO.php (added)
-
tags/1.1/assets (added)
-
tags/1.1/assets/icon-128x128.png (added)
-
tags/1.1/assets/icon-256x256.png (added)
-
tags/1.1/options.php (added)
-
tags/1.1/readme.txt (added)
-
trunk/WPCREO.php (modified) (1 diff)
-
trunk/options.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wpcreo/trunk/WPCREO.php
r1007256 r1017974 1 1 <?php 2 /* 3 Plugin Name: WPCREO 4 Version: 1.0 5 Author: WPCREO 6 Author URI: http://www.wpcreo.com 7 Description: Transform your WordPress into an iOS, Android and Windows apps without writing a single line of code. 8 9 Network: True 10 11 License: GPLv2 or later 12 13 Copyright (C) 2014 WPCREO 14 */ 15 16 class WPCREOBroadcast { 17 18 // Register actions and filters on class instanation 19 function __construct() { 2 /* 3 Plugin Name: WPCREO 4 Version: 1.1 5 Author: WPCREO 6 Author URI: http://www.wpcreo.com 7 Description: Transform your WordPress into an iOS, Android and Windows apps without writing a single line of code. 8 9 Network: True 10 11 License: GPLv2 or later 12 13 Copyright (C) 2014 WPCREO 14 */ 15 16 class WPCREOBroadcast { 17 18 // Register actions and filters on class instanation 19 function __construct() { 20 21 // DEFINE PLUGIN ID 22 define('WPCREOPLUGINOPTIONS_ID', 'WPCREO-plugin'); 20 23 21 // DEFINE PLUGIN ID22 define('WPCREOPLUGINOPTIONS_ID', 'WPCREO-plugin');23 24 24 // DEFINE PLUGIN NICK 25 define('WPCREOPLUGINOPTIONS_NICK', 'WPCREO');26 25 define('WPCREOPLUGINOPTIONS_NICK', 'WPCREO'); 26 27 27 /** Plugin Directory URL **/ 28 28 define( 'LCIBF_PLUGIN_URL', plugin_dir_path( __FILE__ ) ); 29 30 // Add metabox action 31 //add_action( 'add_meta_boxes', array( &$this, 'register_metabox' ) ); 32 33 // Add save post action 34 add_action( 'publish_post', array( &$this, 'WPCREOBroadcast_post' ) ); 35 36 37 if ( is_admin() ) 38 { 39 add_action('admin_init', array(&$this, 'register')); 40 add_action('admin_menu', array(&$this, 'menu')); 41 } 42 29 30 // Add metabox action 31 //add_action( 'add_meta_boxes', array( &$this, 'register_metabox' ) ); 32 33 // Add save post action 34 add_action( 'publish_post', array( &$this, 'WPCREOBroadcast_post' ) ); 35 36 37 if ( is_admin() ) 38 { 39 add_action('admin_init', array(&$this, 'register')); 40 add_action('admin_menu', array(&$this, 'menu')); 41 42 add_action( 'wp_ajax_syncAllPost', array( &$this, 'syncAllPost') ); 43 } 44 43 45 //add_filter('the_content', array( &$this, 'content_with_quote')); 44 }45 46 // WPCREOBroadcast the post47 function WPCREOBroadcast_post( $post_id )48 { 49 $url = get_option('magazineUrl');50 51 error_log("WPCREOBroadcast_post URL: " . $url);52 53 // Check that I am only WPCREOBroadcasting once54 if ( $url != '' /*&& did_action( 'save_post' ) == 1 */) {55 56 // Retrieve the post57 $post = get_post( $post_id, 'ARRAY_A' );58 46 } 47 48 // WPCREOBroadcast the post 49 public function WPCREOBroadcast_post( $post_id ) 50 { 51 $url = get_option('magazineUrl'); 52 53 error_log("WPCREOBroadcast_post URL: " . $url); 54 55 // Check that I am only WPCREOBroadcasting once 56 if ( $url != '' /*&& did_action( 'save_post' ) == 1 */) { 57 58 // Retrieve the post 59 $post = get_post( $post_id, 'ARRAY_A' ); 60 59 61 if( ( $post['post_status'] == 'publish' ) && ( $post['post_type'] == 'post' ) ) { 60 //error_log("WPCREOBroadcast_post STEP 2");61 62 // List of data to keep in WPCREOBroadcasted posts63 $post_data = array(62 //error_log("WPCREOBroadcast_post STEP 2"); 63 64 // List of data to keep in WPCREOBroadcasted posts 65 $post_data = array( 64 66 'ID', 65 'post_author',66 'post_date',67 'post_date_gmt',68 'post_content',69 'post_title',70 'post_excerpt',71 'post_status',72 'comment_status',73 'ping_status',74 'post_password',75 'post_name',76 'post_modified',77 'post_modified_gmt',78 'post_type'79 );80 81 // Create a new post array82 foreach ( $post_data as $key )83 $new_post[$key] = $post[$key];84 85 $new_post['post_linkurl'] = get_permalink($post_id);86 87 if (has_post_thumbnail( $post_id )){88 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'single-post-thumbnail' );89 $new_post['post_image'] = $image[0];90 }91 67 'post_author', 68 'post_date', 69 'post_date_gmt', 70 'post_content', 71 'post_title', 72 'post_excerpt', 73 'post_status', 74 'comment_status', 75 'ping_status', 76 'post_password', 77 'post_name', 78 'post_modified', 79 'post_modified_gmt', 80 'post_type' 81 ); 82 83 // Create a new post array 84 foreach ( $post_data as $key ) 85 $new_post[$key] = $post[$key]; 86 87 $new_post['post_linkurl'] = get_permalink($post_id); 88 89 if (has_post_thumbnail( $post_id )){ 90 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'single-post-thumbnail' ); 91 $new_post['post_image'] = $image[0]; 92 } 93 92 94 $categories = get_the_category($post_id); 93 95 if($categories){ 94 96 $new_post['post_categories'] = json_encode($categories); 95 97 } 96 98 97 99 $new_post['site_language'] = get_bloginfo('language'); 98 99 error_log("WPCREOBroadcast_post Before Post"); 100 101 $response = wp_remote_post( $url, array( 102 'method' => 'POST', 103 'timeout' => 45, 104 'redirection' => 5, 105 'httpversion' => '1.0', 106 'blocking' => true, 107 'headers' => array(), 108 'body' => $new_post, 109 'cookies' => array() 110 ) 111 ); 112 113 if ( is_wp_error( $response ) ) { 114 $error_message = $response->get_error_message(); 115 error_log("WPCREOBroadcast_post After Post error: " . $error_message); 116 117 } else { 118 error_log("WPCREOBroadcast_post After Post : " . $response ); 119 } 120 } 121 } 122 } 123 124 // Register metabox 125 function register_metabox() { 126 if ( $_REQUEST['action'] != 'edit' ) 127 add_meta_box( 'WPCREOBroadcast', 'WPCREOBroadcast', array( &$this, 'output_metabox' ), 'post', 'side', 'default', null ); 128 } 129 130 // Output metabox HTML 131 function output_metabox() { 132 $blogs = $this->get_blogs_of_user( get_current_user_id(), 'publish_posts' ); 133 ?> 134 <small>Post to:</small> 135 <?php if ( ! empty( $blogs ) ): ?> 136 <ul> 137 <?php foreach ( $blogs as $blog ): ?> 138 <li> 139 <input type="checkbox" <?php checked( $blog->userblog_id, get_current_blog_id() ) ?> <?php disabled( $blog->userblog_id, get_current_blog_id() ) ?> name="blogs[<?php echo $blog->userblog_id ?>]" id="blog_<?php echo $blog->userblog_id ?>" /> 140 <label for="blog_<?php echo $blog->userblog_id ?>"><?php echo $blog->blogname ?></label> 141 </li> 142 <?php endforeach ?> 143 </ul> 144 <?php else: ?> 145 <p>There are no other blogs.</p> 146 <?php endif ?> 147 <?php 148 } 149 150 151 /** function/method 152 * Usage: hooking the plugin options/settings 153 * Arg(0): null 154 * Return: void 155 */ 156 public function register() 157 { 158 register_setting(WPCREOPLUGINOPTIONS_ID.'_options', 'magazineUrl'); 159 } 160 161 /** function/method 162 * Usage: hooking (registering) the plugin menu 163 * Arg(0): null 164 * Return: void 165 */ 166 public function menu() 167 { 168 // Create menu tab 169 add_options_page(WPCREOPLUGINOPTIONS_NICK.' Plugin Options', WPCREOPLUGINOPTIONS_NICK, 'manage_options', WPCREOPLUGINOPTIONS_ID.'_options', array( &$this, 'options_page')); 170 } 171 /** function/method 172 * Usage: show options/settings form page 173 * Arg(0): null 174 * Return: void 175 */ 176 public function options_page() 177 { 178 if (!current_user_can('manage_options')) 179 { 180 wp_die( __('You do not have sufficient permissions to access this page.') ); 181 } 182 183 $plugin_id = WPCREOPLUGINOPTIONS_ID; 184 // display options page 100 101 error_log("WPCREOBroadcast_post Before Post"); 102 103 $response = wp_remote_post( $url, array( 104 'method' => 'POST', 105 'timeout' => 45, 106 'redirection' => 5, 107 'httpversion' => '1.0', 108 'blocking' => true, 109 'headers' => array(), 110 'body' => $new_post, 111 'cookies' => array() 112 ) 113 ); 114 115 if ( is_wp_error( $response ) ) { 116 $error_message = $response->get_error_message(); 117 error_log("WPCREOBroadcast_post After Post error: " . $error_message); 118 119 } 120 //else { 121 // error_log("WPCREOBroadcast_post After Post : " . $response ); 122 //} 123 } 124 } 125 } 126 127 128 /** function/method 129 * Usage: hooking the plugin options/settings 130 * Arg(0): null 131 * Return: void 132 */ 133 public function register() 134 { 135 register_setting(WPCREOPLUGINOPTIONS_ID.'_options', 'magazineUrl'); 136 } 137 138 function validate_setting($input) { 139 //wp_die('ssss'); 140 //wp_die( __('You do not have sufficient permissions to access this page.' . $input['hSyncMode'] ) ); 141 } 142 143 /** function/method 144 * Usage: hooking (registering) the plugin menu 145 * Arg(0): null 146 * Return: void 147 */ 148 public function menu() 149 { 150 // Create menu tab 151 add_options_page(WPCREOPLUGINOPTIONS_NICK.' Plugin Options', WPCREOPLUGINOPTIONS_NICK, 'manage_options', WPCREOPLUGINOPTIONS_ID.'_options', array( &$this, 'options_page')); 152 } 153 /** function/method 154 * Usage: show options/settings form page 155 * Arg(0): null 156 * Return: void 157 */ 158 public function options_page() 159 { 160 if (!current_user_can('manage_options')) 161 { 162 wp_die( __('You do not have sufficient permissions to access this page.') ); 163 } 164 165 $plugin_id = WPCREOPLUGINOPTIONS_ID; 166 // display options page 185 167 include( LCIBF_PLUGIN_URL . 'options.php' ); 186 168 //require_once( LCIBF_PLUGIN_URL . 'options.php' ); 187 } 188 /** function/method 189 * Usage: filtering the content 190 * Arg(1): string 191 * Return: string 192 */ 193 public function content_with_quote($content) 194 { 195 $quote = '<p><blockquote>' . get_option('magazineUrl') . '</blockquote></p>'; 196 return $content . $quote; 197 } 198 } 199 200 // Instanate WPCREOBroadcast class 201 $WPCREOBroadcast = new WPCREOBroadcast(); 169 } 170 /** function/method 171 * Usage: filtering the content 172 * Arg(1): string 173 * Return: string 174 */ 175 public function content_with_quote($content) 176 { 177 $quote = '<p><blockquote>' . get_option('magazineUrl') . '</blockquote></p>'; 178 return $content . $quote; 179 } 180 181 182 public function syncAllPost(){ 183 184 $args = array( 'numberposts' => -1); 185 $posts= get_posts( $args ); 186 if ($posts) { 187 188 try{ 189 foreach ( $posts as $p ) { 190 //echo $p->ID; 191 $this->WPCREOBroadcast_post($p->ID); 192 } 193 } catch (Exception $e) { 194 echo json_encode(array( 195 'error' => array( 196 'msg' => $e->getMessage(), 197 'code' => $e->getCode(), 198 ), 199 )); 200 } 201 } 202 203 echo "Done!"; 204 205 die(); // this is required to terminate immediately and return a proper response 206 } 207 } 208 209 // Instanate WPCREOBroadcast class 210 $WPCREOBroadcast = new WPCREOBroadcast(); 202 211 ?> -
wpcreo/trunk/options.php
r1007256 r1017974 1 1 <div class="wrap"> 2 2 3 <?php screen_icon(); ?>3 <?php screen_icon(); ?> 4 4 5 <form action="options.php" method="post" id="<?php echo $plugin_id; ?>_options_form" name="<?php echo $plugin_id; ?>_options_form">5 <form action="options.php" method="post" id="<?php echo $plugin_id; ?>_options_form" name="<?php echo $plugin_id; ?>_options_form"> 6 6 7 <?php settings_fields($plugin_id.'_options'); ?>7 <?php settings_fields($plugin_id.'_options'); ?> 8 8 9 <h2>WPCREO » Settings</h2>10 <table class="widefat">11 <tbody>12 <tr>13 <td style="padding:25px;font-family:Verdana, Geneva, sans-serif;color:#666;">14 <label for="magazineUrl">15 <p>Please enter your WPCREO Magazine Url </p>16 <p>17 <input type="text" name="magazineUrl" value="<?php echo get_option('magazineUrl'); ?>" style="width:100%" />18 </p>19 </label>20 </td>21 </tr>9 <h2>WPCREO » Settings</h2> 10 <table class="widefat"> 11 <tbody> 12 <tr> 13 <td style="padding:25px;font-family:Verdana, Geneva, sans-serif;color:#666;"> 14 <label for="magazineUrl"> 15 Please enter your WPCREO Magazine Url 16 </label> 17 <p> 18 <input type="text" id="magazineUrl" name="magazineUrl" value="<?php echo get_option('magazineUrl'); ?>" style="width:100%" /> 19 </p> 20 </td> 21 </tr> 22 22 </tbody> 23 <tfoot> 24 <tr> 25 <th> 26 <input type="submit" name="submit" value="Save Settings" class="button-primary" /> 27 </th> 28 </tr> 23 <tfoot> 24 <tr> 25 <th> 26 27 <input type="submit" name="submit" value="Save Settings" class="button-primary" onclick="return urlValidation();" /> 28 29 <input type="submit" name="sync" value="Sync All Articles" class="button-primary" onclick="setMode();return false;" style="float: right;" /> 30 </th> 31 </tr> 29 32 </tfoot> 30 </table> 33 </table> 34 35 </form> 36 <script type="text/javascript"> 37 function setMode() { 31 38 32 </form> 39 if (urlValidation()) { 40 41 var data = { 42 action: 'syncAllPost' 43 }; 44 jQuery.post(ajaxurl, data, function (response) { 45 alert('Got this from the server: ' + response); 46 }); 33 47 48 alert('We do it in background!'); 49 } 50 } 51 52 function urlValidation() { 53 var url = document.getElementById('magazineUrl').value.toLowerCase(); 54 var isValid = (url.indexOf('http://') == 0 && url.indexOf('full=1') > 0 && url.indexOf('/services/') > 0); 55 56 if (!isValid) 57 alert('Please enter a vlid WPCREO magazine service url!'); 58 59 return isValid; 60 } 61 </script> 34 62 </div> -
wpcreo/trunk/readme.txt
r1007256 r1017974 8 8 Requires at least: 3.4 9 9 Tested up to: 4.0 10 Stable tag: 1. 011 Version: 1. 010 Stable tag: 1.1 11 Version: 1.1 12 12 License: GPLv2 or later 13 13 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 37 37 == Changelog == 38 38 39 = 1.1 = 40 * Add Magazine Url validation. 41 * Add ability to sync all articles. 39 42 40 43 = 1.0 =
Note: See TracChangeset
for help on using the changeset viewer.