Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2012
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: GeoAds LT
  4. Plugin URI: http://Classipro.com
  5. Description: Simple widget for geolocate your Ads. Use inside post/pages with the shortcode <strong>[geoads]</strong> or place it where you want using the php function: <strong> if (function_exists('geoads')) geoads(); ?></strong>Version: 1.0
  6. Author: Alucas & Rubencio
  7. Author URI: http://Classipro.com
  8. License: GPL2
  9. */
  10.  
  11. include('ajax-geo-ads.php');
  12.  
  13. //add_action('widgets_init', create_function('', 'return register_widget("GMap_Widget");'));
  14. add_action('widgets_init', 'load_gmap_widget');
  15.  
  16. function load_gmap_widget()
  17. {
  18. register_widget('GMap_Widget');
  19. }
  20.  
  21. function geoads()
  22. {
  23. include('map.php');
  24. }
  25.  
  26. // Map Widget
  27. class GMap_Widget extends WP_Widget
  28. {
  29. function GMap_Widget()
  30. {
  31. $this->init_plugin_constants();
  32.  
  33. $widget_opts = array('classname'=>PLUGIN_NAME, 'description'=>__('Simple widget for geolocate your Ads', PLUGIN_LOCALE));
  34.  
  35. $this->WP_Widget(PLUGIN_SLUG, __(PLUGIN_NAME, PLUGIN_LOCALE), $widget_opts);
  36.  
  37. //load_plugin_textdomain(PLUGIN_LOCALE, false, dirname(plugin_basename(__FILE__)).'/lang/');
  38.  
  39. $this->register_scripts_and_styles();
  40. }
  41.  
  42. // API functions
  43. function widget($args, $instance)
  44. {
  45. extract($args);
  46. echo $before_widget;
  47.  
  48. //include(WP_PLUGIN_DIR.'/'.PLUGIN_SLUG.'/views/widget.php');
  49. geoads();
  50.  
  51. echo $after_widget;
  52. }
  53.  
  54. function update($new_instance, $old_instance)
  55. {
  56. $instance = $old_instance;
  57. return $instance;
  58. }
  59.  
  60. function form($instance)
  61. {
  62. $instance = wp_parse_args(
  63. (array)$instance,
  64. array("=>")
  65. );
  66. // TODO: store the values of widget in a variable
  67.  
  68.  
  69. //Display the admin form
  70. //include(WP_PLUGIN_DIR.'/'.PLUGIN_SLUG.'/views/admin.php');
  71.  
  72. }
  73.  
  74. // Private functions
  75. private function init_plugin_constants()
  76. {
  77. //wp_enqueue_script('marker_clusterer', plugins_url('/geo-ads/lib/markerclusterer_compiled.js'));
  78.  
  79. if (!defined('PLUGIN_LOCALE'))
  80. {
  81. define('PLUGIN_LOCALE', 'geo-ads-locale');
  82. }
  83. if (!defined('PLUGIN_NAME'))
  84. {
  85. define('PLUGIN_NAME', 'GeoAds LT');
  86. }
  87. if (!defined('PLUGIN_SLUG'))
  88. {
  89. define('PLUGIN_SLUG', 'geo-ads');
  90. }
  91. }
  92.  
  93. // registers and enqueues stylesheets and scripts for admin panel
  94. private function register_scripts_and_styles()
  95. {
  96. if (is_admin())
  97. {
  98. //$this->load_file(PLUGIN_NAME, '/'.PLUGIN_SLUG.'/js/admin.js', true);
  99. //$this->load_file(PLUGIN_NAME, '/'.PLUGIN_SLUG.'/css/admin.css');
  100. $this->load_file('marker_clusterer', '/'.PLUGIN_SLUG.'/lib/markerclusterer_compiled.js', true);
  101.  
  102. }
  103. else
  104. {
  105. //$this->load_file(PLUGIN_NAME, '/'.PLUGIN_SLUG.'/js/admin.js', true);
  106. //$this->load_file(PLUGIN_NAME, '/'.PLUGIN_SLUG.'/css/admin.css');
  107. $this->load_file('marker_clusterer', '/'.PLUGIN_SLUG.'/lib/markerclusterer_compiled.js', true);
  108. }
  109. }
  110.  
  111. // Helper function for registering and equeueing scripts and styles
  112. private function load_file($name, $file_path, $is_script=false)
  113. {
  114. $url = WP_PLUGIN_URL.$file_path;
  115. $file = WP_PLUGIN_DIR.$file_path;
  116.  
  117. if (file_exists($file))
  118. {
  119. if ($is_script)
  120. {
  121. wp_register_script($name, $url);
  122. wp_enqueue_script($name);
  123. }
  124. else
  125. {
  126. wp_register_style($name, $url);
  127. wp_enqueue_style($name);
  128. }
  129. }
  130. }
  131.  
  132. }// end class
  133.  
  134.  
  135. // Start shortcode
  136. if (!function_exists(geo_ads_shortcode))
  137. {
  138. function geo_ads_shortcode($atts, $content = null)
  139. {
  140. ob_start();
  141. geoads();
  142. $out = ob_get_contents();
  143. ob_end_clean();
  144. return $out;
  145. }
  146. add_shortcode('geoads', 'geo_ads_shortcode');
  147. }
  148. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement