<?php
/*****************************************************************************************************************************************************
******************************************************************************************************************************************************

																		Custom Comments
																		
*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function reza_custom_comments( $comment, $args, $depth ) {
			global $smof_data,$post;

		$time_format = reza_option('time_format');	
	$GLOBALS['comment'] = $comment ;
 switch ( $comment->comment_type ) :
		case 'pingback' :
		case 'trackback' :
 	?>
	<li class="rd-pingback"><?php echo esc_html( reza_t('pingback')) ; ?> <?php comment_author_link(); ?><?php edit_comment_link( '('.reza_t('edit').')', '<span class="edit-link">', '</span>' ); ?>
	</li>
	<?php
	 	break;
		 default :
	?>
	<li id="comment-<?php comment_ID(); ?>">
		<div  <?php comment_class('comment-wrap'); ?> >
			<div class="comment-avatar"><div class="avater"><?php echo get_avatar( $comment, 70 ); ?></div></div>
			<div class="author-comment">
            			<div class="author-link">

				<?php printf(  '%s ', sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) );  
			 
				if (  $depth =='1'){}else {?>
 		 <div class="author-link-reply"><?php $pcom = get_comment($comment->comment_parent);?><a href="<?php echo get_comment_link($comment->comment_parent)?>">: @<?php echo esc_html($pcom->comment_author); ?></a></div><?php }?>
 
 	</div>
				<div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"><?php  	if(  $time_format == 'traditional'  ){	 
					printf( '%1$s '.esc_html(reza_t('at')).' %2$s', get_comment_date(),  get_comment_time() ); 

 				}else{
 						echo reza_number_replace(reza_elapsed_string( strtotime("{$comment->comment_date_gmt} GMT"))) ;
 
 				}
				?></a><?php edit_comment_link(  '('.reza_t('edit').')', ' ' ); ?></div><!-- .comment-meta .commentmetadata -->
			</div>
			<div class="clear"></div>
			<div class="comment-content rd-single-content">
				<?php if ( $comment->comment_approved == '0' ) : ?>
					<em class="comment-awaiting-moderation"><?php echo esc_html( reza_t('reza_t_yourcomment')); ?></em>
					<br />
				<?php endif; ?>
					
				<?php comment_text(); ?>
			</div>
			<div class="reply"><?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?></div><!-- .reply -->
		</div><!-- #comment-##  -->

	<?php
	 break;
	 endswitch;
}
/*****************************************************************************************************************************************************
******************************************************************************************************************************************************

																		Custom Pings
																		
*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function reza_custom_pings($comment, $args, $depth) {
    $GLOBALS['comment'] = $comment; ?>
	<li class="comment pingback">
		<p><?php echo esc_html( reza_t('reza_t_yourcomment')); ?><?php comment_author_link(); ?><?php edit_comment_link(   '('.reza_t('edit').')', ' ' ); ?></p>
<?php	
}
/*****************************************************************************************************************************************************
******************************************************************************************************************************************************

																		 Pings Back Header
																		
*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 function reza_pingback_header() {
	if ( is_singular() && pings_open() ) {
		printf( '<link rel="pingback" href="%s">' . "\n", get_bloginfo( 'pingback_url' ) );
	}
}
add_action( 'wp_head', 'reza_pingback_header' );

 
add_filter( 'comment_form_defaults','reza_comment_form_defaults');


 function reza_comment_form_defaults( $fields) {
	  if ( function_exists ( "is_woocommerce" )){
                    $link =  get_permalink( get_option('woocommerce_myaccount_page_id') );
                }else{
                    $link =  wp_login_url();
                }
	    $fields['must_log_in'] = sprintf( __( '<p class="must-log-in">برای نوشتن دیدگاه باید <a href="%s">وارد بشوید</a>.</p>','reza'),$link   );
    return $fields;
}

function reza_comment_reply_link($link, $args, $comment, $post) {
    // آدرس صفحه ورود ووکامرس را تنظیم کنید
 	  if ( function_exists ( "is_woocommerce" )){
                    $woocommerce_login_url =  get_permalink( get_option('woocommerce_myaccount_page_id') );
                }else{
                    $woocommerce_login_url =  wp_login_url();
                }
    $must_log_in = get_option('comment_registration');
    if ($must_log_in &&!is_user_logged_in()) {
        // تغییر لینک به صفحه ورود ووکامرس
        $link = '<a href="' . esc_url($woocommerce_login_url) . '">' . __('برای پاسخ دیدگاه باید وارد شوید', 'reza') . '</a>';
    }
    // بررسی کنید که آیا تنظیمات "برای ارسال دیدگاه باید وارد شوید" فعال است
 
    
    return $link;
}
 add_filter('comment_reply_link', 'reza_comment_reply_link', 10, 4);

/*****************************************************************************************************************************************************
******************************************************************************************************************************************************

																		 Elapesd Stings
																		
*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function reza_elapsed_string($ptime)
{
    $etime = time() - $ptime;

    if ($etime < 1)
    {
        return __('0 Second','reza');
    }

    $a = array( 365 * 24 * 60 * 60  => 'year' ,
                 30 * 24 * 60 * 60  => 'month' ,
                      24 * 60 * 60  => 'day' ,
                           60 * 60  => 'hour' ,
                                60  => 'minute' ,
                                 1  => 'second' ,
                );
    $a_dates = array( 'year'   => esc_html(reza_t('years')),
                       'month'  => esc_html(reza_t('months')),
                       'day'    => esc_html(reza_t('days')),
                       'hour'   => esc_html(reza_t('hours')),
                       'minute' => esc_html(reza_t('minutes' )),
                       'second' => esc_html(reza_t('seconds')),
                );
    $a_date = array( 'year'   => esc_html(reza_t('year')),
                       'month'  => esc_html(reza_t('month')),
                       'day'    => esc_html(reza_t('day')),
                       'hour'   => esc_html(reza_t('hour')),
                       'minute' => esc_html(reza_t('minute' )),
                       'second' => esc_html(reza_t('second')),
                );


    foreach ($a as $secs => $str)
    {
        $d = $etime / $secs;
        if ($d >= 1)
        {
            $r = round($d);
            return $r . ' ' . ($r > 1 ? $a_dates[$str] : $a_date[$str]) . " ". esc_html(reza_t('ago'));
        }
    }
}  