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