============== ¼Ò °³ (INTRO) ============== ÅÛÇø´ÀÌ ±â´ÉÀÌ ¸¹¾ÆÁü¿¡ µû¶ó µ¢Ä¡µµ Ä¿Áö°í ºÒÇÊÇÑ ±â´Éµéµµ ¸¹ÀÌ Æ÷ÇԵȰÍÀÌ ¸¹½À´Ï´Ù. º» Ŭ·¡½º´Â ¾ÆÁÖ °¡º¿î ÅÛÇø´ Ŭ·¡½ºÀÔ´Ï´Ù. ÇÏÁö¸¸ ´ÙÁß Block±â´ÉÀ» °¡Áö°í ÀÖÀ¸¸ç »ç¿ë¹ýÀÌ ºñ±³Àû °£´ÜÇÕ´Ï´Ù. ±»ÀÌ »ç¿ëÇÏÁö ¾Ê´õ¶óµµ ÇÁ·Î±×·¥ ±¸¼º°ú °øºÎ¿¡ µµ¿òÀÌ µÉµíÇÑ Å¬·¡½º ÀÔ´Ï´Ù. ============== ¶óÀ̼¾½º ============== GNU GPL ============= ¼³ Ä¡ ============= ÅÛÇø´ Ŭ·¡½º´Â ÀÚüÀûÀ¸·Î ÀÛµ¿ÇÏ´Â °ÍÀÌ ¾Æ´Ï¹Ç·Î ¼³Ä¡°úÁ¤ÀÌ µû·Î ¾ø°í ÇØ´ç ÆÄÀÏÀ» ¾÷·Îµå ÇÏ´Â °Í¸¸À¸·Î ¼³Ä¡´Â ¿Ï·á µË´Ï´Ù. ============= ¼Ò½ºÄÚµå ============= ÁÖ¼®Àº Á¦°¡ÇÏ¿´½À´Ï´Ù. ( ´Ù¿î¹Þ´Â ¼Ò½º³»¿¡´Â ÁÖ¼®Æ÷ÇÔ ) <?php define("TEMPLATE_ERR_FILE","Could not load template file."); class Template { var $delimiterStart = "{"; var $delimiterEnd = "}"; var $t; var $templatefile; function Template($filename = "") { /* todo: - remove setting error messages from constructor ( to a base class ? ) */ $this->loadTemplateFile($filename); } function loadTemplateFile($filename = "") { if (!$filename) return false; if ($filename) $this->templatefile = $filename; if (!$fp = @fopen($this->templatefile,'r')) { $this->halt(TEMPLATE_ERR_FILE); } $this->t = fread($fp,filesize($this->templatefile)); fclose($fp); $this->_initTemplate(); } function loadTemplateContent($templatestring="") { $this->t = $templatestring; $this->_initTemplate(); } function _initTemplate() { preg_match_all("/<!--s+BEGINs+(.*)?s+-->s*n*s*(.*)s*n*s*<!--s+ENDs+(1)s+-->/ms",$this->t,$ma); for ($i = 0; $i < count($ma[0]); $i++) { $search = "/s*n*<!--s+BEGINs+(" . $ma[1][$i] . ")?s+-->(.*)<!--s+ENDs+(" . $ma[1][$i]. ")s+-->s*n*/ms"; $replace = $this->delimiterStart . $ma[1][$i] . $this->delimiterEnd; $this->bl[$ma[1][$i]] =& new Template(); $this->bl[$ma[1][$i]]->loadTemplateContent($ma[2][$i]); $this->t = preg_replace($search,$replace,$this->t); } } function fetchBlock($blockName) { if (isset($this->bl[$blockName])) return $this->bl[$blockName]; else return false; } function assign($varName,$varValue=false) { if (is_array($varName)) { foreach ($varName as $key => $value) { $this->pl[$key][] = $value; } } else { $this->pl[$varName][] = $varValue; } } function reset() { unset($this->pl); } function out() { print $this->get(); } function get() { if (is_array($this->pl)) { foreach ($this->pl as $key => $value) { $search = $this->delimiterStart . $key . $this->delimiterEnd; $replaceText = ""; for ($i = 0; $i < count($this->pl[$key]); $i++) { if (is_object($this->pl[$key][$i])) $replaceText .= $this->pl[$key][$i]->get(); else $replaceText .= $this->pl[$key][$i]; } $this->t = str_replace($search,$replaceText,$this->t); } } return $this->t; } } ?>