Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 * 스킨 파서 시스템 수정
 * 모든 치환자의 목록을 가지고 있습니다.
 * dress시 스킨 자체를 스캐닝하지 않고, 치환자의 목록을 참조하여 있으면 바꾸기를 시도합니다.
 * 문제점
  * dress할 때 들어오는 컨텐츠가 block으로, 스킨의 일부인 경우에는 해당 치환자가 존재하지 않을 수도 있는데 치환을 시도합니다. (블럭별로 치환자를 기록하게 하는게 더 낭비일 것 같기도 합니다.
  • Loading branch information
inureyes committed May 27, 2008
1 parent f3015b9 commit f0e9733
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 40 deletions.
22 changes: 16 additions & 6 deletions components/Textcube.Function.misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,23 @@ function getFileListByRegExp($path, $pattern, $deepScan=false) {
return $fileList;
}

function dress($tag, $value, & $contents) {
if (preg_match('/\[##_' . preg_quote($tag, '/') . '_##\]/i', $contents, $temp)) {
$contents = str_replace("[##_{$tag}_##]", $value, $contents);
return true;
function dress($tag, $value, & $contents, $force = false) {
global $__gDressTags;
if($force == true) { // Use Textcube skin cache system.
if(strpos($tag, 'sidebar_') !== false || in_array($tag, $__gDressTags) ) {
$contents = str_replace("[##_{$tag}_##]", $value, $contents);
return true;
} else {
return false;
}
} else {
return false;
}
if (preg_match('/\[##_' . preg_quote($tag, '/') . '_##\]/i', $contents, $temp)) {
$contents = str_replace("[##_{$tag}_##]", $value, $contents);
return true;
} else {
return false;
}
}
}

function isSpace($string) {
Expand Down
46 changes: 23 additions & 23 deletions components/Textcube.Model.Paging.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ function getPagingView( & $paging, & $template, & $itemTemplate) {
ob_start();
if (isset($paging['first'])) {
$itemView = "$itemTemplate <span class=\"interword\">...</span> ";
misc::dress('paging_rep_link_num', '1', $itemView);
misc::dress('paging_rep_link', "href='$url$prefix{$paging['first']}$postfix'", $itemView);
misc::dress('paging_rep_link_num', '1', $itemView, true);
misc::dress('paging_rep_link', "href='$url$prefix{$paging['first']}$postfix'", $itemView, true);
print ($itemView);
} else if ($paging['page'] > 5) {
$itemView = "$itemTemplate <span class=\"interword\">...</span> ";
misc::dress('paging_rep_link_num', '1', $itemView);
misc::dress('paging_rep_link', "href='$url{$prefix}1$postfix'", $itemView);
misc::dress('paging_rep_link_num', '1', $itemView, true);
misc::dress('paging_rep_link', "href='$url{$prefix}1$postfix'", $itemView, true);
print ($itemView);
}
if (isset($paging['before']))
Expand All @@ -42,63 +42,63 @@ function getPagingView( & $paging, & $template, & $itemTemplate) {
if (isset($paging['before'])) {
foreach ($paging['before'] as $value) {
$itemView = $itemTemplate;
misc::dress('paging_rep_link_num', "$page", $itemView);
misc::dress('paging_rep_link', "href='$url$prefix$value$postfix'", $itemView);
misc::dress('paging_rep_link_num', "$page", $itemView, true);
misc::dress('paging_rep_link', "href='$url$prefix$value$postfix'", $itemView, true);
print ($itemView);
$page++;
}
} else {
for ($i = 0; ($i < 4) && ($page < $paging['page']); $i++) {
$itemView = $itemTemplate;
misc::dress('paging_rep_link_num', "$page", $itemView);
misc::dress('paging_rep_link', "href='$url$prefix$page$postfix'", $itemView);
misc::dress('paging_rep_link_num', "$page", $itemView, true);
misc::dress('paging_rep_link', "href='$url$prefix$page$postfix'", $itemView, true);
print ($itemView);
$page++;
}
}
if (($page == $paging['page']) && ($page <= $paging['pages'])) {
$itemView = $itemTemplate;
misc::dress('paging_rep_link_num', "$page", $itemView);
misc::dress('paging_rep_link', 'class="selected"', $itemView);
misc::dress('paging_rep_link_num', "$page", $itemView, true);
misc::dress('paging_rep_link', 'class="selected"', $itemView, true);
print ($itemView);
$page++;
}
if (isset($paging['before'])) {
foreach ($paging['after'] as $value) {
$itemView = $itemTemplate;
misc::dress('paging_rep_link_num', "$page", $itemView);
misc::dress('paging_rep_link', "href='$url$prefix$value$postfix'", $itemView);
misc::dress('paging_rep_link_num', "$page", $itemView, true);
misc::dress('paging_rep_link', "href='$url$prefix$value$postfix'", $itemView, true);
print ($itemView);
$page++;
}
} else {
for ($i = 0; ($i < 4) && ($page <= $paging['pages']); $i++) {
$itemView = $itemTemplate;
misc::dress('paging_rep_link_num', "$page", $itemView);
misc::dress('paging_rep_link', "href='$url$prefix$page$postfix'", $itemView);
misc::dress('paging_rep_link_num', "$page", $itemView, true);
misc::dress('paging_rep_link', "href='$url$prefix$page$postfix'", $itemView, true);
print ($itemView);
$page++;
}
}
if (isset($paging['last'])) {
$itemView = " <span class=\"interword\">...</span> $itemTemplate";
misc::dress('paging_rep_link_num', "{$paging['pages']}", $itemView);
misc::dress('paging_rep_link', "href='$url$prefix{$paging['last']}$postfix'", $itemView);
misc::dress('paging_rep_link_num', "{$paging['pages']}", $itemView, true);
misc::dress('paging_rep_link', "href='$url$prefix{$paging['last']}$postfix'", $itemView, true);
print ($itemView);
} else if (($paging['pages'] - $paging['page']) > 4) {
$itemView = " <span class=\"interword\">...</span> $itemTemplate";
misc::dress('paging_rep_link_num', "{$paging['pages']}", $itemView);
misc::dress('paging_rep_link', "href='$url$prefix{$paging['pages']}$postfix'", $itemView);
misc::dress('paging_rep_link_num', "{$paging['pages']}", $itemView, true);
misc::dress('paging_rep_link', "href='$url$prefix{$paging['pages']}$postfix'", $itemView, true);
print ($itemView);
}
$itemsView = ob_get_contents();
ob_end_clean();
$view = $template;
misc::dress('prev_page', isset($paging['prev']) ? "href='$url$prefix{$paging['prev']}$postfix'" : '', $view);
misc::dress('paging_rep', $itemsView, $view);
misc::dress('next_page', isset($paging['next']) ? "href='$url$prefix{$paging['next']}$postfix'" : '', $view);
misc::dress('no_more_prev', isset($paging['prev']) ? '' : 'no-more-prev', $view);
misc::dress('no_more_next', isset($paging['next']) ? '' : 'no-more-next', $view);
misc::dress('prev_page', isset($paging['prev']) ? "href='$url$prefix{$paging['prev']}$postfix'" : '', $view, true);
misc::dress('paging_rep', $itemsView, $view, true);
misc::dress('next_page', isset($paging['next']) ? "href='$url$prefix{$paging['next']}$postfix'" : '', $view, true);
misc::dress('no_more_prev', isset($paging['prev']) ? '' : 'no-more-prev', $view, true);
misc::dress('no_more_next', isset($paging['next']) ? '' : 'no-more-next', $view, true);

return $view;
}
Expand Down
31 changes: 27 additions & 4 deletions lib/blog.skin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
/// Copyright (c) 2004-2008, Needlworks / Tatter Network Foundation
/// All rights reserved. Licensed under the GPL.
/// See the GNU General Public License for more details. (/doc/LICENSE, /doc/COPYRIGHT)

global $__gDressTags;

class Skin {
var $outter;
var $skin;
Expand Down Expand Up @@ -81,9 +84,12 @@ class Skin {

var $microformatDebug;
var $hentryExisted;


var $dressTags = array();

function Skin($name, $previewMode = false) {
global $service, $blogURL, $suri, $blog;
global $service, $blogURL, $suri, $blog, $__gDressTags;
$__gDressTags = array();
if($previewMode == true || ($service['skincache'] != true) || !$this->loadCache()) {
requireComponent('Textcube.Function.Setting');
$this->noneCommentMessage = setting::getBlogSettingGlobal('noneCommentMessage',null);
Expand Down Expand Up @@ -120,7 +126,7 @@ function Skin($name, $previewMode = false) {
replaceSkinTag($sval, 'body');
insertGeneratorVersion($sval);

$sval = str_replace('<s_t3>','',$sval); // For Skin compatibility with < Textcube 1.7
$sval = str_replace('<s_t3>','',$sval); // Prune s_t3. For Skin compatibility with < Textcube 1.7
$sval = str_replace('</s_t3>','',$sval);

// 사이드바 작업.
Expand Down Expand Up @@ -183,7 +189,10 @@ function Skin($name, $previewMode = false) {
$this->noneTrackbackMessage = str_replace('./', "{$service['path']}/skin/$name/", $this->noneTrackbackMessage);
$this->singleTrackbackMessage = str_replace('./', "{$service['path']}/skin/$name/", $this->singleTrackbackMessage);


// Store skin tags.
$__gDressTags = $this->getDressTags($sval);

// Cutting skin.
list($sval, $this->coverItem) = $this->cutSkinTag($sval, 'cover_rep');
list($sval, $this->cover) = $this->cutSkinTag($sval, 'cover');

Expand Down Expand Up @@ -289,11 +298,13 @@ function Skin($name, $previewMode = false) {
list($sval, $this->pageTitle) = $this->cutSkinTag($sval, 'page_title');
$this->outter = $sval;
$this->applyMicroformats();
$this->dressTags = $__gDressTags;
if($previewMode == false) $this->saveCache();
}
}

function cutSkinTag($contents, $tag, $replace = null) {
global $__gDressTags;
if (is_null($replace)) {
$replace = "[##_{$tag}_##]";
}
Expand All @@ -306,10 +317,12 @@ function cutSkinTag($contents, $tag, $replace = null) {
return array($contents, NULL);
$inner = substr($contents, $begin + $tagSize, $end - $begin - $tagSize);
$outter = substr($contents, 0, $begin) . $replace . substr($contents, $end + $tagSize + 1);
array_push($__gDressTags, $tag);
return array($outter, $inner);
}

function cutSkinReplacer($contents, $tag, $replace = null) {
global $__gDressTags;
if (is_null($replace)) {
$replace = "[##_{$tag}_##]";
}
Expand All @@ -320,9 +333,17 @@ function cutSkinReplacer($contents, $tag, $replace = null) {
}
$inner = "[##_{$tag}_##]";
$outter = substr($contents, 0, $pos) . $replace . substr($contents, $pos + $tagSize);
array_push($__gDressTags, $tag);
return array($outter, $inner);
}

function getDressTags($contents) {
$matches = array();
$result = array();
preg_match_all('/\[##_(.+?)_##\]/',$contents,$matches);
return $matches[1];
}

function saveCache() {
$skinCache = get_object_vars($this);
$cache = new pageCache('skinCache');
Expand All @@ -331,12 +352,14 @@ function saveCache() {
}

function loadCache() {
global $__gDressTags;
$cache = new pageCache('skinCache');
if(!$cache->load()) return false;
$skinCache = unserialize($cache->contents);
foreach($skinCache as $key=>$value) {
$this->$key = $value;
}
$__gDressTags = $this->dressTags;
return true;
}

Expand Down
12 changes: 5 additions & 7 deletions lib/view/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ function printHtmlFooter() {
<?php
}

function dress($tag, $value, & $contents, $force = false) {
if($force) {
$contents = str_replace("[##_{$tag}_##]", $value, $contents);
return true;
}
if (preg_match("@\\[##_{$tag}_##\\]@iU", $contents)) {
function dress($tag, $value, & $contents) {
global $__gDressTags;
if(strpos($tag, 'sidebar_') !== false || in_array($tag, $__gDressTags) ) {
$contents = str_replace("[##_{$tag}_##]", $value, $contents);
return true;
} else {
Expand All @@ -36,7 +33,8 @@ function dress($tag, $value, & $contents, $force = false) {
}

function dressInsertBefore($tag, $value, & $contents) {
if (preg_match("@\\[##_{$tag}_##\\]@iU", $contents)) {
global $__gDressTags;
if(strpos($tag, 'sidebar_') !== false || in_array($tag, $__gDressTags) ) {
$tempContents = preg_split("@\\[##_{$tag}_##\\]@iU", $contents, 2);
$contents = $tempContents[0].$value.'[##_'.$tag.'_##]'.$tempContents[1];
return true;
Expand Down

0 comments on commit f0e9733

Please sign in to comment.