Пример #1
0
 function write($log_file_data, $string)
 {
     $log_dir = $log_file_data[0];
     $log_name = $log_file_data[1];
     $file_name = $log_dir . $log_name;
     if (!is_dir($log_dir)) {
         fs::mkdir($log_dir, 0775, true);
     }
     $oldumask = @umask(0);
     $file_existed = @file_exists($file_name);
     $log_file = @fopen($file_name, 'a');
     if ($log_file) {
         $time = strftime("%b %d %Y %H:%M:%S", strtotime('now'));
         $notice = '[ ' . $time . " ]\n";
         $user =& user::instance();
         if (($user_id = $user->get_id()) != DEFAULT_USER_ID) {
             $notice .= '[ ' . $user_id . ' ] [ ' . $user->get_login() . ' ] [ ' . $user->get_email() . ' ] ';
         }
         $notice .= '[' . sys::client_ip() . '] [' . (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '') . "]\n" . $string . "\n\n";
         @fwrite($log_file, $notice);
         @fclose($log_file);
         if (!$file_existed) {
             @chmod($file_name, 0664);
         }
         @umask($oldumask);
         $result = true;
     } else {
         @umask($oldumask);
         $result = false;
         debug::write_error("Cannot open log file '{$file_name}' for writing\n" . "The web server must be allowed to modify the file.\n" . "File logging for '{$file_name}' is disabled.", __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, false);
     }
     return $result;
 }
/**
* Writes a compiled template file
*
* @param string $ filename
* @param string $ content to write to the file
* @return void
* @access protected
*/
function write_template_file($file, $data)
{
    if (!is_dir(dirname($file))) {
        fs::mkdir(dirname($file), 0777, true);
    }
    $fp = fopen($file, "wb");
    if (fwrite($fp, $data, strlen($data))) {
        fclose($fp);
    }
}
 function write(&$content)
 {      
   if(!$id = $this->get_cache_id())
     return false;      
   
   fs :: mkdir(PAGE_CACHE_DIR);
   
   $tmp = tempnam(PAGE_CACHE_DIR, '_');
   $f = fopen($tmp, 'w');
   fwrite($f, $content);
   fclose($f);
   
   if(file_exists(PAGE_CACHE_DIR . $id))
     unlink(PAGE_CACHE_DIR . $id);
   
   return rename($tmp,  PAGE_CACHE_DIR . $id);
 }
 function _update_media_record($id, $tmp_file_path, $file_name, $mime_type)
 {
     if (!file_exists($tmp_file_path)) {
         debug::write_error('file doesnt exist', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('tmp' => $tmp_file_path));
         return false;
     }
     if (function_exists('md5_file')) {
         $etag = md5_file($tmp_file_path);
     } else {
         $fd = fopen($data['tmp_name'], 'rb');
         $contents = fread($fd, filesize($tmp_file_path));
         fclose($fd);
         $etag = md5($contents);
     }
     fs::mkdir(MEDIA_DIR);
     if (!copy($tmp_file_path, MEDIA_DIR . $id . '.media')) {
         debug::write_error('temporary file copy failed', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('src' => $tmp_file_path, 'dst' => MEDIA_DIR . $id . '.media'));
         return false;
     }
     $media_db_table = db_table_factory::instance('media');
     $media_db_table->update_by_id($id, array('file_name' => $file_name, 'mime_type' => $mime_type, 'size' => filesize($tmp_file_path), 'etag' => $etag));
     $this->set_attribute('etag', $etag);
     return true;
 }
 function get_cache_size()
 {
     fs::mkdir(PAGE_CACHE_DIR);
     $files = fs::find_subitems(PAGE_CACHE_DIR, 'f', '~^[^p]~');
     $size = 0;
     foreach ($files as $file) {
         $size += filesize($file);
     }
     return $size;
 }
 function _cache_media_file($media_id, $extension)
 {
   fs :: mkdir(IMAGE_CACHE_DIR);
   
   if(file_exists(MEDIA_DIR . $media_id . '.media') && !file_exists(IMAGE_CACHE_DIR . $media_id . $extension))
     copy(MEDIA_DIR . $media_id . '.media', IMAGE_CACHE_DIR . $media_id . $extension);
 }
Пример #7
0
	function _load_cache()
	{
		$this->reset();

		$cache_dir = $this->cache_dir;

		if (!is_dir($cache_dir))
		{
			if (!fs :: mkdir($cache_dir, 0777, true))
				debug::write_error("Couldn't create cache directory $cache_dir, perhaps wrong permissions", __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__);
		} 

		$this->cache_file = $this->cache_dir . md5($this->file_path) . '.php';

		if (file_exists($this->cache_file) && 
		    filemtime($this->cache_file) > filemtime($this->file_path))
		{
			$charset = null;
			$group_values = array();
			
			include($this->cache_file);
			
			$this->charset = $charset;
			$this->group_values = $group_values;
			unset($group_values);		
		} 
		else
		{
			$this->_parse();
			$this->_save_cache();
	  }
	} 
  function _write_media_file($media_id)
  {
    fs :: mkdir(MEDIA_DIR);

    $f = fopen(MEDIA_DIR . $media_id . '.media', 'w');
    fwrite($f, 'test');
    fclose($f);
  }
Пример #9
0
 function &parse_html_console($server_file_path = VAR_WEB_DIR)
 {
     if (!debug::is_debug_enabled()) {
         return '';
     }
     $debug =& debug::instance();
     $report =& $debug->_parse_report_internal(true);
     $ip = sys::client_ip();
     $js_window = "\r\n            <script language='javascript'>\r\n            <!-- hide this script from old browsers\r\n\r\n            function show_debug( file_name, title )\r\n            {\r\n              rn = Math.random();\r\n              debug_window = window.open( file_name + '?rn=' + rn, title, 'top=370,left=550,height=300,width=400,scrollbars,resizable');\r\n            }\r\n\r\n            show_debug('{$server_file_path}{$ip}-debug.html', 'debug');\r\n\r\n            //-->\r\n            </script>";
     $header = '<html><head><script>var NEED_TO_FOCUS = false</script><title>debug</title></head><body onload="if(NEED_TO_FOCUS)window.focus();else window.blur()">';
     $footer = '</body></html>';
     fs::mkdir(VAR_DIR);
     $fp = fopen(VAR_DIR . $ip . '-debug.html', 'w+');
     fwrite($fp, $header);
     fwrite($fp, $report);
     fwrite($fp, $footer);
     fclose($fp);
     return $js_window;
 }
Пример #10
0
  function cp($src, $dest, $as_child = false, $exclude_regex = '', $include_hidden = false)
  {
  	$src = fs :: clean_path($src);
  	$dest = fs :: clean_path($dest);
  	
    if (!is_dir($src))
    {
			debug :: write_error('no such a directory',
			 __FILE__ . ' : ' . __LINE__ . ' : ' .  __FUNCTION__,
			array('dir' => $src));

    	return false;
    }
    
    if(!fs :: mkdir($dest))
    	return false;
    	
    $separator = fs :: separator();
    
    if ($as_child)
    {
    	$separator_regex = preg_quote($separator);
      if (preg_match( "#^.+{$separator_regex}([^{$separator_regex}]+)$#", $src, $matches))
      {
        fs :: _do_mkdir($dest . $separator . $matches[1], 0777);
        $dest .= $separator . $matches[1];
      }
      else
      	return false;//???
    }
    $items = fs :: find_subitems($src, 'df', $exclude_regex, false, $include_hidden);
    
    $total_items = $items;
    while (count($items) > 0)
    {
      $current_items = $items;
      $items = array();
      foreach ($current_items as $item)
      {
        $full_path = $src . $separator . $item;
        if (is_file( $full_path))
        	copy($full_path, $dest . $separator . $item);
        elseif (is_dir( $full_path))
        {
          fs :: _do_mkdir($dest . $separator . $item, 0777);
          
          $new_items = fs :: find_subitems($full_path, 'df', $exclude_regex, $item, $include_hidden);
          
          $items = array_merge($items, $new_items);
          $total_items = array_merge($total_items, $new_items);
          
          unset($new_items);
        }
      }
    }
    if($total_items)
    	clearstatcache();
    	
		return $total_items;
  }
Пример #11
0
 function test_mkdir_relative_path_no_trailing_slash()
 { 
 	fs :: rm(TEST_DIR_RELATIVE_PATH . '/tmp/');
 	
 	$this->assertFalse(is_dir(TEST_DIR_RELATIVE_PATH . '/tmp/wow/hey/'));
 	
 	fs :: mkdir(TEST_DIR_RELATIVE_PATH . '/./tmp\../tmp/wow////hey');
 	
 	$this->assertTrue(is_dir(TEST_DIR_RELATIVE_PATH . '/tmp/wow/hey/'));
 }
 function _write_simple_cache($file_id, $contents)
 {
   fs :: mkdir(PAGE_CACHE_DIR);
   $f = fopen(PAGE_CACHE_DIR . $file_id, 'w');
   fwrite($f, $contents);
   fclose($f);
 }
 function cache_registry()
 {
   $this->session_id = session_id();
   fs :: mkdir(CACHE_DIR);
 }
Пример #14
0
 /**
  * Set a cache dir
  * 
  * @param string $cache_dir 
  * @access public 
  */
 function set_cache_dir($cache_dir)
 {
     $this->_cache_dir = $cache_dir;
     fs::mkdir($this->_cache_dir);
 }
  function get_cache_size()
  {
    fs :: mkdir(IMAGE_CACHE_DIR);

    $files = fs :: find_subitems(IMAGE_CACHE_DIR, 'f');

    $size = 0;

    foreach($files as $file)
    {
      $size += (filesize($file));
    }

    return $size;
  }
Пример #16
0
	/**
	* Constructor
	* 
	* $attributes is an assoc. Available attributes are :
	* 
	* @param array $attributes attributes
	* @access public 
	*/
	function cache_lite($attributes = array(null))
	{
		$this->import_attributes($attributes);

		if (!is_dir(CACHE_DIR))
			fs :: mkdir(CACHE_DIR, 0777, true);
	}