Skip to content

Commit

Permalink
Много изменений, нет сил все рассписывать...
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsite committed Apr 20, 2015
1 parent ba17ad3 commit 25eb82b
Show file tree
Hide file tree
Showing 59 changed files with 6,127 additions and 1,040 deletions.
138 changes: 29 additions & 109 deletions application/maxsite/common/comments.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -178,55 +178,43 @@ function mso_get_comments($page_id = 0, $r = array())
} }


# парсер текста для комментариев # парсер текста для комментариев
function mso_comments_autotag($text, $commentator, $r) function mso_comments_autotag($text, $commentator = 3, $r = array('tags' => '<p><img><strong><em><i><b><u><s><pre><code><blockquote>', 'tags_comusers' => '<p><img><strong><em><i><b><u><s><pre><code><blockquote>', 'tags_users' => '<p><img><strong><em><i><b><u><s><pre><code><blockquote>'))
{ {
// раньше использовался mso_auto_tag теперь свой вариант // раньше использовался mso_auto_tag теперь свой вариант


// защитим pre
$text = str_replace('&lt;/pre>', '</pre>', $text); // проставим pre - исправление ошибки CodeIgniter

$text = preg_replace_callback('!<pre>(.*?)</pre>!is', '_comments_clean_html_do', $text);

if ($commentator==1) if ($commentator==1)
$text = strip_tags($text, $r['tags_comusers']); $text = strip_tags($text, $r['tags_comusers']);
elseif($commentator==2) elseif($commentator==2)
$text = strip_tags($text, $r['tags_users']); $text = strip_tags($text, $r['tags_users']);
else else
$text = strip_tags($text, $r['tags']); $text = strip_tags($text, $r['tags']);


$text = mso_xss_clean($text);

$text = str_replace('[html_base64]', '<pre>[html_base64]', $text); // проставим pre
$text = str_replace('[/html_base64]', '[/html_base64]</pre>', $text);


// обратная замена $text = mso_comments_content($text);
$text = preg_replace_callback('!\[html_base64\](.*?)\[\/html_base64\]!is', '_comments_clean_html_posle', $text);


// pr($text,1);

$text = mso_hook('comments_content', $text); $text = mso_hook('comments_content', $text);


$text = str_replace("\n", "<br>", $text); //$text = mso_hook('comments_content_out', $text);
$text = str_replace('<p>', '&lt;p&gt;', $text);
$text = str_replace('</p>', '&lt;/p&gt;', $text);
$text = str_replace('<P>', '&lt;P&gt;', $text);
$text = str_replace('</P>', '&lt;/P&gt;', $text);

$text = mso_hook('comments_content_out', $text);


return $text; return $text;
} }


function _comments_clean_html_do($matches)
{
$arr1 = array('&amp;', '&lt;', '&gt;', '<br />', '<br>', '&nbsp;');
$arr2 = array('&', '<', '>', "\n", "\n", ' ');
$m = trim( str_replace($arr1, $arr2, $matches[1]) );
$m = '[html_base64]' . base64_encode($m) . '[/html_base64]';
return $m;
}


function _comments_clean_html_posle($matches) function mso_comments_content($text = '')
{ {
return base64_decode($matches[1]); // текст комментария прогоняется через стандартный парсер
if ( !function_exists('parser_default_content') )
{
require_once(getinfo('plugins_dir') . 'parser_default/index.php');
}

$text = str_replace("\n", "<br>", $text); // обязательная замена

$text = parser_default_content($text);

return $text;
} }


# функция отправляет админу уведомление о новом комментарии # функция отправляет админу уведомление о новом комментарии
Expand Down Expand Up @@ -288,7 +276,6 @@ function mso_email_message_new_comment($id = 0, $data = array(), $page_title = '
elseif (isset($data['comments_comusers_id'])) elseif (isset($data['comments_comusers_id']))
{ {
$text .= tf('Комюзер'). ': id=' . $data['comments_comusers_id']; $text .= tf('Комюзер'). ': id=' . $data['comments_comusers_id'];



$CI->db->select('comusers_nik, comusers_email'); $CI->db->select('comusers_nik, comusers_email');
$CI->db->from('comusers'); $CI->db->from('comusers');
Expand Down Expand Up @@ -382,19 +369,18 @@ function mso_get_new_comment($args = array())
if ( !isset($args['xss_clean_die']) ) $args['xss_clean_die'] = false; if ( !isset($args['xss_clean_die']) ) $args['xss_clean_die'] = false;


// запрещенные слова как имя автора // запрещенные слова как имя автора
if ( !isset($args['noword']) ) $args['noword'] = array('.com', '.ru', '.net', '.org', '.info', '.ua', if ( !isset($args['noword']) )
'.su', '.name', '/', 'www.', 'http', ':', '-', '"', $args['noword'] = array('.com', '.ru', '.net', '.org', '.info', '.ua',
'«', '»', '%', '<', '>', '&', '*', '+', '\'' ); '.su', '.name', '/', 'www.', 'http', ':', '-', '"',
'«', '»', '%', '<', '>', '&', '*', '+', '\'' );


mso_hook('add_new_comment'); mso_hook('add_new_comment');



if (!mso_checksession($post['comments_session']) ) if (!mso_checksession($post['comments_session']) )
return '<div class="' . $args['css_error']. '">'. tf('Ошибка сессии! Обновите страницу'). '</div>'; return '<div class="' . $args['css_error']. '">'. tf('Ошибка сессии! Обновите страницу'). '</div>';


if (!$post['comments_page_id']) return '<div class="' . $args['css_error']. '">'. tf('Ошибка!'). '</div>'; if (!$post['comments_page_id']) return '<div class="' . $args['css_error']. '">'. tf('Ошибка!'). '</div>';



$comments_page_id = $post['comments_page_id']; $comments_page_id = $post['comments_page_id'];
$id = (int) $comments_page_id; $id = (int) $comments_page_id;
if ( (string) $comments_page_id != (string) $id ) $id = false; // $comments_page_id не число if ( (string) $comments_page_id != (string) $id ) $id = false; // $comments_page_id не число
Expand All @@ -419,19 +405,8 @@ function mso_get_new_comment($args = array())
// вычищаем от запрещенных тэгов // вычищаем от запрещенных тэгов
if ($args['tags']) if ($args['tags'])
{ {
// перед этим нужно все pre защитить
$t = $post['comments_content']; $t = $post['comments_content'];

$t = strip_tags($t, $args['tags']); // оставим только разрешенные тэги
$t = preg_replace_callback('!<pre>(.*?)</pre>!is', 'mso_clean_html_do', $t);

$t = strip_tags($t, $args['tags']); // теперь оставим только разрешенные тэги

$t = str_replace('[html_base64]', '<pre>[html_base64]', $t); // проставим pre
$t = str_replace('[/html_base64]', '[/html_base64]</pre>', $t);

// обратная замена
$t = preg_replace_callback('!\[html_base64\](.*?)\[\/html_base64\]!is', 'mso_clean_html_posle', $t);

$post['comments_content'] = $t; // сохраним как текст комментария $post['comments_content'] = $t; // сохраним как текст комментария
} }


Expand Down Expand Up @@ -651,7 +626,6 @@ function mso_get_new_comment($args = array())


if ($res) if ($res)
{ {

// сохраним в сессии время отправления комментария - используется в mso_last_activity_comment // сохраним в сессии время отправления комментария - используется в mso_last_activity_comment
$CI->session->set_userdata('last_activity_comment', time()); $CI->session->set_userdata('last_activity_comment', time());


Expand Down Expand Up @@ -867,10 +841,8 @@ function mso_get_new_comment($args = array())
} }
} }
} }
// else return '<div class="comment-new">Комментарий добавлен и возможно ожидает модерации.</div>';
} }



# получаем данные комюзера. # получаем данные комюзера.
# если id = 0, то номер получаем из сессии или текущего сегмента (2) # если id = 0, то номер получаем из сессии или текущего сегмента (2)
function mso_get_comuser($id = 0, $args = array()) function mso_get_comuser($id = 0, $args = array())
Expand Down Expand Up @@ -947,47 +919,7 @@ function mso_get_comuser($id = 0, $args = array())


foreach ($comments as $key=>$comment) foreach ($comments as $key=>$comment)
{ {
$comments_content = $comment['comments_content']; $comments[$key]['comments_content'] = mso_comments_content($comment['comments_content']);
// защитим pre
$t = $comments_content;
$t = str_replace('&lt;/pre>', '</pre>', $t); // проставим pre - исправление ошибки CodeIgniter

$t = preg_replace_callback('!<pre>(.*?)</pre>!is', 'mso_clean_html_do', $t);

$t = strip_tags($t, $args['tags']);

$t = mso_xss_clean($t);

$t = str_replace('[html_base64]', '<pre>[html_base64]', $t); // проставим pre
$t = str_replace('[/html_base64]', '[/html_base64]</pre>', $t);

// обратная замена
$t = preg_replace_callback('!\[html_base64\](.*?)\[\/html_base64\]!is', 'mso_clean_html_posle', $t);

$comments_content = $t; // сохраним как текст комментария

$comments_content = mso_hook('comments_content', $comments_content);

$comments_content = str_replace("\n", "<br>", $comments_content);

$comments_content = str_replace('<p>', '&lt;p&gt;', $comments_content);
$comments_content = str_replace('</p>', '&lt;/p&gt;', $comments_content);
$comments_content = str_replace('<P>', '&lt;P&gt;', $comments_content);
$comments_content = str_replace('</P>', '&lt;/P&gt;', $comments_content);

if (mso_hook_present('comments_content_custom'))
{
$comments_content = mso_hook('comments_content_custom', $comments_content);
}
else
{
$comments_content = mso_auto_tag($comments_content, true);
$comments_content = mso_hook('content_balance_tags', $comments_content);
}

$comments_content = mso_hook('comments_content_out', $comments_content);

$comments[$key]['comments_content'] = $comments_content;
} }


$comuser[0]['comments'] = $comments; $comuser[0]['comments'] = $comments;
Expand Down Expand Up @@ -1497,13 +1429,9 @@ function mso_comuser_lost($args = array())
} }
} }





# список всех комюзеров # список всех комюзеров
function mso_get_comusers_all($args = array()) function mso_get_comusers_all($args = array())
{ {

$cache_key = mso_md5('mso_get_comusers_all'); $cache_key = mso_md5('mso_get_comusers_all');
$k = mso_get_cache($cache_key); $k = mso_get_cache($cache_key);
if ($k) return $k; // да есть в кэше if ($k) return $k; // да есть в кэше
Expand Down Expand Up @@ -1569,8 +1497,6 @@ function mso_get_comusers_all($args = array())


$all_comments = $r_array; $all_comments = $r_array;




// добавляем в каждого комюзера элемент массива meta, comments и comments_pages_id // добавляем в каждого комюзера элемент массива meta, comments и comments_pages_id
$r_array = array(); $r_array = array();
foreach ($comusers as $key=>$val) foreach ($comusers as $key=>$val)
Expand Down Expand Up @@ -1603,12 +1529,6 @@ function mso_get_comusers_all($args = array())
return $comusers; return $comusers;
} }



function mso_comments_content($text = '')
{
return $text;
}

# рассылаем по email уведомление о новом комментарии # рассылаем по email уведомление о новом комментарии
function mso_email_message_new_comment_subscribe($data) function mso_email_message_new_comment_subscribe($data)
{ {
Expand Down Expand Up @@ -1677,7 +1597,6 @@ function mso_email_message_new_comment_subscribe($data)
} }
} }
} }

} }




Expand Down Expand Up @@ -1712,8 +1631,7 @@ function mso_comuser_auth($data)
if ($die) die(tf('Данный email уже используется на сайте админом или автором.')); if ($die) die(tf('Данный email уже используется на сайте админом или автором.'));
else return tf('Данный email уже используется на сайте админом или автором.'); else return tf('Данный email уже используется на сайте админом или автором.');
} }



// имя email и пароль нужно проверить, чтобы такие были в базе // имя email и пароль нужно проверить, чтобы такие были в базе
// вначале нужно проверить наличие такого email // вначале нужно проверить наличие такого email
// если есть, то сверяем и пароль // если есть, то сверяем и пароль
Expand Down Expand Up @@ -1889,7 +1807,7 @@ function mso_last_activity_comment()


# вывод аватарки комментатора # вывод аватарки комментатора
# на входе массив комментария из page-comments.php # на входе массив комментария из page-comments.php
function mso_avatar($comment, $img_add = 'style="float: left; margin: 5px 10px 10px 0;" class="gravatar"', $echo = false, $size = false) function mso_avatar($comment, $img_add = 'style="float: left; margin: 5px 10px 10px 0;" class="gravatar"', $echo = false, $size = false, $url_only = false)
{ {
extract($comment); extract($comment);


Expand Down Expand Up @@ -1939,8 +1857,10 @@ function mso_avatar($comment, $img_add = 'style="float: left; margin: 5px 10px 1
} }
} }


if ($avatar_url) if (!$url_only)
$avatar_url = '<img src="' . $avatar_url . '" width="' . $avatar_size . '" height="'. $avatar_size . '" alt="" title="" '. $img_add . '>'; {
if ($avatar_url) $avatar_url = '<img src="' . $avatar_url . '" width="' . $avatar_size . '" height="'. $avatar_size . '" alt="" title="" '. $img_add . '>';
}


if ($echo) echo $avatar_url; if ($echo) echo $avatar_url;
else return $avatar_url; else return $avatar_url;
Expand Down
47 changes: 41 additions & 6 deletions application/maxsite/common/common.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1527,11 +1527,18 @@ function mso_login_form($conf = array(), $redirect = '', $echo = true)
$hook_login_form_auth = '<div class="login-form-auth">' . str_replace(' ', ', ', $hook_login_form_auth) . '</div>'; $hook_login_form_auth = '<div class="login-form-auth">' . str_replace(' ', ', ', $hook_login_form_auth) . '</div>';
} }


// в loginform.php результат возвращается в $out if ($echo)
if ($fn = mso_find_ts_file('type/loginform/units/form.php')) require($fn); {

eval(mso_tmpl_ts('type/loginform/units/loginform-common-tmpl.php'));
if ($echo) echo $out; }
else return $out; else
{
ob_start();
eval(mso_tmpl_ts('type/loginform/units/loginform-common-tmpl.php'));
$out = ob_get_contents();
ob_end_clean();
return $out;
}
} }




Expand Down Expand Up @@ -4063,4 +4070,32 @@ function mso_add_file($fn)
} }
} }


# end file # HTML-шаблонизатор
# получает текст файла, выполняет замены, отдает php-код
# если $replace = true то в коде удаляются табуляторы и двойные \n
# код выполнять через eval();
# if (file_exists($fn)) eval(mso_tmpl($fn));
function mso_tmpl($fn, $replace = true)
{
$template = file_get_contents($fn);

$template = '?>' . str_replace(array('{{', '}}', '{%', '%}'), array('<?=', '?>', '<?php', '?>'), $template);

if ($replace)
$template = str_replace(array("\t", "\r", "\n\n"), array("", "", "\n"), $template);

return $template;
}

# HTML-шаблонизатор
# файл относительно шаблона/shared-каталога как в mso_find_ts_file()
# eval(mso_tmpl_ts('article-tmpl.php'));
function mso_tmpl_ts($fn, $replace = true)
{
if ($fn = mso_find_ts_file($fn))
return mso_tmpl($fn, $replace);
else
return '?>';
}

# end file
10 changes: 5 additions & 5 deletions application/maxsite/plugins/parser_default/default.php
Original file line number Original file line Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); <?php if (!defined('BASEPATH')) exit('No direct script access allowed');


# авторасстановка тэгов # авторасстановка тэгов
function autotag_default($pee, $pre_special_chars = false) function autotag_default($pee)
{ {
$pee = str_replace(array("\r\n", "\r"), "\n", $pee); $pee = str_replace(array("\r\n", "\r"), "\n", $pee);


if ( mso_hook_present('content_auto_tag_custom') ) // if ( mso_hook_present('content_auto_tag_custom') )
return mso_hook('content_auto_tag_custom', $pee); // return mso_hook('content_auto_tag_custom', $pee);


$pee = mso_hook('content_auto_tag_do', $pee); // $pee = mso_hook('content_auto_tag_do', $pee);


if ( // отдавать как есть - слово в начале текста if ( // отдавать как есть - слово в начале текста
( strpos($pee, '[volkman]') !== false and strpos(trim($pee), '[volkman]') == 0 ) ( strpos($pee, '[volkman]') !== false and strpos(trim($pee), '[volkman]') == 0 )
Expand Down Expand Up @@ -154,7 +154,7 @@ function autotag_default($pee, $pre_special_chars = false)
$pee = $pee . "\n"; $pee = $pee . "\n";


# кастомный автотэг # кастомный автотэг
$pee = mso_hook('content_auto_tag_my', $pee); // $pee = mso_hook('content_auto_tag_my', $pee);


// _pr($pee, true); # контроль // _pr($pee, true); # контроль


Expand Down
Loading

0 comments on commit 25eb82b

Please sign in to comment.