This repository has been archived by the owner on Aug 10, 2023. It is now read-only.
/
WP-CollectiveAccess.php
executable file
·145 lines (124 loc) · 5.62 KB
/
WP-CollectiveAccess.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
<?php
/**
* Plugin Name: WP-CollectiveAccess
* Plugin URI: http://github.com/ideesculture/wp-collectiveaccess
* Description: Display CollectiveAccess data & medias in Wordpress
* Version: 0.5.0
* Author: Gautier Michelin, idéesculture.
* Funding : Project originally funded by Pro-Memoria
* Author URI: http://www.ideesculture.com
* License: GPLv3
*
* Copyright 2014 Gautier Michelin, idéesculture (email : gm@ideesculture.com)
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
// Requiring common handlers & functions
require_once(plugin_dir_path( __FILE__ ) ."collectiveaccess_common_functions.php");
// Requiring admin page file
require_once(plugin_dir_path( __FILE__ ) ."collectiveaccess_settings.php");
// Add a link on the plugin page to the setting
add_filter('plugin_action_links', 'collectiveaccess_add_settings_link', 10, 2 );
// Requiring idéesculture simpleview class
require_once(plugin_dir_path( __FILE__ ) ."lib/simpleview/simpleview_idc.php");
// The idéesculture simpleview class requires a place where the views are stored, if empty
// or not defined, they will be load from current dir.
define("SIMPLEVIEW_IDC_DIR",plugin_dir_path( __FILE__ )."views/");
// Requiring details & search functions
require_once(plugin_dir_path( __FILE__ ) ."collectiveaccess_object_detail.php");
require_once(plugin_dir_path( __FILE__ ) ."collectiveaccess_objects_search.php");
require_once(plugin_dir_path( __FILE__ ) ."collectiveaccess_browse.php");
require_once(plugin_dir_path( __FILE__ ) ."collectiveaccess_objects_hierarchy.php");
// Requiring widget functions
// require_once(plugin_dir_path( __FILE__ ) ."widget_random_object.php");
require_once(plugin_dir_path( __FILE__ ) ."widget_search_form.php");
require_once(plugin_dir_path( __FILE__ ) ."widget_browse_links.php");
// Install & update functions
register_activation_hook( __FILE__, "collectiveaccess_install" );
//add_action( 'plugins_loaded', 'collectiveaccess_update_db_check' );
// i18n
add_action('init', 'collectiveaccess_i18n_init');
global $wpca_version;
$wpca_version = "0.5.1";
define("WP_CA_MAIN_FILE",__FILE__);
define("WP_CA_DIR",__DIR__."/");
define("WP_CA_VIEWS_DIR",__DIR__."/views/");
define("WP_CA_CONF_DIR",__DIR__."/conf/");
define("WP_CA_ASSETS_DIR",__DIR__."/assets/");
define("WP_CA_LIB_DIR",__DIR__."/lib/");
define("WP_CA_JS_DIR",__DIR__."/js/");
/**
*
*/
function collectiveaccess_install() {
global $wpca_version, $wpdb;
// Force DB install
update_option( "wpca_version", "" );
$installed_version = get_option( "wpca_version" );
// if version < 3.9, deactivate our plugin (not tested with a version under 3.9)
if( version_compare( get_bloginfo( "version" ), "3.7", "<" ) ) {
die( 'This plugin requires Wordpress version 3.7. Sorry about that.' );
} elseif (!is_callable('curl_init')) {
die( 'This plugin requires PHP_CURL, please contact your server administrator.' );
// We need mod_rewrite to activate the module
} elseif(!in_array('mod_rewrite',apache_get_modules())) {
die( 'This plugin requires Apache mod_rewrite.' );
} else {
// everything OK, continue the activation
if($installed_version != $wpca_version) {
$table_name = $wpdb->prefix . "collectiveaccess_cache";
// for easier reading & maintenance, $sql var is written in conf/db_table_creation.php
include(plugin_dir_path( __FILE__ )."conf/db_table_creation.php");
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
update_option( "wpca_version", $wpca_version );
}
// for easier reading & maintenance, default options values are written in conf/default_options_values.php
include(plugin_dir_path( __FILE__ )."conf/default_options_values.php");
update_option("collectiveaccess_options", $collectiveaccess_options);
}
}
function collectiveaccess_mod_rewrite_not_available() {
$html = '<div class="updated"><p>'.__('Mod_rewrite is not available on your server. Please ask your administrator to install it.', 'collectiveaccess').'</p></div>';
echo $html;
}
function collectiveaccess_uninstall() {
global $wpca_version;
if (get_site_option( 'wpca_version' ) != $wpca_version) {
collectiveaccess_install();
}
}
function collectiveaccess_i18n_init() {
// Textdomain
$domain = 'collectiveaccess';
$path = dirname(plugin_basename( __FILE__ )) . '/lang/';
$loaded = load_plugin_textdomain( 'collectiveaccess', false, $path);
if ($_GET['page'] == basename(__FILE__) && !$loaded) {
echo '<div class="error">'.__('Problem with localization files : ','collectiveaccess') . __('Could not load the localization file: ' . $path, $domain) . '</div>';
return;
}
}
/**
* add a settings link to the the plugin on the plugin page
* @param array $links
* @param string $file
* @return array
*/
function collectiveaccess_add_settings_link( $links, $file ) {
if ( $file == plugin_basename( __FILE__ ) ) {
$settings_link = '<a href="options-general.php?page=collectiveaccess">' . __('Settings' )/*get this from WP core*/ . '</a>';
array_unshift( $links, $settings_link );
}
return $links;
}