All pastes #989731 Raw Edit

Stuff

public text v1 · immutable
#989731 ·published 2008-04-19 17:23 UTC
rendered paste body
<?php

/**
*
* @version $Id$
* @copyright 2008
*/

/**
*/
class PageView {
    /**
    * Constructor
    *
    * @access protected
    */
    protected $data = array();
    protected $file = "";
    protected $patterns = array();
    protected $default = "";
    protected $expRepeat = '/<% repeat %>([\s\S]*?)<% end_repeat %>/e';
	protected $phpControl='/<% php %>([\s\S]*?)<% end_php %>/';

    function PageView()
    {
    }

    function render()
    {
   		global $view;

        $isRepeat = false;


        if (fopen($this->file, "r")) {
            $content = file_get_contents($this->file);
            //preg_match($this->phpControl, $content,$functions);
			$content=preg_replace($this->phpControl,'\\1',$content);

			$content=preg_replace('/\\$([\w]+)->([\w]+)/e','$\\1->\\2()',$content);
		    $content=preg_replace($this->expRepeat,'$this->processRepeat(\\1)',$content);
		   /* if (preg_match($this->expRepeat, $content, $matches)) {
                $isRepeat = true;
                $repeatContent = $this->processRepeat($matches[1]);
                $split = preg_split($this->expRepeat, $content);

                if (is_array($split)) {
                    $content = $split[0];
                }
            }*/

          foreach($this->patterns as $pattern => $field) {
                for($i = 0;$i < count($this->data);$i++) {
                    $content = ereg_replace($pattern, $this->data[$i][$field] , $content);
                }
            }

            if ($isRepeat) {
                $content .= $repeatContent . $split[1];
            }
        } else {
            return $this->default;
            }
            return $content;
        }
        private function processRepeat($content)
        {
            $data = "";

			 for($i = 0;$i < count($this->data);$i++) {
			 	$tmp=$content;
           		 foreach($this->patterns as $pattern => $field) {

                    $tmp= ereg_replace($pattern, $this->data[$i][$field] , $tmp);
                }
                $data .=$tmp;
            }
            return $data;
        }
    }

    ?>


// template file
 <div id="pageContent">
          <div id="pageTitle">{ContestName} Submissions.</div>
          <br/>
          <div id="searchList" class="contentBlock">
         <% repeat %>
            <div class="submission">
              <ul>
				<li class="ub_list">
					<a href="{WidgetID}/submission/{ChildID}">
					<span class="image" style="
	background: rgb(0, 0, 0) url({ProfileImage}) no-repeat scroll center; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"/>	
	</a>
                <div class="info">
                  <h4>{ProfileTitle}</h4>
                  <ul class="submissionDetails">
                    <li><strong>Views: </strong>{Views}</li>
                    <li><strong>Since: </strong>{SignupDate}</li>
                  </ul>
                </div>
			</li>
              </ul>
			 
            </div>
		<% end_repeat %>
			<div id="pagination">
			 	<% php %>
				$view->getSubmissionsCount
				<% end_php %>
				
			 </div>
          </div>
        </div>