diff -r c7c0fbc09788 -r 5e8dcbe22c24 web/wp-content/plugins/social/social.php
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/web/wp-content/plugins/social/social.php Tue Dec 04 18:43:10 2012 -0800
@@ -0,0 +1,2253 @@
+MailChimp.
+Version: 2.6
+Author: Crowd Favorite
+Author URI: http://crowdfavorite.com/
+*/
+
+if (!class_exists('Social')) { // try to avoid double-loading...
+
+/**
+ * Social Core
+ *
+ * @package Social
+ */
+final class Social {
+
+ /**
+ * @var string URL of the API
+ */
+ public static $api_url = 'https://sopresto.mailchimp.com/';
+
+ /**
+ * @var string version number
+ */
+ public static $version = '2.6';
+
+ /**
+ * @var string CRON lock directory.
+ */
+ public static $cron_lock_dir = null;
+
+ /**
+ * @var string plugins URL
+ */
+ public static $plugins_url = '';
+
+ /**
+ * @var string plugins file path
+ */
+ public static $plugins_path = '';
+
+ /**
+ * @var bool loaded by theme?
+ */
+ public static $loaded_by_theme = false;
+
+ /**
+ * @var string duplicate comment message
+ */
+ public static $duplicate_comment_message = 'duplicate comment';
+
+ /**
+ * @var Social_Log logger
+ */
+ private static $log = null;
+
+ /**
+ * @var array default options
+ */
+ protected static $options = array(
+ 'debug' => false,
+ 'install_date' => 0,
+ 'installed_version' => 0,
+ 'broadcast_format' => '{title}: {content} {url}',
+ 'comment_broadcast_format' => '{content} {url}',
+ 'system_cron_api_key' => null,
+ 'fetch_comments' => '1',
+ 'broadcast_by_default' => '0',
+ 'use_standard_comments' => '0',
+ );
+
+ /**
+ * @var Social instance of Social
+ */
+ public static $instance = null;
+
+ /**
+ * Loads the instance of Social.
+ *
+ * @static
+ * @return Social
+ */
+ public static function instance() {
+ if (self::$instance === null) {
+ self::$instance = new self;
+ }
+
+ return self::$instance;
+ }
+
+ /**
+ * Handles the auto loading of classes.
+ *
+ * @static
+ *
+ * @param string $class
+ *
+ * @return bool
+ */
+ public static function auto_load($class) {
+ if (substr($class, 0, 7) == 'Social_' or substr($class, 0, 7) == 'Kohana_') {
+ try {
+ $file = Social::$plugins_path.'lib/'.str_replace('_', '/', strtolower($class)).'.php';
+ $file = apply_filters('social_auto_load_file', $file, $class);
+ if (file_exists($file)) {
+ require $file;
+
+ return true;
+ }
+
+ return false;
+ }
+ catch (Exception $e) {
+ Social::log(sprintf(__('Failed to auto load class %s.', 'social'), $class));
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns the broadcast format tokens.
+ *
+ * Format:
+ *
+ * {key} => __('Description', 'social')
+ *
+ * @static
+ * @return array
+ */
+ public static function broadcast_tokens() {
+ $query = new WP_Query(array(
+ 'posts_per_page' => 1
+ ));
+ if (count($query->posts) and $post = $query->posts[0]) {
+ $url = wp_get_shortlink($post->ID);
+ $date = get_date_from_gmt($post->post_date_gmt);
+ }
+ else {
+ $url = home_url('?p=123');
+ $date = get_date_from_gmt(current_time('mysql', true));
+ }
+
+ $defaults = array(
+ '{url}' => sprintf(__('Example: %s', 'social'), $url),
+ '{title}' => '',
+ '{content}' => '',
+ '{date}' => sprintf(__('Example: %s', 'social'), $date),
+ '{author}' => '',
+ );
+
+ return apply_filters('social_broadcast_tokens', $defaults);
+ }
+
+ /**
+ * Returns the comment broadcast format tokens.
+ *
+ * Format:
+ *
+ * {key} => __('Description', 'social')
+ *
+ * @static
+ * @return mixed
+ */
+ public static function comment_broadcast_tokens() {
+ $defaults = array(
+ '{content}' => '',
+ '{url}' => '',
+ );
+ return apply_filters('social_comment_broadcast_tokens', $defaults);
+ }
+
+ /**
+ * Sets or gets an option based on the key defined.
+ *
+ * Get Format:
+ *
+ * Running Social::option('option_name') will load "social_option_name" using get_option()
+ *
+ * Set Format:
+ *
+ * Running Social::option('option_name', 'new_value') will update "social_option_name" to "new_value"
+ * using update_option().
+ *
+ * @static
+ * @param string $key option key
+ * @param mixed $value option value
+ * @return bool|mixed
+ * @uses get_option()
+ * @uses update_option()
+ */
+ public static function option($key, $value = null) {
+ if ($value === null) {
+ $default = null;
+ if (isset(Social::$options[$key])) {
+ $default = Social::$options[$key];
+ }
+
+ return get_option('social_'.$key, $default);
+ }
+
+ update_option('social_'.$key, $value);
+ return false;
+ }
+
+ /**
+ * Add a message to the log.
+ *
+ * @static
+ * @param string $message message to add to the log
+ * @param array $args arguments to pass to the writer
+ * @param string $context context of the log message
+ * @param bool $backtrace show the backtrace
+ * @return void
+ */
+ public static function log($message, array $args = null, $context = null, $backtrace = false) {
+ Social::$log->write($message, $args, $context, $backtrace);
+ }
+
+ /**
+ * Sets the loaded by theme.
+ *
+ * @static
+ * @return void
+ */
+ public static function social_loaded_by_theme() {
+ self::$loaded_by_theme = true;
+ }
+
+ /**
+ * Sets the customer die handler.
+ *
+ * @static
+ * @param string $handler
+ * @return array
+ */
+ public static function wp_die_handler($handler) {
+ return array('Social', 'wp_comment_die_handler');
+ }
+
+ /**
+ * Don't actually die for aggregation runs.
+ *
+ * @static
+ * @param string $message
+ * @param string $title
+ * @param array $args
+ * @return mixed
+ */
+ public static function wp_comment_die_handler($message, $title, $args) {
+ if ($message == __('Duplicate comment detected; it looks as though you’ve already said that!')) {
+ // Keep going
+ throw new Exception(Social::$duplicate_comment_message);
+ }
+ }
+
+ /**
+ * @var bool is Social enabled?
+ */
+ private $_enabled = null;
+
+ /**
+ * Returns an array of all of the services.
+ *
+ * Format of the data returned:
+ *
+ * $services = array(
+ * 'twitter' => Social_Service_Twitter,
+ * 'facebook' => Social_Service_Facebook,
+ * // ... any other services registered
+ * )
+ *
+ * @return array
+ */
+ public function services() {
+ return $this->load_services();
+ }
+
+ /**
+ * Returns a service by access key.
+ *
+ * Loading a service:
+ *
+ * $twitter = Social::instance()->service('twitter');
+ *
+ * @param string $key service key
+ * @return mixed Social_Service|Social_Service_Twitter|Social_Service_Facebook|false
+ */
+ public function service($key) {
+ $services = $this->load_services();
+ if (!isset($services[$key])) {
+ return false;
+ }
+ return $services[$key];
+ }
+
+ /**
+ * Returns a service by comment type.
+ *
+ * Loading a service:
+ *
+ * $twitter = Social::instance()->service_for_comment_type('social-twitter-rt');
+ *
+ * @param string $key service key
+ * @return mixed Social_Service|Social_Service_Twitter|Social_Service_Facebook|false
+ */
+ public function service_for_comment_type($comment_type) {
+ $services = $this->load_services();
+ foreach ($services as $service) {
+ if (in_array($comment_type, $service->comment_types())) {
+ return $service;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Initializes Social.
+ *
+ * @wp-action init
+ * @return void
+ */
+ public function init() {
+ // Load the language translations
+ if (Social::$loaded_by_theme) {
+ $path = trailingslashit(Social::$plugins_path).'lang';
+ load_theme_textdomain('social', $path);
+ }
+ else {
+ $plugin_dir = basename(dirname(SOCIAL_FILE)).'/lang';
+ load_plugin_textdomain('social', false, $plugin_dir);
+ }
+
+ if (version_compare(PHP_VERSION, '5.2.4', '<')) {
+ deactivate_plugins(basename(__FILE__)); // Deactivate ourself
+ wp_die(__("Sorry, Social requires PHP 5.2.4 or higher. Ask your host how to enable PHP 5 as the default on your servers.", 'social'));
+ }
+
+ // Just activated?
+ if (!Social::option('install_date')) {
+ Social::option('install_date', current_time('timestamp', 1));
+ Social::option('system_cron_api_key', wp_generate_password(16, false));
+ }
+
+ // Plugins URL
+ $url = plugins_url('', SOCIAL_FILE);
+ Social::$plugins_url = trailingslashit(apply_filters('social_plugins_url', $url));
+
+ Social::$plugins_path = trailingslashit(apply_filters('social_plugins_path', SOCIAL_PATH));
+
+ // Set the logger
+ Social::$log = Social_Log::factory();
+
+ // Require Facebook and Twitter by default.
+ require Social::$plugins_path.'social-twitter.php';
+ require Social::$plugins_path.'social-facebook.php';
+ }
+
+ /**
+ * Auth Cookie expiration for API users.
+ *
+ * @return int
+ */
+ public function auth_cookie_expiration() {
+ return 31536000; // 1 Year
+ }
+
+ /**
+ * Enqueues the assets for Social.
+ *
+ * @wp-action wp_enqueue_scripts
+ * @wp-action load-post-new.php
+ * @wp-action load-post.php
+ * @wp-action load-profile.php
+ * @wp-action load-settings_page_social
+ * @return void
+ */
+ public function enqueue_assets() {
+ if (Social::option('use_standard_comments') == '1') {
+ return;
+ }
+ // JS/CSS
+ if (!defined('SOCIAL_COMMENTS_JS')) {
+ define('SOCIAL_COMMENTS_JS', Social::$plugins_url.'assets/social.js');
+ }
+ if (SOCIAL_COMMENTS_JS !== false) {
+ wp_enqueue_script('jquery');
+ wp_enqueue_script('social_js', SOCIAL_COMMENTS_JS, array('jquery'), Social::$version, true);
+ wp_localize_script('social_js', 'Sociali18n', array(
+ 'commentReplyTitle' => __('Post a Reply', 'social'),
+ ));
+ }
+
+ if (!is_admin()) {
+ if (!defined('SOCIAL_COMMENTS_CSS')) {
+ define('SOCIAL_COMMENTS_CSS', Social::$plugins_url.'assets/comments.css');
+ }
+ if (SOCIAL_COMMENTS_CSS !== false) {
+ wp_enqueue_style('social_comments', SOCIAL_COMMENTS_CSS, array(), Social::$version, 'screen');
+ }
+ }
+
+ }
+
+ /**
+ * Enqueues the assets for Social.
+ *
+ * @wp-action admin_enqueue_scripts
+ * @return void
+ */
+ public function admin_enqueue_assets() {
+ if (!defined('SOCIAL_ADMIN_JS')) {
+ define('SOCIAL_ADMIN_JS', Social::$plugins_url.'assets/admin.js');
+ }
+
+ if (!defined('SOCIAL_ADMIN_CSS')) {
+ define('SOCIAL_ADMIN_CSS', Social::$plugins_url.'assets/admin.css');
+ }
+
+ if (SOCIAL_ADMIN_CSS !== false) {
+ wp_enqueue_style('social_admin', SOCIAL_ADMIN_CSS, array(), Social::$version, 'screen');
+ }
+
+ if (SOCIAL_ADMIN_JS !== false) {
+ wp_enqueue_script('social_admin', SOCIAL_ADMIN_JS, array(), Social::$version, true);
+ $data = apply_filters('social_admin_js_strings', array(
+ 'protectedTweet' => __('Protected Tweet', 'social'),
+ 'invalidUrl' => __('Invalid URL', 'social'),
+ ));
+ wp_localize_script('social_admin', 'socialAdminL10n', $data);
+ }
+ }
+
+ /**
+ * Loads the services on every page if the user is an admin.
+ *
+ * @wp-action admin_init
+ * @return void
+ */
+ public function admin_init() {
+ if (current_user_can('manage_options') or current_user_can('publish_posts')) {
+ // Trigger upgrade?
+ if (isset($_GET['page']) and $_GET['page'] == basename(SOCIAL_FILE)) {
+ global $wpdb;
+
+ // First check for the semaphore options, they need to be added before the upgrade starts.
+ $results = $wpdb->get_results("
+ SELECT option_id
+ FROM $wpdb->options
+ WHERE option_name IN ('social_locked', 'social_unlocked')
+ ");
+ if (!count($results)) {
+ update_option('social_unlocked', '1');
+ update_option('social_last_lock_time', current_time('mysql', 1));
+ update_option('social_semaphore', '0');
+ }
+
+ if (version_compare(Social::option('installed_version'), Social::$version, '<')) {
+ $this->_enabled = false;
+ $this->upgrade();
+ }
+ }
+
+ if ($this->_enabled === null) {
+ $this->load_services();
+ }
+ }
+
+ // Redirect to the home_url() if the user is a commenter.
+ if (!current_user_can('publish_posts')) {
+ $commenter = get_user_meta(get_current_user_id(), 'social_commenter', true);
+ if (!empty($commenter) and $commenter == 'true') {
+ wp_redirect(trailingslashit(home_url()));
+ }
+ }
+ }
+
+ /**
+ * Checks to see if system crons are disabled.
+ *
+ * @wp-action load-settings_page_social
+ * @return void
+ */
+ public function check_system_cron() {
+ Social::log('Checking system CRON');
+ // Schedule CRONs
+ if (Social::option('fetch_comments') == '1') {
+ if (wp_next_scheduled('social_cron_15_init') === false) {
+ Social::log('Adding Social 15 CRON schedule');
+ wp_schedule_event(time() + 900, 'every15min', 'social_cron_15_init');
+ }
+ wp_remote_get(
+ admin_url('options_general.php?'.http_build_query(array(
+ 'social_controller' => 'cron',
+ 'social_action' => 'check_crons',
+ 'social_api_key' => Social::option('system_cron_api_key')
+ ), null, '&')),
+ array(
+ 'timeout' => 0.01,
+ 'blocking' => false,
+ 'sslverify' => apply_filters('https_local_ssl_verify', true),
+ )
+ );
+ }
+ }
+
+ /**
+ * Handlers requests.
+ *
+ * @wp-action init
+ * @return void
+ */
+ public function request_handler() {
+ if (isset($_GET['social_controller'])) {
+ Social_Request::factory()->execute();
+ }
+ }
+
+ /**
+ * Adds a link to the "Settings" menu in WP-Admin.
+ *
+ * @wp-action admin_menu
+ * @return void
+ */
+ public function admin_menu() {
+ add_options_page(
+ __('Social Options', 'social'),
+ __('Social', 'social'),
+ 'manage_options',
+ basename(SOCIAL_FILE),
+ array(
+ $this,
+ 'admin_options_form'
+ )
+ );
+ }
+
+ /**
+ * Add Settings link to plugins - code from GD Star Ratings
+ *
+ * @wp-filter plugin_action_links
+ * @param array $links
+ * @param string $file
+ * @return array
+ */
+ public function add_settings_link($links, $file) {
+ static $this_plugin;
+ if (!$this_plugin) {
+ $this_plugin = plugin_basename(__FILE__);
+ }
+
+ if ($file == $this_plugin) {
+ $settings_link = ''.__('Settings', 'social').'';
+ array_unshift($links, $settings_link);
+ }
+ return $links;
+ }
+
+ /**
+ * Handles the display of different messages for admin notices.
+ *
+ * @wp-action admin_notices
+ * @action admin_notices
+ */
+ public function admin_notices() {
+ if (current_user_can('manage_options') or current_user_can('publish_posts')) {
+ // Upgrade notice
+ if (version_compare(Social::option('installed_version'), Social::$version, '<')) {
+ $message = sprintf(__('Social is shiny and new! Please verify and save your settings to complete the upgrade.', 'social'), esc_url(Social::settings_url()));
+ echo '
'.$message.'
';
+ }
+
+ $suppress_no_accounts_notice = get_user_meta(get_current_user_id(), 'social_suppress_no_accounts_notice', true);
+ if (!$this->_enabled and (!isset($_GET['page']) or $_GET['page'] != basename(SOCIAL_FILE)) and empty($suppress_no_accounts_notice)) {
+ $dismiss = sprintf(__('[Dismiss]', 'social'), esc_url(admin_url('options-general.php?social_controller=settings&social_action=suppress_no_accounts_notice')));
+ $message = sprintf(__('To start using Social, please add an account.', 'social'), esc_url(Social::settings_url()));
+ echo '
'.$message.' '.$dismiss.'
';
+ }
+
+ if (isset($_GET['page']) and $_GET['page'] == basename(SOCIAL_FILE)) {
+ // CRON Lock
+ if (Social::option('cron_lock_error') !== null) {
+ $upload_dir = wp_upload_dir();
+ if (is_writeable(Social::$plugins_path) or (isset($upload_dir['basedir']) and is_writeable($upload_dir['basedir']))) {
+ delete_option('social_cron_lock_error');
+ }
+ else {
+ if (isset($upload_dir['basedir'])) {
+ $message = sprintf(__('Social requires that either %s or %s be writable for CRON jobs.', 'social'), esc_html(Social::$plugins_path), esc_html($upload_dir['basedir']));
+ }
+ else {
+ $message = sprintf(__('Social requires that %s is writable for CRON jobs.', 'social'), esc_html(Social::$plugins_path));
+ }
+
+ echo '
'.esc_html($message).'
';
+ }
+ }
+
+ // Enable notice?
+ $suppress_enable_notice = get_user_meta(get_current_user_id(), 'social_suppress_enable_notice', true);
+ if (empty($suppress_enable_notice)) {
+ $message = __('When you enable Social, users will be created when they log in with Facebook or Twitter to comment. These users are created without a role and will be prevented from accessing the admin side of WordPress until an administrator edits the user to give them a role.', 'social');
+ $dismiss = sprintf(__('[Dismiss]', 'social'), esc_url(admin_url('options-general.php?social_controller=settings&social_action=suppress_enable_notice')));
+ echo '