Поддержка Плагины [Плагин: Born On This Day] поменять местами дату и имя формат

  • Поскольку пока что с автором не получается связаться, прошу помощи у вас:
    плагин — http://wordpress.org/extend/plugins/born-on-this-day/
    помогите пжлст сделать:
    а) изменить формат даты на — (дд.мм.гггг)
    б) поменять местами аргументы на — имя (дата)
    итого (например) — Anton Rodgers (10.01.1933)

    вот код самого /wp-content/plugins/born-on-this-day/born-on-this-day.php

    <?php
    
    /*
     *
     *	Plugin Name: Born On This Day
     *	Plugin URI: http://www.joeswebtools.com/wordpress-plugins/born-on-this-day/
     *	Description: Adds a sidebar widget that display famous people born on this day in history.
     *	Version: 2.0
     *	Author: Joe's Web Tools
     *	Author URI: http://www.joeswebtools.com/
     *
     *	Copyright (c) 2009 Joe's Web Tools. All Rights Reserved.
     *
     *	This program is free software; you can redistribute it and/or modify
     *	it under the terms of the GNU General Public License as published by
     *	the Free Software Foundation; either version 2 of the License, or
     *	(at your option) any later version.
     *
     *	This program is distributed in the hope that it will be useful,
     *	but WITHOUT ANY WARRANTY; without even the implied warranty of
     *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     *	GNU General Public License for more details.
     *
     *	You should have received a copy of the GNU General Public License
     *	along with this program; if not, write to the Free Software
     *	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
     *
     *	If you are unable to comply with the terms of this license,
     *	contact the copyright holder for a commercial license.
     *
     *	We kindly ask that you keep links to Joe's Web Tools so
     *	other people can find out about this plugin.
     *
     */
    
    /*
     *
     *	born_on_this_day_shortcode_handler
     *
     */
    
    function born_on_this_day_shortcode_handler($atts, $content = nul) {
    
    	// Load language file
    	$current_locale = get_locale();
    	if(!empty($current_locale)) {
    		$mo_file = dirname(__FILE__) . '/languages/born-on-this-day-' . $current_locale . ".mo";
    		if(@file_exists($mo_file) && is_readable($mo_file)) {
    			load_textdomain('born-on-this-day', $mo_file);
    		}
    	}
    
    	// Prepare the date
    	$current_date = date_i18n(get_option('date_format'), strtotime('now'));
    	$current_date = '<strong>' . $current_date . '</strong><br />';
    
    	// Prepare the people
    	$month_array = file(dirname(__FILE__) . '/data/' . date('n') . '.dat');
    	$day = date('j');
    	$day_line = $month_array[$day + 3];
    	$day_array = explode('<month>', $day_line);
    	$people_array = explode('<name>', $day_array[1]);
    	for($i = 0; $i < sizeof($people_array); $i++) {
    		$person_array = explode('<year>', $people_array[$i]);
    		$people .= $person_array[0] . ' ' . $person_array[1] . '<br />';
    	}
    
    	// Display
    	$content = '<table style="border-width: thin thin thin thin; border-style: solid solid solid solid;">';
    	$content .= '<thead><tr><th><center><font face="arial" size="+1"><b>' . __('Born on this day', 'born-on-this-day') . '</b></center></font></th></tr></thead>';
    	$content .= '<tbody><tr><td>';
    
    	$content .= '<div style="text-align: left;">';
    	$content .= $current_date;
    	$content .= $people;
    	$content .= '</div>';
    
    	$content .= '</td></tr></tbody>';
    	$content .= '<tfoot><tr><td><div style="text-align: right;"><font face="arial" size="-3"><a href="http://www.ka81.com/">ka81\'s</a></font></div></td></tr></tfoot>';
    	$content .= '</table>';
    
    	return $content;
    }
    
    add_shortcode('born-on-this-day', 'born_on_this_day_shortcode_handler');
    
    /*
     *
     *	WP_Widget_Born_On_This_Day
     *
     */
    
    class WP_Widget_Born_On_This_Day extends WP_Widget {
    
    	function WP_Widget_Born_On_This_Day() {
    
    		parent::WP_Widget(false, $name = 'Born On This Day');
    	}
    
    	function widget($args, $instance) {
    
    		// Load language file
    		$current_locale = get_locale();
    		if(!empty($current_locale)) {
    			$mo_file = dirname(__FILE__) . '/languages/born-on-this-day-' . $current_locale . ".mo";
    			if(@file_exists($mo_file) && is_readable($mo_file)) {
    				load_textdomain('born-on-this-day', $mo_file);
    			}
    		}
    
    		// Get options
    		extract($args);
    		$option_title = apply_filters('widget_title', empty($instance['title']) ? __('Born on this day', 'born-on-this-day') : $instance['title']);
    		$option_alignment = empty($instance['alignment']) ? 'left' : $instance['alignment'];
    		$option_date_style = empty($instance['date_style']) ? 'bold' : $instance['date_style'];
    
    		// Prepare the date
    		$current_date = date_i18n(get_option('date_format'), strtotime('now'));
    		switch($option_date_style) {
    			case 'bold':
    				$current_date = '<strong>' . $current_date . '</strong><br />';
    				break;
    			case 'bold_italic':
    				$current_date = '<strong><em>' . $current_date . '</em></strong><br />';
    				break;
    			case 'italic':
    				$current_date = '<em>' . $current_date . '</em><br />';
    				break;
    			case 'regular':
    				$current_date .= '<br />';
    				break;
    		}
    
    		// Prepare the people
    		$month_array = file(dirname(__FILE__) . '/data/' . date('n') . '.dat');
    		$day = date('j');
    		$day_line = $month_array[$day + 3];
    		$day_array = explode('<month>', $day_line);
    		$people_array = explode('<name>', $day_array[1]);
    
    		// Help widget to conform to the active theme: before_widget, before_title and after_title
    		echo $before_widget;
    		echo $before_title . $option_title . $after_title;
    
    		if($option_alignment == 'right') {
    
    			echo '<div style="text-align: right;">';
    			for($i = 0; $i < sizeof($people_array); $i++) {
    				$person_array = explode('<year>', $people_array[$i]);
    				echo $person_array[1] . ' ' . $person_array[0] . '<br />';
    			}
    			echo '</div>';
    			echo '<div style="text-align: left;"><font face="arial" size="-3"><a href="http://www.ka81.com/">ka81\'s</a></font></div>';
    		} else {
    
    			echo '<div style="text-align: left;">';
    			for($i = 0; $i < sizeof($people_array); $i++) {
    				$person_array = explode('<year>', $people_array[$i]);
    				echo $person_array[0] . ' ' . $person_array[1] . '<br />';
    			}
    			echo '</div>';
    		}
    
    		echo $after_widget;
    	}
    
    	function update($new_instance, $old_instance) {
    
    		return $new_instance;
    	}
    
    	function form($instance) {
    
    		// Load language file
    		$current_locale = get_locale();
    		if(!empty($current_locale)) {
    			$mo_file = dirname(__FILE__) . '/languages/born-on-this-day-' . $current_locale . ".mo";
    			if(@file_exists($mo_file) && is_readable($mo_file)) {
    				load_textdomain('born-on-this-day', $mo_file);
    			}
    		}
    
    		// Get options
    		$instance = wp_parse_args((array)$instance, array('title' => __('Born on this day', 'born-on-this-day'), 'date_style' => 'bold', 'alignment' => 'left'));
    		$option_title = esc_attr($instance['title']);
    
    		// Display form
    		echo '<p>';
    		echo 	'<label for="' . $this->get_field_id('title') . '">' . __('Title: ', 'born-on-this-day') . '</label>';
    		echo 	'<input class="widefat" type="text" value="' . $option_title . '" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" />';
    		echo	'<br />';
    		echo	'<br />';
    		echo 	'<label for="' . $this->get_field_id('date_style') . '">' . __('Date style: ', 'born-on-this-day') . '</label>';
    		echo 	'<select class="widefat" id="' . $this->get_field_id('date_style') . '" name="' . $this->get_field_name('date_style') . '">';
    		echo 		'<option value="bold"' . selected($instance['date_style'], 'bold') . '>' . __('Bold', 'born-on-this-day') . '</option>';
    		echo 		'<option value="bold_italic"' . selected($instance['date_style'], 'bold_italic') . '>' . __('Bold + Italic', 'born-on-this-day') . '</option>';
    		echo 		'<option value="italic"' . selected($instance['date_style'], 'italic') . '>' . __('Italic', 'born-on-this-day') . '</option>';
    		echo 		'<option value="regular"' . selected($instance['date_style'], 'regular') . '>' . __('Regular', 'born-on-this-day') . '</option>';
    		echo 	'</select>';
    		echo	'<br />';
    		echo	'<br />';
    		echo 	'<label for="' . $this->get_field_id('alignment') . '">' . __('Alignment: ', 'born-on-this-day') . '</label>';
    		echo 	'<select class="widefat" id="' . $this->get_field_id('alignment') . '" name="' . $this->get_field_name('alignment') . '">';
    		echo 		'<option value="left"' . selected($instance['alignment'], 'left') . '>' . __('Left', 'born-on-this-day') . '</option>';
    		echo 		'<option value="right"' . selected($instance['alignment'], 'right') . '>' . __('Right', 'born-on-this-day') . '</option>';
    		echo 	'</select>';
    		echo '</p>';
    	}
    }
    
    add_action('widgets_init', create_function('', 'return register_widget("WP_Widget_Born_On_This_Day");'));
    
    ?>

Просмотр 15 ответов — с 1 по 15 (всего 16)
  • поменять местами как я понял просто:

    echo '<div style="text-align: left;">';
    			for($i = 0; $i < sizeof($people_array); $i++) {
    				$person_array = explode('<year>', $people_array[$i]);
    				echo $person_array[0] . ' ' . $person_array[1] . '<br />';
    			}
    			echo '</div>';

    меняем echo $person_array[0] . ' ' . $person_array[1] . '<br />'; на echo $person_array[1] . ' ' . $person_array[0] . '<br />';
    а вот как формат даты изменить и скобки добавить — никак не выходит у меня…

    Модератор Sergey Biryukov

    (@sergeybiryukov)

    Live and Learn

    echo $person_array[1] . ' (' . mysql2date('d.m.', $current_date) . $person_array[0] . ')<br />';

    Сергей, спасибо большое.
    визуально — именно то что и хотелось.
    Однако, используя ваш вариант у меня вышло так:
    Anton Rodgers (29.01.2010)
    (29.01.2010)

    тобишь:
    а) два раза дата
    б) год берется текущий, а не тот что указан в *.dat файле.

    а там указано так (это я там для теста попрописывал одно и то же):

    29<day>1<month>1933<year>Anton Rodgers<name>
    30<day>1<month>1933<year>Anton Rodgers<name>
    31<day>1<month>1933<year>Anton Rodgers<name>

    Модератор Sergey Biryukov

    (@sergeybiryukov)

    Live and Learn

    Исправил год. В этой строчке дата выводится только один раз — наверное, рядом осталась другая

    спсб.
    теперь вот так показывает:

    Anton Rodgers (29.01.1933)
    (29.01. )

    Модератор Sergey Biryukov

    (@sergeybiryukov)

    Live and Learn

    1. Как выглядит изменённый фрагмент полностью?
    2. Было бы здорово взглянуть на сайт.

    виджет справа День Народження

    сам код:

    <?php
    
    /*
     *
     *	Plugin Name: Born On This Day
     *	Plugin URI: http://www.joeswebtools.com/wordpress-plugins/born-on-this-day/
     *	Description: Adds a sidebar widget that display famous people born on this day in history.
     *	Version: 2.0
     *	Author: Joe's Web Tools
     *	Author URI: http://www.joeswebtools.com/
     *
     *	Copyright (c) 2009 Joe's Web Tools. All Rights Reserved.
     *
     *	This program is free software; you can redistribute it and/or modify
     *	it under the terms of the GNU General Public License as published by
     *	the Free Software Foundation; either version 2 of the License, or
     *	(at your option) any later version.
     *
     *	This program is distributed in the hope that it will be useful,
     *	but WITHOUT ANY WARRANTY; without even the implied warranty of
     *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     *	GNU General Public License for more details.
     *
     *	You should have received a copy of the GNU General Public License
     *	along with this program; if not, write to the Free Software
     *	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
     *
     *	If you are unable to comply with the terms of this license,
     *	contact the copyright holder for a commercial license.
     *
     *	We kindly ask that you keep links to Joe's Web Tools so
     *	other people can find out about this plugin.
     *
     */
    
    /*
     *
     *	born_on_this_day_shortcode_handler
     *
     */
    
    function born_on_this_day_shortcode_handler($atts, $content = nul) {
    
    	// Load language file
    	$current_locale = get_locale();
    	if(!empty($current_locale)) {
    		$mo_file = dirname(__FILE__) . '/languages/born-on-this-day-' . $current_locale . ".mo";
    		if(@file_exists($mo_file) && is_readable($mo_file)) {
    			load_textdomain('born-on-this-day', $mo_file);
    		}
    	}
    
    	// Prepare the date
    	$current_date = date_i18n(get_option('date_format'), strtotime('now'));
    	$current_date = '<strong>' . $current_date . '</strong><br />';
    
    	// Prepare the people
    	$month_array = file(dirname(__FILE__) . '/data/' . date('n') . '.dat');
    	$day = date('j');
    	$day_line = $month_array[$day + 3];
    	$day_array = explode('<month>', $day_line);
    	$people_array = explode('<name>', $day_array[1]);
    	for($i = 0; $i < sizeof($people_array); $i++) {
    		$person_array = explode('<year>', $people_array[$i]);
    		$people .= $person_array[0] . ' ' . $person_array[1] . '<br />';
    	}
    
    	// Display
    	$content = '<table style="border-width: thin thin thin thin; border-style: solid solid solid solid;">';
    	$content .= '<thead><tr><th><center><font face="arial" size="+1"><b>' . __('Born on this day', 'born-on-this-day') . '</b></center></font></th></tr></thead>';
    	$content .= '<tbody><tr><td>';
    
    	$content .= '<div style="text-align: left;">';
    	$content .= $current_date;
    	$content .= $people;
    	$content .= '</div>';
    
    	$content .= '</td></tr></tbody>';
    	$content .= '<tfoot><tr><td><div style="text-align: right;"><font face="arial" size="-3"><a href="http://www.ka81.com/">ka81\'s</a></font></div></td></tr></tfoot>';
    	$content .= '</table>';
    
    	return $content;
    }
    
    add_shortcode('born-on-this-day', 'born_on_this_day_shortcode_handler');
    
    /*
     *
     *	WP_Widget_Born_On_This_Day
     *
     */
    
    class WP_Widget_Born_On_This_Day extends WP_Widget {
    
    	function WP_Widget_Born_On_This_Day() {
    
    		parent::WP_Widget(false, $name = 'Born On This Day');
    	}
    
    	function widget($args, $instance) {
    
    		// Load language file
    		$current_locale = get_locale();
    		if(!empty($current_locale)) {
    			$mo_file = dirname(__FILE__) . '/languages/born-on-this-day-' . $current_locale . ".mo";
    			if(@file_exists($mo_file) && is_readable($mo_file)) {
    				load_textdomain('born-on-this-day', $mo_file);
    			}
    		}
    
    		// Get options
    		extract($args);
    		$option_title = apply_filters('widget_title', empty($instance['title']) ? __('Born on this day', 'born-on-this-day') : $instance['title']);
    		$option_alignment = empty($instance['alignment']) ? 'left' : $instance['alignment'];
    		$option_date_style = empty($instance['date_style']) ? 'bold' : $instance['date_style'];
    
    		// Prepare the date
    		$current_date = date_i18n(get_option('date_format'), strtotime('now'));
    		switch($option_date_style) {
    			case 'bold':
    				$current_date = '<strong>' . $current_date . '</strong><br />';
    				break;
    			case 'bold_italic':
    				$current_date = '<strong><em>' . $current_date . '</em></strong><br />';
    				break;
    			case 'italic':
    				$current_date = '<em>' . $current_date . '</em><br />';
    				break;
    			case 'regular':
    				$current_date .= '<br />';
    				break;
    		}
    
    		// Prepare the people
    		$month_array = file(dirname(__FILE__) . '/data/' . date('n') . '.dat');
    		$day = date('j');
    		$day_line = $month_array[$day + 3];
    		$day_array = explode('<month>', $day_line);
    		$people_array = explode('<name>', $day_array[1]);
    
    		// Help widget to conform to the active theme: before_widget, before_title and after_title
    		echo $before_widget;
    		echo $before_title . $option_title . $after_title;
    
    		if($option_alignment == 'right') {
    
    			echo '<div style="text-align: right;">';
    			for($i = 0; $i < sizeof($people_array); $i++) {
    				$person_array = explode('<year>', $people_array[$i]);
    				echo $person_array[1] . ' ' . $person_array[0] . '<br />';
    			}
    			echo '</div>';
    		} else {
    
    			echo '<div style="text-align: left;">';
    			for($i = 0; $i < sizeof($people_array); $i++) {
    				$person_array = explode('<year>', $people_array[$i]);
    				echo $person_array[1] . ' (' . mysql2date('d.m.', $current_date) . $person_array[0] . ')<br />';
    			}
    			echo '</div>';
    		}
    
    		echo $after_widget;
    	}
    
    	function update($new_instance, $old_instance) {
    
    		return $new_instance;
    	}
    
    	function form($instance) {
    
    		// Load language file
    		$current_locale = get_locale();
    		if(!empty($current_locale)) {
    			$mo_file = dirname(__FILE__) . '/languages/born-on-this-day-' . $current_locale . ".mo";
    			if(@file_exists($mo_file) && is_readable($mo_file)) {
    				load_textdomain('born-on-this-day', $mo_file);
    			}
    		}
    
    		// Get options
    		$instance = wp_parse_args((array)$instance, array('title' => __('Born on this day', 'born-on-this-day'), 'date_style' => 'bold', 'alignment' => 'left'));
    		$option_title = esc_attr($instance['title']);
    
    		// Display form
    		echo '<p>';
    		echo 	'<label for="' . $this->get_field_id('title') . '">' . __('Title: ', 'born-on-this-day') . '</label>';
    		echo 	'<input class="widefat" type="text" value="' . $option_title . '" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" />';
    		echo	'<br />';
    		echo	'<br />';
    		echo 	'<label for="' . $this->get_field_id('date_style') . '">' . __('Date style: ', 'born-on-this-day') . '</label>';
    		echo 	'<select class="widefat" id="' . $this->get_field_id('date_style') . '" name="' . $this->get_field_name('date_style') . '">';
    		echo 		'<option value="bold"' . selected($instance['date_style'], 'bold') . '>' . __('Bold', 'born-on-this-day') . '</option>';
    		echo 		'<option value="bold_italic"' . selected($instance['date_style'], 'bold_italic') . '>' . __('Bold + Italic', 'born-on-this-day') . '</option>';
    		echo 		'<option value="italic"' . selected($instance['date_style'], 'italic') . '>' . __('Italic', 'born-on-this-day') . '</option>';
    		echo 		'<option value="regular"' . selected($instance['date_style'], 'regular') . '>' . __('Regular', 'born-on-this-day') . '</option>';
    		echo 	'</select>';
    		echo	'<br />';
    		echo	'<br />';
    		echo 	'<label for="' . $this->get_field_id('alignment') . '">' . __('Alignment: ', 'born-on-this-day') . '</label>';
    		echo 	'<select class="widefat" id="' . $this->get_field_id('alignment') . '" name="' . $this->get_field_name('alignment') . '">';
    		echo 		'<option value="left"' . selected($instance['alignment'], 'left') . '>' . __('Left', 'born-on-this-day') . '</option>';
    		echo 		'<option value="right"' . selected($instance['alignment'], 'right') . '>' . __('Right', 'born-on-this-day') . '</option>';
    		echo 	'</select>';
    		echo '</p>';
    	}
    }
    
    add_action('widgets_init', create_function('', 'return register_widget("WP_Widget_Born_On_This_Day");'));
    
    ?>

    Вместо того, чтобы вставлять весь код плагина, лучше бы вы вставили ссылку на код в pastebin… Это как пожелание на будущее.

    Вот в этом коде (строки 122-125):

    for($i = 0; $i < sizeof($people_array); $i++) {
    	$person_array = explode('<year>', $people_array[$i]);
    	echo $person_array[1] . ' (' . mysql2date('d.m.', $current_date) . $person_array[0] . ')<br />';
    }

    попробуйте сделать вот так:

    for($i = 0; $i < sizeof($people_array); $i++) {
    	$person_array = explode('<year>', $people_array[$i]);
    	echo $person_array[1] . ' (' . $person_array[0] . ')<br />';
    }

    Модератор Sergey Biryukov

    (@sergeybiryukov)

    Live and Learn

    При редактировании .dat-файлов допущена ошибка: после последнего имени в строке не должно быть тега <name>, иначе получается пустое значение:

    29<day>1<month>1933<year>Anton Rodgers
    30<day>1<month>1933<year>Anton Rodgers
    31<day>1<month>1933<year>Anton Rodgers

    2 slaFFik
    а зачем там еще менять, если указанные изменения от SergeyBiryukov сработали?
    нет, если нужно, то я конечно сделаю, просто вроде как работает уже как и нужно было…
    +
    данные изменения скорее всего имелись в виду относительно строки 166 и вы написали так, как оно изначально в плагине! а мы тут как раз и изменяли ее на другое для нужд автора, тобишь меня 😉

    2 SergeyBiryukov
    Сергей, как всегда — спасибо за помощь.
    вопрос, а если вообще нет человека в строке то оставлять так: 21<day>1<month> или так: 21<day>1 ?

    П.С. Сереж, посмотрите пжлст почту, если будет минутка 🙂

    Модератор Sergey Biryukov

    (@sergeybiryukov)

    Live and Learn

    Второй вариант — 21<day>1. Также нужно изменить строчку

    $people_array = explode('<name>', $day_array[1]);

    на такую:

    $people_array = !empty($day_array[1]) ? explode('<name>', $day_array[1]) : array();

    Можно вообще не отображать заголовок виджета при отсутствии событий, если сразу после этого добавить:

    if ( empty($people_array) )
    	return;

    $people_array = explode(‘<name>’, $day_array[1]);

    Сергей, а там два раза такая строка — 66 и 147
    66

    // Prepare the people
    	$month_array = file(dirname(__FILE__) . '/data/' . date('n') . '.dat');
    	$day = date('j');
    	$day_line = $month_array[$day + 3];
    	$day_array = explode('<month>', $day_line);
    	$people_array = explode('<name>', $day_array[1]);
    	for($i = 0; $i < sizeof($people_array); $i++) {
    		$person_array = explode('<year>', $people_array[$i]);
    		$people .= $person_array[0] . ' ' . $person_array[1] . '<br />';
    	}

    147

    // Prepare the people
    		$month_array = file(dirname(__FILE__) . '/data/' . date('n') . '.dat');
    		$day = date('j');
    		$day_line = $month_array[$day + 3];
    		$day_array = explode('<month>', $day_line);
    		$people_array = explode('<name>', $day_array[1]);

    Модератор Sergey Biryukov

    (@sergeybiryukov)

    Live and Learn

    К виджету относится вторая — 147.

    я и там и там изменил
    и и там и там дописал про return;
    все работает, все ок.
    не навредит же, верно?..

    Модератор Sergey Biryukov

    (@sergeybiryukov)

    Live and Learn

    Верно 🙂

Просмотр 15 ответов — с 1 по 15 (всего 16)
  • Тема «[Плагин: Born On This Day] поменять местами дату и имя формат» закрыта для новых ответов.