修訂 | 2a89cdb3824c68dcae9f4254497382bacd3493e9 (tree) |
---|---|
時間 | 2017-10-24 02:28:38 |
作者 | umorigu <umorigu@gmai...> |
Commiter | umorigu |
BugTrack/2446 Fasten calendar_viewer plugin with get_existpage cache
@@ -110,52 +110,34 @@ function plugin_calendar_viewer_convert() | ||
110 | 110 | $s_page = htmlsc($pagename); |
111 | 111 | return "#calendar_viewer(): Exceeded the limit of show count: $s_page<br />"; |
112 | 112 | } |
113 | - | |
114 | - // 一覧表示するページ名とファイル名のパターン ファイル名には年月を含む | |
115 | - if ($pagename == '') { | |
116 | - // pagename無しのyyyy-mm-ddに対応するための処理 | |
117 | - $pagepattern = ''; | |
118 | - $pagepattern_len = 0; | |
119 | - $filepattern = encode($page_YM); | |
120 | - $filepattern_len = strlen($filepattern); | |
121 | - } else { | |
122 | - $pagepattern = strip_bracket($pagename) . '/'; | |
123 | - $pagepattern_len = strlen($pagepattern); | |
124 | - $filepattern = encode($pagepattern . $page_YM); | |
125 | - $filepattern_len = strlen($filepattern); | |
113 | + // page name pattern | |
114 | + $pagepattern = strip_bracket($pagename) . '/'; | |
115 | + if ($pagename === '') { | |
116 | + // Support non-pagename yyyy-mm-dd pattern | |
117 | + $pagepattern = ''; | |
126 | 118 | } |
127 | - | |
128 | - // ページリストの取得 | |
119 | + $pagepattern_len = strlen($pagepattern); | |
120 | + // Get pagelist | |
129 | 121 | $pagelist = array(); |
130 | - if ($dir = @opendir(DATA_DIR)) { | |
131 | - $_date = get_date('Y' . $date_sep . 'm' . $date_sep . 'd'); | |
132 | - $page_date = ''; | |
133 | - while($file = readdir($dir)) { | |
134 | - if ($file == '..' || $file == '.') continue; | |
135 | - if (substr($file, 0, $filepattern_len) != $filepattern) continue; | |
136 | - | |
137 | - $page = decode(trim(preg_replace('/\.txt$/', ' ', $file))); | |
138 | - $page_date = substr($page, $pagepattern_len); | |
139 | - | |
140 | - // Verify the $page_date pattern (Default: yyyy-mm-dd). | |
141 | - // Past-mode hates the future, and | |
142 | - // Future-mode hates the past. | |
143 | - if ((plugin_calendar_viewer_isValidDate($page_date, $date_sep) == FALSE) || | |
144 | - ($page_date > $_date && ($mode == 'past')) || | |
145 | - ($page_date < $_date && ($mode == 'future'))) | |
146 | - continue; | |
147 | - | |
148 | - $pagelist[] = $page; | |
122 | + $_date = get_date('Y' . $date_sep . 'm' . $date_sep . 'd'); | |
123 | + foreach (get_existpages() as $page) { | |
124 | + if (strncmp($page, $pagepattern, $pagepattern_len) !== 0) continue; | |
125 | + $page_date = substr($page, $pagepattern_len); | |
126 | + // Verify the $page_date pattern (Default: yyyy-mm-dd). | |
127 | + // Past-mode hates the future, and | |
128 | + // Future-mode hates the past. | |
129 | + if ((plugin_calendar_viewer_isValidDate($page_date, $date_sep) === FALSE) || | |
130 | + ($page_date > $_date && ($mode === 'past')) || | |
131 | + ($page_date < $_date && ($mode === 'future'))) { | |
132 | + continue; | |
149 | 133 | } |
134 | + $pagelist[] = $page; | |
150 | 135 | } |
151 | - closedir($dir); | |
152 | - | |
153 | 136 | if ($mode == 'past') { |
154 | 137 | rsort($pagelist, SORT_STRING); // New => Old |
155 | 138 | } else { |
156 | 139 | sort($pagelist, SORT_STRING); // Old => New |
157 | 140 | } |
158 | - | |
159 | 141 | // Include start |
160 | 142 | $tmppage = $vars['page']; |
161 | 143 | $return_body = ''; |