All pastes #807937 Raw Edit

Miscellany

public php v1 · immutable
·published 2007-12-07 03:40 UTC
rendered paste body
<?phpclass TemplatesController extends AppController {	var $uses = array('Template', 'Article');	function admin_index() {		// Show an index of available templates/gems		$this->set('templateList', $this->Template->findAll());	}	function admin_add() {		// Add an template/gem		if ( !empty($this->data) ) {			if ( @$this->Template->save($this->data) ) {				$this->Session->setFlash(__('Layout/Gem has been saved to the database.', True));				$this->redirect('/admin/templates/');				exit;			} else {				$this->Session->setFlash(__('Layout/Gem could not be saved to the database.', True));			}		}	}	function admin_view($param1 = Null) {		// View an template/gem		if ( $param1 != Null ) {			$template = $this->Template->findById((int)$param1);			// Get anything between [] and retrieve the gems. Replace the [] with the gems.			if ( preg_match_all('`\[(.+?)\]`is', $template['Template']['code'], $matches) ) {				// Get rid of the doubles first....do that once internet is back online.				foreach ( $matches[1] as $key => $value ) {					if ( $gem = $this->Template->findByName($value) ) {						$template['Template']['code'] = str_ireplace('['.$value.']', $gem['Template']['code'], $template['Template']['code']);					}				}				unset($gem);				unset($matches);			}			if ( preg_match_all('`\$article_([a-zA-Z0-9_.]+)`is', $template['Template']['code'], $matches) ) {				// Variables to access fields related to the article				$article = $this->Article->findById(1);				foreach ( $matches[1] as $key => $value ) {					if ( isset($article['Article'][$value]) ) {						$template['Template']['code'] = str_ireplace('$article_'.$value, $article['Article'][$value], $template['Template']['code']);					}				}			}			if ( preg_match_all('`<\?php (.+?)\?>`is', $template['Template']['code'], $matches) ) {				# THIS IS VERY DANGEROUS! Try to avoid it when possible.				foreach ( $matches[1] as $key => $value ) {					ob_start(); eval($value); $output = ob_get_clean();					$template['Template']['code'] = str_ireplace('<?php '.$value.'?>', $output, $template['Template']['code']);				}			}			var_dump($template);		}	}	function admin_edit($param1 = Null) {		// Edit an template/gem		if ( $param1 != Null ) {			if ( !empty($this->data) ) {				if ( @$this->Template->save($this->data) ) {					$this->Session->setFlash(__('Layout/Gem has been edited and saved to the database.', True));					$this->redirect('/admin/templates/');					exit;				} else {					$this->Session->setFlash(__('Layout/Gem could not be saved to the database.', True));				}			} else {				$this->data = $this->Template->findById((int)$param1);			}		}	}	function admin_delete($param1 = Null) {		// Delete an template/gem		if ( $param1 != Null ) {			if ( @$this->Template->del((int)$param1) ) {				$this->Session->setFlash(__('Layout/Gem has been deleted from the database.', True));				$this->redirect('/admin/templates/');				exit;			} else {				$this->Session->setFlash(__('Layout/Gem could not be deleted from the database.', True));			}		}	}}?>