if (isset($_GET['success'])) { if ($_GET['success'] == 'activated' or $_GET['success'] == 'deactivated') { yourls_add_notice('Plugin ' . $_GET['success']); } } yourls_html_head('plugins', 'Manage Plugins'); yourls_html_logo(); yourls_html_menu(); ?> <h2>Plugins</h2> <?php $plugins = (array) yourls_get_plugins(); $count = count($plugins); $count_active = yourls_has_active_plugins(); ?> <p id="plugin_summary">You currently have <strong><?php echo $count . ' ' . yourls_plural('plugin', $count); ?> </strong> installed, and <strong><?php echo $count_active; ?> </strong> activated</p> <table id="main_table" class="tblSorter" cellpadding="0" cellspacing="1"> <thead> <tr> <th>Plugin Name</th> <th>Version</th>
/** * Activate a plugin * * @param string $plugin Plugin filename (full or relative to plugins directory) * @return mixed string if error or true if success */ function yourls_activate_plugin($plugin) { // validate file $plugin = yourls_plugin_basename($plugin); $plugindir = yourls_sanitize_filename(YOURLS_PLUGINDIR); if (!yourls_validate_plugin_file($plugindir . '/' . $plugin)) { return 'Not a valid plugin file'; } // check not activated already global $ydb; if (yourls_has_active_plugins() && in_array($plugin, $ydb->plugins)) { return 'Plugin already activated'; } // attempt activation. TODO: uber cool fail proof sandbox like in WP. ob_start(); include YOURLS_PLUGINDIR . '/' . $plugin; if (ob_get_length() > 0) { // there was some output: error $output = ob_get_clean(); return 'Plugin generated expected output. Error was: <br/><pre>' . $output . '</pre>'; } // so far, so good: update active plugin list $ydb->plugins[] = $plugin; yourls_update_option('active_plugins', $ydb->plugins); yourls_do_action('activated_plugin', $plugin); yourls_do_action('activated_' . $plugin); return true; }
/** * Check api.yourls.org if there's a newer version of YOURLS * * This function collects various stats to help us improve YOURLS. See the blog post about it: * http://blog.yourls.org/2014/01/on-yourls-1-7-and-api-yourls-org/ * Results of requests sent to api.yourls.org are stored in option 'core_version_checks' and is an object * with the following properties: * - failed_attempts : number of consecutive failed attempts * - last_attempt : time() of last attempt * - last_result : content retrieved from api.yourls.org during previous check * - version_checked : installed YOURLS version that was last checked * * @since 1.7 * @return mixed JSON data if api.yourls.org successfully requested, false otherwise */ function yourls_check_core_version() { global $ydb, $yourls_user_passwords; $checks = yourls_get_option('core_version_checks'); // Invalidate check data when YOURLS version changes if (is_object($checks) && YOURLS_VERSION != $checks->version_checked) { $checks = false; } if (!is_object($checks)) { $checks = new stdClass(); $checks->failed_attempts = 0; $checks->last_attempt = 0; $checks->last_result = ''; $checks->version_checked = YOURLS_VERSION; } // Config file location ('u' for '/user' or 'i' for '/includes') $conf_loc = str_replace(YOURLS_ABSPATH, '', YOURLS_CONFIGFILE); $conf_loc = str_replace('/config.php', '', $conf_loc); $conf_loc = $conf_loc == '/user' ? 'u' : 'i'; // The collection of stuff to report $stuff = array('md5' => md5(YOURLS_SITE . YOURLS_ABSPATH), 'failed_attempts' => $checks->failed_attempts, 'yourls_site' => defined('YOURLS_SITE') ? YOURLS_SITE : 'unknown', 'yourls_version' => defined('YOURLS_VERSION') ? YOURLS_VERSION : 'unknown', 'php_version' => phpversion(), 'mysql_version' => $ydb->mysql_version(), 'locale' => yourls_get_locale(), 'db_driver' => defined('YOURLS_DB_DRIVER') ? YOURLS_DB_DRIVER : 'unset', 'db_ext_pdo' => extension_loaded('pdo_mysql') ? 1 : 0, 'db_ext_mysql' => extension_loaded('mysql') ? 1 : 0, 'db_ext_mysqli' => extension_loaded('mysqli') ? 1 : 0, 'ext_curl' => extension_loaded('curl') ? 1 : 0, 'num_users' => count($yourls_user_passwords), 'config_location' => $conf_loc, 'yourls_private' => defined('YOURLS_PRIVATE') && YOURLS_PRIVATE ? 1 : 0, 'yourls_unique' => defined('YOURLS_UNIQUE_URLS') && YOURLS_UNIQUE_URLS ? 1 : 0, 'yourls_url_convert' => defined('YOURLS_URL_CONVERT') ? YOURLS_URL_CONVERT : 'unknown', 'num_active_plugins' => yourls_has_active_plugins(), 'num_pages' => defined('YOURLS_PAGEDIR') ? count((array) glob(YOURLS_PAGEDIR . '/*.php')) : 0); $stuff = yourls_apply_filter('version_check_stuff', $stuff); // Send it in $url = 'http://api.yourls.org/core/version/1.0/'; if (yourls_can_http_over_ssl()) { $url = yourls_set_url_scheme($url, 'https'); } $req = yourls_http_post($url, array(), $stuff); $checks->last_attempt = time(); $checks->version_checked = YOURLS_VERSION; // Unexpected results ? if (is_string($req) or !$req->success) { $checks->failed_attempts = $checks->failed_attempts + 1; yourls_update_option('core_version_checks', $checks); return false; } // Parse response $json = json_decode(trim($req->body)); if (isset($json->latest) && isset($json->zipurl)) { // All went OK - mark this down $checks->failed_attempts = 0; $checks->last_result = $json; yourls_update_option('core_version_checks', $checks); return $json; } // Request returned actual result, but not what we expected return false; }