Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Miscellany
Sunday, July 29th, 2007 at 2:12:14pm MDT 

  1. // Load settings
  2. require_once('./config.php');
  3.  
  4. // Errors
  5. define("INPUT_FILE_OPEN_ERROR", 1);
  6. define("INPUT_FILE_READ_ERROR", 2);
  7.  
  8. class ch_data {
  9.         public $level = 0;
  10.         public $string;
  11. }
  12.  
  13. class Chameleon {
  14.         private $nr_rep;   // elements to be parsed
  15.         private $nr_done// elements parsed
  16.         private $static_file; // static filename
  17.         private $initialized; // object must be initialized before use
  18.         private $data = 0;     // static file data
  19.         private $ddata;
  20.         private $stfile_handle = 0;
  21.         private $replace_pos;
  22.         private $replaceable_data;
  23.        
  24.         public function __construct($filename = null) {
  25.                 $this->static_file = $filename;
  26.                 $this->initialized = false;
  27.                 if ($filename !== null)
  28.                         $this->load($filename);
  29.                 $this->replace_pos = Array();
  30.                 $this->replaceable_data = Array();
  31.         }
  32.         public function load($filename) {
  33.                 $this->initialized = false;
  34.                
  35.                 if ($this->stfile_handle !== 0) {
  36.                         fclose($this->stfile_handle);
  37.                         $this->data = 0;
  38.                 }
  39.                
  40.                 $real_filename = $this->calculate_filename($filename);
  41.                 $stfile_handle = @fopen($real_filename, 'rb');
  42.                 if ($stfile_handle == FALSE) {
  43.                         throw new Exception("Error opening file: $real_filename.",
  44.                                             INPUT_FILE_OPEN_ERROR);
  45.                 }
  46.        
  47.                 $contents = @fread($stfile_handle, filesize($real_filename));
  48.                 if ($contents == FALSE) {
  49.                         fclose($stfile_handle);
  50.                         throw new Exception("Error reading from file: $real_filename",
  51.                                             INPUT_FILE_READ_ERROR);
  52.                 }
  53.                 $this->data = $contents;
  54.                 $this->ddata = $this->data;
  55.                
  56.                 $this->init();
  57.         }
  58.         public function update($name, $value) {
  59.                
  60.         }
  61.         public function isparsed() {
  62.                 if ($this->nr_done == $this->nr_rep)
  63.                         return true;
  64.                 return false;
  65.         }
  66.         public function submit() {
  67.                 return $this->ddata;
  68.         }
  69.         public function __destruct() {
  70.                 if ($this->stfile_handle !== 0)
  71.                         fclose($this->stfile_handle);
  72.         }
  73.        
  74.         private function calculate_filename($filename) {
  75.                 $workname = $filename;
  76.                 $firstchar = substr($workname, 0, 1);
  77.                
  78.                 if (($firstchar == '.') || ($firstchar == '/'))
  79.                         return $workname;
  80.                
  81.                 $workname = STATIC_DIR."/".$workname;
  82.                 return $workname;
  83.         }
  84.        
  85.         private function init() {
  86.                 $old_pos = 0;
  87.                 $i = 0;
  88.                
  89.                 while (true) {
  90.                         $new_pos = strpos($this->data, CHAMELEON, $old_pos + 1);
  91.                         if ($new_pos < $old_pos)
  92.                                 break;
  93.                         $this->replace_pos[$i] = $new_pos;
  94.                         $old_pos = $new_pos;
  95.                        
  96.                         $new_pos = strpos($this->data, ")", $old_pos + 1);
  97.                         $tmp_string = substr($this->data,
  98.                                              $old_pos + strlen(CHAMELEON) + 1,
  99.                                              $new_pos - ($old_pos + strlen(CHAMELEON) + 1));
  100.                         $this->replaceable_data[$i]->string = $tmp_string;
  101.                        
  102.                         $i++;
  103.                 }
  104.                
  105.                 print_r($this->replace_pos);
  106.                
  107.                 $this->nr_rep = $i;
  108.                 $this->initialized = true;
  109.         }
  110. }
  111.  
  112. ?>

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

fantasy-obligation