# HG changeset patch # User Yoshiki Yazawa # Date 1268551910 -32400 # Node ID f5d58cf2842ffee783e7a70d5b83fc9331d712fc # Parent 9b9e22be8407ceb3d3add0a0da54b5e5c46efdd0# Parent f268d7d1059088de978f3d51a0ade64d478a6c44 merged with upstream diff -r 9b9e22be8407 -r f5d58cf2842f Keyword.class.php --- a/Keyword.class.php Sat Mar 13 18:53:41 2010 +0900 +++ b/Keyword.class.php Sun Mar 14 16:31:50 2010 +0900 @@ -16,42 +16,51 @@ } } - private function getPrograms() { - if( $this->id == 0 ) return false; + static public function search( $keyword = "", + $use_regexp = false, + $type = "*", + $category_id = 0, + $channel_id = 0, + $weekofday = 7, + $prgtime = 24, + $limit = 300 ) { + $sts = Settings::factory(); + + $dbh = @mysql_connect($sts->db_host, $sts->db_user, $sts->db_pass ); // ちょっと先を検索する - $options = " WHERE starttime > '".date("Y-m-d H:i:s", time() + $this->settings->padding_time + 120 )."'"; + $options = " WHERE starttime > '".date("Y-m-d H:i:s", time() + $sts->padding_time + 60 )."'"; - if( $this->keyword != "" ) { - if( $this->use_regexp ) { - $options .= " AND CONCAT(title,description) REGEXP '".mysql_real_escape_string($this->keyword)."'"; + if( $keyword != "" ) { + if( $use_regexp ) { + $options .= " AND CONCAT(title,description) REGEXP '".mysql_real_escape_string($keyword)."'"; } else { - $options .= " AND CONCAT(title,description) like '%".mysql_real_escape_string($this->keyword)."%'"; + $options .= " AND CONCAT(title,description) like '%".mysql_real_escape_string($keyword)."%'"; } } - if( $this->type != "*" ) { - $options .= " AND type = '".$this->type."'"; + if( $type != "*" ) { + $options .= " AND type = '".$type."'"; } - if( $this->category_id != 0 ) { - $options .= " AND category_id = '".$this->category_id."'"; + if( $category_id != 0 ) { + $options .= " AND category_id = '".$category_id."'"; } - if( $this->channel_id != 0 ) { - $options .= " AND channel_id = '".$this->channel_id."'"; + if( $channel_id != 0 ) { + $options .= " AND channel_id = '".$channel_id."'"; } - if( $this->weekofday != 7 ) { - $options .= " AND WEEKDAY(starttime) = '".$this->weekofday."'"; + if( $weekofday != 7 ) { + $options .= " AND WEEKDAY(starttime) = '".$weekofday."'"; } - if( $this->prgtime != 24 ) { - $options .= " AND time(starttime) BETWEEN cast('".sprintf( "%02d:00:00", $this->prgtime)."' as time) AND cast('".sprintf("%02d:59:59", $this->prgtime)."' as time)"; + if( $prgtime != 24 ) { + $options .= " AND time(starttime) BETWEEN cast('".sprintf( "%02d:00:00", $prgtime)."' as time) AND cast('".sprintf("%02d:59:59", $prgtime)."' as time)"; } - $options .= " ORDER BY starttime ASC"; + $options .= " ORDER BY starttime ASC LIMIT ".$limit ; $recs = array(); try { @@ -63,6 +72,17 @@ return $recs; } + private function getPrograms() { + if( $this->id == 0 ) return false; + $recs = array(); + try { + $recs = self::search( trim($this->keyword), $this->use_regexp, $this->type, $this->category_id, $this->channel_id, $this->weekofday, $this->prgtime ); + } + catch( Exception $e ) { + throw $e; + } + return $recs; + } public function reservation() { if( $this->id == 0 ) return; @@ -74,22 +94,17 @@ catch( Exception $e ) { throw $e; } - if( count($precs) < 300 ) { - // 一気に録画予約 - foreach( $precs as $rec ) { - try { - if( $rec->autorec ) { - Reservation::simple( $rec->id, $this->id, $this->autorec_mode ); - usleep( 100 ); // あんまり時間を空けないのもどう? - } - } - catch( Exception $e ) { - // 無視 + // 一気に録画予約 + foreach( $precs as $rec ) { + try { + if( $rec->autorec ) { + Reservation::simple( $rec->id, $this->id, $this->autorec_mode ); + usleep( 100 ); // あんまり時間を空けないのもどう? } } - } - else { - throw new Exception( "300件以上の自動録画は実行できません" ); + catch( Exception $e ) { + // 無視 + } } } diff -r 9b9e22be8407 -r f5d58cf2842f Reservation.class.php --- a/Reservation.class.php Sat Mar 13 18:53:41 2010 +0900 +++ b/Reservation.class.php Sun Mar 14 16:31:50 2010 +0900 @@ -199,39 +199,38 @@ $day_of_week = array( "日","月","火","水","木","金","土" ); $filename = $settings->filename_format; + // %TITLE% + $filename = mb_str_replace("%TITLE%", $fn_title, $filename); + // %ST% 開始日時 + $filename = mb_str_replace("%ST%",date("YmdHis", $start_time), $filename ); + // %ET% 終了日時 + $filename = mb_str_replace("%ET%",date("YmdHis", $end_time), $filename ); + // %TYPE% GR/BS + $filename = mb_str_replace("%TYPE%",$crec->type, $filename ); + // %CH% チャンネル番号 + $filename = mb_str_replace("%CH%","".$crec->channel, $filename ); + // %DOW% 曜日(Sun-Mon) + $filename = mb_str_replace("%DOW%",date("D", $start_time), $filename ); + // %DOWJ% 曜日(日-土) + $filename = mb_str_replace("%DOWJ%",$day_of_week[(int)date("w", $start_time)], $filename ); + // %YEAR% 開始年 + $filename = mb_str_replace("%YEAR%",date("Y", $start_time), $filename ); + // %MONTH% 開始月 + $filename = mb_str_replace("%MONTH%",date("m", $start_time), $filename ); + // %DAY% 開始日 + $filename = mb_str_replace("%DAY%",date("d", $start_time), $filename ); + // %HOUR% 開始時 + $filename = mb_str_replace("%HOUR%",date("H", $start_time), $filename ); + // %MIN% 開始分 + $filename = mb_str_replace("%MIN%",date("i", $start_time), $filename ); + // %SEC% 開始秒 + $filename = mb_str_replace("%SEC%",date("s", $start_time), $filename ); + // %DURATION% 録画時間(秒) + $filename = mb_str_replace("%DURATION%","".$duration, $filename ); // あると面倒くさそうな文字を全部_に $fn_title = mb_ereg_replace("[ \./\*:<>\?\\|()\'\"&]","_", trim($title) ); - // %TITLE% - $filename = str_replace("%TITLE%", $fn_title, $filename); - // %ST% 開始日時 - $filename = str_replace("%ST%",date("YmdHis", $start_time), $filename ); - // %ET% 終了日時 - $filename = str_replace("%ET%",date("YmdHis", $end_time), $filename ); - // %TYPE% GR/BS - $filename = str_replace("%TYPE%",$crec->type, $filename ); - // %CH% チャンネル番号 - $filename = str_replace("%CH%","".$crec->channel, $filename ); - // %DOW% 曜日(Sun-Mon) - $filename = str_replace("%DOW%",date("D", $start_time), $filename ); - // %DOWJ% 曜日(日-土) - $filename = str_replace("%DOWJ%",$day_of_week[(int)date("w", $start_time)], $filename ); - // %YEAR% 開始年 - $filename = str_replace("%YEAR%",date("Y", $start_time), $filename ); - // %MONTH% 開始月 - $filename = str_replace("%MONTH%",date("m", $start_time), $filename ); - // %DAY% 開始日 - $filename = str_replace("%DAY%",date("d", $start_time), $filename ); - // %HOUR% 開始時 - $filename = str_replace("%HOUR%",date("H", $start_time), $filename ); - // %MIN% 開始分 - $filename = str_replace("%MIN%",date("i", $start_time), $filename ); - // %SEC% 開始秒 - $filename = str_replace("%SEC%",date("s", $start_time), $filename ); - // %DURATION% 録画時間(秒) - $filename = str_replace("%DURATION%","".$duration, $filename ); - // 文字コード変換 if( defined("FILESYSTEM_ENCODING") ) { // $filename = mb_convert_encoding( $filename, FILESYSTEM_ENCODING, "UTF-8" ); diff -r 9b9e22be8407 -r f5d58cf2842f config.php.sample --- a/config.php.sample Sat Mar 13 18:53:41 2010 +0900 +++ b/config.php.sample Sun Mar 14 16:31:50 2010 +0900 @@ -223,76 +223,5 @@ define( "CATEGORY_TBL", "categoryTbl" ); // カテゴリテーブル define( "KEYWORD_TBL", "keywordTbl" ); // キーワードテーブル -// 予約テーブル -define( "RESERVE_STRUCT", - "id integer not null auto_increment primary key,". // ID - "channel_disc varchar(128) not null default 'none',". // channel disc - "channel_id integer not null default '0',". // channel ID - "program_id integer not null default '0',". // Program ID - "type varchar(8) not null default 'GR',". // 種別(GR/BS/CS) - "channel varchar(10) not null default '0',". // チャンネル - "title varchar(512) not null default 'none',". // タイトル - "description varchar(512) not null default 'none',". // 説明 text->varchar - "category_id integer not null default '0',". // カテゴリID - "starttime datetime not null default '1970-01-01 00:00:00',". // 開始時刻 - "endtime datetime not null default '1970-01-01 00:00:00',". // 終了時刻 - "job integer not null default '0',". // job番号 - "path blob default null,". // 録画ファイルパス - "complete boolean not null default '0',". // 完了フラグ - "reserve_disc varchar(128) not null default 'none',". // 識別用hash - "autorec integer not null default '0',". // キーワードID - "mode integer not null default '0',". //録画モード - "index reserve_ch_idx (channel_disc),". // インデックス - "index reserve_st_idx (starttime)". - "" -); - -// 番組表テーブル -define( "PROGRAM_STRUCT", - "id integer not null auto_increment primary key,". // ID - "channel_disc varchar(128) not null default 'none',". // channel disc - "channel_id integer not null default '0',". // channel ID - "type varchar(8) not null default 'GR',". // 種別(GR/BS/CS) - "channel varchar(10) not null default '0',". // チャンネル - "title varchar(512) not null default 'none',". // タイトル - "description varchar(512) not null default 'none',". // 説明 text->varchar - "category_id integer not null default '0',". // カテゴリID - "starttime datetime not null default '1970-01-01 00:00:00',". // 開始時刻 - "endtime datetime not null default '1970-01-01 00:00:00',". // 終了時刻 - "program_disc varchar(128) not null default 'none',". // 識別用hash - "autorec boolean not null default '1',". // 自動録画有効無効 - "index program_ch_idx (channel_disc),". // インデックス - "index program_st_idx (starttime)". - "" -); - - -define( "CHANNEL_STRUCT", - "id integer not null auto_increment primary key,". // ID - "type varchar(8) not null default 'GR',". // 種別 - "channel varchar(10) not null default '0',". // channel - "name varchar(512) not null default 'none',". // 表示名 - "channel_disc varchar(128) not null default 'none',". // 識別用hash - "sid varchar(64) not null default 'hd'" // サービスID用02/23/2010追加 -); - -define( "CATEGORY_STRUCT", - "id integer not null auto_increment primary key,". // ID - "name_jp varchar(512) not null default 'none',". // 表示名 - "name_en varchar(512) not null default 'none',". // 同上 - "category_disc varchar(128) not null default 'none'" // 識別用hash -); - - -define( "KEYWORD_STRUCT", - "id integer not null auto_increment primary key,". // ID - "keyword varchar(512) not null default '*',". // 表示名 - "type varchar(8) not null default '*',". // 種別 - "channel_id integer not null default '0',". // channel ID - "category_id integer not null default '0',". // カテゴリID - "use_regexp boolean not null default '0',". // 正規表現を使用するなら1 - "autorec_mode integer not null default '0',". // 自動録画のモード02/23/2010追加 - "weekofday enum ('0','1','2','3','4','5','6','7' ) default '7'" // 曜日、同追加 -); -?> +?> \ No newline at end of file diff -r 9b9e22be8407 -r f5d58cf2842f install/step3.php --- a/install/step3.php Sat Mar 13 18:53:41 2010 +0900 +++ b/install/step3.php Sun Mar 14 16:31:50 2010 +0900 @@ -4,6 +4,7 @@ include_once("../DBRecord.class.php"); include_once("../Settings.class.php"); include_once("../reclib.php" ); +include_once("../tableStruct.inc.php"); $settings = Settings::factory(); $settings->post(); // いったん保存する diff -r 9b9e22be8407 -r f5d58cf2842f programTable.php --- a/programTable.php Sat Mar 13 18:53:41 2010 +0900 +++ b/programTable.php Sun Mar 14 16:31:50 2010 +0900 @@ -3,6 +3,7 @@ include_once( INSTALL_PATH . '/DBRecord.class.php' ); include_once( INSTALL_PATH . '/Smarty/Smarty.class.php' ); include_once( INSTALL_PATH . '/Settings.class.php' ); +include_once( INSTALL_PATH . '/Keyword.class.php' ); $settings = Settings::factory(); @@ -24,73 +25,45 @@ $autorec_modes = $RECORD_MODE; $autorec_modes[(int)($settings->autorec_mode)]['selected'] = "selected"; -$weekofday = 7; $search = ""; $use_regexp = 0; $type = "*"; $category_id = 0; -$station = 0; +$channel_id = 0; +$weekofday = 7; $prgtime = 24; - -// mysql_real_escape_stringより先に接続しておく必要がある -$dbh = @mysql_connect($settings->db_host, $settings->db_user, $settings->db_pass ); - - // パラメータの処理 +// パラメータの処理 if(isset( $_POST['do_search'] )) { if( isset($_POST['search'])){ - if( $_POST['search'] != "" ) { - $search = $_POST['search']; - if( isset($_POST['use_regexp']) && ($_POST['use_regexp']) ) { - $use_regexp = $_POST['use_regexp']; - $options .= " AND CONCAT(title,description) REGEXP '".mysql_real_escape_string($search)."'"; - } - else { - $search = mb_convert_kana($search, "A", "UTF-8"); - $options .= " AND CONCAT(title,description) like '%".mysql_real_escape_string($search)."%'"; - } + $search = $_POST['search']; + if( isset($_POST['use_regexp']) && ($_POST['use_regexp']) ) { + $use_regexp = (int)($_POST['use_regexp']); } } if( isset($_POST['type'])){ - if( $_POST['type'] != "*" ) { - $type = $_POST['type']; - $options .= " AND type = '".$_POST['type']."'"; - } + $type = $_POST['type']; } if( isset($_POST['category_id'])) { - if( $_POST['category_id'] != 0 ) { - $category_id = $_POST['category_id']; - $options .= " AND category_id = '".$_POST['category_id']."'"; - } + $category_id = (int)($_POST['category_id']); } if( isset($_POST['station'])) { - if( $_POST['station'] != 0 ) { - $station = $_POST['station']; - $options .= " AND channel_id = '".$_POST['station']."'"; - } + $channel_id = (int)($_POST['station']); } if( isset($_POST['weekofday']) ) { - $weekofday = $_POST['weekofday']; - if( $weekofday != 7 ) { - $options .= " AND WEEKDAY(starttime) = '".$weekofday."'"; - } + $weekofday = (int)($_POST['weekofday']); } if( isset($_POST['prgtime']) ) { $prgtime = (int)($_POST['prgtime']); - if( $prgtime != 24 ) { - $options .= " AND time(starttime) BETWEEN cast('".sprintf( "%02d:00:00", $prgtime)."' as time) AND cast('".sprintf("%02d:59:59", $prgtime)."' as time)"; - } } } -$options .= " ORDER BY starttime ASC LIMIT 300"; - $do_keyword = 0; -if( ($search != "") || ($type != "*") || ($category_id != 0) || ($station != 0) ) +if( ($search != "") || ($type != "*") || ($category_id != 0) || ($channel_id != 0) ) $do_keyword = 1; try{ - $precs = DBRecord::createRecords(PROGRAM_TBL, $options ); + $precs = Keyword::search( $search, $use_regexp, $type, $category_id, $channel_id, $weekofday, $prgtime ); $programs = array(); foreach( $precs as $p ) { @@ -158,13 +131,13 @@ $stations = array(); $stations[0]['id'] = 0; $stations[0]['name'] = "すべて"; - $stations[0]['selected'] = (! $station) ? "selected" : ""; + $stations[0]['selected'] = (! $channel_id) ? "selected" : ""; foreach( $crecs as $c ) { $arr = array(); $arr['id'] = $c->id; $arr['name'] = $c->name; - $arr['selected'] = $station == $c->id ? "selected" : ""; - if( $station == $c->id ) $k_station_name = $c->name; + $arr['selected'] = $channel_id == $c->id ? "selected" : ""; + if( $channel_id == $c->id ) $k_station_name = $c->name; array_push( $stations, $arr ); } $weekofdays["$weekofday"]["selected"] = "selected" ; @@ -193,7 +166,7 @@ $smarty->assign( "search" , $search ); $smarty->assign( "use_regexp", $use_regexp ); $smarty->assign( "stations", $stations ); - $smarty->assign( "k_station", $station ); + $smarty->assign( "k_station", $channel_id ); $smarty->assign( "k_station_name", $k_station_name ); $smarty->assign( "weekofday", $weekofday ); $smarty->assign( "k_weekofday", $weekofdays["$weekofday"]["name"] ); diff -r 9b9e22be8407 -r f5d58cf2842f reclib.php --- a/reclib.php Sat Mar 13 18:53:41 2010 +0900 +++ b/reclib.php Sun Mar 14 16:31:50 2010 +0900 @@ -21,4 +21,23 @@ "// -->\n" ); } +// マルチバイトstr_replace + +function mb_str_replace($search, $replace, $target, $encoding = "UTF-8" ) { + $notArray = !is_array($target) ? TRUE : FALSE; + $target = $notArray ? array($target) : $target; + $search_len = mb_strlen($search, $encoding); + $replace_len = mb_strlen($replace, $encoding); + + foreach ($target as $i => $tar) { + $offset = mb_strpos($tar, $search); + while ($offset !== FALSE){ + $tar = mb_substr($tar, 0, $offset).$replace.mb_substr($tar, $offset + $search_len); + $offset = mb_strpos($tar, $search, $offset + $replace_len); + } + $target[$i] = $tar; + } + return $notArray ? $target[0] : $target; +} + ?> \ No newline at end of file diff -r 9b9e22be8407 -r f5d58cf2842f tableStruct.inc.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tableStruct.inc.php Sun Mar 14 16:31:50 2010 +0900 @@ -0,0 +1,82 @@ +varchar + "category_id integer not null default '0',". // カテゴリID + "starttime datetime not null default '1970-01-01 00:00:00',". // 開始時刻 + "endtime datetime not null default '1970-01-01 00:00:00',". // 終了時刻 + "job integer not null default '0',". // job番号 + "path blob default null,". // 録画ファイルパス + "complete boolean not null default '0',". // 完了フラグ + "reserve_disc varchar(128) not null default 'none',". // 識別用hash + "autorec integer not null default '0',". // キーワードID + "mode integer not null default '0',". // 録画モード + "index reserve_ch_idx (channel_disc),". // インデックス + "index reserve_st_idx (starttime)". + "" +); + + +// 番組表テーブル +define( "PROGRAM_STRUCT", + "id integer not null auto_increment primary key,". // ID + "channel_disc varchar(128) not null default 'none',". // channel disc + "channel_id integer not null default '0',". // channel ID + "type varchar(8) not null default 'GR',". // 種別(GR/BS/CS) + "channel varchar(10) not null default '0',". // チャンネル + "title varchar(512) not null default 'none',". // タイトル + "description varchar(512) not null default 'none',". // 説明 text->varchar + "category_id integer not null default '0',". // カテゴリID + "starttime datetime not null default '1970-01-01 00:00:00',". // 開始時刻 + "endtime datetime not null default '1970-01-01 00:00:00',". // 終了時刻 + "program_disc varchar(128) not null default 'none',". // 識別用hash + "autorec boolean not null default '1',". // 自動録画有効無効 + "index program_ch_idx (channel_disc),". // インデックス + "index program_st_idx (starttime)". + "" +); + + +define( "CHANNEL_STRUCT", + "id integer not null auto_increment primary key,". // ID + "type varchar(8) not null default 'GR',". // 種別 + "channel varchar(10) not null default '0',". // channel + "name varchar(512) not null default 'none',". // 表示名 + "channel_disc varchar(128) not null default 'none',". // 識別用hash + "sid varchar(64) not null default 'hd',". // サービスID用02/23/2010追加 + "skip boolean not null default '0'". // チャンネルスキップ用03/13/2010追加 + "" +); + +define( "CATEGORY_STRUCT", + "id integer not null auto_increment primary key,". // ID + "name_jp varchar(512) not null default 'none',". // 表示名 + "name_en varchar(512) not null default 'none',". // 同上 + "category_disc varchar(128) not null default 'none'" // 識別用hash +); + + +define( "KEYWORD_STRUCT", + "id integer not null auto_increment primary key,". // ID + "keyword varchar(512) not null default '*',". // 表示名 + "type varchar(8) not null default '*',". // 種別 + "channel_id integer not null default '0',". // channel ID + "category_id integer not null default '0',". // カテゴリID + "use_regexp boolean not null default '0',". // 正規表現を使用するなら1 + "autorec_mode integer not null default '0',". // 自動録画のモード02/23/2010追加 + "weekofday enum ('0','1','2','3','4','5','6','7' ) default '7'".// 曜日、同追加 + ",prgtime enum ('0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24') default '24'". // 時間 03/13/2010追加 + "" +); + +?> \ No newline at end of file