| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* @package ZephyrProjectManager |
| 5 |
* Plugin Name: Zephyr Project Manager |
| 6 |
* Description: A modern project manager for WordPress to keep track of all your projects from within WordPress. |
| 7 |
* Plugin URI: https://zephyr-one.com |
| 8 |
* Version: 3.3.206 |
| 9 |
* Author: Dylan James |
| 10 |
* License: GPLv2 or later |
| 11 |
* Text Domain: zephyr-project-manager |
| 12 |
* Domain Path: /languages |
| 13 |
*/ |
| 14 |
if (!defined('ABSPATH')) { |
| 15 |
die; |
| 16 |
} |
| 17 |
|
| 18 |
if (file_exists(dirname(__FILE__) . '/vendor/autoload.php')) { |
| 19 |
require_once dirname(__FILE__) . '/vendor/autoload.php'; |
| 20 |
} |
| 21 |
|
| 22 |
global $wpdb; |
| 23 |
global $zpm_settings; |
| 24 |
global $zpmMessages; |
| 25 |
|
| 26 |
use ZephyrProjectManager\Core\Tasks; |
| 27 |
use ZephyrProjectManager\Base\Activate; |
| 28 |
use ZephyrProjectManager\Base\Deactivate; |
| 29 |
use ZephyrProjectManager\Core\Utillities; |
| 30 |
use ZephyrProjectManager\Init; |
| 31 |
use ZephyrProjectManager\Core\Controllers\MessageController; |
| 32 |
|
| 33 |
define('ZPM_PLUGIN_PATH', plugin_dir_path(__FILE__)); |
| 34 |
define('ZPM_PLUGIN_URL', plugin_dir_url(__FILE__)); |
| 35 |
define('ZPM_PLUGIN', plugin_basename(__FILE__)); |
| 36 |
define('ZPM_PROJECTS_TABLE', $wpdb->prefix . 'zpm_projects'); |
| 37 |
define('ZPM_TASKS_TABLE', $wpdb->prefix . 'zpm_tasks'); |
| 38 |
define('ZPM_MESSAGES_TABLE', $wpdb->prefix . 'zpm_messages'); |
| 39 |
define('ZPM_CATEGORY_TABLE', $wpdb->prefix . 'zpm_categories'); |
| 40 |
define('ZPM_ACTIVITY_TABLE', $wpdb->prefix . 'zpm_activity'); |
| 41 |
define('ZEPHYR_PRO_LINK', 'https://zephyr-one.com/purchase-pro/'); |
| 42 |
define('ZPM_REQUIRED_PRO_VERSION', '3.3.101'); |
| 43 |
define('ZPM_PLUGIN_VERSION', '3.3.200'); |
| 44 |
define('ZPM_REQUIRED_MAX_PRO_VERSION', '3.4.2'); |
| 45 |
|
| 46 |
if (class_exists('ZephyrProjectManager\\Pro\\Plugin')) { |
| 47 |
$plugin = new \ZephyrProjectManager\Pro\Plugin(); |
| 48 |
$version = $plugin->getVersion(); |
| 49 |
if (version_compare($version, ZPM_REQUIRED_MAX_PRO_VERSION, '>=')) { |
| 50 |
return; |
| 51 |
} |
| 52 |
} |
| 53 |
require_once(ZPM_PLUGIN_PATH . 'includes/functions.php'); |
| 54 |
global $zpmSettings; |
| 55 |
$zpmMessages = new MessageController(); |
| 56 |
$zpmSettings = Utillities::general_settings(); |
| 57 |
|
| 58 |
function activate_project_manager_plugin($networkwide) { |
| 59 |
if (is_multisite() && $networkwide) { |
| 60 |
// Get all sites in the network |
| 61 |
$sites = get_sites(array('number' => 0)); |
| 62 |
foreach ($sites as $site) { |
| 63 |
switch_to_blog($site->blog_id); |
| 64 |
Activate::activate(); |
| 65 |
if (function_exists('zephyr_project_manager_activate_pro')) { |
| 66 |
zephyr_project_manager_activate_pro(); |
| 67 |
} |
| 68 |
restore_current_blog(); |
| 69 |
} |
| 70 |
} else { |
| 71 |
Activate::activate(); |
| 72 |
if (function_exists('zephyr_project_manager_activate_pro')) { |
| 73 |
zephyr_project_manager_activate_pro(); |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
register_activation_hook(__FILE__, 'activate_project_manager_plugin'); |
| 79 |
|
| 80 |
function deactivate_project_manager_plugin() { |
| 81 |
Deactivate::deactivate(); |
| 82 |
} |
| 83 |
|
| 84 |
register_deactivation_hook(__FILE__, 'deactivate_project_manager_plugin'); |
| 85 |
|
| 86 |
// When a new site is created in multisite, activate the plugin on it |
| 87 |
function activate_project_manager_new_site($site) { |
| 88 |
if (is_plugin_active_for_network(ZPM_PLUGIN)) { |
| 89 |
switch_to_blog($site->blog_id); |
| 90 |
Activate::activate(); |
| 91 |
if (function_exists('zephyr_project_manager_activate_pro')) { |
| 92 |
zephyr_project_manager_activate_pro(); |
| 93 |
} |
| 94 |
restore_current_blog(); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
add_action('wp_initialize_site', 'activate_project_manager_new_site', 900); |
| 99 |
|
| 100 |
function zpm_plugin_loaded() { |
| 101 |
global $zpm_settings; |
| 102 |
$version = zpm_get_version(); |
| 103 |
$db_version = get_option('zpm_db_version', '0'); |
| 104 |
if (version_compare($db_version, $version, '<')) { |
| 105 |
Activate::installTables(); |
| 106 |
update_option('zpm_db_version', $version); |
| 107 |
} |
| 108 |
Utillities::check_save_general_settings(); |
| 109 |
$tasks = new Tasks(); |
| 110 |
$zpm_settings = Utillities::general_settings(); |
| 111 |
} |
| 112 |
|
| 113 |
add_action('init', 'zephyr_project_manager_init'); |
| 114 |
|
| 115 |
function zephyr_project_manager_init() { |
| 116 |
$locale = apply_filters('plugin_locale', get_locale(), 'zephyr-project-manager'); |
| 117 |
$language = substr($locale, 0, 2); |
| 118 |
if ($language == 'en') { |
| 119 |
$locale = 'en_EN'; |
| 120 |
} |
| 121 |
load_plugin_textdomain('zephyr-project-manager', false, basename(dirname(__FILE__)) . '/languages/'); |
| 122 |
} |
| 123 |
|
| 124 |
if (class_exists('ZephyrProjectManager\\Init')) { |
| 125 |
Utillities::install_missing_columns(); |
| 126 |
Init::register_services(); |
| 127 |
zpm_add_scheduled_events(); |
| 128 |
// $currentVersion = Zephyr::getPluginVersion(); |
| 129 |
// $databaseVersion = get_option( 'zpm_database_version', 1 ); |
| 130 |
// if (version_compare($currentVersion, $databaseVersion, '>')) { |
| 131 |
// Activate::activate(); |
| 132 |
// } |
| 133 |
} |
| 134 |
|
| 135 |
function zpm_admin_init() { |
| 136 |
if (isset($_POST['zpm_save_general_settings'])) { |
| 137 |
check_admin_referer('zpm_save_general_settings'); |
| 138 |
$ics = isset($_POST['zpm-settings-ics-sync-enabled']); |
| 139 |
if ($ics) { |
| 140 |
Tasks::syncIcs(); |
| 141 |
} else { |
| 142 |
Tasks::unsyncIcs(); |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
add_action('plugins_loaded', 'zpm_plugin_loaded'); |
| 148 |
add_action('admin_init', 'zpm_admin_init'); |
| 149 |
add_filter('admin_body_class', 'zpm_body_classes'); |
| 150 |
|
| 151 |
if (!zpm_is_required_pro_version()) { |
| 152 |
add_action('admin_notices', 'zpm_incompatible_pro_version'); |
| 153 |
} |
| 154 |
|
| 155 |
function zpm_incompatible_pro_version() { |
| 156 |
?> |
| 157 |
<div class="notice notice-error"> |
| 158 |
<?php /* translators: Pro version requirement message. %s: Required Pro version number */ ?> |
| 159 |
<p> |
| 160 |
<?php echo esc_html(sprintf(esc_html('Zephyr Project Manager PRO version %s or higher is required. To continue using all the Pro features and avoid any incompatibility, please update it by going to Plugins > Zephyr Project Manager Pro and clicking the Update button.', 'zephyr-project-manager'), esc_html(ZPM_REQUIRED_PRO_VERSION))) ?> |
| 161 |
</p> |
| 162 |
</div> |
| 163 |
<?php |
| 164 |
} |
| 165 |
|
| 166 |
function zpm_body_classes($classes) { |
| 167 |
if (isZephyrPage()) { |
| 168 |
return "$classes zephyr-project-manager"; |
| 169 |
} |
| 170 |
|
| 171 |
return $classes; |
| 172 |
} |
| 173 |
|
| 174 |
function zpm_logged_in_redirect() { |
| 175 |
$redirectTo = isset($_GET['redirect_to']) ? filter_var($_GET['redirect_to'], FILTER_SANITIZE_URL) : ''; |
| 176 |
if (!empty($redirectTo) && strpos($redirectTo, 'zephyrprojectmanager') !== false) { |
| 177 |
if (is_user_logged_in()) { |
| 178 |
$redirected = wp_safe_redirect($redirectTo); |
| 179 |
if ($redirected) { |
| 180 |
die; |
| 181 |
} |
| 182 |
} |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
add_action('admin_menu', 'zpm_logged_in_redirect'); |
| 187 |
add_action('network_admin_menu', 'zpm_logged_in_redirect'); |
| 188 |
add_filter('zpm/user/data', 'zpm_filter_user_data', 10, 2); |
| 189 |
|
| 190 |
function zpm_filter_user_data($user, $id) { |
| 191 |
if (function_exists('bp_core_get_user_displayname')) { |
| 192 |
$data = get_user_by('ID', $id); |
| 193 |
$user['name'] = $data->display_name; //bp_core_get_user_displayname($id); |
| 194 |
} |
| 195 |
if (function_exists('bp_core_fetch_avatar')) { |
| 196 |
$user['avatar'] = bp_core_fetch_avatar(array( |
| 197 |
'item_id' => $id, |
| 198 |
'type' => 'thumb', |
| 199 |
'width' => 32, |
| 200 |
'height' => 32, |
| 201 |
'class' => 'friend-avatar', |
| 202 |
'html' => false |
| 203 |
)); |
| 204 |
} |
| 205 |
|
| 206 |
return $user; |
| 207 |
} |
| 208 |
|
| 209 |
function zpm_upload_file_arguments($query) { |
| 210 |
if (isset($_REQUEST['query']['user'])) { |
| 211 |
if (!current_user_can('administrator')) { |
| 212 |
$query['author'] = $_REQUEST['query']['user']; |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
return $query; |
| 217 |
} |
| 218 |
|
| 219 |
add_filter('ajax_query_attachments_args', 'zpm_upload_file_arguments'); |
| 220 |
|