- Timestamp:
- 2013/05/02 18:11:36 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_12-dev/data/class/helper/SC_Helper_Transform.php
r22567 r22796 28 28 * @version $Id$ 29 29 */ 30 class SC_Helper_Transform 31 { 30 class SC_Helper_Transform { 32 31 protected $objDOM; 33 32 protected $arrSmartyTagsOrg; … … 50 49 * @return void 51 50 */ 52 public function __construct($source) 53 { 51 public function __construct($source) { 54 52 $this->objDOM = new DOMDocument(); 55 53 $this->objDOM->strictErrorChecking = false; … … 134 132 * @return SC_Helper_Transformオブジェクト 135 133 */ 136 public function select($selector, $index = NULL, $require = true, $err_msg = NULL) 137 { 134 public function select($selector, $index = NULL, $require = true, $err_msg = NULL) { 138 135 $this->arrSelectElements = array(); 139 136 $this->search_depth = 0; … … 175 172 * @return SC_Helper_Transformオブジェクト 176 173 */ 177 public function find($selector, $index = NULL, $require = true, $err_msg = NULL) 178 { 174 public function find($selector, $index = NULL, $require = true, $err_msg = NULL) { 179 175 $arrParentElements = $this->arrSelectElements[$this->search_depth]; 180 176 $this->search_depth++; … … 216 212 * @return SC_Helper_Transformオブジェクト 217 213 */ 218 public function end($back_num = 1) 219 { 214 public function end($back_num = 1) { 220 215 if ($this->search_depth >= $back_num) { 221 216 $this->search_depth -= $back_num; … … 234 229 * @return SC_Helper_Transformオブジェクト 235 230 */ 236 public function insertBefore($html_snip) 237 { 231 public function insertBefore($html_snip) { 238 232 foreach ($this->arrSelectElements[$this->search_depth] as $key => $objElement) { 239 233 $this->lfSetTransform('insertBefore', $objElement[0], $html_snip); … … 249 243 * @return SC_Helper_Transformオブジェクト 250 244 */ 251 public function insertAfter($html_snip) 252 { 245 public function insertAfter($html_snip) { 253 246 foreach ($this->arrSelectElements[$this->search_depth] as $key => $objElement) { 254 247 $this->lfSetTransform('insertAfter', $objElement[0], $html_snip); … … 264 257 * @return SC_Helper_Transformオブジェクト 265 258 */ 266 public function appendFirst($html_snip) 267 { 259 public function appendFirst($html_snip) { 268 260 foreach ($this->arrSelectElements[$this->search_depth] as $key => $objElement) { 269 261 $this->lfSetTransform('appendFirst', $objElement[0], $html_snip); … … 279 271 * @return SC_Helper_Transformオブジェクト 280 272 */ 281 public function appendChild($html_snip) 282 { 273 public function appendChild($html_snip) { 283 274 foreach ($this->arrSelectElements[$this->search_depth] as $key => $objElement) { 284 275 $this->lfSetTransform('appendChild', $objElement[0], $html_snip); … … 294 285 * @return SC_Helper_Transformオブジェクト 295 286 */ 296 public function replaceElement($html_snip) 297 { 287 public function replaceElement($html_snip) { 298 288 foreach ($this->arrSelectElements[$this->search_depth] as $key => &$objElement) { 299 289 $this->lfSetTransform('replaceElement', $objElement[0], $html_snip); … … 308 298 * @return SC_Helper_Transformオブジェクト 309 299 */ 310 public function removeElement() 311 { 300 public function removeElement() { 312 301 foreach ($this->arrSelectElements[$this->search_depth] as $key => &$objElement) { 313 302 $this->lfSetTransform('replaceElement', $objElement[0], ''); … … 322 311 * @return string トランスフォーム済みHTML。まったくトランスフォームが行われなかった場合は元のHTMLを返す。。 323 312 */ 324 public function getHTML() 325 { 313 public function getHTML() { 326 314 if (count($this->arrErr)) { 327 315 // エラーメッセージ組み立て … … 370 358 * @return string 代わりの文字列 371 359 */ 372 protected function lfCaptureSmartyTags2Comment(array $arrMatches) 373 { 360 protected function lfCaptureSmartyTags2Comment(array $arrMatches) { 374 361 $substitute_tag = sprintf('<!--###%08d###-->', $this->smarty_tags_idx); 375 362 $this->arrSmartyTagsOrg[$this->smarty_tags_idx] = $arrMatches[0]; … … 388 375 * @return string 代わりの文字列 389 376 */ 390 protected function lfCaptureHeadTags2Comment(array $arrMatches) 391 { 377 protected function lfCaptureHeadTags2Comment(array $arrMatches) { 392 378 $substitute_tag = sprintf('<!--###%08d###-->', $this->smarty_tags_idx); 393 379 $this->arrSmartyTagsOrg[$this->smarty_tags_idx] = $arrMatches[2]; … … 412 398 * @return string 代わりの文字列 413 399 */ 414 protected function lfCaptureSmartyTagsInTag(array $arrMatches) 415 { 400 protected function lfCaptureSmartyTagsInTag(array $arrMatches) { 416 401 // Smartyタグ内のクォートを処理しやすいよう、いったんダミーのタグに 417 402 $html = preg_replace_callback('/<\!--{.+?\}-->/s', array($this, 'lfCaptureSmartyTags2Temptag'), $arrMatches[0]); … … 430 415 * @return string 代わりの文字列 431 416 */ 432 protected function lfCaptureSmartyTags2Temptag(array $arrMatches) 433 { 417 protected function lfCaptureSmartyTags2Temptag(array $arrMatches) { 434 418 $substitute_tag = sprintf('###TEMP%08d###', $this->smarty_tags_idx); 435 419 $this->arrSmartyTagsOrg[$this->smarty_tags_idx] = $arrMatches[0]; … … 448 432 * @return string 代わりの文字列 449 433 */ 450 protected function lfCaptureSmartyTagsInQuote(array $arrMatches) 451 { 434 protected function lfCaptureSmartyTagsInQuote(array $arrMatches) { 452 435 $html = preg_replace_callback( 453 436 '/###TEMP(\d{8})###/s', … … 467 450 * @return string 代わりの文字列 468 451 */ 469 protected function lfCaptureSmartyTags2Value(array $arrMatches) 470 { 452 protected function lfCaptureSmartyTags2Value(array $arrMatches) { 471 453 $tag_idx = (int)$arrMatches[1]; 472 454 $substitute_tag = sprintf('###%08d###', $tag_idx); … … 484 466 * @return string 代わりの文字列 485 467 */ 486 protected function lfCaptureSmartyTags2Attr(array $arrMatches) 487 { 468 protected function lfCaptureSmartyTags2Attr(array $arrMatches) { 488 469 $tag_idx = (int)$arrMatches[1]; 489 470 $substitute_tag = sprintf('rel%08d="######"', $tag_idx); … … 499 480 * @return void 500 481 */ 501 protected function lfScanChild(DOMNode $objDOMElement, $parent_selector = '') 502 { 482 protected function lfScanChild(DOMNode $objDOMElement, $parent_selector = '') { 503 483 $objNodeList = $objDOMElement->childNodes; 504 484 if (is_null($objNodeList)) return; … … 536 516 * @return string 正規表現文字列 537 517 */ 538 protected function lfSelector2Regex($selector, $parent_index = NULL) 539 { 518 protected function lfSelector2Regex($selector, $parent_index = NULL){ 540 519 // jQueryライクなセレクタを正規表現に 541 520 $selector = preg_replace('/ *> */', ' >', $selector); // 子セレクタをツリー検索用に 「A >B」の記法にする … … 572 551 * @return void 573 552 */ 574 protected function lfAddElement($elementNo, array &$arrElement) 575 { 553 protected function lfAddElement($elementNo, array &$arrElement) { 576 554 if (is_array($this->arrSelectElements[$this->search_depth]) && array_key_exists($arrElement[0], $this->arrSelectElements[$this->search_depth])) { 577 555 //nop … … 591 569 * @return boolean 592 570 */ 593 protected function lfSetTransform($mode, $target_key, $html_snip) 594 { 571 protected function lfSetTransform($mode, $target_key, $html_snip) { 595 572 596 573 $substitute_tag = sprintf('<!--###%08d###-->', $this->smarty_tags_idx); … … 658 635 * @return void 659 636 */ 660 protected function lfSetError($selector, $type, $err_msg = NULL) 661 { 637 protected function lfSetError($selector, $type, $err_msg = NULL) { 662 638 $this->arrErr[] = array( 663 639 'selector' => $selector,
Note: See TracChangeset
for help on using the changeset viewer.
