Top  Branding  Banner 
blank.gif
blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Base  /  Writer   Login nu   Login
blank.gif
««« Se kilde koden
blank.gif
tls.gif     Base  trs.gif tl.gif Basic tr.gif tl.gif Dto tr.gif tl.gif Form tr.gif tl.gif Language tr.gif tl.gif Layout tr.gif tl.gif Menu tr.gif tl.gif Mvc tr.gif tl.gif Netbank.eksperter.dk tr.gif tl.gif Tab tr.gif tl.gif Table tr.gif tl.gif Util tr.gif
blank.gif
blank.gif
arrow-headline.gif Index
MenuLink  MenuLeft  
Tilbage

Skjul: Navn

Writer.php


Vis: Sample code, tutorial

Writer, Sample code, tutorial

Sådan benyttes komponenten Writer klassen

Først skal du inkludere den fil der beskriver komponenten, som en klasse fil

  • <?
    require_once(HTML_PACKAGE_PATH.'/Writer.php');
    ?>

Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):

  • <?
    Writer
    ::display($param1$param2$param3, ...);
    ?>

eller du kan lave en instance af komponenten og benytte metoderne direkte:

  • <?
    $object 
    = new Writer($param1$param2$param3, ...);
    print 
    $object->getHtml();
    ?>

Skjul: Sådan vises komponenten

Writer, Sådan vises komponenten

Sådan vises komponenten Writer klassen

Writer.php

Write the content of the specified filename and language

Use default filename, if no language found

Usage:

  • $filename = "/var/doc/root/www/dir/content.txt";
  • $rc = Write::save($content, $filename, $classname);

Write the content of the specified filename

Usage:

  • $rc = Write::write($content, $filename, $classname);

Vis: PHP source code

Writer, PHP source code

Den fulde PHP kildekode for Writer klassen

<?php
/**
 * @package base
 * @see HTML_BASE_COMMON_PATH.'/Writer.php'
 * @copyright (c) http://Finn-Rasmussen.com
 * @license http://Finn-Rasmussen.com/license/ myPHP License conditions
 * @author http://Finn-Rasmussen.com
 * @version 1.11
 * @since 27-nov-2009
 */

/**
 * The required files
 */
require_once(HTML_BASE_UTIL_PATH.'/Htmlspecialchars.php');
// Problem here, because the Html class is NOT included first
//require_once(HTML_BASE_COMMON_PATH.'/Html.php');
if (defined('HTML_BASE_PAGE_PATH')) {
    require_once(
HTML_BASE_PAGE_PATH.'/Info.php');
}
if (
defined('HTML_LOG_UTIL_PATH')) {
    require_once(
HTML_LOG_UTIL_PATH.'/Log.php');
}

/**
 * The Writer class used during writing to files on the filesystem
 * <code>
 * Usage:
 *    $writer = new Writer();
 *     $content = $writer->save();
 * Or
 *    $domainname = 'finn-rasmussen.com';
 *    $language   = 'en';
 *    $filename   = 'demo.html';
 *    $filepath   = '.'; // Current directory
 *    $content = Writer::save($domainname, $language, $filename, $filepath); 
 * Or
 *    $file = '/var/www/html/test.php';
 *    $content = Writer::save($file);
 * </code>
 *
 * @package base
 */

class Writer {
    
/**
     * Constructor
     */
    
function __construct() {
    }

    
/**
     * Returns the name of the cache file name
     * If empty name, create a cache file name
     * @param  String $path The Path, Where to store the cache files
     * @param  String $className The class name to use for debug info
     * @return String The path/name of the cache file
     */
    
public static function getCacheFileName($path$className) {
        
$cachefilename '';
        if (
count($_POST) == 0) {
            
$ext '';
            if (
count($_GET) == 0) {
                
// No request params
                
$cachefilename = ($path != '' $path OBJECT_CACHE_PATH).'/'.$className.'-'.md5($className).$ext.'.php';
            } else {
                
/**
                 * Build the language extension
                 */
                
if (defined('REQUEST_LANGUAGE') && isset($_GET[REQUEST_LANGUAGE]) && $_GET[REQUEST_LANGUAGE] != '') {
                    if (
array_key_exists($_GET[REQUEST_LANGUAGE], $GLOBALS[DEFINE_LANGUAGE])) {
                        
$ext .= '-'.$_GET[REQUEST_LANGUAGE];
                    } else {
                        
// Ignore, unknown language
                        
$msg $className.'->getCacheFileName($path), not a valid language (da,de,en,it,fr,no,se,us), found '.REQUEST_LANGUAGE.'='.$_GET[REQUEST_LANGUAGE];
                        if (
defined('HTML_LOG_UTIL_PATH')) {
                            
Log::fatal($msg__FILE____LINE__);
                        } else {
                            die(
'File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n".$msg);
                        }
                    }
                }
                
/**
                 * Build the tab extension
                 */
//                    if (isset($_GET[REQUEST_TAB]) && $_GET[REQUEST_TAB] != '') {
//                        $ext .= '-'.$_GET[REQUEST_TAB];
//                    }
                
$cachefilename = ($path != '' $path OBJECT_CACHE_PATH).'/'.$className.'-'.md5($className).$ext.'.php';
            }
        }
        return 
$cachefilename;
    } 

    
/**
     * Save the cache file
     * @param  String $content   The html content to save as sql cache
     * @param  String $cachefile The cachefile to use
     * @param  String $className The class name to use for debug info
     * @return boolean True on succes, false if failure
     */
    
public static function save($content$cachefile$className='') {
        
$html "";
        
$rc true;
        if (
HTTP_USER_AGENT === HTTP_USER_AGENT_P900) {
            
// Skip Sony Ericsson P900
        
} else {
            
$html .= $content."\r\n";
            if (
defined('DEBUG_LEVEL_SHOW_INFO') && DEBUG_LEVEL DEBUG_LEVEL_SHOW_INFO) {
                
$package   '';
                
$info      '';
                
$extension '';
//                $className = '';
//                $cachefile = '';
                
if (defined('HTML_BASE_PAGE_PATH')) {
                     
$info = new Info($package$info$extension$className$cachefile);
                     
$html .= $info->getHtml();
                }
            }
            
$rc Writer::write($html$cachefile$className);
            if (
$rc) {
                
$msg '<!-- '.$className.'->save(), OK, Created: file='.$cachefile.' -->';
                if (
defined('HTML_LOG_UTIL_PATH')) {
                    
Log::debug($msg__FILE____LINE__);
                    if (
defined('DEBUG_LEVEL_SHOW_INFO') && DEBUG_LEVEL DEBUG_LEVEL_SHOW_INFO) {
                        
Message::add($msg__FILE____LINE__);
                    }
                } else {
                    
Message::add($msg__FILE____LINE__);
                }
            } else {
                
$msg $className.'->save(), Error Writing: file='.$cachefile;
                if (
defined('HTML_LOG_UTIL_PATH')) {
                    
Log::error($msg__FILE____LINE__);
                } else {
                    
Message::add($msg__FILE____LINE__);
                }
            }
        }
        return 
$rc;
    }

    
/**
     * Write the content to the file opened by fp
     * @param  String $content The content to write 
     * @param  String $cachefile The cachefile to use
     * @param  String $className The class name to use for debug info
     * @return boolean Returns true on success
     */
    
public static function write($content$cachefile$className='') {
        if (
$cachefile != '') {
            
$fp fopen($cachefile,'w');
            if (!
$fp) {
                
$msg $className.'->write(), Not found, file='.$cachefile;
                if (
defined('HTML_LOG_UTIL_PATH')) {
                    
Log::fatal($msg__FILE____LINE__);
                } else {
                    die(
'File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n$msg");
                }
                return 
false;
            } else {
                
// ok
            
}
            if (!
fwrite($fp$content)) {
                
$msg $className.'->write(), Unable to write to file='.$cachefile;
                if (
defined('HTML_LOG_UTIL_PATH')) {
                    
Log::fatal($msg__FILE____LINE__);
                } else {
                    die(
'File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n$msg");
                }
                return 
false;
            } else {
                
// ok
            
}
            if (!
fclose($fp)) {
                
$msg $className.'->write(), Unable to close file='.$cachefile;
                if (
defined('HTML_LOG_UTIL_PATH')) {
                    
Log::fatal($msg__FILE____LINE__);
                } else {
                    die(
'File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n$msg");
                }
                return 
false;
            } else {
                
// ok
            
}
        } else {
            
//print $className."->write(), cachefile is empty<br />\r\n";
        
}
        return 
true;
    }
    
    
/**
     * Returns the html for the element
     * @sample
     * @return String The complete html
     */
    
function getHtml() {
        
$html  "<h1>Writer.php</h2>\r\n";
        
$html .= "<p>Write the content of the specified filename and language\r\n";
        
$html .= "<p>Use default filename, if no language found\r\n";
        
$html .= "<p>Usage:</p>\r\n";
        
$html .= "<ul>\r\n";
        
$html .= '<li>$filename = "/var/doc/root/www/dir/content.txt";</li>'."\r\n";
        
$html .= '<li>$rc = Write::save($content, $filename, $classname);</li>'."\r\n"
        
$html .= "</ul>\r\n";
        
$html .= "<p>Write the content of the specified filename</p>\r\n";
        
$html .= "<p>Usage:</p>\r\n";
        
$html .= "<ul>\r\n";
        
$html .= '<li>$rc = Write::write($content, $filename, $classname);</li>'."\r\n";
        
$html .= "</ul>\r\n";
        return 
$html;
    }
}
?>

Vis: HTML source code

Writer, HTML source code

Den fulde HTML kildekode for Writer klassen

<?
<h1>Writer.php</h2>
<
p>Write the content of the specified filename and language
<p>Use default filename, if no language found
<p>Usage:</p>
<
ul>
<
li>$filename "/var/doc/root/www/dir/content.txt";</li>
<
li>$rc Write::save($content$filename$classname);</li>
</
ul>
<
p>Write the content of the specified filename</p>
<
p>Usage:</p>
<
ul>
<
li>$rc Write::write($content$filename$classname);</li>
</
ul>

?>

Vis: Class methods

Writer, Class methods

Her er 'klasse metoderne' for Writer klassen:

  • __construct
  • getCacheFileName
  • save
  • write
  • getHtml

Vis: Object vars

Writer, Object vars

Her er 'objekt variable' for Writer klassen:


MenuRight 
triangle.gif

Dansk

Deutch

English (UK)

France

Italy

Norsk

Svensk

English (USA)


 
blank.gif
MenuBottom 
triangle.gif Copyright @ 1999-2010 www.Finn-Rasmussen.com Powered by myPHP Version (5.2.6-1+lenny9) 1.11
blank.gif