-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpojo-places.php
200 lines (157 loc) · 6.23 KB
/
pojo-places.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
/*
Plugin Name: Pojo Places
Plugin URI: http://pojo.me/
Description: Add a location finder or directory to your WordPress site with Pojo Framework in minutes. Link to Google Map or Waze, Share Location, compatible for mobile devices.
Author: Pojo Team
Author URI: http://pojo.me/
Version: 1.0.0
Text Domain: pojo-places
Domain Path: /languages/
License: GPLv2 or later
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
define( 'POJO_PLACES__FILE__', __FILE__ );
define( 'POJO_PLACES_BASE', plugin_basename( POJO_PLACES__FILE__ ) );
define( 'POJO_PLACES_URL', plugins_url( '/', POJO_PLACES__FILE__ ) );
define( 'POJO_PLACES_ASSETS_URL', POJO_PLACES_URL . 'assets/' );
final class Pojo_Places {
/**
* @var Pojo_Places The one true Pojo_Places
* @since 1.0.0
*/
private static $_instance = null;
/** @var Pojo_Places_Shortcode */
public $shortcode;
/** @var Pojo_Places_CPT */
public $cpt;
/** @var Pojo_Places_Settings */
public $settings;
public function load_textdomain() {
load_plugin_textdomain( 'pojo-places', false, basename( dirname( POJO_PLACES__FILE__ ) ) . '/languages' );
}
/**
* Throw error on object clone
*
* The whole idea of the singleton design pattern is that there is a single
* object therefore, we don't want the object to be cloned.
*
* @since 1.0.0
* @return void
*/
public function __clone() {
// Cloning instances of the class is forbidden
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'pojo-places' ), '1.0.0' );
}
/**
* Disable unserializing of the class
*
* @since 1.0.0
* @return void
*/
public function __wakeup() {
// Unserializing instances of the class is forbidden
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'pojo-places' ), '1.0.0' );
}
/**
* @since 1.0.0
* @return Pojo_Places
*/
public static function instance() {
if ( is_null( self::$_instance ) )
self::$_instance = new Pojo_Places();
return self::$_instance;
}
public function admin_notices() {
echo '<div class="error"><p>' . sprintf( __( '<a href="%s" target="_blank">Pojo Framework</a> is not active. Please activate any theme by Pojo before you are using "Pojo Places" plugin.', 'pojo-places' ), 'http://pojo.me/' ) . '</p></div>';
}
public function is_need_google_maps() {
if ( is_admin() ) {
global $pagenow;
return in_array( $pagenow, array( 'edit.php', 'post.php', 'post-new.php' ) ) || 'pojo_places_page_pojo-places' === get_current_screen()->id;
}
return true;
}
public function print_google_maps() {
if ( ! $this->is_need_google_maps() )
return;
$map_lang = pojo_get_option( 'places_map_language' );
if ( empty( $map_lang ) )
$map_lang = 'en';
?>
<script type="text/javascript" src="//maps.google.com/maps/api/js?sensor=true&v=3&libraries=geometry,places&language=<?php echo esc_attr( $map_lang ); ?>"></script>
<?php
}
public function enqueue_scripts() {
wp_register_script( 'pojo-places', POJO_PLACES_ASSETS_URL . 'js/app.min.js', array( 'jquery' ), false, true );
wp_enqueue_script( 'pojo-places' );
wp_enqueue_style( 'pojo-places', POJO_PLACES_ASSETS_URL . 'css/style.css' );
}
public function admin_enqueue_scripts() {
wp_register_script( 'pojo-places', POJO_PLACES_ASSETS_URL . 'admin/js/app.min.js', array( 'jquery' ), false, true );
if ( ! $this->is_need_google_maps() )
return;
wp_enqueue_script( 'pojo-places' );
}
public function add_localize_script_array( $array ) {
$places = array();
$places['address_line'] = (string) pojo_get_option( 'places_start_point_text' );
$geo_location = explode( ';', pojo_get_option( 'places_start_point_geo' ) );
if ( empty( $geo_location[0] ) || empty( $geo_location[1] ) ) {
$geo_location = array( 32.066157, 34.777821 );
}
$places['lat'] = $geo_location[0];
$places['lng'] = $geo_location[1];
$array['places'] = $places;
return $array;
}
public function include_settings() {
include( 'includes/class-pojo-places-settings.php' );
$this->settings = new Pojo_Places_Settings( 80 );
}
public function bootstrap() {
// This plugin for Pojo Themes..
if ( ! class_exists( 'Pojo_Core' ) ) {
add_action( 'admin_notices', array( &$this, 'admin_notices' ) );
return;
}
include( 'includes/class-pojo-places-cpt.php' );
include( 'includes/class-pojo-places-shortcode.php' );
$this->cpt = new Pojo_Places_CPT();
$this->shortcode = new Pojo_Places_Shortcode();
add_action( 'wp_head', array( &$this, 'print_google_maps' ), 9 );
add_action( 'admin_head', array( &$this, 'print_google_maps' ), 9 );
add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ), 100 );
add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ), 100 );
add_action( 'pojo_framework_base_settings_included', array( &$this, 'include_settings' ) );
}
public function register_widget() {
include( 'includes/class-pojo-places-widget.php' );
register_widget( 'Pojo_Places_Widget' );
}
public function register_widget_builder( $widgets ) {
$widgets[] = 'Pojo_Places_Widget';
return $widgets;
}
private function __construct() {
add_action( 'init', array( &$this, 'bootstrap' ) );
add_action( 'plugins_loaded', array( &$this, 'load_textdomain' ) );
add_action( 'pojo_admin_localize_scripts_array', array( &$this, 'add_localize_script_array' ) );
add_action( 'pojo_localize_scripts_array', array( &$this, 'add_localize_script_array' ) );
add_action( 'pojo_widgets_registered', array( &$this, 'register_widget' ) );
add_action( 'pojo_builder_widgets', array( &$this, 'register_widget_builder' ) );
}
}
Pojo_Places::instance();
// EOF