PHPカレンダークラス

Jun 23, 2016 pm 02:34 PM

以下はCIのカレンダークラスです。参考にしてください。

/* *
* CodeIgniter
*
* PHP 5.1.6 以降用のオープンソース アプリケーション開発フレームワーク
*
* @package CodeIgniter
* @author ExpressionEngine Devチーム
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since バージョン 1.0
* @filesource
*/

// - -------------------------------------------------- ----------

/* *
* CodeIgniter Calendar クラス
*
* この クラス により カレンダーの作成 が可能になります
*
* @package CodeIgniter
* @subpackage ライブラリ
* @category ライブラリ
* @author ExpressionEngine 開発チーム
* @link http://codeigniter.com/user_guide/libraries/calendar.html
*/
class CI_Calendar {

var $CI;
var $lang;
var $local_time;
var $template = '';
var $start_day = '日曜日';
var $month_type = 'long';
var $day_type = 'abr';
var $show_next_prev = FALSE;
var $next_prev_url = '';

/* *
* コンストラクター
*
* カレンダー言語ファイルをロードし、デフォルトの時間参照を設定します
*/
public function __construct( $config = array())
{
$this->CI =& get_instance ();

if ( ! in_array('calendar_lang.php', $this->CI->lang->is_loaded, TRUE))
{
$this->CI->lang->load('カレンダー');
}

$this->local_time = time();

if ( count( $config) >gt; 0)
{
$this->initialize( $config);
}

log_message('debug', "カレンダークラスが初期化されました");
}

// -------------------------------------------- ------------------------

/* *
* ユーザー設定を初期化します
*
     * 表示設定を含む連想配列を入力として受け入れます
*
* @access public
* @param array config preferences
* @return void
*/
function initialize( $config = array())
{
foreach ( $ config as $key => $val)
{
if ( isset( $this-> $key))
{
$this-> $key = $val;
}

}

// ------------------------------------------ ----------------------------

/* *
* カレンダーを生成する
*
* @access public
* @param integer年
* @param integer 月
* @param array カレンダーセルに表示されるデータ
* @return string
*/
function generate( $year = ''、$month = ''、$data = array())
{
// 指定された月/年を設定および検証します
if ( $year == '')
$year = date("Y", $this->local_time);

if ( $month == '')
$month = date("m", $this->local_time);

if ( strlen( $year) == 1)
$year = '200'。 $年;

if ( strlen( $year) == 2)
$year = '20'。 $年;

if ( strlen( $month) == 1)
$month = '0'。 $月;

$adjusted_date = $this->adjust_date( $month, $year);

$month = $adjusted_date['month'];
$year = $adjusted_date['year'];

// その月の合計日数を決定します
$total_days = $this->get_total_days( $month, $year);

// 週の開始日を設定します
         $start_days = array('sunday' => 0, 'monday' => 1, 'tuesday' => 2, 'wednesday' => 3, 'thursday' => 4, 'friday' => ; 5, '土曜日' => 6);
$start_day = ( ! isset( $start_days[ $this->start_day])) ? 0 : $start_days[ $this->start_day];

// 開始日の番号を設定します
$local_date = mktime(12, 0, 0, $month, 1, $year);
$date = getdate( $local_date);
$day = $start_day + 1 - $date["wday"];

while ( $day > 1)
{
$day -= 7;
}

// 現在の月/年/日を設定します
// 「今日」の日付を決定するために これを使用します
$cur_year = date("Y", $this->local_time );
$cur_month = date("m", $this->local_time);
$cur_day = date("j", $this->local_time);

$is_current_month = ( $cur_year == $year AND $cur_month == $month) ?  真/偽;

// テンプレート データ 配列を生成します
$this->parse_template();

// カレンダー出力の構築を開始します
$out = $this->temp['table_open'];
$out .= "n";

$out .= "n";
$out .= $this->temp['Heading_row_start'];
$out .= "n";

// 「前」月のリンク
if ( $this->show_next_prev == TRUE)
{
// 必要な場合は、URL の末尾にスラッシュを追加しますed
$this->next_prev_url = preg_replace("/(. +?)/*$/","\1/", $this->next_prev_url);

$adjusted_date = $this->adjust_date( $month - 1, $year);
$out .= str_replace('{previous_url}', $this->next_prev_url. $adjusted_date['year'].'/'. $adjusted_date['month'], $this->temp['Heading_previous_cell' ]);
$out .= "n";
}

// 月/年を含む見出し
$colspan = ( $this->show_next_prev == TRUE) ? 5 : 7;

         $this->temp['Heading_title_cell'] = str_replace('{colspan}', $colspan, $this->temp['Heading_title_cell']);
$this->temp['Heading_title_cell'] = str_replace('{Heading}', $this->get_month_name( $month)." ". $year, $this->temp['Heading_title_cell' ]);

$out .= $this->temp['Heading_title_cell'];
$out .= "n";

// 「次の」 月のリンク
if ( $this->show_next_prev == TRUE)
{
$adjusted_date = $this->adjust_date( 1、年ドル);
$out .= str_replace('{next_url}', $this->next_prev_url. $adjusted_date['year'].'/'. $adjusted_date['month'], $this->temp['Heading_next_cell' ]);
}

$out .= "n";
$out .= $this->temp['Heading_row_end'];
$out .= "n";

// 曜日を含むセルを書き込みます
$out .= "n";
$out .= $this->temp['week_row_start'];
$out .= "n";

$day_names = $this->get_day_names();

for ( $i = 0; $i < 7; $i ++)
{
$out .= str_replace('{week_day}', $day_names[( $start_day + $i) %7], $ this->temp['week_day_cell']);
}

$out .= "n";
$out .= $this->temp['week_row_end'];
$out .= "n";

// カレンダーの本体を作成します
while ( $day <= $total_days)
{
$out .= "n";
$out .= $this->temp['cal_row_start'];
$out .= "n";

for ( $i = 0; $i < 7; $i++)
{
$out .= ( $is_current_month == TRUE AND $day == $cur_day) ?  $this->temp['cal_cell_start_today'] : $this->temp['cal_cell_start'];

if ( $day > 0 AND $day <= $total_days)
{
if ( isset( $data[ $day]))
                    {
// コンテンツを含むセル
$temp = ( $is_current_month == TRUE AND $day == $cur_day) ?  $this->temp['cal_cell_content_today'] : $this->temp['cal_cell_content'];
$out .= str_replace('{day}', $day, str_replace('{content}', $data[ $day], $temp));

else
{
// コンテンツのないセル
$temp = ( $is_current_month == TRUE AND $day == $cur_day) ?  $this->temp['cal_cell_no_content_today'] : $this->temp['cal_cell_no_content'];
$out .= str_replace('{day}', $day, $temp);
}

else
{
ブランk セル
$out .= $this->temp['cal_cell_blank'];
}

$out .= ( $is_current_month == TRUE AND $day == $cur_day) ?  $this->temp['cal_cell_end_today'] : $this->temp['cal_cell_end'];                    
$day++;
}

$out .= "n";
$out .= $this->temp['cal_row_end'];
$out .= "n";
}

$out .= "n";
$out .= $this->temp['table_close'];

戻り $out;
}

// -------------------------------------------- ------------------------

/* *
* 月の名前を取得する
*
* 数値の
* 月に基づいてテキストの月の名前を生成します提供された。
     *
* @access public
* @param integer 月
* @return string
*/
function get_month_name( $month)
{ if ( $this->month_type == 'short')
{
$month_names = array('01' => 'cal_jan', '02' => 'cal_feb', '03' => 'cal_mar', '04' => 'cal_apr', '05' => ' cal_may'、'06'、=>、'cal_jun'、'07'、=>、'09'、'=> cal_oct', '11' => 'cal_nov', '12' => 'cal_dec');
}
else
{
$month_names = array('01' => 'cal_january', '02' => 'cal_february', '03' => 'cal _march', '04' => 'cal_april ','05' => '06' => 'cal_june', '08' => '09' => ','10' => 'cal_october', '11' => 'cal_november', '12' => 'cal_december');
}

$month = $month_names[ $month];

if ( $this->CI->lang->line( $month) === FALSE)
{
return ucfirst( str_replace('cal_', '', $month));
}

return $this->CI->gt;lang->line( $month);
}

// -------------------------------------------- ------------------------

/* *
* 曜日の名前を取得する
*
* 曜日の名前の配列を返します(日曜日、月曜日など) .) タイプに基づいて
* タイプに基づいて。  オプション: long、short、abrev
*
* @access public
* @param string
* @return array
*/
function get_day_names( $day_type = '')
{
if ( $day_type != '')
$this->day_type = $day_type;

if ( $this->day_type == 'long')
{
$day_names = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', '土曜日');
}
elseif ( $this->day_type == 'short')
{
$day_names = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 」土');
        }
else
{
$day_names = array('su', 'mo', 'tu', 'we', 'th', 'fr', 'sa');
}

$days = array();
foreach ( $day_names as $val)
{
$days[] = ( $this->CI->lang->line('cal_'. $val) === FALSE) ?  ucfirst( $val) : $this->CI->lang->line('cal_'. $val);
}

戻り $days;
}

// -------------------------------------------- ------------------------

/* *
* 日付を調整する
*
* この 関数は、有効な月/年があることを確認します。
* たとえば、月として 13 を送信すると、年が
* インクリメントされ、月は 1 月になります。
*
* @access public
* @param integer 月
* @param integer 年
* @return array
*/
function adjust_date( $month, $year)
{
$date = array();

$date['month'] = $month;
$date['年'] = $年;

while ( $date['month'] > 12)
{
$date['month'] -= 12;
$date['year']++;
}

while ( $date['month'] <= 0)
{
$date['month'] += 12;
$date['年']--;
}

if ( strlen( $date['month']) == 1)
{
$date['month'] = '0'。 $date['月'];
}

return $date;
}

// -------------------------------------------- ------------------------

/* *
* 特定の月の合計日数
*
* @access public
* @param integer the月
* @param integer 年
* @return integer
*/
function get_total_days( $month, $year)
{
$days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

if ( $month < 1 OR $month > 12)
        {
             return 0;
        }

         //  Is the year a leap year?
         if ( $month == 2)
        {
             if ( $year % 400 == 0 OR ( $year % 4 == 0 AND  $year % 100 != 0))
            {
                 return 29;
            }
        }

         return  $days_in_month[ $month - 1];
    }

     //  --------------------------------------------------------------------

     /* *
     * Set Default Template Data
     *
     * This is used in the event that the user has not created their own template
     *
     * @access    public
     * @return array
      */
     function default_template()
    {
         return   array (
                        'table_open'                => '

',
                        'heading_row_start'            => '',
                        'heading_previous_cell'        => '',
                        'heading_title_cell'        => '',
                        'heading_next_cell'            => '',
                        'heading_row_end'            => '',
                        'week_row_start' => ''、
'week_day_cell' => '',
'week_row_end' => '',
'cal_row_start' => ''、
'cal_cell_start' => ''、
'cal_cell_end_today' => '',
'cal_row_end' => '',
'table_close' => ''
);
}

// -------------------------------------------- ------------------------

/* *
* テンプレートを解析する
*
* テンプレート {疑似変数} 内のデータを収集する
     * カレンダーの表示に使用されます
*
* @access public
* @return void
*/
function parse_template()
{
{ $this-> ;temp = $this->default_template();

if ( $this->template == '')
{
return;
}

$today = array('cal_cell_start_today', 'cal_cell_content_today', 'cal_cell_no_content_today', 'cal_cell_end_today');

foreach ( array('table_open', 'table_close', 'Heading_row_start', 'Heading_previous_cell', 'Heading_title_cell', 'Heading_next_cell', 'Heading_row_end', 'week_row_start', 'week_day_cell', 'week_row_end', 'cal_row_start', 'cal_cell_start'、'cal_cell_content'、'cal_cell_no_content'、'cal_cell_blank'、'cal_cell_end'、'cal_row_end'、'cal_cell_start_today'、'cal_cell_content_today'、'cal_cell_no_content_today'、'cal_cell_end_today') として $val)
{
if ( preg_match ("/{". $val."}(.*?){/". $val."}/si", $this->template, $match))
{
$this->temp[ $val] = $match['1'];
{ $this->temp[ $val] = $this->temp[ str_replace('_today', '', $val)];



}

}

// END CI_Calendar クラス

/* ファイルの終わり カレンダー。 php */
/* 場所: ./system/libraries/Calendar.php */



このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

Laravelでフラッシュセッションデータを使用します Laravelでフラッシュセッションデータを使用します Mar 12, 2025 pm 05:08 PM

Laravelは、直感的なフラッシュメソッドを使用して、一時的なセッションデータの処理を簡素化します。これは、アプリケーション内に簡単なメッセージ、アラート、または通知を表示するのに最適です。 データは、デフォルトで次の要求のためにのみ持続します。 $リクエスト -

PHPのカール:REST APIでPHPカール拡張機能を使用する方法 PHPのカール:REST APIでPHPカール拡張機能を使用する方法 Mar 14, 2025 am 11:42 AM

PHPクライアントURL(CURL)拡張機能は、開発者にとって強力なツールであり、リモートサーバーやREST APIとのシームレスな対話を可能にします。尊敬されるマルチプロトコルファイル転送ライブラリであるLibcurlを活用することにより、PHP Curlは効率的なexecuを促進します

Laravelテストでの簡略化されたHTTP応答のモッキング Laravelテストでの簡略化されたHTTP応答のモッキング Mar 12, 2025 pm 05:09 PM

Laravelは簡潔なHTTP応答シミュレーション構文を提供し、HTTP相互作用テストを簡素化します。このアプローチは、テストシミュレーションをより直感的にしながら、コード冗長性を大幅に削減します。 基本的な実装は、さまざまな応答タイプのショートカットを提供します。 Illuminate \ support \ facades \ httpを使用します。 http :: fake([[ 'google.com' => 'hello world'、 'github.com' => ['foo' => 'bar']、 'forge.laravel.com' =>

Codecanyonで12の最高のPHPチャットスクリプト Codecanyonで12の最高のPHPチャットスクリプト Mar 13, 2025 pm 12:08 PM

顧客の最も差し迫った問題にリアルタイムでインスタントソリューションを提供したいですか? ライブチャットを使用すると、顧客とのリアルタイムな会話を行い、すぐに問題を解決できます。それはあなたがあなたのカスタムにより速いサービスを提供することを可能にします

PHPにおける後期静的結合の概念を説明します。 PHPにおける後期静的結合の概念を説明します。 Mar 21, 2025 pm 01:33 PM

記事では、PHP 5.3で導入されたPHPの後期静的結合(LSB)について説明し、より柔軟な継承を求める静的メソッドコールのランタイム解像度を可能にします。 LSBの実用的なアプリケーションと潜在的なパフォーマ

フレームワークセキュリティ機能:脆弱性から保護します。 フレームワークセキュリティ機能:脆弱性から保護します。 Mar 28, 2025 pm 05:11 PM

記事では、入力検証、認証、定期的な更新など、脆弱性から保護するためのフレームワークの重要なセキュリティ機能について説明します。

フレームワークのカスタマイズ/拡張:カスタム機能を追加する方法。 フレームワークのカスタマイズ/拡張:カスタム機能を追加する方法。 Mar 28, 2025 pm 05:12 PM

この記事では、フレームワークにカスタム機能を追加し、アーキテクチャの理解、拡張ポイントの識別、統合とデバッグのベストプラクティスに焦点を当てています。

See all articles
<<{heading}>>
{week_day}
'、
'cal_cell_start_today' => '
'、
'cal_cell_content' => '{day}',
'cal_cell_content_today' => '{日}',
'cal_cell_no_content' => '{day}'、
'cal_cell_no_content_today' => '{日}'、
'cal_cell_blank' => ' '、
'cal_cell_end' => '