Exemplo n.º 1
0
 function test_largo_fb_url_to_username()
 {
     /**
     * A short list of valid Facebook IDs:
     	https://www.facebook.com/Foo-bar.1
     			https://www.facebook.com/profile.php?id=012345678901234&fref=ts
     			https://www.facebook.com/Foo-bar.2?rf=012345678901234
     			https://www.facebook.com/pages/Foo-bar.3/012345678901234
     			https://m.facebook.com/Foo-bar.4?_e_pi_=7%2CPAGE_ID10%2C0123456789
     			https://m.facebook.com/profile.php?id=012345678901234
     			https://m.facebook.com/?_rdr#!/Foo-bar.5?__user=012345678901234
     */
     /**
      * With no input, it should return an empty string
      */
     $result = largo_fb_url_to_username("");
     $this->assertEquals("", $result);
     unset($result);
     /**
      * With a valid username, it should return that username
      */
     $result = largo_fb_url_to_username("Foo-bar.0");
     $this->assertEquals("Foo-bar.0", $result);
     unset($result);
     $result = largo_fb_url_to_username("012345678901234");
     $this->assertEquals("012345678901234", $result);
     unset($result);
     /**
      * With a valid URL, it should return the username
      */
     $result = largo_fb_url_to_username("https://www.facebook.com/Foo-bar.1");
     $this->assertEquals("Foo-bar.1", $result);
     unset($result);
     $result = largo_fb_url_to_username("https://www.facebook.com/profile.php?id=012345678901234&fref=ts");
     $this->assertEquals("012345678901234", $result);
     unset($result);
     $result = largo_fb_url_to_username("https://www.facebook.com/Foo-bar.2?rf=012345678901234");
     $this->assertEquals("Foo-bar.2", $result);
     unset($result);
     // For making a URL, Foo-bar.3 is a valid username, but so is the ID listed here.
     $result = largo_fb_url_to_username("https://www.facebook.com/pages/Foo-bar.3/012345678901234");
     $this->assertEquals("012345678901234", $result);
     unset($result);
     $result = largo_fb_url_to_username("https://m.facebook.com/Foo-bar.4?_e_pi_=7%2CPAGE_ID10%2C0123456789");
     $this->assertEquals("Foo-bar.4", $result);
     unset($result);
     $result = largo_fb_url_to_username("https://m.facebook.com/profile.php?id=012345678901234");
     $this->assertEquals("012345678901234", $result);
     unset($result);
     $result = largo_fb_url_to_username("https://m.facebook.com/?_rdr#!/Foo-bar.5?__user=012345678901234");
     $this->assertEquals("Foo-bar.5", $result);
     unset($result);
 }
Exemplo n.º 2
0
function validate_fb_username($errors, $update, $user)
{
    if (isset($_POST["fb"])) {
        $fb_suspect = trim($_POST["fb"]);
        if (!empty($fb_suspect)) {
            $fb_user = largo_fb_url_to_username($fb_suspect);
            if (preg_match('/[^a-zA-Z0-9\\.\\-]/', $fb_user)) {
                // it's not a valid Facebook username, because it uses an invalid character
                $errors->add('fb_username', '<b>' . $fb_suspect . '</b> ' . __('is an invalid Facebook username.') . '</p>' . '<p>' . __('Facebook usernames only use the uppercase and lowercase alphabet letters (a-z A-Z), the Arabic numbers (0-9), periods (.) and dashes (-)'));
            }
            if (!largo_fb_user_is_followable($fb_user)) {
                $errors->add('fb_username', ' <b>' . $fb_suspect . '</b> ' . __('does not allow followers on Facebook.') . '</p>' . '<p>' . __('<a href="https://www.facebook.com/help/201148673283205#How-can-I-let-people-follow-me?">Follow these instructions</a> to allow others to follow you.'));
            }
        }
    }
}
<ul class="social-links">
	<?php 
if ($fb = $author_obj->fb) {
    ?>
		<li class="facebook">
			<a href="https://facebook.com/<?php 
    echo largo_fb_url_to_username(esc_url($fb));
    ?>
" title="<?php 
    echo esc_attr($author_obj->display_name);
    ?>
 on Facebook" rel="me"><i class="icon-facebook"></i></a>
		</li>
	<?php 
}
?>

	<?php 
if ($twitter = $author_obj->twitter) {
    ?>
		<li class="twitter">
			<a href="https://twitter.com/<?php 
    echo largo_twitter_url_to_username($twitter);
    ?>
"><i class="icon-twitter"></i></a>
		</li>
	<?php 
}
?>

	<?php