All pastes #585543 Raw Edit

Untitled

public php v1 · immutable
·published 2007-06-23 09:41 UTC
rendered paste body
<?php/* * @ File by Erti 'easter' * @ Created (17/06/2007) * @ Class for loading puzzle. */  class puzzleLoader { 	 	var $main_dir = "user_puzzles"; # Where are user puzzles 	var $admin_puzzles = "admin_puzzles"; # Where are admin puzzles 	var $puzzle_name; # Name of puzzle witch is being loaded 	var $difficulty; # Difficult of puzzle 	var $full_path; # Full path to puzz 	var $realPic; # Real picture 	 	function puzzleLoader($puzzle_name, $difficulty, $admin_pict = 0) { 		if($admin_pict === 1) $this->main_dir = $this->admin_puzzles; 		$this->puzzle_name = $puzzle_name; 		$this->difficulty = $difficulty; 		$this->full_path = $this->main_dir."/".$this->puzzle_name."/".$difficulty."/"; 		$this->realPic = $this->main_dir."/".$this->puzzle_name."/picture.jpg"; 	} 	 	# Function for loading puzzle 	function load() { 		if(file_exists($this->realPic)) { 			if(!is_dir($this->full_path)) { 				mkdir($this->full_path); 			  } 			} else { 		      return 0; 			} 		$file_array = glob($this->full_path."*.jpg"); 		if(count($file_array) < ($this->difficulty-1)) { 		if(is_file($this->realPic)) { 			 			// There is a picture not not that generated sequence yet, so yeah lets do it 			require("puzzleGenerator.inc.php"); 			$fapa = $this->full_path; 			$geneRator = new puzzleGenerator($this->realPic, $this->difficulty, $fapa); 			$geneRator->image2pieces(); 			if($geneRator != true) { 			 return 0; 			} else { 				$file_array = glob($this->full_path."*.jpg"); 				 			} 		} elseif(!is_dir($this->full_path)) { 			return 0; 		} 		} 		$files = array(); 		foreach($file_array as $key => $file) { 			$file = basename($file); 			$name = basename($file,".jpg"); 			$files[$name] = $this->full_path.$file; 		} 		return $files; 	} 	 	# Function to make up piece HTML 	function code2html($s_array) {  		if(!is_array($s_array)) return 0; 		$counter = 0; 		$output = "\n<tr>"; 		$sol = array_keys($s_array); 		shuffle($sol); 		//$geneRatedRes = file($this->full_path."info.txt"); 		//$x = (int)$geneRatedRes[0]+1; 		//$y = (int)$geneRatedRes[1]+1; 		//$this->solvedSol = "\n var nr_key = \"".implode("",$sol)."\";"; 		  foreach($sol as $key) { 		  	if($counter == $this->difficulty) { 		  		$output .= "\n</tr>\n<tr>"; 		  		$counter = 0; 		  	} 		  	$output .= "\n\t<td id = 'a{$key}' onClick='select_(this.id); return false;'><img src='{$s_array[$key]}' alt='tükk #{$key}' style='vertical-align: bottom;'></td>"; 		  	$counter++; 		  } 		  return $output."\n</tr>"; 	} } 			 		?>