2 /********************************************************************
6 Copyright 2009 Radosław Pietruszewski
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 version 2 as published by the Free Software Foundation.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 ********************************************************************/
34 * public static void CacheView(string $name, string $content)
36 * cache'uje widok o nazwie $name z treścią $content
38 * string $name - nazwa widoku, wraz z folderem i końcówką .php
40 * string $content - treść widoku do zacache'owania
43 public static function CacheView($name, $content)
45 if(strpos($name, '/') === false)
47 $fp = fopen(WTRMLN_CACHE
. 'views/' . $name, 'w');
48 fwrite($fp, $content);
53 $name = explode('/', $name);
57 if(!file_exists(WTRMLN_CACHE
. 'views/' . $dir))
59 mkdir(WTRMLN_CACHE
. 'views/' . $dir);
62 $fp = fopen(WTRMLN_CACHE
. 'views/' . $dir . '/' . $name, 'w');
63 fwrite($fp, $content);
69 * public static string GetView(string $name)
71 * zwraca zacache'owany widok o nazwie $name
72 * zwraca false gdy widok wcale nie został zacache'owany
74 * string $name - nazwa widoku, wraz z folderem i końcówką .php
78 public static function GetView($name)
80 $name = explode('/', $name);
84 $path = WTRMLN_CACHE
. 'views/' . $dir . '/' . $name;
86 if(!file_exists($path))
91 return file_get_contents($path);
95 * public static void CacheBBCode(string $bbcode, string $parsed)
97 * cache'uje fragment treści bbcode
99 * string $bbcode - fragment bbcode do zacache'owania
100 * string $parsed - ten sam fragment, ale po parsowaniu
103 public static function CacheBBCode($bbcode, $parsed)
105 $bbcodehash = strHash($bbcode);
107 $fp = fopen(WTRMLN_CACHE
. 'bbcode/' . $bbcodehash . '.php', 'w');
108 fwrite($fp, '<?php exit; ?>' . $parsed);
113 * public static string GetBBCode(string $bbcode)
115 * pobiera i zwraca sparsowaną formę BBCode'u
119 public static function GetBBCode($bbcode)
121 $bbcodehash = strHash($bbcode);
123 $path = WTRMLN_CACHE
. 'bbcode/' . $bbcodehash . '.php';
125 if(!file_exists($path))
130 return substr(file_get_contents($path), 14);
134 * public static void ClearCache()
139 public static function ClearCache()
141 foreach(new DirectoryIterator(WTRMLN_CACHE
. 'views/') as $_res)
151 self
::removeResource($_res->getPathName());
153 elseif($_res->isDir())
155 self
::removeResource($_res->getRealPath());
161 foreach(new DirectoryIterator(WTRMLN_CACHE
. 'bbcode/') as $_res)
171 self
::removeResource($_res->getPathName());
173 elseif($_res->isDir())
175 self
::removeResource($_res->getRealPath());
183 * private static void removeResource(string $_target)
185 * niszczy zasób (folder lub plik)
187 * based on http://pl.php.net/manual/pl/function.rmdir.php#86112
189 * string $_target - ścieżka zasobu do usunięcia
192 private static function removeResource($_target)
194 if(is_file($_target))
196 if(is_writable($_target))
198 if(@unlink
($_target))
209 if(is_writeable($_target))
211 foreach(new DirectoryIterator($_target) as $_res)
221 self
::removeResource($_res->getPathName());
223 elseif($_res->isDir())
225 self
::removeResource($_res->getRealPath());