Changeset 1024190
- Timestamp:
- 11/11/2014 10:53:40 PM (11 years ago)
- Location:
- mg-webtrends-graphs/trunk
- Files:
-
- 3 edited
-
index.php (modified) (4 diffs)
-
js/mgtrends_plugin.js (modified) (1 diff)
-
readme.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
mg-webtrends-graphs/trunk/index.php
r1021050 r1024190 4 4 Plugin URI: http://www.mirkogrewing.it/mg-webtrends-graphs/ 5 5 Description: Embed a Google Trends graphic in your website in a handful of second thanks to the shortcode provided by this plugin and the shortcode builder integrated in the editor. 6 Version: 0.3.16 Version: 1.0 7 7 Author: Mirko Grewing 8 8 Author URI: http://www.mirkogrewing.it … … 13 13 */ 14 14 15 if (!defined('ABSPATH')) 16 die("Can't load this file directly");15 add_action('admin_head', 'mgtrends_add_my_tc_button'); 16 load_plugin_textdomain('mgtrends_tc_button', false, dirname(plugin_basename(__FILE__)) . '/languages/'); 17 17 18 class MGTrends 18 /** 19 * Main function to call the button 20 * 21 * @return null 22 */ 23 function mgtrends_add_my_tc_button() 19 24 { 20 /** 21 * Construct function 22 * 23 * @return null 24 */ 25 function __construct() 26 { 27 add_action('admin_init', array($this, 'action_admin_init')); 25 global $typenow; 26 // check user permissions 27 if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) { 28 return; 28 29 } 29 /** 30 * Add feature for the right user 31 * 32 * @return null 33 */ 34 function action_admin_init() 35 { 36 if (current_user_can('edit_posts') && current_user_can('edit_pages')) { 37 add_filter('mce_buttons', array($this, 'filter_mce_button')); 38 add_filter('mce_external_plugins', array($this, 'filter_mce_plugin')); 39 } 40 } 41 42 /** 43 * Add the button to the editor 44 * 45 * @return array 46 */ 47 function filter_mce_button($buttons) 48 { 49 array_push($buttons, '|', 'mgtrends_button'); 50 return $buttons; 51 } 52 53 /** 54 * Associate the JavaScript 55 * 56 * @return array 57 */ 58 function filter_mce_plugin($plugins) 59 { 60 $plugins['mgtrends'] = plugin_dir_url(__FILE__) . 'js/mgtrends_plugin.js'; 61 return $plugins; 30 // verify the post type 31 if (!in_array($typenow, array('post', 'page'))) 32 return; 33 // check if WYSIWYG is enabled 34 if (get_user_option('rich_editing') == 'true') { 35 add_filter("mce_external_plugins", "mgtrends_add_tinymce_plugin"); 36 add_filter('mce_buttons', 'mgtrends_register_my_tc_button'); 62 37 } 63 38 } 39 40 /** 41 * Specify the path of TinyMCE plugin 42 * 43 * @return array 44 */ 45 function mgtrends_add_tinymce_plugin($plugin_array) 46 { 47 $plugin_array['mgtrends_tc_button'] = plugins_url( '/js/mgtrends_plugin.js', __FILE__ ); 48 return $plugin_array; 49 } 50 51 /** 52 * Add a button to the editor 53 * 54 * @return array 55 */ 56 function mgtrends_register_my_tc_button($buttons) 57 { 58 array_push($buttons, "mgtrends_tc_button"); 59 return $buttons; 60 } 61 62 /** 63 * Load a specific CSS 64 * 65 * @return array 66 */ 67 function mgtrends_tc_css() 68 { 69 wp_enqueue_style('mgtrends-tc', plugins_url('/css/mgtrends.css', __FILE__)); 70 } 71 72 add_action('admin_enqueue_scripts', 'mgtrends_tc_css'); 73 74 /** 75 * Load translations 76 * 77 * @return string 78 */ 79 function mgtrends_lang($locales) 80 { 81 $locales['mgtrends_tc_button'] = plugin_dir_path ( __FILE__ ) . 'languages/translations.php'; 82 return $locales; 83 } 84 85 add_filter( 'mce_external_languages', 'mgtrends_lang'); 64 86 65 87 /** … … 74 96 'h' => '330', // height 75 97 'q' => '', // query 76 'loc' => ' US',// location98 'loc' => '', // location 77 99 'val' => 'std', // average trigger 78 100 'sdate' => '', // start date … … 94 116 95 117 add_shortcode('mgtrends', 'mg_trend'); 96 $mygallery = new MGTrends(); -
mg-webtrends-graphs/trunk/js/mgtrends_plugin.js
r805750 r1024190 1 // closure to avoid namespace collision 2 (function () { 3 // creates the plugin 4 tinymce.create('tinymce.plugins.mgtrends', { 5 // creates control instances based on the control's id. 6 // our button's id is "mgtrends_button" 7 createControl: function (id, controlManager) { 8 if (id == 'mgtrends_button') { 9 // creates the button 10 var button = controlManager.createButton('mgtrends_button', { 11 title: 'MG Trends Shortcode', // title of the button 12 image: '../wp-content/plugins/mg-webtrends-graphs/img/mg_webtrends_graph.png', // path to the button's image 13 onclick: function () { 14 // triggers the thickbox 15 var width = jQuery(window).width(), H = jQuery(window).height(), W = (720 < width) ? 720 : width; 16 W = W - 80; 17 H = H - 84; 18 tb_show('MG Trends Shortcode', '#TB_inline?width=' + W + '&height=' + H + '&inlineId=mgtrends-form'); 19 } 20 }); 21 return button; 22 } 23 return null; 24 } 25 }); 26 27 // registers the plugin. DON'T MISS THIS STEP!!! 28 tinymce.PluginManager.add('mgtrends', tinymce.plugins.mgtrends); 29 30 // executes this when the DOM is ready 31 jQuery(function () { 32 // creates a form to be displayed everytime the button is clicked 33 // you should achieve this using AJAX instead of direct html code like this 34 var form = jQuery('<div id="mgtrends-form"><table id="mgtrends-table" class="form-table">\ 35 <tr>\ 36 <th><label for="mgtrends-w">Width</label></th>\ 37 <td><input type="text" id="mgtrends-w" name="w" value="500" /><br />\ 38 <small>Specify the width of the graph in pixels.</small></td>\ 39 </tr>\ 40 <tr>\ 41 <th><label for="mgtrends-h">Height</label></th>\ 42 <td><input type="text" name="h" id="mgtrends-h" value="330" /><br />\ 43 <small>Specify the height of the graph in pixels</small>\ 44 </tr>\ 45 <tr>\ 46 <th><label for="mgtrends-q">Query</label></th>\ 47 <td><input type="text" name="q" id="mgtrends-q" value="" /><br />\ 48 <small>Enter the value to look for, separated by comma.</small></td>\ 49 </tr>\ 50 <tr>\ 51 <th><label for="mgtrends-loc">Geolocalization</label></th>\ 52 <td><input type="text" name="loc" id="mgtrends-loc" value="US" /><br />\ 53 <small>Enter the two-letters country code (es. US).</small></td>\ 54 </tr>\ 55 <tr>\ 56 <th><label for="mgtrends-val">Values</label></th>\ 57 <td><select name="val" id="mgtrends-val"><option value="std">Standard</option><option value="avg">Average</option></select><br />\ 58 <small>Show average values?</small></td>\ 59 </tr>\ 60 <tr>\ 61 <th><label for="mgtrends-sdate">Start Date</label></th>\ 62 <td><input type="text" name="sdate" id="mgtrends-sdate" value="" /><br />\ 63 <small>Enter the starting date of your graph - MM/YYYY (es. 01/2010).</small></td>\ 64 </tr>\ 65 <tr>\ 66 <th><label for="mgtrends-elaps">Duration</label></th>\ 67 <td><input type="text" name="elaps" id="mgtrends-elaps" value="" /><br />\ 68 <small>Specify how many months you want to show - (es. 12).</small></td>\ 69 </tr>\ 70 </table>\ 71 <p class="submit">\ 72 <input type="button" id="mgtrends-submit" class="button-primary" value="Insert Shortcode" name="submit" />\ 73 </p>\ 74 </div>'); 75 76 var table = form.find('table'); 77 form.appendTo('body').hide(); 78 79 // handles the click event of the submit button 80 form.find('#mgtrends-submit').click(function () { 81 // defines the options and their default values 82 // again, this is not the most elegant way to do this 83 // but well, this gets the job done nonetheless 84 var options = { 85 'w': '500', 86 'h': '330', 87 'q': '', 88 'loc': 'US', 89 'val': 'std', 90 'sdate': '', 91 'elaps': '' 92 }; 93 var shortcode = '[mgtrends'; 94 95 for (var index in options) { 96 var value = table.find('#mgtrends-' + index).val(); 97 if (index == 'q') { 98 value = value.replace(/(^\s+|\s+$)/g, ''); 99 value = value.replace(/\s{2,}/g, ' '); 100 value = value.replace(/, /g, ","); 101 value = value.replace(/ ,/g, ","); 102 value = value.replace(/ /g, "+"); 103 value = value.replace(/,/g, ",+"); 104 value = "+" + value; 105 } 106 // attaches the attribute to the shortcode only if it's different from the default value 107 if (value !== options[index]) 108 shortcode += ' ' + index + '="' + value + '"'; 109 } 110 111 shortcode += ']'; 112 113 // inserts the shortcode into the active editor 114 tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcode); 115 116 // closes Thickbox 117 tb_remove(); 1 (function() { 2 tinymce.PluginManager.add('mgtrends_tc_button', function( editor, url ) { 3 editor.addButton( 'mgtrends_tc_button', { 4 title: 'MG Web Trends', 5 icon: 'icon dashicons-chart-bar', 6 onclick: function() { 7 editor.windowManager.open( { 8 title: editor.getLang('mgtrends_tc_button.popup_title'), 9 body: [ 10 { 11 type: 'textbox', 12 name: 'width', 13 label: editor.getLang('mgtrends_tc_button.width_label') 14 }, 15 { 16 type: 'textbox', 17 name: 'height', 18 label: editor.getLang('mgtrends_tc_button.height_label') 19 }, 20 { 21 type: 'textbox', 22 name: 'geoloc', 23 label: editor.getLang('mgtrends_tc_button.geoloc_label') 24 }, 25 { 26 type: 'listbox', 27 name: 'values', 28 label: editor.getLang('mgtrends_tc_button.values_label'), 29 'values': [ 30 {text: 'Standard', value: 'std'}, 31 {text: editor.getLang('mgtrends_tc_button.average_label'), value: 'avg'} 32 ] 33 }, 34 { 35 type: 'textbox', 36 name: 'sdate', 37 label: editor.getLang('mgtrends_tc_button.sdate_label') 38 }, 39 { 40 type: 'textbox', 41 name: 'elaps', 42 label: editor.getLang('mgtrends_tc_button.elapsed_label') 43 }, 44 { 45 type: 'textbox', 46 name: 'query', 47 label: editor.getLang('mgtrends_tc_button.keywords_label') 48 } 49 ], 50 onsubmit: function( e ) { 51 var shortcode = '[mgtrends'; 52 var newKeyword = e.data.query; 53 newKeyword = newKeyword.replace(/(^\s+|\s+$)/g, ''); 54 newKeyword = newKeyword.replace(/\s{2,}/g, ' '); 55 newKeyword = newKeyword.replace(/, /g, ","); 56 newKeyword = newKeyword.replace(/ ,/g, ","); 57 newKeyword = newKeyword.replace(/ /g, "+"); 58 newKeyword = newKeyword.replace(/,/g, ",+"); 59 newKeyword = "+" + newKeyword; 60 if (e.data.width === '') { 61 shortcode += ' w="500"'; 62 } else { 63 shortcode += ' w="' + e.data.width + '"'; 64 } 65 if (e.data.height === '') { 66 shortcode += ' h="300"'; 67 } else { 68 shortcode += ' h="' + e.data.height + '"'; 69 } 70 if (e.data.geoloc !== '') { 71 shortcode += ' loc="' + e.data.geoloc + '"'; 72 } 73 if (e.data.values !== '') { 74 shortcode += ' val="' + e.data.values + '"'; 75 } 76 if (e.data.sdate !== '') { 77 shortcode += ' sdate="' + e.data.sdate + '"'; 78 } 79 if (e.data.elaps !== '') { 80 shortcode += ' elaps="' + e.data.elaps + '"'; 81 } 82 shortcode += ' q="' + newKeyword + '"'; 83 shortcode += ']'; 84 editor.insertContent(shortcode); 85 } 86 }); 87 } 118 88 }); 119 89 }); 120 })() 90 })(); -
mg-webtrends-graphs/trunk/readme.txt
r1021050 r1024190 1 1 === MG Webtrends Graphs === 2 Contributors: rashef2 Contributors: Mirko Grewing <mirko.grewing@live.com> 3 3 Donate link: http://cl.ly/0m1h2L3u0K3Y 4 4 Tags: Google, Trends, graph, chart, shortcode 5 Requires at least: 3. 36 Tested up to: 3.7.17 Stable tag: 0.35 Requires at least: 3.9 6 Tested up to: 4.0 7 Stable tag: 1.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 10 11 This plugin provides a shortcode that allows to embed a Google Trends graph in your website .11 This plugin provides a shortcode that allows to embed a Google Trends graph in your website through a very easy-to-use wizard! 12 12 13 13 == Description == … … 15 15 If you want to embed Google Trends graphs in your website this is the plugin for you: with a simple shortcode you will get the graph you need in a few seconds. A nice wizard will help you choosing the proper options and automatically get the needed shortcode. 16 16 17 Apart from the keywords , through the shortcode builder you can specify:17 Apart from the keywords for which you want the analytics, through the shortcode builder you can specify: 18 18 * dimensions of the graph (in pixels) 19 * localization (using the two letters country code) 20 * [NEW] whether you want to use average values 21 * [NEW] start date of the graph 22 * [NEW] timeframe of the graph (from the starting date - in months) 19 * geolocalization (using the two letters country code) 20 * whether you want to use average values rather than the standard ones 21 * start date of the graph 22 * timeframe of the graph (from the starting date - in months) 23 24 The plugin is now fully localized in English, Italian and Spanish! 23 25 24 26 == Installation == … … 27 29 1. Activate the plugin through the 'Plugins' menu in WordPress 28 30 1. While editing a document, click on the icon of MG WebTrends Graph in the toolbar and fill in the text fields. 29 1. Click on the "Insert" button to place the shortcode inside the page.30 31 31 32 == Frequently asked questions == 32 33 33 TB 34 = The plugin is not working anymore! = 35 Starting from v1.0 the plugin requires Wordpress 3.9 or higher (i.e. TinyMCE 4.x). 34 36 35 37 == Screenshots == … … 41 43 42 44 == Changelog == 45 46 = v1.0 = 47 * The plugin has been completely rewritten in order to comply with TinyMCE 4. 48 * Italian translation added. 49 * Spanish translation added. 43 50 44 51 = v0.3.1 = … … 60 67 == Upgrade notice == 61 68 62 Nothing you should worry about! ;) 69 The plugin has been completely rewritten in order to comply with TinyMCE 4, included in Wordpress 3.9 and higher. This is why the plugin will stop working if you upgrade it having an older version of Wordpress. The wizard has been also completely localized in Italian and Spanish. Please feel free to send forwards new translations and they will be included in the package.
Note: See TracChangeset
for help on using the changeset viewer.