За последние 24 часа нас посетил 22671 программист и 1273 робота. Сейчас ищут 838 программистов ...

Откуда берет дату?

Тема в разделе "PHP для новичков", создана пользователем Тишина, 26 июл 2016.

Метки:
  1. Тишина

    Тишина Новичок

    С нами с:
    25 июл 2016
    Сообщения:
    24
    Симпатии:
    0
    Хотел русифицировать этот виджет, получилось только изменить вводные данные месяца(chooser), а результат выводит на английском, мне интересно откуда берет результат, потому что только результат выходит на англ, то есть только месяц, помогите пожалуйста узнать. Мне кажется это database, но я не знаю как к нему добраться






    PHP:
    1. <?php
    2. /*
    3. Plugin Name: Ovulation Predictor
    4. Plugin URI: http://calendarscripts.info/ovulation-predictor-wordpress-plugin.html
    5. Description: This plugin displays functional ovulation and due date predictor. It can be used from women to check their future fertile time and due date.
    6. Author: CalendarScripts
    7. Version: 1.2
    8. Author URI: http://calendarscripts.info
    9. */
    10.  
    11. /*  Copyright 2008  CalendarScripts (email : info@calendarscripts.info)
    12.  
    13.     This program is free software; you can redistribute it and/or modify
    14.     it under the terms of the GNU General Public License as published by
    15.     the Free Software Foundation; either version 2 of the License, or
    16.     (at your option) any later version.
    17.  
    18.     This program is distributed in the hope that it will be useful,
    19.     but WITHOUT ANY WARRANTY; without even the implied warranty of
    20.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    21.     GNU General Public License for more details.
    22.  
    23.     You should have received a copy of the GNU General Public License
    24.     along with this program; if not, write to the Free Software
    25.     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    26. */
    27.  
    28.  
    29. function ovpredct_add_page()
    30. {
    31.     add_submenu_page('plugins.php', 'Ovulation Predictor', 'Ovulation Predictor', 8, __FILE__, 'ovpredct_options');
    32. }
    33.  
    34. // ovpredct_options() displays the page content for the Ovpredct Options submenu
    35. function ovpredct_options($widget_mode=false)
    36. {
    37.     // Read in existing option value from database
    38.     $ovpredct_table = stripslashes( get_option( 'ovpredct_table' ) );
    39.  
    40.     // See if the user has posted us some information
    41.     // If they did, this hidden field will be set to 'Y'
    42.     if( $_POST[ 'ocalc_update' ] == 'Y' )
    43.     {
    44.         // Read their posted value
    45.         $ovpredct_table = $_POST[ 'ovpredct_table' ];
    46.      
    47.  
    48.         // Save the posted value in the database
    49.         update_option( 'ovpredct_table', $ovpredct_table );
    50.      
    51.         // Put an options updated message on the screen
    52.         ?>
    53.         <div class="updated"><p><strong><?php _e('Options saved.', 'ovpredct_domain' ); ?></strong></p></div>
    54.         <?php    
    55.      }
    56.      
    57.          // Now display the options editing screen
    58.             echo '<div class="wrap">';    
    59.             // header
    60.             echo "<h2>" . __( 'Ovulation Predictor Options', 'ovpredct_domain' ) . "</h2>";    
    61.             // options form        
    62.             ?>
    63.      
    64.         <?php if(!$widget_mode):?>
    65.         <form name="form1" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
    66.         <?php endif;?>
    67.         <input type="hidden" name="ocalc_update" value="Y">
    68.      
    69.         <p><?php _e("<p>You can use this calculator in two ways: as a standard Wordpress widget or by placing it in your post or page. For the latter please include the tag <b>[ovulation-predictor]</b> in the content of your page or post and the calculator will appear there.</p>
    70.        <p>These options are accessible both from the \"Ovulation Predictor\" page under your Plugins menu or from your Widgets section.</p>
    71.        <p>Check out some more of our <a href='http://calendarscripts.info/free-calculators.html' target='_blank'>free calculators</a>.</p>
    72.        <p>CSS class definition for the predictor wrapper div &lt;div&gt;:</p>", 'ovpredct_domain' ); ?>
    73.         <textarea name="ovpredct_table" rows='5' cols='70'><?php echo stripslashes ($ovpredct_table); ?></textarea>
    74.         </p><hr />
    75.      
    76.         <?php if(!$widget_mode):?>
    77.             <p class="submit">
    78.             <input type="submit" name="Submit" value="<?php _e('Update Options', 'ovpredct_domain' ) ?>" />
    79.             </p>
    80.          
    81.             </form>
    82.         <?php endif;?>
    83.         </div>
    84.         <?php
    85. }
    86.  
    87. function ovpredct_datechooser($name,$value="")
    88. {
    89.     $months=array('','January','February','March','April','May','June','July','August',
    90.     'September','October','November','December');
    91.  
    92.     if(empty($value)) $value=date("Y-m-d");
    93.  
    94.     $parts=explode("-",$value);
    95.  
    96.     $day=$parts[2]+0;
    97.     $month=$parts[1]+0;
    98.     $year=$parts[0];
    99.  
    100.     $chooser="";
    101.  
    102.     $chooser.="<select name=".$name."month>";
    103.     for($i=1;$i<=12;$i++)
    104.     {
    105.         if($i==$month) $selected='selected';
    106.         else $selected='';
    107.         $chooser.="<option $selected value=$i>$months[$i]</option>";
    108.     }
    109.     $chooser.="</select> / ";
    110.  
    111.     $chooser.="<select name=".$name."day>";
    112.     for($i=1;$i<=31;$i++)
    113.     {
    114.         if($i==$day) $selected='selected';
    115.         else $selected='';
    116.         $chooser.="<option $selected>$i</option>";
    117.     }
    118.     $chooser.="</select> / ";
    119.  
    120.     $chooser.="<select name=".$name."year>";
    121.     for($i=(date("Y")-1);$i<=2050;$i++)
    122.     {
    123.         if($i==$year) $selected='selected';
    124.         else $selected='';
    125.         $chooser.="<option $selected>$i</option>";
    126.     }
    127.     $chooser.="</select> ";
    128.  
    129.     return $chooser;
    130. }
    131.  
    132. function ovpredct_generate_html()
    133. {
    134.     //construct the calculator page
    135.     $ovcalc="<style type=\"text/css\">
    136.    .ovpredct_table
    137.    {
    138.        ".get_option('ovpredct_table')."
    139.    }
    140.    </style>\n\n";
    141.  
    142.     if(!empty($_POST['calculator_ok']))
    143.     {
    144.         //last cycle date
    145.         $date="$_POST[dateyear]-$_POST[datemonth]-$_POST[dateday]";
    146.      
    147.         //convert to time
    148.         $lasttime=mktime(0,0,0,$_POST[datemonth],$_POST[dateday],$_POST[dateyear]);
    149.      
    150.         //first fertile day
    151.         $firstdaytime=$lasttime + $_POST[days]*24*3600 - 16*24*3600;
    152.         $firstday=date("F d, Y",$firstdaytime);
    153.      
    154.         //last fertile day
    155.         $lastdaytime=$lasttime + $_POST[days]*24*3600 - 12*24*3600;
    156.         $lastday=date("F d, Y",$lastdaytime);
    157.      
    158.         //have to adjust due date?
    159.         $diff=$_POST[days] - 28;
    160.      
    161.         //due date $date + 280 days
    162.         $duedatetime=$lasttime + 280*24*3600 + $diff*24*3600;
    163.         $duedate=date("F d, Y",$duedatetime);
    164.  
    165.          
    166.         //the result is here
    167.         $ovcalc.='<div class="ovpredct_table">
    168.        Here are the results based on the information you provided:<br /><br />
    169.        You next most fertile period is <strong>'.$firstday.' to '.$lastday.'</strong>.<br ><br />
    170.        If you conceive within this timeframe, your estimated due date will be <strong>'.$duedate.'</strong>
    171.        <p align="center"><input type="button" value="Calculate again!" onclick="javascript:history.back();"></p>
    172.        </div>';
    173.      
    174.     }
    175.     else
    176.     {
    177.         $ovcalc.='<div class="ovpredct_table">
    178.        <form method="post">
    179.        Please select the first day of your last menstrual period:<br /><br />
    180.        '.ovpredct_datechooser("date",date("Y-m-d")).'<br><br>
    181.        Usual number of days in your cycle: <select name="days">';
    182.              
    183.         for($i=20;$i<=45;$i++)
    184.         {
    185.             if($i==28) $selected='selected';
    186.             else $selected='';
    187.             $ovcalc.="<option $selected value='$i'>$i</option>";
    188.         }
    189.      
    190.         $ovcalc.='</select>
    191.        <p align="center"><input type="submit" name="calculator_ok" value="Calculate"></p>
    192.        </form>    
    193.        </div>';
    194.     }
    195.  
    196.     return $ovcalc;
    197. }
    198.  
    199. // This just echoes the text
    200. function ovpredct($content)
    201. {
    202.     if(!strstr($content,"[ovulation-predictor]")) return $content;
    203.  
    204.     $ovcalc=ovpredct_generate_html();
    205.  
    206.     $content=str_replace("[ovulation-predictor]",$ovcalc,$content);
    207.     return $content;
    208. }
    209.  
    210. // the widget object
    211. class OvPredct extends WP_Widget {
    212.     /** constructor */
    213.     function OvPredct() {
    214.         parent::WP_Widget(false, $name = 'Ovulation Predictor');
    215.     }
    216.  
    217.     function form()
    218.     {
    219.         ovpredct_options(true);
    220.     }
    221.  
    222.     function widget($args, $instance)
    223.     {
    224.         echo ovpredct_generate_html();
    225.     }
    226. }
    227.  
    228. add_action('admin_menu','ovpredct_add_page');
    229. add_filter('the_content', 'ovpredct');
    230. add_action('widgets_init', create_function('', 'return register_widget("OvPredct");'));
    231. ?>
     

    Вложения:

    #1 Тишина, 26 июл 2016
    Последнее редактирование: 26 июл 2016
  2. Ganzal

    Ganzal Суперстар
    Команда форума Модератор

    С нами с:
    15 мар 2007
    Сообщения:
    9.902
    Симпатии:
    969
    какую из дат? там много вызовов.
     
  3. Тишина

    Тишина Новичок

    С нами с:
    25 июл 2016
    Сообщения:
    24
    Симпатии:
    0
    $firstday $lastday $duedate

    вижу вот инициализация, а не знаю $_POST[dateyear], datemonth,dateday
     
  4. denis01

    denis01 Суперстар
    Команда форума Модератор

    С нами с:
    9 дек 2014
    Сообщения:
    12.230
    Симпатии:
    1.715
    Адрес:
    Молдова, г.Кишинёв
  5. Тишина

    Тишина Новичок

    С нами с:
    25 июл 2016
    Сообщения:
    24
    Симпатии:
    0
    Спасибо, а можно еще один вопрос, как нибудь до этих dateyear, datemonth, dateday можно добраться и отредактировать? извиняюсь за глупый вопрос. просто понял что они находятся внутри calculator_ok, но не знаю где находится он
     
    #5 Тишина, 26 июл 2016
    Последнее редактирование: 26 июл 2016
  6. denis01

    denis01 Суперстар
    Команда форума Модератор

    С нами с:
    9 дек 2014
    Сообщения:
    12.230
    Симпатии:
    1.715
    Адрес:
    Молдова, г.Кишинёв
    Можно после 144 строчки можно с ними делать что хочешь

    что конкретно нужно с ними сделать?
     
  7. Тишина

    Тишина Новичок

    С нами с:
    25 июл 2016
    Сообщения:
    24
    Симпатии:
    0
    Я так понял значения datemonth стоит на англ, я хочу просто перевести месяца на русский, но не могу найти где менять, где именно стоят эти значения на англ
     
  8. denis01

    denis01 Суперстар
    Команда форума Модератор

    С нами с:
    9 дек 2014
    Сообщения:
    12.230
    Симпатии:
    1.715
    Адрес:
    Молдова, г.Кишинёв
    @Тишина 89 строчка, там я вижу перечисление месяцев на английском, ты искал? Есть ctrl+F комбинация клавиш для поиска
     
  9. Тишина

    Тишина Новичок

    С нами с:
    25 июл 2016
    Сообщения:
    24
    Симпатии:
    0
    89-ая строчка это всего лишь chooser, для выбора и ввода, а результат вычисления выходит то на англ, потому что с 132 строчки идет как раз эти даты, но я не знаю как именно здесь исправить англ месяцы на русский, мне просто месяцы надо перевести и все
     
  10. denis01

    denis01 Суперстар
    Команда форума Модератор

    С нами с:
    9 дек 2014
    Сообщения:
    12.230
    Симпатии:
    1.715
    Адрес:
    Молдова, г.Кишинёв
    @Тишина понял, тогда смотри date("F d, Y",
    можно заменить на
    https://secure.php.net/manual/ru/intldateformatter.format.php
    шаблоны для формата даты и времени http://userguide.icu-project.org/formatparse/datetime

    PHP:
    1. $formatter = new IntlDateFormatter('ru_RU', IntlDateFormatter::FULL, IntlDateFormatter::FULL);
    2. $formatter->setPattern('d MMMM');
    3. echo $formatter->format(new DateTime());
    у тебя там mktime, вот пример
    PHP:
    1. $dt = new DateTime();
    2. $dt->setTimestamp(mktime(1, 2, 3, 4, 5, 2006));
    3. echo $formatter->format($dt);
     
  11. Тишина

    Тишина Новичок

    С нами с:
    25 июл 2016
    Сообщения:
    24
    Симпатии:
    0
    спасибо, разобрался