<?php

/*  Alternate WebKit
(C) 2011 by Alternate Tools
-----------------------------------------------------

File:         class_textfile.php
Description:  Class cTextFile definition,
              to load and save text into files

*/

if (!defined("CLASS_TEXTFILE"))
{
    define ("CLASS_TEXTFILE", "DEFINED");

    class cTextFile
    {
        var $m_fileName;

        function cTextFile() // PHP 4
        {
            $this->InitFile();
        }

        function __construct()
        {
            $this->InitFile();
        }

        function InitFile()
        {
            $this->m_fileName = "";
        }

        function SaveToFile($fileName, $strContent)
        {
            $this->m_fileName = $fileName;
            $fp = fopen($this->m_fileName, "w");
            if ($fp == false)
                return false;
            if (get_magic_quotes_gpc())  // Magic quotes??
                fputs($fp, stripslashes($strContent));
            else
                fputs($fp, $strContent);
            fclose($fp);

            return true;
        }
        
        function LoadFromFile($fileName)
        {
            $this->m_fileName = $fileName;
            $fileContent = "";
            
            $fp = fopen($this->m_fileName, "r");
            if (filesize($this->m_fileName) > 0)
                $fileContent = fread($fp, filesize($this->m_fileName));
            fclose($fp);
            if (get_magic_quotes_gpc())  // Magic quotes??
                return stripslashes($fileContent);
                
            return $fileContent;
        }
    }
}