-
Notifications
You must be signed in to change notification settings - Fork 1
/
remote-url-summarizer.php
127 lines (105 loc) · 3.09 KB
/
remote-url-summarizer.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
<?php
/*
Plugin Name: Remote URL Summarizer
Description: Scan remote / external links with a post or comments, and provide a summary of the scanned links during display.
Plugin URI: https://github.com/daggerhart/remote-url-summarizer
Version: 1.2
Author: daggerhart
Author URI: http://www.daggerhart.com
License: GPLv2 Copyright (c) 2015 daggerhart
*/
define( 'RURLS_VERSION', '1.2' );
define( 'RURLS_PLUGIN_DIR', dirname( __FILE__ ) );
define( 'RURLS_SETTINGS_NAME', 'rurls_settings' );
define( 'RURLS_META_KEY_SCANNED', 'rurls_scanned' );
define( 'RURLS_META_KEY_URLS', 'rurls_remote_urls' );
define( 'RURLS_META_KEY_DATA', 'rurls_data' );
class Remote_URL_Summarizer {
// default plugin settings values
private $default_settings = array(
'mime_types' => array(
'image/jpeg' => 1,
),
'post_types' => array(
'post' => 1
),
'image_size' => 'thumbnail',
'default_stylesheet' => 1,
);
// storage for plugin settings
private $settings = array();
// singleton instance
static private $instance = null;
/**
* Access singleton instance
*
* @return \Remote_URL_Summarizer
*/
static public function get_instance(){
if ( is_null( self::$instance ) ){
self::$instance = new Remote_URL_Summarizer();
}
return self::$instance;
}
/**
* Hook into WP init
*/
private function __construct(){
add_action( 'init', array( $this, 'init' ) );
}
/**
* Complete the requirements of this plugin
*/
function init(){
define( 'RURLS_PLUGIN_URL', plugins_url( basename( RURLS_PLUGIN_DIR ) ) );
// common files
include_once RURLS_PLUGIN_DIR . '/rurls/helper-functions.php';
// common classes
new \Rurls\Common\Fetch( $this->get_settings() );
new \Rurls\Common\Display( $this->get_settings() );
new \Rurls\Common\Mimetypes\Images( $this->get_settings() );
new \Rurls\Common\Mimetypes\Html( $this->get_settings() );
// admin only
if ( is_admin() ) {
new \Rurls\Admin\Settings( $this->get_settings() );
}
}
/**
* Get plugin settings
* - settings field logic in admin/settings class
*
* @return array
*/
public function get_settings() {
if ( ! empty( $this->settings ) ){
return $this->settings;
}
$this->settings = wp_parse_args( get_option( RURLS_SETTINGS_NAME, array() ), $this->default_settings );
return $this->settings;
}
}
// autoloader
spl_autoload_register(function ($class) {
// project-specific namespace prefix
$prefix = 'Rurls\\';
// base directory for the namespace prefix
$base_dir = __DIR__ . '/rurls/';
// does the class use the namespace prefix?
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
// no, move to the next registered autoloader
return;
}
// get the relative class name
$relative_class = substr($class, $len);
// replace the namespace prefix with the base directory, replace namespace
// separators with directory separators in the relative class name, append
// with .php
$file = strtolower($base_dir . str_replace('\\', '/', $relative_class) . '.php');
// if the file exists, require it
if (file_exists($file)) {
require $file;
}
});
// What a lovely day!
Remote_URL_Summarizer::get_instance();