Exemplo n.º 1
0
function reformat($input, $max_word_size = 100, $cut = 0, $nolink = 0)
{
    $pat = array("/([^(http:\\/\\/)])(www\\.[^ \\<\\;\r\\(\\)\\.\\,]*)([\\; \\<\r\\(\\)\\,]?)/", "/ \\- /", "/ \\-- /", "/^(www\\.[^ \\<\\;\r\\(\\)\\.\\,]*)([\\; \\<\r\\(\\)\\,]?)/", "/\\&nbsp\\;/", "/\n/");
    $repl = array("\$1http://\$2\$3", " &#150; ", " &mdash; ", "http://\$1\$2", " ", "<br>");
    $out = preg_replace($pat, $repl, $input);
    if (!$nolink) {
        $out = preg_replace_callback("/(http:\\/\\/([^ \\<\\;\r\\(\\)\\,]*)([ \\<\r\\;\\(\\)\\.\\,]?))/", 'reformat_callback', $out);
    }
    if ($cut) {
        $out = preg_replace("'<cut[^>]*?>.*?</cut>'si", "", $out);
    } else {
        $out = preg_replace("'<[\\/\\!]*?cut[^>]*?>'si", "", $out);
    }
    if ($max_word_size) {
        $out = textWrap($out, $max_word_size, " ");
    }
    return $out;
}
Exemplo n.º 2
0
 }
 // Clean the posted variables
 $osid = preg_replace('#[^0-9]#', '', $_POST['sid']);
 $account_name = preg_replace('#[^a-z0-9]#i', '', $_POST['user']);
 $data = htmlentities($_POST['data']);
 $data = mysqli_real_escape_string($db_conx, $data);
 // Make sure account name exists (the profile being posted on)
 $sql = "SELECT COUNT(id) FROM users WHERE username='******' AND activated='1' LIMIT 1";
 $query = mysqli_query($db_conx, $sql);
 $row = mysqli_fetch_row($query);
 if ($row[0] < 1) {
     mysqli_close($db_conx);
     echo "{$account_no_exist}";
     exit;
 }
 $chopIt = textWrap($data);
 // Insert the status reply post into the database now
 $sql = "INSERT INTO status(osid, account_name, author, type, data, postdate)\n           VALUES('{$osid}','{$account_name}','{$log_username}','b','{$chopIt}',now())";
 $query = mysqli_query($db_conx, $sql);
 $id = mysqli_insert_id($db_conx);
 // Insert notifications for everybody in the conversation except this author
 $sql = "SELECT author FROM status WHERE osid='{$osid}' AND author!='{$log_username}' GROUP BY author";
 $query = mysqli_query($db_conx, $sql);
 while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
     $participant = $row["author"];
     $app = "Status Reply";
     $note = $log_username . ' commented here:<br /><a href="user.php?u=' . $account_name . '#status_' . $osid . '">Click here to view the conversation</a>';
     mysqli_query($db_conx, "INSERT INTO notifications(username, initiator, app, note, date_time)\n                     VALUES('{$participant}','{$log_username}','{$app}','{$note}',now())");
 }
 mysqli_close($db_conx);
 echo "reply_ok|{$id}";
Exemplo n.º 3
0
     } else {
         $result['success'] = true;
         $article = articles::getArticle($id, $uid);
         if (count($article['kwords']) > 0) {
             foreach ($article['kwords'] as $n => $val) {
                 $article['kwords'][$n]['name'] = iconv('CP1251', 'UTF-8', htmlspecialchars($val['name']));
             }
         }
         if ($article['logo']) {
             $article['logo_url'] = WDCPREFIX . '/' . $article['path'] . $article['fname'];
         }
         if ($page_view != 'view') {
             $article['short'] = reformat($article['short'], 50, 0, 0, 1);
             $article['short'] = iconv('CP1251', 'UTF-8', $article['short']);
         } else {
             $article['msgtext'] = textWrap(stripslashes($article['msgtext']), 70);
             $article['msgtext'] = iconv('CP1251', 'UTF-8', $article['msgtext']);
         }
         $article['title'] = reformat($article['title'], $page_view == 'view' ? 59 : 32, 0, 1);
         $article['title'] = iconv('CP1251', 'UTF-8', $article['title']);
         $result['article'] = $article;
         $result['page_view'] = $page_view;
     }
     echo json_encode($result);
     exit;
     break;
     /* получение одной статьи (для редактирования)*/
 /* получение одной статьи (для редактирования)*/
 case 'get-article':
     $result = array();
     $article = articles::getArticle($id, $uid);
Exemplo n.º 4
0
?>
            
            <h1><?php 
echo !$article['title'] ? 'Без названия' : reformat($article['title'], 59, 0, 1);
?>
</h1>
            
            <div class="interview-body utxt" id="interview" style="font-size: <?php 
echo $fs;
?>
px">
                <?php 
//=reformat($article['msgtext'], 55, 0, 0, 1)
?>
                <?php 
echo textWrap($article['msgtext'], 70);
?>
            </div>
            <?php 
if (($count_tags = count($article['kwords'])) > 0) {
    ?>
        <div class="b-tags">
        	<span class="b-tags__txt">Темы:</span>
        	<ul class="b-tags__list">
        	   <?php 
    foreach ($article['kwords'] as $n => $word) {
        ?>
 
        		<li class="b-tags__item"><a class="b-tags__link" href="/articles/?tag=<?php 
        echo $word['word_id'];
        ?>
Exemplo n.º 5
0
/**
 * Основная функция для форматирования текстов на выходе.
 *
 * @see textWrap()
 * @see reformat_callback()
 *
 * @param $input           string    исходный текст.
 * @param $max_word_size   integer   максимальное кол-во непробельных символов в слове (при превышении,
 *                                   слово рубится пробелами {@link textWrap()}).
 * @param $cut             boolean   обрабатывать ли тег <cut>:
 *                                   true: тег и все его содержимое заменяется на '...';
 *                                   false: убираем теги из исходного текста.
 * @param $nolink          boolean   формирование ссылок:
 *                                   1:  нельзя формировать ссылки (все вхождения http://www..... остаются просто текстом);
 *                                   0:  можно, содержащиеся в тексте URI оформаляются тегами <a>. Если
 *                                       это внутренний адрес, то ссылка прямая, иначе формируется адрес
 *                                       промежуточной страницы ({@link reformat_callback()}).
 *                                   -1: При включенном {@link globals.php HYPER_LINKS} можно использовать
 *                                       спец. формат, для вывода гипер-ссылок. В данном случае ссылка тоже всегда прямая.
 * @param $space           boolean   если true, то обрабатывается последовательность в два пробела (см. внутрь).
 * @param $max_link_len    integer   на каком символе обрезать хвост текста ссылки и заменять
 *                                   его на '...'. Имеет значение только при $nolink==false.
 * @return string                    отформатированный текст.
 */
function reformat($input, $max_word_size = 100, $cut = 0, $nolink = 0, $space = 0, $max_link_len = 25, $is_wysiwyg = false)
{
    $out = wysiwyg_video_replace($input, $wysiwyg_videos, true);
    $out = wysiwyg_image_replace($out, $wysiwyg_images, true);
    //сохранить в $wysiwyg_images изображения с классом wysiwyg_images
    $out = wysiwyg_code_replace($out, $wysiwyg_codes);
    $out = str_replace(array(' - ', ' -- ', "\r\n", "\n"), array(' &#150; ', ' &mdash; ', ' <br />', ' <br />'), $out);
    $out = str_replace("\r", ' <br />', $out);
    //в постах блогов переносы текста почему-то работают только так
    // Все что обрамлено как код в визивиге там мы не режем ничего и не заменяем на ссылки #0016101
    /*list($out, $code) = str_replace_mask('#((<p\sclass="code.*?>)(.*?)(<\/p>))#mix', $out);
      $code = str_replace("\n", "<br />", $code);*/
    if (!$is_wysiwyg) {
        $out = str_replace('&nbsp;', ' ', $out);
    }
    if ($cut) {
        $out = preg_replace('~<cut[^>]*?>.*?(?:</cut>|$)~si', '... ', $out);
        // обязательно пробел на конце, чтобы ссылки не испортить (http://zzz.com...textпослеcut).
        $out = preg_replace('~<\\!-- -W-EDITOR-CUT- -->.*?$~si', '... ', $out);
    } else {
        $out = preg_replace('~<[/!]*cut[^>]*>~i', ' ', $out);
        $out = preg_replace('~<\\!-- -W-EDITOR-CUT- -->~si', ' ', $out);
    }
    if ($nolink <= 0) {
        $GLOBALS['reformat.max_link_len'] = $max_link_len;
        $GLOBALS['reformat.can_hyper'] = $nolink == -1;
        $hre = HYPER_LINKS ? '{([^}]+)}' : '()';
        // отключается в globals.php.
        // сначала обрабатываем все ссылки обрамленные тегами <a>
        $out = preg_replace_callback('~<a[^>]+?href=\\"(https?:/(' . $hre . ')?/|www\\.)(([\\da-z-_а-яёА-ЯЁ]+\\.)*([a-zа-я]{2,15})(:\\d+)?([/?#][^"\\s<]*)*)\\"[^>]*?>.*?</a>~i', 'reformat_callback', $out);
        list($out, $url) = str_replace_mask('#((<a[^>]*>)(.*?)(<\\/a>))#mix', $out);
        $out = preg_replace_callback('~(https?:/(' . $hre . ')?/|www\\.)(([\\da-z-_а-яёА-ЯЁ]+\\.)*([a-zа-я]{2,15})(:\\d+)?([/?#][^"\\s<]*)*)~i', 'reformat_callback', $out);
        $out = str_unreplace_mask($url, $out);
    }
    if ($max_word_size) {
        $out = textWrap($out, $max_word_size);
    }
    if ($space) {
        $mx = 7;
        do {
            $out = str_replace('  ', '&nbsp; ', $out, $cnt);
        } while ($cnt && --$mx >= 0);
        if ($out[0] == ' ') {
            $out = '&nbsp;' . substr($out, 1);
        }
    }
    // #0016101
    //$out = str_unreplace_mask($code, $out);
    $out = wysiwyg_code_restore($out, $wysiwyg_codes);
    $out = wysiwyg_image_restore($out, $wysiwyg_images);
    //вернуть изображения с классом wysiwyg_images
    $out = wysiwyg_video_restore($out, $wysiwyg_videos);
    return $out;
}
Exemplo n.º 6
0
 /**
  * Конвертирует plain text в HTML
  * 
  * @param   string   $text    исходный текст
  * @param   boolean  $body    если 1, то ссылки обрабатываться не будут
  * @return  string            html-сообщение.
  */
 public function ToHtml($text, $nolink = 0)
 {
     $text = str_replace(array("<", ">", "'", "\"", ' - ', ' -- ', "\n"), array("&lt;", "&gt;", "&#039;", "&quot;", ' &#150; ', ' &mdash; ', ' <br/>'), $text);
     $text = preg_replace('~(https?:/){[^}]+}/~', '$1/', $text);
     // чистим шаблоны гиперссылок.
     if (!$nolink) {
         $text = preg_replace_callback("/((https?\\:\\/\\/|www\\.)[-a-zA-Zа-яА-ЯёЁ0-9\\.]+\\.[a-zA-Zа-яА-ЯёЁ]{2,30}(?:\\/[^\\s]+)?)/", array($this, 'ToHtml_callback'), $text);
         $text = preg_replace("/([-_a-zA-Z0-9\\.]+?\\@[-a-zA-Zа-яА-ЯёЁ0-9\\.]+\\.[a-zA-Zа-яА-ЯёЁ]{2,30})/", "<a href='mailto:\$1'>\$1</a>", $text);
     }
     $text = textWrap($text, 76);
     return $text;
 }