pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

PHP pastebin - collaborative debugging tool View Help


Posted by Thomas on Fri 7 Mar 09:58
report abuse | download | new post

  1. <?php
  2. class tsk_template {
  3.         public $folder = 'templates/';
  4.         public $ending = '.tpl.htm';
  5.         public $loggedIn = false;
  6.         public $top = '';
  7.         public $btm = '';
  8.         public $main = '';
  9.        
  10.         private $data = array();
  11.         private $sdata = array();
  12.         private $templates = array();
  13.        
  14.         function top($var) {
  15.                 $this->top = file_get_contents($this->folder . $var . $this->ending);
  16.         }
  17.        
  18.         function btm($var) {
  19.                 $this->btm = file_get_contents($this->folder . $var . $this->ending);
  20.         }
  21.        
  22.         function setDefault() {
  23.                 $this->top('overall_top');
  24.                 $this->btm('overall_btm');
  25.         }
  26.        
  27.         function main($var) {
  28.                 $this->main = file_get_contents($this->folder . $var . $this->ending);
  29.         }
  30.        
  31.         function loginout() {
  32.                 if($this->loggedIn == false) {
  33.                         $this->top = preg_replace("#<!-- Logged_In START -->.*?<!-- Logged_In END -->#is", '', $this->top);
  34.                         $this->main = preg_replace("#<!-- Logged_In START -->.*?<!-- Logged_In END -->#is", '', $this->main);
  35.                         $this->btm = preg_replace("#<!-- Logged_In START -->.*?<!-- Logged_In END -->#is", '', $this->btm);
  36.                 }
  37.                 else{
  38.                         $this->top = preg_replace("#<!-- Logged_Out START -->.*?<!-- Logged_Out END -->#is", '', $this->top);
  39.                         $this->main = preg_replace("#<!-- Logged_Out START -->.*?<!-- Logged_Out END -->#is", '', $this->main);
  40.                         $this->btm = preg_replace("#<!-- Logged_Out START -->.*?<!-- Logged_Out END -->#is", '', $this->btm);
  41.                 }
  42.         }
  43.        
  44.         function OnlyLogout($redirect = 'index.php') {
  45.                 if($this->loggedIn == true) {
  46.                         header('Location: '. $redirect);
  47.                         return 0;
  48.                 }
  49.                 else
  50.                         return 1;
  51.         }
  52.        
  53.         function OnlyLogin($redirect = 'index.php?side=registrer') {
  54.                 if($this->loggedIn == false) {
  55.                         header('Location: '. $redirect);
  56.                         return 0;
  57.                 }
  58.                 else
  59.                         return 1;
  60.         }
  61.        
  62.         function output() {
  63.                 echo $this->top ."\n". $this->main ."\n". $this->btm;
  64.         }
  65.        
  66.         function format() {
  67.                 $this->top = preg_replace('/\{(.*?):(.*?)\}/e',  '$this->replace(${1}, ${2})', $this->top);
  68.                 $this->main = preg_replace('/\{(.*?):(.*?)\}/e',  '$this->replace(${1}, ${2})', $this->main);
  69.                 $this->btm = preg_replace('/\{(.*?):(.*?)\}/e',  '$this->replace(${1}, ${2})', $this->btm);
  70.         }
  71.        
  72.         function loop($array, $name, $content) {
  73.                 $temp = '';
  74.                 $var = '';
  75.                
  76.                 preg_match("#<!-- START ". $name ." -->(.*?)<!-- END ". $name ." -->#is", $content, $var);
  77.                
  78.                 foreach ($array as $array2) {
  79.                         $this->temp = $var[1];
  80.                         foreach ($array2 as $n => $v) {
  81.                                 $this->temp = str_replace('{DATA:'. $n .'}', $v, $this->temp);
  82.                         }
  83.                         $temp .= $this->temp;
  84.                 }
  85.                 $content = preg_replace("#<!-- START ". $name ." -->.*?<!-- END ". $name ." -->#is", $temp, $content);
  86.                
  87.                 return $content;
  88.         }
  89.        
  90.         function setData($array) {
  91.                 if(is_array($array)){
  92.                         foreach($array as $n => $v)
  93.                                 $this->data[$n] = $v;
  94.                 }
  95.         }
  96.        
  97.         function setSData($array) {
  98.                 if(is_array($array)) {
  99.                         foreach($array as $n => $v)
  100.                                 $this->sdata[$n] = $v;
  101.                 }
  102.         }
  103.        
  104.         function replace($array, $var)
  105.         {
  106.                 switch($array)
  107.                 {
  108.                         case 'GET':
  109.                                 return $_GET[$var];
  110.                         case 'POST':
  111.                                 return $_POST[$var];
  112.                         case 'DATA':
  113.                                 return $this->data[$var];
  114.                         case 'SDATA':
  115.                                 return $this->sdata[$var];
  116.                         case 'TPL':
  117.                                 return $this->templates[$var];
  118.                         case 'FORM':
  119.                                 return $this->createFormElement(func_get_args());
  120.                 }
  121.                
  122.                 return '';
  123.         }
  124.  
  125.         function loadTPL($name, $file) {
  126.                 $this->templates[$name] = file_get_contents($this->folder . $file . $this->ending);
  127.         }
  128.        
  129.         function createLeftBar($type = 'offline') {
  130.                 $leftBar = new leftBar($type);
  131.                
  132.                 $leftBar->run();
  133.                 $this->templates['leftBar'] = $leftBar->get();
  134.         }
  135.        
  136.         function createFormElement($var) {
  137.                
  138.                 if($var[1] == 'select') {
  139.                         if($var[3] == 'loop'){
  140.                                 $t = '<select name="'. $var[2] .'" style="width:'. $var[6] .'px" id="'. $var[2] .'">';
  141.                                 for($i = $var[4]; $i <= $var[5]; $i++) {
  142.                                         $t .= '<option value="'. $i .'"';
  143.                                         if($i == $_POST[$var[2]] || (!$_POST && $i == $var[7]))
  144.                                                 $t .= ' selected';
  145.                                         $t .= '>'. $i .'</option>'."\n";
  146.                                 }
  147.                                 $t .= '</select>';
  148.                                
  149.                                 return $t;
  150.                         }
  151.                        
  152.                         // {FORM:select,school_type,data,school_types,40}
  153.                         elseif($var[3] == 'data') {
  154.                                 $t = '<select name="'. $var[2] .'" style="width:'. $var[5] .'px" id="'. $var[2] .'">';
  155.                                
  156.                                 foreach($this->data[$var[4]] as $n => $v )
  157.                                 {
  158.                                         $t .= '<option value="'. $n .'"';
  159.                                         if($n == $_POST[$var[2]] || (!$_POST && isset($var[6])))
  160.                                                 $t .= ' selected';
  161.                                         $t .= '>'. $v .'</option>'."\n";
  162.                                 }
  163.                                 $t .= '</select>';
  164.                                
  165.                                 return $t;
  166.                         }
  167.                 }
  168.                 elseif($var[1] == 'text') {
  169.                         $t = '<input type="text" name="'. $var[2] .'" id="'. $var[2] .'" value="';
  170.                         $t .= (!$_POST[$var[2]]) ? $var[3] : $_POST[$var[2]];
  171.                         $t .= '">';
  172.                        
  173.                         return $t;
  174.                 }
  175.                 elseif($var[1] == 'checkbox') {
  176.                         $t = '<input type="checkbox" name="'. $var[2] .'" id="'. $var[2] .'" value="'. $var[3] .'"';
  177.                         if($_POST[$var[2]] == $var[3] || isset($var[4]))
  178.                                 $t .= ' checked';
  179.                         $t .= ' style="width:auto;">';
  180.                        
  181.                         return $t;
  182.                 }
  183.                 return '';
  184.         }
  185.        
  186.         function debug() {
  187.                 $this->btm = '<b>Session:</b><pre>'. print_r($_SESSION, true) . '
  188.                     </pre><hr><b>Get:</b><pre>'. print_r($_GET, true) . '
  189.                     </pre><hr><b>Post:</b><pre>'. print_r($_POST, true) . '
  190.                     </pre><hr><b>Data:</b><pre>'. print_r($this->data, true) . '
  191.                     </pre><hr><b>Templates:</b><pre>'. print_r($this->templates, true) . '
  192.                     </pre><hr>'. $this->btm;
  193.         }
  194.        
  195.         function eregs($ereg, $str, $min = 1, $max = 100){
  196.             // Enter other valid characters below
  197.            
  198.             if(ereg("^[". $ereg ."]$", $str)) {
  199.                 if(strlen($str) <= $min && strlen($str) >= $max)
  200.                         return 3;
  201.                 else return 2;
  202.             }
  203.             else return 1;
  204.         }
  205.        
  206.         function checkHack($valid, $against) {
  207.                 foreach($against as $n => $v)
  208.                         if(!in_array($n, $valid))
  209.                                 $this->hackAttempt();
  210.         }
  211.        
  212.         function hackAttempt() {
  213.                 die('<h1>Hacking forsøk</h1>Din IP er lagret. Hvis dette ikke var et ment hacke-forsøk; ignorer denne meldingen og prøv igjen.');
  214.         }
  215.        
  216. }
  217. ?>

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post