Example #1
0
 /**
  * Clean up provided shortcode values
  *
  * Be liberal in what we accept in shortcode syntax before constructing a Follow button
  *
  * @since 1.0.0
  *
  * @param array $attributes provided shortcode attributes {
  *   @type string shortcode attribute name
  *   @type mixed  shortcode attribute value
  * }
  *
  * @return array simplified shortcode values with defaults removed {
  *   @type string      shortcode attribute name
  *   @type bool|string shortcode attribute value
  * }
  */
 public static function sanitizeShortcodeParameters($attributes = array())
 {
     if (!is_array($attributes)) {
         return array();
     }
     $options = array();
     if (isset($attributes['screen_name'])) {
         $screen_name = \Twitter\Helpers\Validators\ScreenName::trim($attributes['screen_name']);
         if ($screen_name) {
             $options['screen_name'] = $screen_name;
         }
         unset($screen_name);
     }
     foreach (array('show_count', 'show_screen_name') as $falsey_option) {
         // check for falsey values passed to shortcode
         if (isset($attributes[$falsey_option])) {
             if (false === $attributes[$falsey_option] || '0' == $attributes[$falsey_option] || is_string($attributes[$falsey_option]) && in_array(strtolower($attributes[$falsey_option]), array('false', 'no', 'off'))) {
                 $options[$falsey_option] = false;
             }
         }
     }
     // large is the only option
     if (isset($attributes['size'])) {
         if (is_string($attributes['size']) && in_array(strtolower($attributes['size']), array('large', 'l'))) {
             $options['size'] = 'large';
         }
     }
     return $options;
 }
Example #2
0
 /**
  * Construct a new follow intent for the given Twitter screen name
  *
  * @since 1.0.0
  *
  * @param string $screen_name Twitter screen name
  * @param bool $validate      validate screen name matches Twitter username allowed characters and length before saving
  */
 public function __construct($screen_name, $validate = true)
 {
     $screen_name = \Twitter\Helpers\Validators\ScreenName::trim($screen_name);
     if ($screen_name) {
         if (false === $validate || \Twitter\Helpers\Validators\ScreenName::isValid($screen_name)) {
             $this->screen_name = $screen_name;
         }
     }
 }
Example #3
0
 /**
  * Clean up user inputted Twitter username value before saving the option
  *
  * @since 1.0.0
  *
  * @param string $screen_name inputted Twitter username value
  *
  * @return string sanitized Twitter username value
  */
 public static function sanitize($screen_name)
 {
     if (!is_string($screen_name)) {
         return '';
     }
     $screen_name = trim($screen_name);
     if (!$screen_name) {
         return '';
     }
     $screen_name = sanitize_text_field($screen_name);
     if (!$screen_name) {
         return '';
     }
     return \Twitter\Helpers\Validators\ScreenName::sanitize($screen_name);
 }
Example #4
0
 /**
  * Add a related Twitter account
  *
  * @since 1.0.0
  *
  * @param string $username Twitter username
  * @param string $label brief description of how the account relates to the Tweet content
  *
  * @return __CLASS__ support chaining
  */
 public function addRelated($username, $label = '')
 {
     $username = \Twitter\Helpers\Validators\ScreenName::trim($username);
     if ($username) {
         // normalize passed parameter
         $comparison_username = strtolower($username);
         if (!isset($this->related[$comparison_username])) {
             if ($this->validate_inputs) {
                 if (\Twitter\Helpers\Validators\ScreenName::isValid($username)) {
                     $this->related[$comparison_username] = trim($label);
                 }
             } else {
                 $this->related[$comparison_username] = trim($label);
             }
         }
     }
     return $this;
 }
Example #5
0
 /**
  * Set a Twitter screen_name for a Twitter account
  *
  * @since 1.0.0
  *
  * @param string $screen_name Twitter screen name
  *
  * @return self support chaining
  */
 public function setScreenName($screen_name)
 {
     if (!is_string($screen_name)) {
         return $this;
     }
     // remove any preceding @
     $screen_name = \Twitter\Helpers\Validators\ScreenName::trim($screen_name);
     if (!$screen_name) {
         return $this;
     }
     $this->screen_name = $screen_name;
     return $this;
 }
Example #6
0
 /**
  * Test sanitizing user-provided inputs into a simplified screen_name
  *
  * @since 1.0.0
  *
  * @covers ::sanitize
  * @small
  *
  * @dataProvider sanitizeInputProvider
  *
  * @param string $test_string input possibly in need of a cleanup
  * @param string $message message to display on test failure
  *
  * @return void
  */
 public function testSanitize($test_string, $message = '')
 {
     $this->assertEquals('jack', \Twitter\Helpers\Validators\ScreenName::sanitize($test_string), $message);
 }