/** * Truncates a string to be shorter than or equal to the length specified * Attempts to truncate on word boundaries * * @param string $string * @param int $length * @return string */ public static function crop_str($string, $length = 256) { $string = Publicize_Util::sanitize_message($string); $length = absint($length); if (mb_strlen($string, 'UTF-8') <= $length) { return $string; } // @see wp_trim_words() if ('characters' == _x('words', 'word count: words or characters?', 'jetpack')) { return trim(mb_substr($string, 0, $length - 1, 'UTF-8')) . "…"; // ellipsis } $words = explode(' ', $string); $return = ''; while (strlen($word = array_shift($words))) { $new_return = $return ? "{$return} {$word}" : $word; $new_return_length = mb_strlen($new_return, 'UTF-8'); if ($new_return_length < $length - 1) { $return = $new_return; continue; } elseif ($new_return_length == $length - 1) { $return = $new_return; break; } if (!$return) { $return = mb_substr($new_return, 0, $length - 1, 'UTF-8'); } break; } return "{$return}…"; // ellipsis }
/** * Sets up the basics of Publicize */ function __construct() { $this->default_message = Publicize_Util::build_sprintf(array(apply_filters('wpas_default_message', $this->default_message), 'title', 'url')); $this->default_prefix = Publicize_Util::build_sprintf(array(apply_filters('wpas_default_prefix', $this->default_prefix), 'url')); $this->default_suffix = Publicize_Util::build_sprintf(array(apply_filters('wpas_default_suffix', $this->default_suffix), 'url')); /** * Filter the capability to change global Publicize connection options. * * All users with this cap can un-globalize all other global connections, and globalize any of their own * Globalized connections cannot be unselected by users without this capability when publishing. * * @module publicize * * @since 2.2.1 * * @param string $this->GLOBAL_CAP default capability in control of global Publicize connection options. Default to edit_others_posts. */ $this->GLOBAL_CAP = apply_filters('jetpack_publicize_global_connections_cap', $this->GLOBAL_CAP); // stage 1 and 2 of 3-stage Publicize. Flag for Publicize on creation, save meta, // then check meta and publicize based on that. stage 3 implemented on wpcom add_action('transition_post_status', array($this, 'flag_post_for_publicize'), 10, 3); add_action('save_post', array(&$this, 'save_meta'), 20, 2); // Connection test callback add_action('wp_ajax_test_publicize_conns', array($this, 'test_publicize_conns')); }
/** * Sets up the basics of Publicize */ function __construct() { $this->default_message = Publicize_Util::build_sprintf(array(apply_filters('wpas_default_message', $this->default_message), 'title', 'url')); $this->default_prefix = Publicize_Util::build_sprintf(array(apply_filters('wpas_default_prefix', $this->default_prefix), 'url')); $this->default_suffix = Publicize_Util::build_sprintf(array(apply_filters('wpas_default_suffix', $this->default_suffix), 'url')); // stage 1 and 2 of 3-stage Publicize. Flag for Publicize on creation, save meta, // then check meta and publicze based on that. stage 3 implemented on wpcom add_action('transition_post_status', array($this, 'flag_post_for_publicize'), 10, 3); add_action('save_post', array(&$this, 'save_meta'), 20, 2); }