From 18 Jan, 2021 0:00 UTC: All services will be temporary unavailable for maintenance
  • R/O
  • SSH
  • HTTPS

text2html: Commit


Commit MetaInfo

Revisión79 (tree)
Tiempo2008-08-25 14:08:55
Autortenman

Log Message

(empty log message)

Cambiar Resumen

Diferencia incremental

--- branches/php4/trans.php (nonexistent)
+++ branches/php4/trans.php (revision 79)
@@ -0,0 +1,2415 @@
1+<?php
2+/*------------------------------------------------------------------------------+
3+ *<meta http-equiv="Content-Type" content="text/php; charset=utf-8">
4+
5+ This program is free software: you can redistribute it and/or modify
6+ it under the terms of the GNU General Public License as published by
7+ the Free Software Foundation, either version 3 of the License, or
8+ (at your option) any later version.
9+
10+ This program is distributed in the hope that it will be useful,
11+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ GNU General Public License for more details.
14+
15+ You should have received a copy of the GNU General Public License
16+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17+ *------------------------------------------------------------------------------*/
18+
19+/*------------------------------------------------------------------------------+
20+ *スクリプトは、text2html てきでこ -1.0.3 をPHP4環境で動作確認した時のものです。
21+ *このほかに、php.iniで、改行が入っている場合、php4では利用できません。
22+ * php4環境で制限付でもいいから利用したい場合に、お役立てください。2008/08/25
23+ *------------------------------------------------------------------------------*/
24+
25+ mb_language( 'Japanese' );
26+
27+ if(preg_match("/^[A-z]:.+/",__FILE__)){
28+ $separater = '\\';
29+ }else{
30+ $separater = '/';
31+ }
32+
33+ if(!isset($text2html_url)){
34+ $text2html_url = "http://". $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']).$separater;
35+ }
36+
37+ if(!isset($text2html_dir_path)){
38+ $text2html_dir_path = dirname(dirname(__FILE__)).$separater;
39+ }
40+
41+ if(!isset($cache)){
42+ $cache = true;
43+
44+ }
45+//スクリプトディレクトリ
46+
47+ define("TEXTTOHTML_SCRIPTS_DIR_PATH",$text2html_dir_path."scripts{$separater}");
48+
49+//主に、htmlパターン用のストック
50+ define("TEXTTOHTML_DATA_DIR_PATH", $text2html_dir_path ."data{$separater}");
51+ define("TEXTTOHTML_CHANGE_TXT",TEXTTOHTML_DATA_DIR_PATH."change.txt");
52+ define("CHANGE_PATTERN_PATH",TEXTTOHTML_DATA_DIR_PATH."change.xml");
53+
54+//画像保管用ディレクトリ
55+ define("TEXTTOHTML_IMAGE_DIR_PATH", $text2html_dir_path."images{$separater}");
56+ define("TEXTTOHTML_IMAGE_DIR_URL", $text2html_url."images{$separater}");
57+//イメージコピー用スクリプト
58+ define("TEXTTOHTML_COPY_IMG_WIDTH","100");
59+ define("IMAGE_IMPORT_PATH", $text2html_dir_path."import{$separater}");
60+ define("IMAGE_IMPORT_SVR", $text2html_url."import{$separater}image.php");
61+//source true
62+ define("TEXTTOHTML_CODE_WRAP_WIDTH",48);
63+//画像コピーディレクトリ
64+ define("TEXTTOHTML_IMPORT_DIR_PATH","import{$separater}");
65+
66+ //トラックバックフォーム WEBサービス
67+ //define("TEXTTOHTML_TRACKBACK_URL","");
68+
69+//キャッシュディレクトリ
70+
71+ define("CACHE_LITE_PATH","Cache{$separater}Lite.php");
72+ define("CACHE_DIR_PATH",$text2html_dir_path."cache{$separater}");
73+ define("CACHE_LIFE_TIME",3600);
74+ define("CACHE_SWITCH",$cache); //falseキャッシュの破棄
75+
76+//設定ファイル
77+ define("HTML_RULE_CONFIG_FILE_PATH",TEXTTOHTML_SCRIPTS_DIR_PATH."html.ini");
78+ define("TEXTTOHTML_FONT_DIR_PATH",$text2html_dir_path."font{$separater}");
79+ define("TEXTTOHTML_FONTS_PATH",TEXTTOHTML_FONT_DIR_PATH."fonts.inc");
80+
81+//MEMO
82+/*----------------------------------------------------------------------+
83+ * get_querys()で使用する配列の説明。
84+
85+ "tenki"=>array(
86+ 'charset'=>'UTF-8',
87+ 'type'=>'contents',
88+ 'url'=>'http://www.odekake.biz/branch/?date=+++E_KEYWORD+++',
89+ "response"=>"+++CONTENTS+++\n"),
90+
91+ ['type']
92+ contents_rebuild
93+
94+ 関数による処理を行ったうえでコンテンツとする。
95+ url function
96+ クラス外部のメソッド
97+ 必須
98+ contents
99+ 単純なレスポンスをコンテンツとする URL必須
100+ link
101+ a img用のURLとして
102+------------------------------------------------------------------------*/
103+
104+class trans{
105+
106+ var $document;
107+ var $source;
108+ var $html;
109+ var $header;
110+ var $header_info = array();
111+ var $midasilist;
112+ var $footNote = array();
113+ var $footNoteList;
114+ var $content_no_h1;
115+ var $content_no_h2;
116+ var $content_no_h3;
117+ var $content_no_h4;
118+ var $content_no_h5;
119+ var $content_no_h6;
120+
121+ var $separator;
122+ var $element;
123+ var $wm;
124+ var $content;
125+ var $attr;
126+ var $content_attr;
127+ var $description;
128+ var $copy_target;
129+ var $copy_uri;
130+
131+
132+ function trans($document){
133+
134+ $document = str_replace(array("\r"),"\n",$document);
135+ $document = $this->tag_br($document);
136+ $this->document = $this->tag_clear($document);
137+ }
138+
139+ function delete_break($matches){
140+ $result = "";
141+
142+ foreach($matches as $key=>$match){
143+ if($key==0){
144+ $result .= str_replace("\n","",$match);
145+ }
146+ }
147+
148+ $result = preg_replace("/\s{2,}/"," ",$result);
149+
150+ return $result;
151+ }
152+
153+ function tag_br($text){
154+ $text = str_replace("\r","",$text);
155+ $text = preg_replace("/\s=/","=",$text);
156+ $text = preg_replace_callback("/[^(code:)](<[^>]+\s{2,}[^>]+>)/usi",array($this, 'delete_break'),$text);
157+
158+ return $text;
159+
160+ }
161+/*
162+ function get_querys($text){
163+
164+ if(ini_get("allow_url_fopen") == false){
165+
166+ return $text;
167+ }
168+
169+ //重複名の誤変換を避けるために、文字数の長い順にソート
170+$get_querys = array(
171+//キー名は10文字未満
172+ "googlemaps"=>array(
173+ 'charset'=>'UTF-8',
174+ 'type'=>'link',
175+ 'response'=>"<sup class=\"gmaps\"><a href=\"http://www.google.co.jp/maps?f=q&amp;hl=ja&amp;oe=UTF8&amp;ie=UTF8&amp;q=+++E_KEYWORD+++\" title=\"[ +++KEYWORD+++ 地図リンク]\">Map</a></sup>"),
176+
177+ "qrcode"=>array(
178+ 'charset'=>'SHIFT_JIS',
179+ 'type'=>'link',
180+ "response"=>"<img src=\"http://www.odekake.biz/images/qr/qr_img.php?s=3&amp;v=0&amp;e=m&amp;d=+++E_KEYWORD+++\" alt=\"+++KEYWORD+++\" width=\"87\" height=\"87\" />"),
181+
182+ "goo_search"=>array(
183+ 'charset'=>'UTF-8',
184+ 'type'=>'link',
185+ "response"=>"<a href=\"http://search.goo.ne.jp/web.jsp?PT=bb_tp&amp;from=query&amp;MT=+++E_KEYWORD+++&amp;web.x=54&amp;web.y=13&amp;DC=10\">goo検索+++KEYWORD+++</a>"),
186+
187+ "pdf"=>array(
188+ 'charset'=>'UTF-8',
189+ 'type'=>'link',
190+ "response"=>"<a href=\"http://html2pdf.biz/api?url=+++E_KEYWORD+++&amp;ret=pdf\">+++KEYWORD+++PDF</a>"),
191+
192+ "円グラフ"=>array(
193+ 'charset'=>'UTF-8',
194+ 'type'=>'query',
195+ "response"=>"<img src=\"http://graph.heartrails.com/api/?+++E_KEYWORD+++\" alt=\"+++KEYWORD+++\" />\n"),
196+ "郵便番号"=>array(
197+ 'charset'=>'UTF-8',
198+ 'type'=>'contents_rebuild',
199+ 'function'=>'postal_code',
200+ 'url'=>'http://zip.cgis.biz/xml/zip.php?zn=+++E_KEYWORD+++',
201+ "response"=>"+++CONTENTS+++"),
202+ "wikipedia"=>array(
203+ 'charset'=>'UTF-8',
204+ 'type'=>'contents_rebuild',
205+ 'function'=>'simpleapi_wikipedia',
206+ 'url'=>'http://wikipedia.simpleapi.net/api?keyword=+++E_KEYWORD+++&output=php',
207+ "response"=>"+++CONTENTS+++"),
208+
209+"tenki"=>array(
210+ 'charset'=>'UTF-8',
211+ 'type'=>'contents',
212+ 'url'=>'http://www.odekake.biz/branch/?date=+++E_KEYWORD+++',
213+ "response"=>"+++CONTENTS+++\n"),
214+ );
215+
216+ uksort($get_querys,"text2html_cmp");
217+
218+ if(isset($get_querys)){
219+ foreach($get_querys as $key=>$val){
220+ if(preg_match_all("/($key>\()([^\)]+)(\))/u", $text, $matches, PREG_SET_ORDER)){
221+
222+ foreach($matches as $key=>$match){
223+
224+ $cache = use_cache($matches[$key][0]);
225+ if($cache[0]){
226+
227+ $text = str_replace($matches[$key][0],$cache[1],$text)."\n";
228+ }else{
229+
230+ $enc = mb_convert_encoding($match[2],$val['charset'],"auto");
231+ $no_enc = mb_convert_encoding($match[2],"UTF-8","auto");
232+ $no_enc = str_replace("\n","",$no_enc);
233+
234+ switch($val['type']){
235+
236+ case('link'):
237+
238+ $enc = urlencode($enc);
239+ $replacement = mb_convert_encoding($val['response'],"UTF-8","auto");
240+ $replacement = str_replace(array("+++E_KEYWORD+++","+++KEYWORD+++"),array($enc,$no_enc),$val['response']);
241+ $replacement = trim($replacement);
242+ break;
243+
244+ case('contents'):
245+
246+ $enc = urlencode($enc);
247+ $target = mb_convert_encoding($val['url'],"UTF-8","auto");
248+ $target = str_replace(array("+++E_KEYWORD+++","+++KEYWORD+++"),array($enc,$no_enc),$target);
249+ $host = parse_url($target);
250+ $host = $host['host'];
251+
252+ try{
253+
254+ if(!$fp = fsockopen ($host, 80, $errno, $errstr, 5)){
255+
256+ throw new Exception('を、取得できません。サービスを停止してるかどうか確認してください。');
257+ }
258+
259+ socket_set_timeout($fp, 3);
260+ fputs ($fp, "GET / HTTP/1.0\r\nHost: ".$_SERVER['HTTP_HOST']."\r\n\r\n");
261+ $replacement = mb_convert_encoding(file_get_contents($target),"UTF-8","auto");
262+ $stat = socket_get_status($fp);
263+
264+ if ($stat["timed_out"]) {
265+
266+ throw new Exception('タイムアウトしました。');
267+ }
268+
269+ fclose($fp);
270+
271+ }catch (Exception $e) {
272+
273+ $errstr = mb_convert_encoding($errstr,"UTF-8","auto");
274+ echo '<div style="text-align:left;padding:2em;background:#FF99FF;">例外: ',$target,$e->getMessage(), "\n</div>\n";
275+ }
276+
277+ break;
278+
279+ case('query'):
280+
281+ $replacement = mb_convert_encoding($val['response'],"UTF-8","auto");
282+ $querys = explode("&",$enc);
283+ $enc = "";
284+
285+ foreach($querys as $query){
286+
287+ preg_match("/([^=]+)(=)(.+)/", $query, $hit);
288+
289+ if($hit){
290+ $enc .= '&amp;'.urlencode($hit[1]).$hit[2].urlencode($hit[3]);
291+ }
292+
293+ }
294+
295+ $enc = str_replace("\n","",$enc);
296+ $no_enc = "";
297+ $replacement = str_replace(array("+++E_KEYWORD+++","+++KEYWORD+++"),array($enc,$no_enc),$val['response']);
298+
299+ break;
300+
301+ case('contents_rebuild'):
302+
303+ $enc = urlencode($enc);
304+ $replacement = mb_convert_encoding($val['response'],"UTF-8","auto");
305+ $target = str_replace(array("+++E_KEYWORD+++","+++KEYWORD+++"),array($enc,$no_enc),$val['url']);
306+
307+ $host = parse_url($target);
308+ $host = $host['host'];
309+
310+ try{
311+
312+ if(!$fp = fsockopen ($host, 80, $errno, $errstr, 5)){
313+
314+ throw new Exception('を、取得できません。サービスを停止してるかどうか確認してください。');
315+ }
316+
317+ socket_set_timeout($fp, 3);
318+ fputs ($fp, "GET / HTTP/1.0\r\nHost: ".$_SERVER['HTTP_HOST']."\r\n\r\n");
319+
320+ $replacement = mb_convert_encoding(@file_get_contents($target),"UTF-8","auto");
321+ $function_name = $val['function'];
322+ $replacement = $function_name($replacement);
323+
324+ $stat = socket_get_status($fp);
325+
326+ if ($stat["timed_out"]) {
327+
328+ throw new Exception('タイムアウトしました。');
329+ }
330+
331+ fclose($fp);
332+
333+
334+ }catch (Exception $e) {
335+
336+ $errstr = mb_convert_encoding($errstr,"UTF-8","auto");
337+ echo '<div style="text-align:left;padding:2em;background:#FF99FF;">例外: ',$target,$e->getMessage(), "\n</div>\n";
338+ }
339+ break;
340+
341+ }
342+
343+ save_cache($matches[$key][0],$replacement);
344+
345+ $text = str_replace($matches[$key][0],$replacement,$text)."\n";
346+ }
347+
348+ }
349+
350+ }
351+
352+ }
353+ }
354+return $text;
355+}
356+*/
357+ function number(){
358+ static $int = 0;
359+
360+ $int++;
361+ return $int;
362+ }
363+
364+ function text2html(){
365+
366+ global $benchmark;
367+ global $source;
368+ global $content_name;
369+
370+ $pear_file = "";
371+ $timer = false;
372+ $buffer = $this->document;
373+ $output_enc = "UTF-8";
374+
375+ if(isset($benchmark) and $benchmark == true){
376+ include_once ("Benchmark/Timer.php");
377+ $timer = true;
378+ $oTimer =& new Benchmark_Timer();
379+ $oTimer->start ();
380+ }
381+
382+ if($timer){ $oTimer->setMarker( 'preset' );}
383+
384+ $buffer = $this->change_word($buffer);
385+
386+ if($timer){ $oTimer->setMarker( 'change_word' );}
387+//table
388+ $buffer = $this->text2html_table($buffer,"\n","table","tr:","tr","","","table");
389+
390+ if($timer){ $oTimer->setMarker( 'text2html_table' );}
391+//blockquote
392+ $buffer = $this->text2html_code($buffer,"\n","pre",'code:','code','','class="source"','souce');
393+
394+ if($timer){ $oTimer->setMarker( 'text2html_code' );}
395+//heading
396+ $buffer = $this->text2html_element($buffer,"\n","h6",'\*\*\*\*\*','a','', 'href="#TOP"','h6');
397+ if($timer){$oTimer->setMarker( 'elementh6' );}
398+
399+ $buffer = $this->text2html_element($buffer,"\n","h5",'\*\*\*\*','a','', 'href="#TOP"','h5');
400+ if($timer){ $oTimer->setMarker( 'elementh5' );}
401+
402+ $buffer = $this->text2html_element($buffer,"\n","h4",'\*\*\*','a','', 'href="#TOP"','h4');
403+ if($timer){$oTimer->setMarker( 'elementh4' );}
404+
405+ $buffer = $this->text2html_element($buffer,"\n","h3",'\*\*','a','', 'href="#TOP"','h3');
406+ if($timer){ $oTimer->setMarker( 'elementh3' );}
407+
408+ $buffer = $this->text2html_element($buffer,"\n","h2",'\*','a','', 'href="#TOP"','h2');
409+ if($timer){ $oTimer->setMarker( 'elementh2' );}
410+
411+ // $buffer = $this->link_title($buffer);
412+// if($timer){ $oTimer->setMarker( 'link_title' );}
413+
414+//vertical align
415+ $buffer = $this->text2html_element($buffer,"\n","div",'==','p','', 'style="text-align:right;"','right');
416+ if($timer){$oTimer->setMarker( 'align:right' );}
417+
418+ $buffer = $this->text2html_element($buffer,"\n","div",'=','p','', 'style="text-align:center;"','center');
419+ if($timer){$oTimer->setMarker( 'align:center' );}
420+
421+ $buffer = $this->note($buffer,"\n");
422+ if($timer){$oTimer->setMarker( 'note' );}
423+
424+//見出しリスト
425+ asort($this->header_info);
426+ $this->midasilist = "<a name=\"TOP\" id=\"TOP\" >head line</a>\n";
427+ $kihou = "";
428+
429+ foreach($this->header_info as $key=>$link){
430+
431+ $kihou = str_repeat ('+', $link[1]-1);
432+ $this->midasilist .= "$kihou<span><a href=\"#$link[2]\">$link[3]</a></span>\n";
433+ }
434+ $this->midasilist = $this->text2html_list(trim($this->midasilist)."\n","\n","ol",'+','li','','','head-line');
435+
436+//閉じタグチェック
437+ preg_match_all("/(<ol><li>)/u",$this->midasilist,$start,PREG_SET_ORDER);
438+ preg_match_all("/(<\/ol><\/li>)/u",$this->midasilist,$end,PREG_SET_ORDER);
439+
440+ $rep = count($end)-count($start);
441+
442+ switch(true){
443+ case(count($end) == count($start)):
444+
445+ break;
446+
447+ case(count($end) > count($start)):
448+ //閉じタグが多い
449+ $rep = $rep;
450+ $rep = str_repeat("<\/ol><\/li>",$rep + 1);
451+ $this->midasilist = preg_replace("/$rep<\/ol>$/m","</ol>",$this->midasilist);
452+
453+ break;
454+
455+ case(count($end) < count($start)):
456+ //閉じタグが少ない
457+ $rep = str_repeat('</ol></li>',abs($rep)-1);
458+ $this->midasilist = preg_replace("/<\/ol>$/m","",$this->midasilist).$rep."</ol>";
459+
460+ break;
461+ }
462+
463+ $buffer = str_replace("[head_line]", $this->midasilist, $buffer);
464+ if($timer){$oTimer->setMarker( 'head_line' );}
465+
466+//foot note
467+
468+ foreach($this->footNote as $note){
469+ $this->footNoteList .= "<li><p><a href=\"#$note[1]\" name=\"$note[2]\" id=\"$note[2]\" >[".$note[0]."]</a>$note[3]</p></li>";
470+ }
471+
472+ $this->footNoteList = "<ul class=\"foot-note-$content_name\">".$this->footNoteList."</ul>";
473+ $buffer = str_replace("[foot_note]",$this->footNoteList, $buffer);
474+
475+//etc
476+ if($timer){$oTimer->setMarker( 'foot_note' );}
477+
478+ $buffer = $this->keyword_change($buffer,"\n");
479+ if($timer){$oTimer->setMarker( 'keyword_change' );}
480+
481+// $buffer = $this->read_php($buffer,"\n");
482+// if($timer){$oTimer->setMarker( 'read_php' );}
483+
484+ $buffer = $this->keyword_change_inline($buffer,"\n");//ok
485+ if($timer){$oTimer->setMarker( 'keyword_change_inline' );}
486+
487+ $buffer = $this->inline_tag($buffer);
488+ if($timer){$oTimer->setMarker( 'inline_tag' );}
489+
490+ $buffer = $this->ruby($buffer);//これは、IE xthml1.1
491+ if($timer){$oTimer->setMarker( 'inline_tag' );}
492+
493+ $buffer = $this->trackback($buffer,"\n");
494+ if($timer){$oTimer->setMarker( 'trackback' );}
495+
496+ $buffer = $this->maillink($buffer,"\n");
497+ if($timer){$oTimer->setMarker( 'maillink' );}
498+
499+ $buffer = $this->youtube($buffer,"\n");
500+ if($timer){$oTimer->setMarker( 'youtube' );}
501+
502+ // $buffer = $this->txt2img($buffer,"\n");
503+ // if($timer){$oTimer->setMarker( 'text2image' );}
504+
505+ $buffer = $this->sound($buffer,"\n");
506+ if($timer){$oTimer->setMarker( 'text2image' );}
507+
508+ $buffer = $this->foma_movie($buffer,"\n");
509+ if($timer){$oTimer->setMarker( '3gp' );}
510+
511+ $buffer = $this->swf($buffer,"\n");
512+ if($timer){$oTimer->setMarker( '3gp' );}
513+
514+ $buffer = $this->encode_query($buffer,"\n");
515+ if($timer){$oTimer->setMarker( 'encode_query' );}
516+
517+// $buffer = $this->img_copy($buffer,"\n");
518+// if($timer){$oTimer->setMarker( 'img_copy' );}
519+
520+ $buffer = $this->image($buffer,"\n");
521+ if($timer){$oTimer->setMarker( 'image' );}
522+
523+ $buffer = $this->clear_both($buffer,"\n");
524+ if($timer){$oTimer->setMarker( 'clear_both' );}
525+
526+// $buffer = $this->get_querys($buffer,"\n");
527+// if($timer){$oTimer->setMarker( 'get_querys' );}
528+
529+ $buffer = $this->text2html_list($buffer,"\n","ul","\-",'li','','','unorder');
530+ $buffer = $this->text2html_list($buffer,"\n","ol",'+','li','','','order');
531+ $buffer = $this->text2html_list($buffer,"\n","ul",'※','li','style="font:size:70%;color:#66f;"',"style=\"list-style-type:none;\"","caution");
532+ if($timer){$oTimer->setMarker( 'list' );}
533+
534+ //$buffer = $this->text2html_list2($buffer,"\n","blockquote",'引用:','p','','','quote');
535+ //入れ子可
536+ $buffer = $this->text2html_list($buffer,"\n","blockquote",'>','p','','','quote');
537+ if($timer){$oTimer->setMarker( 'list_blockquote' );}
538+
539+ $buffer = $this->paragraf($buffer,"\n\n");
540+ if($timer){$oTimer->setMarker( 'paragraph' );}
541+
542+ $buffer = $this->repair_end($buffer,"\n");
543+ if($timer){$oTimer->setMarker( 'repair_end' );}
544+
545+ $text = $this->result_encoding($buffer,"\n");
546+ if($timer){$oTimer->setMarker( 'result_encoding' );}
547+
548+ if(isset($source) and $source == true){
549+
550+ $source = $this->my_wordwrap($text);
551+ $source = str_replace("&#47;",'/',$source);
552+
553+ $this->source = '<div class="source_view">'.
554+ $this->style_set($source)."\n</div>";
555+ }else{
556+
557+ $this->source = "";
558+ }
559+ if($timer){$oTimer->setMarker( 'create_source' );}
560+
561+ if($timer){
562+ $oTimer->setMarker( 'end' );
563+ $oTimer->stop ();
564+ ob_start();
565+ $oTimer->display ();
566+ $profile = ob_get_contents();
567+ ob_end_clean();
568+
569+ return $text.$profile;
570+ }
571+ return $text;
572+ }
573+
574+ function change_word($text){
575+
576+ if(!defined('TEXTTOHTML_CHANGE_TXT')){return $text;}
577+ $file = TEXTTOHTML_CHANGE_TXT;
578+
579+ if(file_exists($file)){
580+
581+ $chenge_words = file($file);
582+
583+ foreach($chenge_words as $chenge_word){
584+
585+ $chenge_word = mb_convert_encoding($chenge_word, "UTF-8","auto");
586+
587+ if(strstr($chenge_word,"#")){
588+ list($before, $after) = explode("#", $chenge_word);
589+ $text = str_replace($before , trim($after), $text);
590+ }
591+ }
592+
593+ return $text;
594+ }else{
595+
596+ return $text;
597+ }
598+
599+ }
600+
601+
602+function text2html_list($document = "", $separator = "\n",$element = "ul",$wm = '-',$content = 'li',$attr = '',$content_attr = '',$description = ''){
603+
604+ $lines = explode($separator,$document);
605+ $running = false;
606+ $result = '';
607+ $add_front = '';
608+ $add_tail = '';
609+ $add_end = '';
610+ $end ='';
611+ $tag_before = "";
612+ $tag_after = "";
613+ $body = "";
614+ $content_no = 1;
615+ $running = false;
616+ $last_line = false;
617+ $start_line = false;
618+ $next_flag = false;
619+ $diff_prev = 0;
620+ $diff_next = 0;
621+ $diff_count = 0;
622+ $marker_length = 0;
623+ $counter = "";
624+
625+ global $content_name;
626+
627+ if(!empty($content_name) and !empty($description)){
628+ $description = $description.'-'.$content_name;
629+ }else{
630+ $description = $description.$content_name;
631+ }
632+
633+ $start_element_set = "<$element><$content>";
634+ $end_element_set = "</$element></$content>";
635+ $start = true;
636+
637+foreach($lines as $key=>$line){
638+
639+ $line = $line."\n";
640+ if($current_flag = preg_match("/^([$wm]+)(.+)/u",$line,$current)){
641+
642+ $marker_length = @strlen($current[1]);
643+
644+
645+ //リスト変換のオンオフ判定
646+
647+ if($marker_length > 0){$running =true;}else{$running = false;}
648+
649+
650+ //前後する行との関係をマーカー数を数えて判定。
651+
652+ if($key > 0 ){
653+
654+ $prev_flag = preg_match("/^([$wm]+)(.+)/u",$lines[$key - 1],$prev);
655+
656+ if(isset($prev[1])){
657+
658+ $prev_length = strlen($prev[1]);
659+ $diff_prev = $marker_length - $prev_length ;
660+ }
661+
662+ }else{
663+
664+ $prev_flag = false;
665+ }
666+
667+
668+ if($running and !$next_flag){
669+
670+ $last_line = true;
671+ }
672+
673+
674+ if(isset($lines[$key + 1])){
675+
676+ $next_flag = preg_match("/^([$wm]+)(.+)/u",$lines[$key + 1],$next);
677+ $next_length = @strlen($next[1]);
678+ $diff = $marker_length - $next_length;
679+ $diff_count = $marker_length - 1;
680+
681+ }
682+ if(isset($lines[$key + 2])){
683+
684+ $diff_next = $marker_length - $next_length;
685+
686+ }
687+ if(!empty($attr)){
688+ $attr = ' '.$attr;
689+ }
690+
691+ if(!empty($content_attr)){
692+ $content_attr = ' '.$content_attr;
693+ }
694+
695+ switch($running and !$prev_flag){
696+
697+ case(true):
698+
699+ $id_name = ' '."id=\"$element-$description-".trim($content_no)."\"";
700+
701+ if($diff_next > 0 or $marker_length > 1){
702+
703+ $start = str_repeat($start_element_set,abs($marker_length - 1 ))."<$element>";
704+
705+ $content_no++;
706+ }else{
707+
708+ $start = "<$element>";
709+
710+ $content_no++;
711+ }
712+
713+
714+ break;
715+
716+ case(false):
717+ $start = "";
718+
719+ break;
720+
721+ }
722+
723+
724+ switch($running and $key < count($lines) - 1 ){
725+
726+ case(true):
727+
728+ //前行とのマーカーの差
729+
730+ switch(true){
731+
732+ case($diff_prev > 0):
733+ //下位
734+
735+ $tag_before = str_repeat($start_element_set,abs($diff_prev));
736+ $diff_count = $diff_count + $diff_prev;
737+ $start = "";
738+ break;
739+
740+ case($diff_prev < 0):
741+
742+ //上位
743+
744+ $tag_before = "<$content>";
745+ $diff_count = $diff_count + $diff_prev;
746+
747+ break;
748+ case($diff_prev == 0):
749+
750+ //同位
751+
752+ $tag_before = "<$content>";
753+
754+ break;
755+
756+ case(false):
757+
758+ $tag_before = "<$content>";
759+
760+ break;
761+
762+ }
763+
764+ //次行とのマーカーの差
765+
766+ switch(true){
767+ case($diff_next > 0):
768+
769+ //上位
770+
771+ $tag_after = "</$content>";
772+
773+ $repeat = abs($diff_next);
774+ $tag_after .= str_repeat($end_element_set,$repeat);
775+
776+ if($next_flag !== 1){
777+
778+ $repeat = abs($diff_next) - 1;
779+
780+ $tag_after = "</$content>";
781+ $tag_after .= str_repeat($end_element_set,$repeat);
782+ $tag_after .= "</$element>";
783+
784+ }
785+
786+ if(empty($tag_after)){
787+ $tag_after = "</$element>";
788+ }
789+
790+ $diff_count = $diff_next + $diff_count;
791+
792+ break;
793+ case($diff_next < 0):
794+
795+ //下位
796+
797+ $tag_after = "";
798+ $diff_count = $diff_next + $diff_count ;
799+
800+ break;
801+
802+
803+ case($diff_next == 0):
804+
805+ //同位
806+
807+ $tag_after= "</$content>";
808+
809+ break;
810+ }
811+ break;
812+
813+ case(false):
814+
815+ $tag_after= "2</$content>";
816+
817+
818+ break;
819+ }
820+
821+
822+ if($running and !$prev_flag){
823+
824+
825+ $line = $start.$tag_before.$current[2].$tag_after;
826+
827+ }elseif($running and $key < count($lines) - 2 ){
828+
829+
830+
831+ $line = $tag_before.$current[2].$tag_after;
832+
833+ }elseif($last_line and !$next_flag){
834+
835+ $repeat = abs($diff_next) ;
836+
837+ $tag_after = "</$content>";
838+ $tag_after .= str_repeat($end_element_set,$repeat);
839+ $tag_after .= "</$element>";
840+
841+ $line = $tag_before.$current[2].$tag_after.$end;
842+
843+
844+
845+
846+ }
847+
848+ }
849+
850+
851+ $result .= trim($line)."\n";
852+ unset($tag_before,$tag_afrer,$prev,$start);
853+ $enc = "";
854+}
855+ $result = $result;
856+ return $this->tag_clear($result)."\n\n";
857+}
858+
859+
860+function check_element_count_list($html,$element="ul",$content="li"){
861+
862+ //閉じタグチェック
863+ preg_match_all("/(<$element><$content>)/u",$html,$start,PREG_SET_ORDER);
864+ preg_match_all("/(<\/$element><\/$content>)/u",$html,$end,PREG_SET_ORDER);
865+ $rep = count($end)-count($start)-1;
866+
867+ switch(true){
868+
869+ case(count($end) == count($start)):
870+
871+ break;
872+
873+ case(count($end) > count($start)):
874+ //閉じタグが多い
875+ $rep = str_repeat("<\/$element><\/$content>",$rep + 1);
876+ $html = preg_replace("/$rep</$element>$/m","</$element>",$html);
877+
878+ break;
879+
880+ case(count($end) < count($start)):
881+ //閉じタグが少ない
882+ $rep = str_repeat("</$element></$content>",abs($rep) - 1);
883+ $html = preg_replace("/<\/$element>$/m","",$html);
884+ $html = $html.$rep."</$element>";
885+
886+
887+ break;
888+
889+
890+ }
891+ return $html;
892+}
893+
894+function text2html_list2($document, $separator = "\n",$element = "ul",$wm = '-',$content = 'li',$attr = '',$content_attr = '',$description = ''){
895+
896+ $this->separator = $separator;
897+ $this->element = $element;
898+ $this->wm = $wm;
899+ $this->content = $content;
900+ $this->attr = $attr;
901+ $this->content_attr = $content_attr;
902+ $this->description = $description;
903+
904+ global $content_name;
905+
906+ if(!empty($content_name) and !empty($description)){
907+ $description = $description.'-'.$content_name;
908+ }else{
909+ $description = $description.$content_name;
910+ }
911+
912+ $lines = explode($separator,$document);
913+ $start = true;
914+ $this->content_no = 1;
915+ $start_tag = "<{$element} $attr id=\"$element-$description-".$this->content_no."\">";
916+ $end_tag = '';
917+ $result = "";
918+
919+ foreach($lines as $list){
920+
921+ $list = $list. $separator;
922+
923+ if(ereg("(^$wm{1})(.+)",$list,$regs) and !strpos($list,'-->')){
924+
925+ if(!empty($content)){
926+
927+ $start_content = "<$content>";
928+ $end_content = "</$content>\n";
929+ }else{
930+
931+ $start_content = "";
932+ $end_content = "";
933+ }
934+
935+ $res = $this->text2html_list($regs[2],$this->separator,$this->element,$this->wm,$this->content,$this->attr,$this->content_attr,$this->description);
936+
937+ $list = str_replace($regs[0],$start_tag.$start_content.trim($this->sublist($res)).$end_content,$list);
938+ $start_tag = "";
939+ $end_tag = "</{$element}>";
940+
941+ }elseif(!empty($end_tag)){
942+
943+ $list = $end_tag."\n".$list;
944+ $this->content_no++;
945+ $end_tag = '';
946+ $start_tag = "<{$element} $attr id=\"$element-$description-".$this->content_no."\">";
947+ }else{
948+
949+ $start_tag = "<{$element} $attr id=\"$element-$description-".$this->content_no."\">";
950+
951+ }
952+
953+ $result .= $list;
954+
955+ }
956+
957+ return $this->tag_clear($result);
958+ }
959+
960+ function sublist($document,$separator = "\n"){
961+
962+ $element = $this->element;
963+ $wm = $this->wm;
964+ $content = $this->content;
965+ $start = true;
966+ $lines = explode($separator,$document);
967+ $end_tag = "";
968+ $result = "";
969+ $class = "";
970+
971+ foreach($lines as $key=>$list){
972+
973+ $list = $list. "\n";
974+
975+ if(ereg("(^$wm{1})(.+)",$list,$regs)){
976+
977+ if($start == false){$start_tag = "";}else{$start_tag = "<$element>";}
978+
979+ if(!ereg("(^$wm{1})(.+)",$lines[$key+1])){$end_tag= "</$element>";}else{$end_tag= "";}
980+
981+ if(!empty($content)){
982+
983+ $start_content = "<$content>";
984+ $end_content = "</$content>";
985+ }else{
986+
987+ $start_content = "";
988+ $end_content = "";
989+ }
990+
991+ $list= str_replace($regs[0],$start_tag.$start_content.trim($this->sublist($regs[2]))."\n".$end_content,$list);
992+
993+ $start = false;
994+
995+ }elseif(!empty($end_tag)){
996+
997+ $list = $end_tag. "\n".$list;
998+ }
999+ $result .= $list;
1000+
1001+ }
1002+
1003+ return $this->tag_clear($result);
1004+ }
1005+
1006+function text2html_code($document = "", $separator = "\n",$element = "pre",$wm = 'code:',$content = 'code',$attr = '',$content_attr = '',$description = ''){
1007+
1008+ $this->element = $element;
1009+ $this->wm = $wm;
1010+ $this->content = $content;
1011+
1012+ global $content_name;
1013+
1014+ if(!empty($content_name) and !empty($description)){
1015+ $description = $description.'-'.$content_name;
1016+ }else{
1017+ $description = $description.$content_name;
1018+ }
1019+
1020+ $i = 0;
1021+ $lines = explode($separator,$document);
1022+ $start = true;
1023+ $this->content_no = 1;
1024+ $start_tag = "<{$element} $attr id=\"$element-$description-".trim($this->content_no)."\">";
1025+ $end_tag = '';
1026+ $result = "";
1027+
1028+ foreach($lines as $list){
1029+
1030+ $list = $list. "\n";
1031+
1032+ if(preg_match("/(^$wm{1})(.+)/um",$list,$regs)){
1033+
1034+ if(!empty($content)){
1035+ $i++;
1036+ $start_content = "<$content title=\"line$i\">";
1037+ $end_content = "</$content>\n";
1038+ }else{
1039+ $start_content = "";
1040+ $end_content = "\n";
1041+ }
1042+
1043+ $doc = $regs[2];
1044+ $doc = $this->my_wordwrap($doc);
1045+ $doc = htmlspecialchars($doc);
1046+ $doc = str_replace(array('/',"\t",'$','<'),array("&#47;"," ",'&#36;','&#lt'),$doc);
1047+ $doc = str_replace("\n","</code><code>",$doc);//ワードラップは、改行だけ埋め込むので、タグを補充
1048+ $list = str_replace($regs[0],$start_tag.$start_content.trim($doc).$end_content,$list);
1049+ $start_tag = "";
1050+ $end_tag = "</{$element}>";
1051+
1052+ }elseif(!empty($end_tag)){
1053+
1054+ $list = $end_tag."\n".$list;
1055+ $this->content_no++;
1056+ $end_tag = '';
1057+ $start_tag = "<{$element} $attr id=\"$element-$description-".trim($this->content_no)."\">";
1058+ $i = 0;
1059+ }else{
1060+
1061+ $start_tag = "<{$element} $attr id=\"$element-$description-".trim($this->content_no)."\">";
1062+ $i =0;
1063+ }
1064+
1065+ $result .= $list;
1066+ }
1067+
1068+ return $this->tag_clear($result);
1069+ }
1070+
1071+function text2html_table($document, $separator = "\n",$element = "table",$wm = 'tr:',$content = 'tr',$attr = '',$content_attr = '',$description = ''){
1072+
1073+ if(!preg_match("/$wm/si",$document)){ return $document;}
1074+
1075+ $this->element = $element;
1076+ $this->wm = $wm;
1077+ $this->content = $content;
1078+ $this->content_no = 1;
1079+ $start = true;
1080+ $end_tag = '';
1081+ $result = "";
1082+ $row_no = 1;
1083+ global $content_name;
1084+
1085+ if(!empty($content_name) and !empty($description)){
1086+ $description = $description.'-'.$content_name;
1087+ }else{
1088+ $description = $description.$content_name;
1089+ }
1090+
1091+ $start_tag = "<{$element} $attr id=\"table-$description-".$this->content_no."\">";
1092+ $lines = explode($separator,$document);
1093+ $group = "<colgroup><col /></colgroup>";
1094+
1095+ foreach($lines as $key=>$list){
1096+
1097+ $list = $list. $separator;
1098+ $write_group = false;
1099+
1100+ if(ereg("(^$wm{1})(.+)",$list,$regs)){
1101+
1102+ if(preg_match("/({$wm}summary:)(.+)/um",$list,$match)){
1103+
1104+ if($end_tag){
1105+
1106+ $start_tag = "</table>\n<{$element} $attr summary=\"$match[2]\" id=\"table-$description-".$this->content_no."\">";
1107+
1108+ }else{
1109+
1110+ $start_tag = "<{$element} $attr summary=\"$match[2]\" id=\"table-$description-".$this->content_no."\">";
1111+ }
1112+
1113+ $write_group = true;
1114+ unset($regs[2]);
1115+ $list = "";
1116+
1117+ }else{
1118+
1119+ $ht_field = "";
1120+
1121+ if(isset($regs[2])){
1122+
1123+ $fields = explode('|',$regs[2]);
1124+ $col_no =1;
1125+ foreach($fields as $colkey=>$field){
1126+
1127+ $ht_field .= "<td class=\"col{$col_no} row{$row_no}\" id=\"tbl".$this->content_no."{$col_no}{$row_no}\">$field</td>";
1128+ $col_no++;
1129+
1130+ }
1131+
1132+ $row_no++;
1133+ }
1134+
1135+ $list = str_replace($regs[0],$start_tag."<$content>".$ht_field."</$content>\n",$list);
1136+ $start_tag = "";
1137+ $end_tag = "</{$element}>\n";
1138+
1139+ if(!isset($lines[$key + 1]) or !ereg("(^$wm{1})(.+)",$lines[$key + 1])){
1140+
1141+ $list = str_replace($regs[0],$start_tag."<$content>".$ht_field."</$content>{$end_tag}\n",$list);
1142+ $row_no = 1;
1143+ }
1144+ }
1145+ }elseif($end_tag){
1146+
1147+ $list = $end_tag."\n".$list;
1148+ $row_no = 1;
1149+
1150+ $this->content_no++;
1151+
1152+ $start_tag = "<{$element} $attr id=\"table-$description-".$this->content_no."\">";
1153+ $end_tag = false;
1154+ }else{
1155+
1156+ $start_tag = "<{$element} $attr id=\"table-$description-".$this->content_no."\">";
1157+ }
1158+
1159+ $result .= $list;
1160+ }
1161+ return $this->tag_clear($result);
1162+}
1163+
1164+function text2html_element($document, $separator = "\n",$element = "h2",$wm = '*',$content = 'span',$attr = '',$content_attr = '',$description = ''){
1165+
1166+ global $content_name;
1167+
1168+ if(!empty($content_name) and !empty($description)){
1169+ $description = $description.'-'.$content_name;
1170+ }else{
1171+ $description = $description.$content_name;
1172+ }
1173+
1174+ $lines = explode($separator,$document);
1175+ $start = true;
1176+ $end_tag = '';
1177+ $result = "";
1178+ $start_tag = "<{$element} $attr id=\"$element-$description-".$this->content_no."\" >";
1179+ $this->content_no = 1;
1180+
1181+ foreach($lines as $key => $list){
1182+
1183+ $list = $list. "\n";
1184+
1185+ if(preg_match("/(^$wm{1})(.+)/um",$list,$regs)){
1186+
1187+ if(!empty($content)){
1188+
1189+ $content_start = "<$content $content_attr >";
1190+ $content_end = "</$content>";
1191+ }else{
1192+
1193+ $content_start = "";
1194+ $content_end = "";
1195+ }
1196+
1197+ $list = str_replace($regs[0],$start_tag.$content_start.$regs[2].$content_end,$list);
1198+ $start_tag = "";
1199+ $end_tag = "</{$element}>\n";
1200+
1201+ //見出しリスト
1202+
1203+ if(ereg("h([1-6])",$element,$match)){
1204+
1205+ $list = str_replace("\n","",$list);
1206+ array_push($this->header_info,array($key,trim($match[1]),"$element-$description-".$this->content_no,$regs[2]));
1207+ }
1208+
1209+ }elseif(!empty($end_tag)){
1210+
1211+ $list = $end_tag."\n".$list;
1212+ $this->content_no++;
1213+ $end_tag = '';
1214+ $start_tag = "<{$element} $attr id=\"$element-$description-".$this->content_no."\" >";
1215+ }else{
1216+
1217+ $start_tag = "<{$element} $attr id=\"$element-$description-".$this->content_no."\" >";
1218+ }
1219+ $result .= $list;
1220+ }
1221+
1222+ return $this->tag_clear($result);
1223+}
1224+
1225+function paragraf($document, $separator = "\n\n",$element = "p",$wm = '',$content = '',$attr = '',$content_attr = '',$description = 'paragraph'){
1226+
1227+ global $content_name;
1228+
1229+ if(!empty($content_name) and !empty($description)){
1230+ $description = $description.'-'.$content_name;
1231+ }else{
1232+ $description = $description.$content_name;
1233+ }
1234+
1235+ $checks=array('dl','address','blockquote','form','fieldset','table','style','tr','code','div');
1236+
1237+ foreach($checks as $val){
1238+
1239+ $check[] = "<$val";
1240+ $check[] = "$val>";
1241+ $check[] = "</$val";
1242+
1243+ $replace[] = "\n\n<$val";
1244+ $replace[] = "$val>$separator";
1245+ $replace[] = "$separator</$val";
1246+ }
1247+
1248+
1249+ $document = str_replace($check,$replace,$document);
1250+ $document = $this->tag_clear($document);
1251+ $document = ereg_replace("(\n{1})","\n\n",$document);
1252+ $lines = explode($separator,$document);
1253+ $start = true;
1254+ $end_tag = '';
1255+ $result = "";
1256+ $this->content_no = 1;
1257+ $start_tag = "<{$element} $attr id=\"$element-$description-".$this->content_no."\">";
1258+ //$wm = "[^(\*|+|<|\=|\n$|\s|code:|   )]";
1259+ $blocks = true;//pをコンテンツに出来ないタグ内での変換を禁止
1260+ $wm = "[^(\*|\+|\=|\n$|\s| |\-|<)]";
1261+ $tags_block = "(dl|ol|ul|address|blockquote|form|fieldset|table|style|tr|p|code)";
1262+ $cdata_zone = false;
1263+
1264+ foreach($lines as $key => $list){
1265+
1266+ $list = $list."\n\n";
1267+
1268+ if(preg_match("/(<!--|<!\[CDATA\[|<script|<style|<$tags_block)/iu",$list) and !preg_match("/(!--|\]\]>|\/script|\/style|<\/$tags_block)\s?\/?>/iu",$list)){
1269+ $cdata_zone = true;
1270+ //テーブル間にタグを適用できなくなる
1271+ }
1272+
1273+ if(preg_match("/(^($wm).*)/um",$list,$regs) and $cdata_zone == false ){
1274+
1275+ $content_start = "";
1276+
1277+ if(isset($lines[$key + 1]) and $lines[$key + 1] == true){
1278+
1279+ $content_end = "<br />";
1280+ }else{
1281+
1282+ $content_end = "";
1283+ }
1284+
1285+ $list = str_replace($regs[0],$start_tag.$content_start.trim($regs[1]).$content_end,$list);
1286+ $start_tag = "";
1287+ $end_tag = "\n</{$element}>\n\n";
1288+ $paragraph_div = '¶';
1289+
1290+ if(eregi($paragraph_div,$list)){
1291+
1292+ $list = str_replace(array($paragraph_div.$content_end,$paragraph_div),$end_tag, $list);
1293+ $end_tag = '';
1294+ $this->content_no++;
1295+ $start_tag = "<{$element} $attr id=\"$element-$description-".$this->content_no."\">";
1296+ }
1297+
1298+ }elseif(!empty($end_tag) ){
1299+
1300+ $list = $end_tag."\n".$list;
1301+ $end_tag= '';
1302+ $this->content_no++;
1303+ $start_tag = "<{$element} $attr id=\"$element-$description-".$this->content_no."\">";
1304+
1305+ }else{
1306+
1307+ $start_tag = "<{$element} $attr id=\"$element-$description-".$this->content_no."\">";
1308+ }
1309+
1310+
1311+ if(preg_match("/(-->|\]\]>|<\/script|<\/style|<\/$tags_block)/iu",$list)){
1312+
1313+ $cdata_zone = false;
1314+ }
1315+
1316+ $result .= $list;
1317+ }
1318+
1319+ return $this->tag_clear($result);
1320+}
1321+/*
1322+function img_copy($buffer){
1323+
1324+ if(!defined('TEXTTOHTML_IMAGE_DIR_PATH')){return $buffer;}
1325+
1326+ $copy_width = TEXTTOHTML_COPY_IMG_WIDTH;
1327+
1328+ if(preg_match_all("/(copy>\()([^\)]+)(\))/", $buffer, $matches, PREG_SET_ORDER)){
1329+
1330+ foreach($matches as $key=>$match){
1331+
1332+ $cache = use_cache($matches[$key][0],$buffer);
1333+
1334+ if($cache[0]){
1335+
1336+ $buffer= str_replace($matches[$key][0],$cache[1],$buffer)."\n";
1337+ }else{
1338+ clearstatcache();
1339+
1340+ $copy_target = TEXTTOHTML_IMAGE_DIR_PATH.basename($match[2]);
1341+ $copy_target_url = TEXTTOHTML_IMAGE_DIR_URL.basename($match[2]);
1342+ $quote_comment = "<!--from:".$match[2]."--><a href=\"".$match[2]."\" class=\"quoted\">";
1343+ $size = getimagesize($match[2]);
1344+ $uri = htmlspecialchars(trim($match[2]));
1345+
1346+ if($size[0] > $copy_width){
1347+ $aspect = @round($size[1]/$size[0],2);
1348+ $height = @round($copy_width * $aspect,0);
1349+ }else{
1350+ $copy_width = $size[0];
1351+ $height = $size[1];
1352+ }
1353+
1354+ $gdimg = imagecreatetruecolor($copy_width,$height);
1355+
1356+ if($size[2] == 1) {
1357+
1358+ if( $im = imagecreatefromgif($uri)){
1359+ imagecopyresized($gdimg,$im,0,0,0,0,$copy_width,$height,$size[0],$size[1]);
1360+ @imagegif($gdimg,$copy_target);
1361+ }
1362+ }
1363+
1364+ if($size[2] == 2 and $size) {
1365+
1366+ if( $im = imagecreatefromjpeg($uri)){
1367+ imagecopyresized($gdimg,$im,0,0,0,0,$copy_width,$height,$size[0],$size[1]);
1368+ @imagejpeg($gdimg,$copy_target);
1369+ }
1370+ }
1371+ if($size[2] == 3) {
1372+
1373+ if($im = imagecreatefrompng($uri)){
1374+ imagecopyresized($gdimg,$im,0,0,0,0,$copy_width,$height,$size[0],$size[1]);
1375+ @imagepng($gdimg,$copy_target);
1376+ }
1377+ }
1378+ if($size[2] == 15) {
1379+
1380+ if($im = imagecreatefromwbmp($uri)){
1381+ imagecopyresized($gdimg,$im,0,0,0,0,$copy_width,$height,$size[0],$size[1]);
1382+ @imagebmp($gdimg,$copy_target);
1383+ }
1384+ }
1385+
1386+ $buffer= str_replace($matches[$key][0],$quote_comment."<img src=\"".$copy_target_url."\" width=\"$copy_width\" height=\"$height\" alt=\"copyed image\" /></a>",$buffer)."\n";
1387+
1388+
1389+ save_cache($matches[$key][0],$quote_comment."<img src=\"".$copy_target_url."\" width=\"$copy_width\" height=\"$height\" alt=\"copyed image\" /></a>");
1390+ }
1391+
1392+ }
1393+
1394+ }
1395+return $buffer;
1396+}
1397+*/
1398+function keyword_change($document){
1399+
1400+ $keyword_res = array();
1401+ $change_val_res = array();
1402+
1403+ if(phpversion('domDocument')){
1404+
1405+ $dom = new domDocument;
1406+ $dom->load(CHANGE_PATTERN_PATH);
1407+ $root = $dom->documentElement;
1408+ $books = $root->childNodes;
1409+ $keyword_res = array();
1410+ $change_val = array();
1411+
1412+ foreach ($books as $book) {
1413+
1414+ if (@$book->nodeName == 'dl') {
1415+ $content = $book->childNodes;
1416+
1417+ foreach ($content as $elem) {
1418+ if (@$elem->nodeName == 'dd') {
1419+ $change_val[] = $elem->nodeValue;
1420+ }
1421+ if (@$elem->nodeName == 'dt') {
1422+ $keyword[] = $elem->nodeValue;
1423+ }
1424+ }
1425+ }
1426+ }
1427+
1428+ $result = str_replace($keyword , $change_val, $document);
1429+ return $this->tag_clear($result);
1430+
1431+ }else{
1432+
1433+ $data = file_get_contents(CHANGE_PATTERN_PATH);
1434+ $dls = explode("<dl>",$data);
1435+
1436+ foreach($dls as $dl){
1437+
1438+ ereg("(<dt>)([^<]+)(</dt>)",$dl,$keyword);
1439+ array_push($keyword_res,$keyword[2]);
1440+ ereg("(<dd>)([^<]+)(</dd>)",$dl,$change_val);
1441+ array_push($change_val_res,$change_val[2]);
1442+ }
1443+
1444+ $keyword_res = str_replace(array("&gt;","&lt;","&amp;","&quot;"),array(">","<",'&','"'),$keyword_res);
1445+ $change_val_res = str_replace(array("&gt;","&lt;","&amp;","&quot;"),array(">","<",'&','"'),$change_val_res);
1446+ $res = str_replace($keyword_res,$change_val_res,$document);
1447+ return $res;
1448+ }
1449+}
1450+
1451+
1452+ function keyword_change_inline($document, $separator = "\n"){
1453+
1454+ $before_start = "<!--%";
1455+ $before_end = "%-->";
1456+ $start_tag = '【';
1457+ $end_tag = '】';
1458+
1459+ $word = "";
1460+ $change = "";
1461+ $document_result = "";
1462+ $keyword_res = array();
1463+ $change_val_res = array();
1464+ $textdes = explode($separator, $document);
1465+ $record = 0;
1466+
1467+ foreach($textdes as $words){
1468+ $words = $words . "\n";
1469+
1470+ if($record == 0 and ereg("(^$start_tag)([^/]+)($end_tag)",$words,$keyword)){
1471+
1472+ $change = "";
1473+ $keyword = $before_start.$keyword[2].$before_end;
1474+ $record = 1;
1475+ }elseif($record == 1 and !ereg("(^$start_tag\/)(.+)($end_tag)",$words)){
1476+
1477+ $change .= $words . "\n";
1478+ }elseif($record == 1 and ereg("(^$start_tag\/)(.+)($end_tag)",$words)){
1479+
1480+ $record = 0;
1481+
1482+ if(array_search($keyword,$keyword_res) == false and !empty($keyword) and !empty($change)){
1483+
1484+ array_push($keyword_res,$keyword);
1485+ $change = str_replace(array("\r\n","\r","\n"),"<><>",$change);
1486+ array_push($change_val_res,$change);
1487+ $array_res[] = array($keyword=>$change);
1488+ }
1489+ }else{
1490+
1491+ $document_result .= $words;
1492+ }
1493+ }
1494+ $document_result = str_replace($keyword_res,$change_val_res,$document_result);
1495+ $result = str_replace(array("<><>","><"),array("\n",">\n<"),$document_result);
1496+
1497+ return $this->tag_clear($result);
1498+}
1499+
1500+
1501+function inline_tag($text){
1502+
1503+$tags_inline = "(a|abbr|acronym|area|b|base|bdo|big|body|button|caption|cite|code|colgroup|dd|del|dfn|dt|em|head|html|i|img|input|ins|kbd|label|legend|li|link|map|object|optgroup|option|param|q|samp|select|small|span|strong|sub|sup|tbody|td|textarea|tfoot|th|thead|title|tt|var)";
1504+
1505+ if(preg_match_all("/(\[)($tags_inline)(\|)([^\|]+)(\|)([^\]]+)(\])/", $text, $matches, PREG_SET_ORDER)){
1506+ foreach($matches as $key=>$match){
1507+
1508+ $element = mb_convert_encoding($match[2],"UTF-8","auto");
1509+ $attr = mb_convert_encoding($match[5],"UTF-8","auto");
1510+ $value = mb_convert_encoding($match[7],"UTF-8","auto");
1511+ $replacement = "<$element $attr>$value</$element>";
1512+ $text = str_replace($matches[$key][0],$replacement,$text)."\n";
1513+ }
1514+
1515+ $code_hit = true;
1516+ }
1517+
1518+ return $text;
1519+}
1520+
1521+
1522+function ruby($text){
1523+
1524+ if(preg_match_all("/(ruby>\()([^:]+)(:)([^\)]+)(\))/", $text, $matches, PREG_SET_ORDER)){
1525+
1526+ foreach($matches as $key=>$match){
1527+
1528+ $word = mb_convert_encoding($match[2],"UTF-8","auto");
1529+ $kana = mb_convert_encoding($match[4],"UTF-8","auto");
1530+ $word = str_replace("\n","",$word);
1531+ $kana = str_replace("\n","",$kana);
1532+ $replacement = "<ruby><rb>$word</rb><rp>(</rp><rt>$kana</rt><rp>)</rp></ruby>";
1533+ $text = str_replace($matches[$key][0],$replacement,$text)."\n";
1534+ }
1535+
1536+ $code_hit = true;
1537+ }
1538+
1539+ return $text;
1540+}
1541+
1542+
1543+function trackback($text){
1544+
1545+ if(!defined('TEXTTOHTML_TRACKBACK_URL')){return $text;}
1546+
1547+ if(preg_match_all("/(trackback>\()([^\)]+)(\))/", $text, $matches, PREG_SET_ORDER)){
1548+
1549+ foreach($matches as $key=>$match){
1550+
1551+ $tabindex = $key + 1;
1552+
1553+ switch ($key) {
1554+ case 0:
1555+ $accesskey = "a";
1556+ break;
1557+ case 1:
1558+ $accesskey = "b";
1559+ break;
1560+ case 2:
1561+ $accesskey = "c";
1562+ break;
1563+ case 3:
1564+ $accesskey = "d";
1565+ break;
1566+ case 4:
1567+ $accesskey = "e";
1568+ break;
1569+ case 5:
1570+ $accesskey = "f";
1571+ break;
1572+ default:
1573+ $accesskey = "g";
1574+
1575+ }
1576+
1577+ $enc = mb_convert_encoding($match[2],"UTF-8","auto");
1578+ $enc = urlencode($enc);
1579+
1580+ $replacement = "<div class=\"trackback\"><span>トラックバック:".$match[2]."</span><br />Track back URL:<input type=\"text\" value=\"".TEXTTOHTML_TRACKBACK_URL. $enc. "\" accesskey=\"$accesskey\" tabindex=\"".$tabindex."\" /><br /><script type=\"text/javascript\" src=\"".TEXTTOHTML_TRACKBACK_URL. $enc. "\"></script>\n</div>\n";
1581+
1582+ $text = str_replace($matches[$key][0],$replacement,$text)."\n";
1583+ }
1584+
1585+ $code_hit = true;
1586+ }
1587+ return $text;
1588+
1589+}
1590+/*------------------------------------------------------------------------------+
1591+ *URL メールアドレスをリンクに置換
1592+ *------------------------------------------------------------------------------*/
1593+function maillink($text){
1594+
1595+ if(preg_match_all("/(mail>\()([^@]+)@([^\)]+)(\))/", $text, $matches, PREG_SET_ORDER)){
1596+ foreach($matches as $key=>$match){
1597+
1598+ $enc = mb_convert_encoding($match[2]."&#64;".$match[3],"UTF-8","auto");
1599+ $chenge_val = "<a href=\"mailto:$enc\">mailto:".$match[2]."</a>";
1600+
1601+
1602+ $text= str_replace($matches[$key][0],$chenge_val,$text)."\n";
1603+
1604+
1605+ }
1606+
1607+ }
1608+
1609+ return $text;
1610+}
1611+
1612+
1613+
1614+ /*------------------------------------------------------------
1615+ * youtube link
1616+ -------------------------------------------------------------*/
1617+
1618+function youtube($text,$separator = "\n"){
1619+ global $copy_width;
1620+
1621+ if(preg_match_all("/(youtube>\()([^\)]+)(\))/", $text, $matches, PREG_SET_ORDER)){
1622+
1623+ foreach($matches as $key=>$match){
1624+
1625+ $query = parse_url($match[2]);
1626+ $query = str_replace("v=","",$query['query']);
1627+ $copy_target = "http://img.youtube.com/vi/".$query."/default.jpg";
1628+ $quote_comment = "<a href=\"$match[2]\" target=\"blank\">";
1629+
1630+ if($size = getimagesize($match[2])){
1631+ $aspect = round($size[1]/$size[0],2);
1632+ $height = $copy_width * $aspect;
1633+ }else{
1634+ $copy_width = 130;
1635+ $height = 97;
1636+ }
1637+ $text= str_replace($matches[$key][0],$quote_comment."{$copy_target}?w={$copy_width}h={$height}alt=YouTube </a>",$text)."\n";
1638+ }
1639+ }
1640+
1641+ return $text;
1642+}
1643+/*------------------------------------------------------------------------------+
1644+ * 文字列から、イメージの作成とコーディング処理
1645+ *------------------------------------------------------------------------------*/
1646+ /*
1647+function txt2img($buffer,$separator = "\n"){
1648+
1649+ global $default;
1650+
1651+ if(!defined('TEXTTOHTML_FONTS_PATH') ){return $buffer;}else{
1652+
1653+ include(TEXTTOHTML_FONTS_PATH);
1654+ $buffers = explode($separator,$buffer);
1655+ $string = "";
1656+
1657+ foreach($buffers as $buffer){
1658+
1659+ if(preg_match_all("/(txt2img>\()([^\)]+)(\))/", $buffer, $matches, PREG_SET_ORDER)){
1660+
1661+ foreach($matches as $key=>$match){
1662+
1663+ if(ereg("(:)",$match[2])){
1664+ list($element,$val_name,$val) =explode(":",$match[2]);
1665+
1666+ $replacement = $this->convert_image($val,$$val_name,$element);
1667+ }else{
1668+ $replacement = $this->convert_image($match[2],$default,"p");
1669+ }
1670+
1671+ $string .= str_replace($matches[$key][0],$replacement,$buffer);
1672+ }
1673+
1674+
1675+ }else{
1676+
1677+ $string .= $buffer."\n";
1678+ }
1679+ }
1680+
1681+ return $string;
1682+
1683+ }
1684+}
1685+*/
1686+/////////////////////////////////////////////////////////////
1687+/*
1688+function convert_image( $string , $gd_set = array("gt200001","13","class=\"text2image\"","0"),$element = "p"){
1689+
1690+ if(!defined('TEXTTOHTML_IMAGE_DIR_URL')){return $string;}
1691+
1692+ $file_name = md5($string.$gd_set[0].$gd_set[1]);
1693+ $image_file_name = str_replace(array('=','"','\\'),array(""),$gd_set[1])."-".$file_name.'.png';
1694+ $image_file_name = TEXTTOHTML_IMAGE_DIR_URL.$image_file_name;
1695+ $image_file_path = TEXTTOHTML_IMAGE_DIR_PATH.str_replace(array('=','"','\\'),array(""),$gd_set[1])."-".$file_name.'.png';
1696+ $cache = use_cache($file_name);
1697+
1698+ if($cache[0]){
1699+
1700+ $result= $cache[1]."\n";
1701+ return $result;
1702+ }else{
1703+
1704+ $font = TEXTTOHTML_FONT_DIR_PATH.$gd_set[0].'.ttf';
1705+ $string = mb_convert_encoding($string,"UTF-8","auto");
1706+ $len = mb_strlen($string);
1707+ $fontsize = $gd_set[1];
1708+ $height = $fontsize * 2;
1709+ $background_img = $gd_set[3];
1710+ $indent = 20;
1711+ $marginRight = 2;
1712+ $attribute = $gd_set[2];
1713+
1714+ switch(true){
1715+
1716+ case($background_img == "0"): //背景画像を使用しない
1717+
1718+ $timg = imagecreate($fontsize * 2 * $len, $fontsize * 2);
1719+ $background = ImageColorAllocate($timg, 255, 255, 255);
1720+ ImageFill($timg, 0, 0, $background);
1721+ $Color = ImageColorAllocate($timg, 0, 0, 0);
1722+ break;
1723+
1724+ default://背景画像を使用する。
1725+
1726+ $timg = imagecreatefrompng($background_img);
1727+ $Color = ImageColorAllocate($timg, 0, 0, 0);
1728+ break;
1729+ }
1730+
1731+ $vertical_align = $fontsize * 1.5;
1732+ $chr = mb_convert_encoding($string,"UTF-8","auto");
1733+ $box = ImageTTFText($timg, $fontsize, 0, $indent, $vertical_align, $Color, $font, $chr);
1734+ $width = $box[2] + $marginRight;
1735+ $timg_resized = ImageCreate($width, $fontsize * 2);
1736+
1737+ imagecopy($timg_resized, $timg, 0, 0, 0, 0, $width, $fontsize * 2);
1738+ imagepng($timg_resized,$image_file_path);
1739+
1740+ if($timg_resized){
1741+
1742+ $result = "<{$element} $attribute style=\"height:{$height}px;width:{$width}px;background:url($image_file_name);background-repeat:no-repeat;\">\n\t<span style=\"display:none;font-size:{$fontsize}px;\">$string</span></{$element}>\n";
1743+
1744+ save_cache($file_name,$result);
1745+
1746+ return $result;
1747+ }else{
1748+
1749+ return $string;
1750+ }
1751+
1752+ }
1753+}
1754+*/
1755+/*------------------------------------------------------------------------------+
1756+ *サウンドファイル quicktime
1757+ *------------------------------------------------------------------------------*/
1758+
1759+function sound($text){
1760+
1761+ if(preg_match_all("/(quicktime>\()([^\)]+)(\))/", $text, $matches, PREG_SET_ORDER)){
1762+ foreach($matches as $key=>$match){
1763+
1764+ $enc = mb_convert_encoding($match[2],"UTF-8","auto");
1765+
1766+ $replacement = "<object classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" width=\"176\" height=\"20\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\"><param name=\"src\" value=\"$enc\" /><param name=\"autoplay\" value=\"false\" /><param name=\"controller\" value=\"true\" /><embed src=\"$enc\" width=\"176\" height=\"20\" autostart=\"false\" controller=\"true\" pluginspage=\"http://www.apple.com/quicktime/download/\"></embed>.</object>";
1767+
1768+ $text = str_replace($matches[$key][0],$replacement,$text)."\n";
1769+ }
1770+
1771+ $code_hit = true;
1772+ }
1773+return $text;
1774+}
1775+/*------------------------------------------------------------------------------+
1776+ *
1777+ *------------------------------------------------------------------------------*/
1778+ //3gp foma 動画
1779+function foma_movie($text){
1780+
1781+$text = mb_eregi_replace("(https?|ftp)(://[[:alnum:]\+\$\;\?\.%,!#~*/:@&=_-]+\.(3gp))", "<object classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" width=\"176\" height=\"160\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\"><param name=\"src\" value=\"\\1\\2\" /><param name=\"autoplay\" value=\"false\" /><param name=\"controller\" value=\"true\" /><embed src=\"\\1\\2\" width=\"176\" height=\"160\" autostart=\"false\" controller=\"true\" pluginspage=\"http://www.apple.com/quicktime/download/\"></embed>.</object>\n",$text);
1782+
1783+return $text;
1784+}
1785+/*------------------------------------------------------------------------------+
1786+ *
1787+ *------------------------------------------------------------------------------*/
1788+function swf($text){
1789+
1790+$text = mb_eregi_replace("(https?|ftp)(://[[:alnum:]\+\$\;\?\.%,!#~*/:@&=_-]+\.(swf))(\?w=)([0-9]{1,3})(h=)([0-9]{1,3})", "<object class= \"swf\" data=\"\\1\\2\" type=\"image/swf\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" height=\"\\7\" width=\"\\5\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" ><param name=\"allowscriptaccess\" value=\"samedomain\" /><param name=\"movie\" value=\"\\1\\2\" /><param name=\"quality\" value=\"high\" /><param name=\"bgcolor\" value=\"#ffffff\" /><embed src=\"\\1\\2\" width=\"\\5\" height=\"\\7\" bgcolor=\"#ffffff\" loop=\"false\" quality=\"high\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash\" type=\"application/x-shockwave-flash\"></embed></object>\n",$text);
1791+
1792+
1793+return $text;
1794+}
1795+
1796+/*------------------------------------------------------------------------------+
1797+ *指定部分をURLENCODE
1798+ *------------------------------------------------------------------------------*/
1799+
1800+function encode_query($text){
1801+
1802+ if(preg_match_all("/(query>\()([^\)]+)(\))/", $text, $matches, PREG_SET_ORDER)){
1803+
1804+ foreach($matches as $key=>$match){
1805+
1806+ $enc = mb_convert_encoding($match[2],"UTF-8","auto");
1807+ $enc = urlencode($enc);
1808+ $text= str_replace($matches[$key][0],$enc,$text)."\n";
1809+ }
1810+
1811+ }
1812+ return $text;
1813+}
1814+
1815+/*------------------------------------------------------------------------------+
1816+ *$show_img_tag 画像表示uriのみ class= "ins_img"
1817+ *------------------------------------------------------------------------------*/
1818+
1819+function image($text){
1820+
1821+ $allow_img_filetype = "(\.gif|\.png|\.jpe?g)";
1822+
1823+$text = eregi_replace("(https?://[[:alnum:]\+\$\;\?\.%,!#~*/:@&=_-]+)($allow_img_filetype)(\?w=)([0-9]{1,3})(h=)([0-9]{1,3})(alt=)?([^([:space:]|<)]+)?", "<img src=\"\\1\\2\" width=\"\\5\" height=\"\\7\" class=\"picture\" alt=\"\\9\" />",$text);
1824+
1825+return $text;
1826+}
1827+
1828+/*
1829+//リンク名つきリンク
1830+function link_title($text){
1831+
1832+ if(preg_match_all("/(https?)(:\/\/[[:alnum:]\+\$\;\?\.%,!#~*\/:@&=_-]+)(\()(b:|t:|s:)?([^\)]+)(\))/", $text, $matches, PREG_SET_ORDER)){
1833+
1834+ foreach($matches as $key=>$match){
1835+
1836+ $cache = use_cache($matches[$key][0],$text);
1837+
1838+ if($cache[0]){
1839+
1840+ $text = str_replace($matches[$key][0],$cache[1],$text)."\n";
1841+ }else{
1842+
1843+ switch($match[4]){
1844+ case('b:'):
1845+ $attr = '_blank';
1846+ break;
1847+ case('t:'):
1848+ $attr = '_top';
1849+ break;
1850+ case('s:'):
1851+ $attr = '_self';
1852+ break;
1853+
1854+ default:
1855+ $attr = '_self';
1856+
1857+ break;
1858+ }
1859+
1860+ $attr = "onclick=\"this.target='$attr';\" onkeypress=\"this.target='$attr';\"";
1861+ $link_name = mb_convert_encoding($match[5],"UTF-8","auto");
1862+ $url = $match[1].$match[2];
1863+
1864+ if(trim($link_name) == 'title'){
1865+
1866+ $cache = use_cache($matches[$key][0],$link_name);
1867+
1868+ try{
1869+ if(!$data = mb_convert_encoding(file_get_contents($url),"UTF-8","auto")){
1870+
1871+ throw new Exception('リンクタイトルを取得できません');
1872+ }
1873+
1874+ preg_match( "/<title.*?>(.*?)<\/title>/si", $data, $regs );
1875+ $linkname = trim(strip_tags($regs[1]));
1876+ $link_name = htmlspecialchars($linkname);
1877+
1878+ }catch (Exception $e) {
1879+ $link_name = $url;
1880+ echo '例外: ',$url, $e->getMessage(), "\n";
1881+ }
1882+
1883+ if(empty($link_name)){ $link_name = $url;}
1884+ }
1885+
1886+ $link = "<a href=\"".$url."\" $attr >".$link_name."</a>";
1887+ $text = str_replace($matches[$key][0],$link,$text)."\n";
1888+ }
1889+
1890+ }
1891+
1892+ }
1893+
1894+ return $text;
1895+}
1896+
1897+*/
1898+function name_link($text){
1899+
1900+ $text = eregi_replace("(link>)(https?)(://[[:alnum:]\+\$\;\?\.%,!#~*/:@&=_-]+)", "<a href=\"\\2\\3\" title=\"\\2\\3\">\\2\\3</a>\n", $text);
1901+ $text = mb_ereg_replace("(https?)(://[[:alnum:]\+\$\;\?\.%,!#~*/:@&=_-]+)(()([^)]+)())", "<a href=\"\\1\\2\" title=\"\\1\\2\">\\4</a>\n",$text);
1902+
1903+return $text;
1904+}
1905+
1906+
1907+function clear_both($text){
1908+
1909+$text = str_replace("[クリア]", "<br style=\"clear:left;\" />", $text);
1910+$text = str_replace("[クリア]", "<br style=\"clear:left;\" />", $text);
1911+
1912+return $text;
1913+}
1914+
1915+/*
1916+function read_php2($text){
1917+
1918+ if(preg_match_all("/(eval>\[)([^\]]+)(\])/", $text, $matches, PREG_SET_ORDER)){
1919+ foreach($matches as $key=>$match){
1920+
1921+ $str = mb_convert_encoding($match[2],"UTF-8","auto");
1922+ eval("\$str = $str;");
1923+ $text= str_replace($matches[$key][0],$str,$text)."\n";
1924+ }
1925+
1926+ }
1927+return $text;
1928+}
1929+*/
1930+/*
1931+function read_php($text){
1932+
1933+ if(preg_match_all("/(eval>\[)([^\]]+)(\])/", $text, $matches, PREG_SET_ORDER)){
1934+ foreach($matches as $key=>$match){
1935+
1936+ $str = mb_convert_encoding($match[2],"UTF-8","auto");
1937+ if(isset($str) and !empty($str)){
1938+
1939+ try {
1940+
1941+ $replacement = $this->script_on($str);
1942+
1943+ $text= str_replace($matches[$key][0],$replacement,$text)."\n";
1944+
1945+ } catch (Exception $e) {
1946+ echo '例外発生: ', $e->getMessage(), "\n";
1947+ }
1948+
1949+
1950+ }
1951+ }
1952+ }
1953+return $text;
1954+}
1955+*/
1956+/*
1957+function script_on($str){
1958+
1959+ if (eval("\$replacement = $str;") === false ){
1960+ throw new Exception(htmlspecialchars($str).' phpとして評価できません');
1961+ }
1962+
1963+ return $replacement;
1964+}
1965+
1966+*/
1967+function repair_end($text){
1968+ $text = str_replace("<p>[block]</p>", "", $text);
1969+ $text = str_replace("<p>[block]", "", $text);
1970+ $text = str_replace("[block]\n</p>", "", $text);
1971+ $text = preg_replace("/(<br \/>){2,}/", "<br />", $text);
1972+
1973+ return $text;
1974+
1975+}
1976+
1977+function note($text,$separator = "\n"){
1978+ /* ------------------------------------------------------------
1979+ * フットノート
1980+ *-------------------------------------------------------------*/
1981+
1982+ if(preg_match_all("/(《)([^》]+)(》)/su", $text, $matches, PREG_SET_ORDER)){
1983+
1984+ foreach($matches as $key=>$match){
1985+
1986+ $enc = mb_convert_encoding($match[2],"UTF-8","auto");
1987+ $replacement = "<a class=\"foot-note\" href=\"#foot-note-$key\" name=\"anchor-foot-note-$key\" id=\"anchor-foot-note-$key\" title=\"脚注へ移動\">[$key]</a>";
1988+ $text = str_replace($matches[$key][0],$replacement,$text)."\n";
1989+
1990+ array_push($this->footNote, array($key,"anchor-foot-note-$key","foot-note-$key",$enc));
1991+ }
1992+
1993+ $code_hit = true;
1994+ }
1995+
1996+ return $text;
1997+}
1998+
1999+/*------------------------------------------------------------------------------+
2000+ * エンコーディング変更 $_GET['e']で切り替え
2001+ *------------------------------------------------------------------------------*/
2002+ function result_encoding($text){
2003+
2004+ if(isset($_GET['e'])
2005+ and ($_GET['e'] == "s" or
2006+ $_GET['e'] == "e" or
2007+ $_GET['e'] == "u" or
2008+ $_GET['e'] == "j" )){
2009+
2010+ $e = $_GET['e'];
2011+ switch ($e) {
2012+ case "s":
2013+
2014+ return mb_convert_encoding($text,"SHIFT_JIS","UTF-8");
2015+
2016+ break;
2017+ case "e":
2018+ return mb_convert_encoding($text,"UTF-8","UTF-8");
2019+ break;
2020+ case "u":
2021+ return $text;
2022+ break;
2023+ case "j":
2024+ return mb_convert_encoding($text,"JIS","UTF-8");
2025+ break;
2026+
2027+ default:
2028+ return $text;
2029+ }
2030+ }else{
2031+
2032+ return $text;
2033+ }
2034+ }
2035+
2036+ /* ------------------------------------------------------------
2037+ * 整形記号のチェック
2038+ -------------------------------------------------------------*/
2039+
2040+ function basic_cleaner($buffer,$separator = "\n"){
2041+
2042+ global $parm;
2043+
2044+ $buffer = mb_convert_encoding($buffer,"UTF-8","auto");
2045+ $file = explode($separator,$buffer);
2046+ $text = "";
2047+
2048+ foreach($file as $key => $chk){
2049+
2050+ $chk = str_replace("\0", "", $chk);
2051+ $chk = "\n$chk";
2052+ $chk = preg_replace("(^\s|\s{2,100}^\t| $|&emsp;$|\.{2}\/)", "" , $chk);
2053+ $chk = preg_replace("'([\r\n])[\s]+'", "\n", $chk);
2054+ $chk = preg_replace("'([\r\n])[\s]+'", "\n", $chk);
2055+
2056+ $text .= "\n$chk";
2057+
2058+ }
2059+
2060+ return $text;
2061+ }
2062+/*------------------------------------------------------------------------------+
2063+ * イメージサイズの検出
2064+ *------------------------------------------------------------------------------*/
2065+function my_imagesize2($file, $wide ="width=\"200\"" ){
2066+
2067+ if(eregi("\.(gif|jpg|png|swc|psd|tiff|bmp|iff|jp2|jpx|jb2|jpc|xbm|wbmp)",$file)){
2068+ list($width, $height, $type, $attr) = getimagesize($file);
2069+ return $attr;
2070+ }else{
2071+ return $wide;
2072+ }
2073+}
2074+
2075+
2076+/*------------------------------------------------------------------------------+
2077+ *ソースの表示 url等に、改行をはさんでオーバーフローを防止する。
2078+ *------------------------------------------------------------------------------*/
2079+
2080+function my_wordwrap($str){
2081+
2082+ $wrap_width = TEXTTOHTML_CODE_WRAP_WIDTH;
2083+
2084+ if(isset($wrap_width)){
2085+ $old = array();
2086+ $new = array();
2087+ preg_match_all("/([A-z0-9\/-_=\?:#;\.]+)/u", $str, $matches);
2088+ $newtext = "";
2089+ $result = "";
2090+ foreach($matches as $match){
2091+
2092+ foreach($match as $line){
2093+
2094+ if(strlen($line) > $wrap_width){
2095+ $old[] = $line;
2096+ $new[]= wordwrap($line, $wrap_width, "\n", 1);
2097+ }
2098+ }
2099+ }
2100+
2101+ $result = str_replace($old,$new,$str);
2102+
2103+ return $this->tag_clear($result);
2104+ }else{
2105+
2106+ return $str;
2107+ }
2108+}
2109+/*------------------------------------------------------------------------------+
2110+ * ソースの簡易整形
2111+ *------------------------------------------------------------------------------*/
2112+function style_set($str){
2113+
2114+ $tab = "&nbsp;&nbsp;&nbsp;&nbsp;";
2115+ $i = 0;
2116+ $break = "";
2117+ $str = str_replace("<","@@@@@<",$str);
2118+ $result ="";
2119+ $lines = explode("@@@@@",$str);
2120+
2121+ foreach($lines as $key=>$line){
2122+
2123+ if(preg_match("/(<\/?(xml|html|body))/mi",$line) ){
2124+
2125+ $i = 0;
2126+ $space = str_repeat($tab,$i);
2127+ $break = "<br />\n";
2128+
2129+ }elseif(preg_match("/(<\/?(xml|html|head|body|script|!doctype))/mi",$line) ){
2130+
2131+ $i = 2;
2132+ $space = str_repeat($tab,$i);
2133+ $break = "<br />\n";
2134+ }elseif(preg_match("/(<\/)/",$line) ){
2135+
2136+ if($i<0){
2137+ $i = 0;
2138+ }
2139+
2140+ $space = str_repeat($tab,$i);
2141+ $break = "<br />\n";
2142+ $i--;
2143+ }elseif(preg_match("/(\/>?)/",$line) ){
2144+
2145+ if($i<0){
2146+ $i = 0;
2147+ }
2148+
2149+ $space = str_repeat($tab,$i);
2150+ $break = "<br />\n";
2151+ }else{
2152+ $break = "<br />\n";
2153+
2154+ if($i<0){
2155+ $i = 0;
2156+ }
2157+
2158+ $space = str_repeat($tab,$i);
2159+ $i++;
2160+
2161+ }
2162+
2163+ $result .= $space.htmlspecialchars($line).$break;
2164+ }
2165+
2166+ return $this->tag_clear($result);
2167+}
2168+
2169+ /* ------------------------------------------------------------
2170+ *タグ内の改行を削除
2171+ -------------------------------------------------------------*/
2172+
2173+function tag_clear($text){
2174+ clearstatcache ();
2175+
2176+//行頭スペースを削除 全角スペース以外
2177+ $text = preg_replace("/(^[[:space:]]+)(.*)/m","\\2",$text);
2178+
2179+//複数の改行を、ひとつに。
2180+ $text = str_replace("\r","\n",$text);
2181+ $text = preg_replace("/(\n){2,}/","\n\n",$text);
2182+
2183+ return $text;
2184+}
2185+
2186+//end class
2187+}
2188+
2189+
2190+///////////////////////////////////////////////////////////////////////////////////
2191+///////////////////////////////////////////////////////////////////////////////////
2192+
2193+//配列キー文字数の多い順にソート uksort用
2194+
2195+ function text2html_cmp($a, $b){
2196+ $a = mb_strlen($a,"UTF-8");
2197+ $b = mb_strlen($b,"UTF-8");
2198+
2199+ //長い順
2200+ return strcasecmp($b,$a);
2201+ }
2202+
2203+
2204+function postal_code($replacement){
2205+
2206+ $replacement = mb_convert_encoding($replacement,"UTF-8","auto");
2207+ if(preg_match("/(state=\")([^\"]+)/u",$replacement,$state) == 1){$state = $state[2];}else{$state = "";}
2208+
2209+ if(preg_match("/(city=\")([^\"]+)/u",$replacement,$city) == 1){
2210+ $city = $city[2];
2211+ }else{
2212+ $city = "";
2213+ }
2214+ if(preg_match("/(address=\")([^\"]+)/u",$replacement,$address) == 1){
2215+ $address = $address[2];
2216+ }else{
2217+ $address = "";
2218+ }
2219+ if(preg_match("/(company=\")([^\"]+)/u",$replacement,$company) == 1){
2220+ $company = $company[2];
2221+ }else{
2222+ $company = "";
2223+ }
2224+
2225+ if(preg_match("/(state_kana=\")([^\"]+)/u",$replacement,$state_kana) == 1){
2226+ $state_kana = $state_kana[2];
2227+ }else{
2228+ $state_kana = "";
2229+ }
2230+ if(preg_match("/(city_kana=\")([^\"]+)/u",$replacement,$city_kana) == 1){
2231+ $city_kana = $city_kana[2];
2232+ }else{
2233+ $city_kana = "";
2234+ }
2235+ if(preg_match("/(address_kana=\")([^\"]+)/u",$replacement,$address_kana) == 1){
2236+ $address_kana= $address_kana[2];
2237+ }else{
2238+ $address_kana= "";
2239+ }
2240+ if(preg_match("/(company_kana=\")([^\"]+)/u",$replacement,$company_kana) == 1){
2241+ $company_kana= $company_kana[2];
2242+ }else{
2243+ $company_kana= "";
2244+ }
2245+
2246+$title = "title=\"".$state_kana.$city_kana.$address_kana.$company_kana."\"";
2247+
2248+return str_replace("none","","<span $title>".$state.$city.$address.$company."</span>");
2249+
2250+}
2251+
2252+
2253+//wikipedia
2254+ function simpleapi_wikipedia($replacement, $count = 1){
2255+
2256+ $result = unserialize($replacement);
2257+ $results = "<div style=\"margin:1em;\">";
2258+
2259+ for($i=0;$i<$count;$i++){
2260+
2261+ $title = $result[$i]['title'];
2262+ $body = $result[$i]['body'];
2263+ $results .= "<strong>Wikipedia:{$title}</strong><blockquote>".nl2br($body)."</blockquote>";
2264+ }
2265+
2266+ return str_replace(array("<br>","<br/>"),"<br />",$results)."\n</div>";
2267+ }
2268+
2269+/*
2270+function test1(){
2271+
2272+return date("ymd");
2273+
2274+}
2275+*/
2276+
2277+////////////////////////////////////////////////////////////////////////////////////
2278+/*
2279+function use_cache($name){
2280+
2281+ if(!defined('CACHE_LITE_PATH')){return array(false,"");}
2282+
2283+ require_once(CACHE_LITE_PATH);
2284+
2285+ $options = array(
2286+ 'cacheDir' => CACHE_DIR_PATH,
2287+ 'lifeTime' => CACHE_LIFE_TIME,
2288+ );
2289+
2290+ $Cache_Lite = new Cache_Lite($options);
2291+
2292+ if(!CACHE_SWITCH){
2293+
2294+ $Cache_Lite->clean();
2295+ return array(false,"");
2296+ }
2297+
2298+ $name = md5($name);
2299+
2300+ if ($data = $Cache_Lite->get($name)){
2301+ $result = $data;
2302+ $flag = true;
2303+ }else {
2304+
2305+ $flag = false;
2306+ }
2307+
2308+ return array($flag,$data);
2309+}
2310+
2311+function save_cache($name,$value){
2312+
2313+ if(!defined('CACHE_LITE_PATH')){return array(false,$value);}
2314+
2315+ $name = md5($name);
2316+
2317+ require_once(CACHE_LITE_PATH);
2318+
2319+ $options = array(
2320+ 'cacheDir' => CACHE_DIR_PATH,
2321+ 'lifeTime' => CACHE_LIFE_TIME,
2322+ );
2323+
2324+ $Cache_Lite = new Cache_Lite($options);
2325+
2326+ if(!CACHE_SWITCH){
2327+
2328+ $Cache_Lite->clean();
2329+ return array(false,$value);
2330+ }
2331+
2332+ if ($data = $Cache_Lite->get($name)){
2333+ $result = $data;
2334+ $flag = true;
2335+ }else {
2336+
2337+ $Cache_Lite->save($value,$name);
2338+ //print_r($Cache_Lite);
2339+ $result = $value;
2340+ $flag = false;
2341+ }
2342+
2343+ return array($flag,$value);
2344+}
2345+*/
2346+function html_document1($ini_array,$documents,$navi="",$source = ""){
2347+
2348+ global $content_name;
2349+ global $source;
2350+ global $campany_data;
2351+
2352+ $charset = $ini_array['html_header']['charset'];
2353+ $author = $ini_array['html_header']['author'];
2354+ $keyword = $ini_array['html_header']['keyword'];
2355+ $description = $ini_array['html_header']['description'];
2356+ $mail = $ini_array['html_header']['mail'];
2357+ $stylesheet = $ini_array['html_header']['stylesheet'];
2358+ $style_media = $ini_array['html_header']['style_media'];
2359+ $navi_start = $ini_array['html_header']['start'];
2360+ $navi_prev = $ini_array['html_header']['prev'];
2361+ $navi_next = $ini_array['html_header']['next'];
2362+ $navi_help = $ini_array['html_header']['help'];
2363+ $title = $ini_array['html_header']['title'];
2364+ $embed = $ini_array['html_header']['embed'];
2365+
2366+$html=<<<DOC
2367+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2368+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2369+<html lang="ja" xml:lang="ja" xmlns="http://www.w3.org/1999/xhtml">
2370+<head>
2371+ <meta http-equiv="content-type" content="text/html; charset=$charset" />
2372+ <meta http-equiv="content-script-type" content="text/javascript" />
2373+ <meta http-equiv="content-style-type" content="text/css" />
2374+ <meta name="author" content="$author" />
2375+ <meta name="keywords" content="$keyword" />
2376+ <meta name="description" content="$description" />
2377+ <link rev="made" href="mailto:$mail" />
2378+ <link rel="stylesheet" href="$stylesheet" media="$style_media" type="text/css" />
2379+ <link rel="start" href="$navi_start" />
2380+ <link rel="prev" href="$navi_prev" />
2381+ <link rel="next" href="$navi_next" />
2382+ <link rel="help" href="$navi_help" />
2383+ <title>$title</title>
2384+ <script src="/js/jquery.js" type="text/javascript"></script>
2385+ <script src="/js/jquery.flatheights.js" type="text/javascript"></script>
2386+ <link rel="stylesheet" href="/js/ui.tabs.css" type="text/css"
2387+ media="print, projection, screen" />
2388+ <link rel="stylesheet" type="text/css" href="/js/jquery.jcarousel.css" />
2389+ <link rel="stylesheet" type="text/css" href="/js/skins/tango/skin.css" />
2390+ $embed
2391+</head>
2392+<body id="top">
2393+<div id="wrap">
2394+<div id="header">
2395+<h1>$title</h1>
2396+</div>
2397+<div id="common">
2398+$navi
2399+$documents
2400+$source
2401+</div>
2402+<div id="footer">
2403+2008&copy;$title
2404+</div>
2405+</div>
2406+</body>
2407+</html>
2408+DOC;
2409+
2410+$html = str_replace(array("<br >","<br>"),"<br />",$html);
2411+
2412+echo $html;
2413+}
2414+
2415+?>
\ No newline at end of file
Show on old repository browser