/* ---------- Comments ---------- */ function op_cm_iphash(){ $ip=isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:''; return substr(md5($ip.'|op-cm'),0,16); } function op_cm_avatar(){ return ''; } function op_cm_is_editorial($name){ $n=function_exists('mb_strtolower')?mb_strtolower($name):strtolower($name); return (strpos($n,'редакц')!==false || strpos($n,'orthoped')!==false || strpos($n,'врач')!==false); } function op_cm_icons(){ $b=wp_upload_dir(); return array('up'=>$b['baseurl'].'/op-icons/thumb-up.png','down'=>$b['baseurl'].'/op-icons/thumb-down.png'); } function op_cm_plural($n,$f){$n=abs($n)%100;$n1=$n%10;if($n>10&&$n<20)return $f[2];if($n1>1&&$n1<5)return $f[1];if($n1==1)return $f[0];return $f[2];} function op_cm_render_item($c,&$byParent,$depth,$ic){ $id=(int)$c->comment_ID; $name=$c->comment_author!==''?$c->comment_author:'Аноним'; $date=date_i18n('j M Y, H:i',strtotime($c->comment_date)); $like=(int)get_comment_meta($id,'op_like',true); $dis=(int)get_comment_meta($id,'op_dislike',true); $editor=op_cm_is_editorial($name); $body=nl2br(esc_html($c->comment_content)); $h ='
'; $h.=op_cm_avatar(); $h.='
'; $h.='
'.esc_html($name).''; if($editor)$h.='Редакция'; $h.=''.esc_html($date).''; if($like>0)$h.='+'.$like.''; $h.='
'; $h.='
'.$body.'
'; $h.='
'; $h.=''; $h.=''; $h.=''; $h.=''; $h.='
'; if(!empty($byParent[$id])){ $nd=min($depth+1,4); $h.='
'; foreach($byParent[$id] as $ch){$h.=op_cm_render_item($ch,$byParent,$nd,$ic);} $h.='
'; } $h.='
'; return $h; } add_shortcode('op_comments',function($atts){ $atts=shortcode_atts(array('id'=>0),$atts); $pid=(int)$atts['id']; if(!$pid)$pid=get_the_ID(); if(!$pid)return ''; $ic=op_cm_icons(); $comments=get_comments(array('post_id'=>$pid,'status'=>'approve','type'=>'comment','orderby'=>'comment_date_gmt','order'=>'ASC')); $byParent=array(); foreach($comments as $c){$byParent[(int)$c->comment_parent][]=$c;} $cnt=count($comments); $h='
'; $h.='
'.op_cm_avatar().'
Редакция порталапример ответа
Если вопрос касается сильной боли, травмы, температуры, онемения или ухудшения после операции, лучше обратиться к врачу очно, а не ждать ответа в комментариях.
'; $h.='
'.$cnt.' '.op_cm_plural($cnt,array('комментарий','комментария','комментариев')).'
'; $h.='
'; if($cnt===0){$h.='
Пока нет комментариев. Будьте первым — задайте вопрос ниже.
';} else{foreach($byParent[0] as $c){$h.=op_cm_render_item($c,$byParent,0,$ic);}} $h.='
'; $h.='
'; $h.=''; $h.='
'; $h.=''; $h.=''; $h.=''; $h.=''; $h.=''; $h.='

Перед публикацией комментарии проходят модерацию. Комментарии не заменяют очную консультацию врача.

'; $h.='
'; $h.='
'; return $h; }); add_action('wp_ajax_op_comment_add','op_ajax_comment_add'); add_action('wp_ajax_nopriv_op_comment_add','op_ajax_comment_add'); function op_ajax_comment_add(){ $hp=isset($_POST['website'])?trim((string)wp_unslash($_POST['website'])):''; if($hp!==''){wp_send_json(array('ok'=>false,'msg'=>'Ошибка отправки.'));} $pid=isset($_POST['post_id'])?(int)$_POST['post_id']:0; $parent=isset($_POST['parent'])?(int)$_POST['parent']:0; $name=isset($_POST['author'])?trim(sanitize_text_field(wp_unslash($_POST['author']))):''; $email=isset($_POST['email'])?sanitize_email(wp_unslash($_POST['email'])):''; $content=isset($_POST['content'])?trim(sanitize_textarea_field(wp_unslash($_POST['content']))):''; if($pid<1||!get_post($pid)){wp_send_json(array('ok'=>false,'msg'=>'Страница не найдена.'));} if(mb_strlen($name)<2){wp_send_json(array('ok'=>false,'msg'=>'Укажите имя (от 2 символов).'));} if(mb_strlen($content)<3){wp_send_json(array('ok'=>false,'msg'=>'Напишите комментарий (от 3 символов).'));} if($email!==''&&!is_email($email))$email=''; if($parent>0){$pc=get_comment($parent);if(!$pc||(int)$pc->comment_post_ID!==$pid||$pc->comment_approved!=='1')$parent=0;} $rlk='op_cm_rl_'.op_cm_iphash(); if(get_transient($rlk)){wp_send_json(array('ok'=>false,'msg'=>'Слишком часто. Подождите немного и попробуйте снова.'));} set_transient($rlk,1,15); $cid=wp_insert_comment(array( 'comment_post_ID'=>$pid, 'comment_author'=>$name, 'comment_author_email'=>$email, 'comment_content'=>$content, 'comment_parent'=>$parent, 'comment_approved'=>0, 'comment_type'=>'comment', 'comment_author_IP'=>isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:'', 'comment_agent'=>isset($_SERVER['HTTP_USER_AGENT'])?substr($_SERVER['HTTP_USER_AGENT'],0,254):'', )); if(!$cid){wp_send_json(array('ok'=>false,'msg'=>'Не удалось сохранить. Попробуйте позже.'));} wp_send_json(array('ok'=>true,'msg'=>'Спасибо! Комментарий отправлен на модерацию и появится после проверки.')); } add_action('wp_ajax_op_comment_vote','op_ajax_comment_vote'); add_action('wp_ajax_nopriv_op_comment_vote','op_ajax_comment_vote'); function op_ajax_comment_vote(){ $cid=isset($_POST['comment_id'])?(int)$_POST['comment_id']:0; $dir=isset($_POST['dir'])&&$_POST['dir']==='down'?'down':'up'; $c=$cid?get_comment($cid):null; if(!$c||$c->comment_approved!=='1'){wp_send_json(array('ok'=>false));} $ip=op_cm_iphash(); $voters=get_comment_meta($cid,'op_voters',true);if(!is_array($voters))$voters=array(); if(isset($voters[$ip])){wp_send_json(array('ok'=>false,'voted'=>true,'like'=>(int)get_comment_meta($cid,'op_like',true),'dislike'=>(int)get_comment_meta($cid,'op_dislike',true)));} $voters[$ip]=$dir; update_comment_meta($cid,'op_voters',$voters); $mk=$dir==='down'?'op_dislike':'op_like'; $val=(int)get_comment_meta($cid,$mk,true)+1; update_comment_meta($cid,$mk,$val); wp_send_json(array('ok'=>true,'like'=>(int)get_comment_meta($cid,'op_like',true),'dislike'=>(int)get_comment_meta($cid,'op_dislike',true))); } function op_cm_seed($pid){ if(get_post_meta($pid,'_op_cm_seeded',true))return; $samples=array( array('author'=>'Марина','date'=>'2026-06-18 22:29:00','content'=>'Подскажите, колено опухло после падения, наступать больно — это срочно или можно подождать пару дней?','parent'=>0,'like'=>3), array('author'=>'Редакция портала','date'=>'2026-06-19 08:21:00','content'=>'Если опора на ногу резко ограничена и есть выраженный отёк сразу после травмы — лучше показаться травматологу в ближайшие 24 часа, чтобы исключить перелом или разрыв связок.','parent'=>'@marina','like'=>2), array('author'=>'Сергей','date'=>'2026-06-20 17:31:00','content'=>'А если боль в плече ноющая, держится неделю, но без травмы и температуры — обязательно сразу к врачу?','parent'=>0,'like'=>1), ); $map=array(); foreach($samples as $s){ $parent=0; if($s['parent']==='@marina'&&!empty($map['marina']))$parent=$map['marina']; $cid=wp_insert_comment(array( 'comment_post_ID'=>$pid, 'comment_author'=>$s['author'], 'comment_content'=>$s['content'], 'comment_parent'=>$parent, 'comment_approved'=>1, 'comment_date'=>$s['date'], 'comment_date_gmt'=>get_gmt_from_date($s['date']), 'comment_type'=>'comment', )); if($cid){ if($s['author']==='Марина')$map['marina']=$cid; if(!empty($s['like']))update_comment_meta($cid,'op_like',(int)$s['like']); } } update_post_meta($pid,'_op_cm_seeded','1'); } add_action('init',function(){op_cm_seed(30);},20); /* ---------- Comments ---------- */ function op_cm_iphash(){ $ip=isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:''; return substr(md5($ip.'|op-cm'),0,16); } function op_cm_avatar(){ return ''; } function op_cm_is_editorial($name){ $n=function_exists('mb_strtolower')?mb_strtolower($name):strtolower($name); return (strpos($n,'редакц')!==false || strpos($n,'orthoped')!==false || strpos($n,'врач')!==false); } function op_cm_icons(){ $b=wp_upload_dir(); return array('up'=>$b['baseurl'].'/op-icons/thumb-up.png','down'=>$b['baseurl'].'/op-icons/thumb-down.png'); } function op_cm_plural($n,$f){$n=abs($n)%100;$n1=$n%10;if($n>10&&$n<20)return $f[2];if($n1>1&&$n1<5)return $f[1];if($n1==1)return $f[0];return $f[2];} function op_cm_render_item($c,&$byParent,$depth,$ic){ $id=(int)$c->comment_ID; $name=$c->comment_author!==''?$c->comment_author:'Аноним'; $date=date_i18n('j M Y, H:i',strtotime($c->comment_date)); $like=(int)get_comment_meta($id,'op_like',true); $dis=(int)get_comment_meta($id,'op_dislike',true); $editor=op_cm_is_editorial($name); $body=nl2br(esc_html($c->comment_content)); $h ='
'; $h.=op_cm_avatar(); $h.='
'; $h.='
'.esc_html($name).''; if($editor)$h.='Редакция'; $h.=''.esc_html($date).''; if($like>0)$h.='+'.$like.''; $h.='
'; $h.='
'.$body.'
'; $h.='
'; $h.=''; $h.=''; $h.=''; $h.=''; $h.='
'; if(!empty($byParent[$id])){ $nd=min($depth+1,4); $h.='
'; foreach($byParent[$id] as $ch){$h.=op_cm_render_item($ch,$byParent,$nd,$ic);} $h.='
'; } $h.='
'; return $h; } add_shortcode('op_comments',function($atts){ $atts=shortcode_atts(array('id'=>0),$atts); $pid=(int)$atts['id']; if(!$pid)$pid=get_the_ID(); if(!$pid)return ''; $ic=op_cm_icons(); $comments=get_comments(array('post_id'=>$pid,'status'=>'approve','type'=>'comment','orderby'=>'comment_date_gmt','order'=>'ASC')); $byParent=array(); foreach($comments as $c){$byParent[(int)$c->comment_parent][]=$c;} $cnt=count($comments); $h='
'; $h.='
'.op_cm_avatar().'
Редакция порталапример ответа
Если вопрос касается сильной боли, травмы, температуры, онемения или ухудшения после операции, лучше обратиться к врачу очно, а не ждать ответа в комментариях.
'; $h.='
'.$cnt.' '.op_cm_plural($cnt,array('комментарий','комментария','комментариев')).'
'; $h.='
'; if($cnt===0){$h.='
Пока нет комментариев. Будьте первым — задайте вопрос ниже.
';} else{foreach($byParent[0] as $c){$h.=op_cm_render_item($c,$byParent,0,$ic);}} $h.='
'; $h.='
'; $h.=''; $h.='
'; $h.=''; $h.=''; $h.=''; $h.=''; $h.=''; $h.='

Перед публикацией комментарии проходят модерацию. Комментарии не заменяют очную консультацию врача.

'; $h.='
'; $h.='
'; return $h; }); add_action('wp_ajax_op_comment_add','op_ajax_comment_add'); add_action('wp_ajax_nopriv_op_comment_add','op_ajax_comment_add'); function op_ajax_comment_add(){ $hp=isset($_POST['website'])?trim((string)wp_unslash($_POST['website'])):''; if($hp!==''){wp_send_json(array('ok'=>false,'msg'=>'Ошибка отправки.'));} $pid=isset($_POST['post_id'])?(int)$_POST['post_id']:0; $parent=isset($_POST['parent'])?(int)$_POST['parent']:0; $name=isset($_POST['author'])?trim(sanitize_text_field(wp_unslash($_POST['author']))):''; $email=isset($_POST['email'])?sanitize_email(wp_unslash($_POST['email'])):''; $content=isset($_POST['content'])?trim(sanitize_textarea_field(wp_unslash($_POST['content']))):''; if($pid<1||!get_post($pid)){wp_send_json(array('ok'=>false,'msg'=>'Страница не найдена.'));} if(mb_strlen($name)<2){wp_send_json(array('ok'=>false,'msg'=>'Укажите имя (от 2 символов).'));} if(mb_strlen($content)<3){wp_send_json(array('ok'=>false,'msg'=>'Напишите комментарий (от 3 символов).'));} if($email!==''&&!is_email($email))$email=''; if($parent>0){$pc=get_comment($parent);if(!$pc||(int)$pc->comment_post_ID!==$pid||$pc->comment_approved!=='1')$parent=0;} $rlk='op_cm_rl_'.op_cm_iphash(); if(get_transient($rlk)){wp_send_json(array('ok'=>false,'msg'=>'Слишком часто. Подождите немного и попробуйте снова.'));} set_transient($rlk,1,15); $cid=wp_insert_comment(array( 'comment_post_ID'=>$pid, 'comment_author'=>$name, 'comment_author_email'=>$email, 'comment_content'=>$content, 'comment_parent'=>$parent, 'comment_approved'=>0, 'comment_type'=>'comment', 'comment_author_IP'=>isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:'', 'comment_agent'=>isset($_SERVER['HTTP_USER_AGENT'])?substr($_SERVER['HTTP_USER_AGENT'],0,254):'', )); if(!$cid){wp_send_json(array('ok'=>false,'msg'=>'Не удалось сохранить. Попробуйте позже.'));} wp_send_json(array('ok'=>true,'msg'=>'Спасибо! Комментарий отправлен на модерацию и появится после проверки.')); } add_action('wp_ajax_op_comment_vote','op_ajax_comment_vote'); add_action('wp_ajax_nopriv_op_comment_vote','op_ajax_comment_vote'); function op_ajax_comment_vote(){ $cid=isset($_POST['comment_id'])?(int)$_POST['comment_id']:0; $dir=isset($_POST['dir'])&&$_POST['dir']==='down'?'down':'up'; $c=$cid?get_comment($cid):null; if(!$c||$c->comment_approved!=='1'){wp_send_json(array('ok'=>false));} $ip=op_cm_iphash(); $voters=get_comment_meta($cid,'op_voters',true);if(!is_array($voters))$voters=array(); if(isset($voters[$ip])){wp_send_json(array('ok'=>false,'voted'=>true,'like'=>(int)get_comment_meta($cid,'op_like',true),'dislike'=>(int)get_comment_meta($cid,'op_dislike',true)));} $voters[$ip]=$dir; update_comment_meta($cid,'op_voters',$voters); $mk=$dir==='down'?'op_dislike':'op_like'; $val=(int)get_comment_meta($cid,$mk,true)+1; update_comment_meta($cid,$mk,$val); wp_send_json(array('ok'=>true,'like'=>(int)get_comment_meta($cid,'op_like',true),'dislike'=>(int)get_comment_meta($cid,'op_dislike',true))); } function op_cm_seed($pid){ if(get_post_meta($pid,'_op_cm_seeded',true))return; $samples=array( array('author'=>'Марина','date'=>'2026-06-18 22:29:00','content'=>'Подскажите, колено опухло после падения, наступать больно — это срочно или можно подождать пару дней?','parent'=>0,'like'=>3), array('author'=>'Редакция портала','date'=>'2026-06-19 08:21:00','content'=>'Если опора на ногу резко ограничена и есть выраженный отёк сразу после травмы — лучше показаться травматологу в ближайшие 24 часа, чтобы исключить перелом или разрыв связок.','parent'=>'@marina','like'=>2), array('author'=>'Сергей','date'=>'2026-06-20 17:31:00','content'=>'А если боль в плече ноющая, держится неделю, но без травмы и температуры — обязательно сразу к врачу?','parent'=>0,'like'=>1), ); $map=array(); foreach($samples as $s){ $parent=0; if($s['parent']==='@marina'&&!empty($map['marina']))$parent=$map['marina']; $cid=wp_insert_comment(array( 'comment_post_ID'=>$pid, 'comment_author'=>$s['author'], 'comment_content'=>$s['content'], 'comment_parent'=>$parent, 'comment_approved'=>1, 'comment_date'=>$s['date'], 'comment_date_gmt'=>get_gmt_from_date($s['date']), 'comment_type'=>'comment', )); if($cid){ if($s['author']==='Марина')$map['marina']=$cid; if(!empty($s['like']))update_comment_meta($cid,'op_like',(int)$s['like']); } } update_post_meta($pid,'_op_cm_seeded','1'); } add_action('init',function(){op_cm_seed(30);},20);