### DONT READ FILE WITH "dirty windows notepad" .. ######################### 
############################################################################
# hack name : Images Cache 
# By : Saanina [ @gmail.com ] 
# Website : phpbbarabia.com [ the first arabic support for phpbb]
# some copyrights for : Y2K Software
#--------------------------------------------------------------------------
# Time : 2 minutes [ easy hack ] 
# 1 file  will be changed .. 
# 1 empty folder will be added ... [ "imgcache" with 777 premsission] 
############################################################################



---------- OPEN includes/message_parser.php
#find : [ near line 1110] 

$this->prepare_bbcodes(); 

#Add after : 

			//images cache  By Saanina
			/* -> */ $this->make_images_cache();
			// images cache
			

#Find : [ at end of file ] 

}

?>

#Add before : 

	// by saanina@gmail.com // some from Y2K Software
	function make_images_cache() {
	global $phpbb_root_path;

		  // Occurrance check --------------------------------------------------------
		    $n = 0;
		    foreach(array('img') as $key => $value)
		    {
		        $pos_end = -1;
		        $tag1 = '[' . $value . ']';
		        $tag2 = '[/' . $value . ']';
		        $k = strlen($tag1);
		        while(TRUE)
		        {
		            $pos_start = strpos($this->message, $tag1, $pos_end + 1);
		            if($pos_start === FALSE) break;

		            $pos_end = strpos($this->message, $tag2, $pos_start + 1);
		            if($pos_end === FALSE) break;
		        
		            // Adjust pointers
		            $pos_start += $k;
		            $pos_end--;
		        
		            // Add reference to array if valid comparison
		            $files[$n]['url'] = substr($this->message, $pos_start, $pos_end - $pos_start + 1);
		            $n++;
		        }
		    }

			  // If there was no occurrance, exit from function --------------------------
			    if(!$n) return false;
				
			    // Don't change already cached files ---------------------------------------
			    for($i = 0; $i < $n; $i++)
			    {
			        if(strpos($files[$i]['url'], "imgcache/") !== FALSE)
			        {
			            $files[$i]['url'] = '';
			        }
			    }

			    // Discard duplicates ------------------------------------------------------
			    for($i = 0; $i < $n; $i++)
			    {
			        $a = $files[$i]['url'];
			        if($a)
			        {
			            for($j = $i + 1; $j < $n; $j++)
			            {
			                if($files[$j]['url'] == $a)
			                {
			                    $files[$j]['url'] = '';
			                }
			            }
			        }
			    }
				
				 // Get and save file contents to file system -------------------------------
			    for($i = 0; $i < $n; $i++)
			    {
			        // Get content if url is valid
			        if(@getimagesize($files[$i]['url']))
			        {
			            // A localhost file will fail, also not existing references
			            $content = @file_get_contents($files[$i]['url']);
			        }

			        // Write if contents are available
			        $k = strlen($content);
			        if($k)
			        {
			            // Get unique cache ID (collision-free)
			            $id = time().uniqid(rand());
			            // Create filename
			            $f = "imgcache/" . $id . ".cache";
			            // Open file
			            $hFile = @fopen($phpbb_root_path.$f, 'wb');
			            if($hFile)
			            {
			                // Write file contents
			                $m = 0;
			                $m = @fwrite($hFile, $content, $k);
			                // Close file
			                fclose($hFile);
			                // Free some memory
			                $content = '';
			                // Replace URL's if successfully written
			                if($m == $k)
			                {
			                    $old_url = $files[$i]['url'];
			                    $new_url = generate_board_url() .'/'.$f;
			                    $this->message = str_replace($old_url, $new_url, $this->message);
								}
							}
						}
					}
					
			}
			/// end cache images ...
			
#######################################################
# - add new folder in ROOT with name "imgcache" also with 777 chmod
# - to uninstall hack , just remove codes above ..
# - if there is any error , please return your backup..
#######################################################

#######################################################
# thanks .. visit phpbbarabia.com for any help and support 
# Saanina [ Saudi arabia ] at 11:25 pm ,,
#######################################################