-
Notifications
You must be signed in to change notification settings - Fork 2
/
lf-hiker.php
108 lines (96 loc) · 3.11 KB
/
lf-hiker.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
<?php
/*
Plugin Name: LF Hiker
Plugin URI: http://elisabeth.pointal.org/lf-hiker
Description: A responsive and mobile friendly plugin to display gpx track with profile elevation.
Author: epointal
Author URI: http://elisabeth.pointal.org/
Version: 1.13.0
License: GPL2
Text domain: lfh
*/
if ( ! defined( 'ABSPATH' ) ) exit;
if( ! function_exists( "boolval")){
function boolval( $var ){
if( is_null( $var )){
return false;
}
switch( gettype( $var)){
case "boolean":
return $var;
break;
case "integer":
case "double":
if($var >0){
return true;
}else{
return false;
}
break;
case "string":
if( $var === "" || $var === "0" || $var === "false"){
return false;
}else{
return true;
}
break;
case "array":
if( count($var)>0){
return true;
}else{
return false;
}
break;
default:
return true;
}
}
}
class Lf_Hiker_Plugin
{
const VERSION = '1.13.0';
const LEAFLET_VERSION = '1.3.1';
private static $_controller;
public static $url = '';
public static $path = '';
private function __construct()
{
add_action( 'plugins_loaded',array(&$this, 'initialize'));
spl_autoload_register( 'Lf_Hiker_Plugin::autoloader' );
register_activation_hook( __FILE__ , array('Lfh_Controller_Admin', 'activate'));
register_deactivation_hook( __FILE__ , array( 'Lfh_Controller_Admin', 'deactivate') );
register_uninstall_hook( __FILE__ , array( 'Lfh_Controller_Admin', 'uninstall') );
}
public function initialize()
{
self::$url = plugin_dir_url( __FILE__ );
self::$path = plugin_dir_path( __FILE__ );
add_action( 'init', array(&$this, 'load_textdomain') );
if(is_admin()){
self::$_controller = Lfh_Controller_Back::get_instance();
}else{
self::$_controller = Lfh_Controller_Front::get_instance();
}
}
public static function autoloader( $class_name )
{
if( false !== strpos($class_name, 'Lfh_') ){
$classes_dir = realpath( plugin_dir_path( __FILE__ ) ) . DIRECTORY_SEPARATOR ;
$class_name = str_replace('Lfh_' , '', $class_name);
$class_file = str_replace( '_', DIRECTORY_SEPARATOR, $class_name ) . '.php';
require_once $classes_dir . $class_file;
}
}
public static function get_controller()
{
if(is_null(self::$_controller)) {
self::$_controller = new Lf_Hiker_Plugin();
}
return self::$_controller;
}
public function load_textdomain()
{
load_plugin_textdomain( 'lfh', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
}
Lf_Hiker_Plugin::get_controller();