Ejemplo n.º 1
0
 public function testIsNormalLink()
 {
     $this->assertTrue(is_normal_link('http://ya.ru/hello.txt'));
     $this->assertTrue(is_normal_link('https://ya.ru/hello.txt'));
     $this->assertTrue(is_normal_link('HTTP://ya.ru/hello.txt'));
     $this->assertFalse(is_normal_link('//ya.ru/hello.txt'));
     $this->assertFalse(is_normal_link('mailto:bubujka@ya.ru'));
 }
Ejemplo n.º 2
0
 * Это ссылка на сайт?
 */
def('is_normal_link', function ($href) {
    return !!preg_match('@^https?:@i', $href);
});
/**
 * Это ссылка на мыло?
 */
def('is_email_link', function ($href) {
    return !!preg_match('@^mailto:@i', $href);
});
/**
 * Взять ссылку и обернуть в <a>, если это целесообразно
 */
def('nice_link', function ($href) {
    if (is_normal_link($href)) {
        $name = parse_url($href, PHP_URL_HOST);
    } elseif (is_email_link($href)) {
        $name = str_replace('mailto:', '', $href);
    } elseif (is_man_link($href)) {
        return $href;
    } else {
        return $href;
    }
    return '<a href="' . $href . '">' . $name . '</a>';
});
/**
 * Узнать сколько примеров в базе
 */
def('count_examples', function () {
    return trim(`cd data; find * -type f -name '[0-9]*' | wc -l`);