00001 <?php
00002
00015
00016
00017
00018 class HelpMappingFile {
00020 var $filename;
00021 var $cache;
00022
00026 function HelpMappingFile($filename) {
00027 $this->filename = $filename;
00028 }
00029
00030 function &_getCache() {
00031 if (!isset($this->cache)) {
00032 import('cache.CacheManager');
00033 $cacheManager =& CacheManager::getManager();
00034 $this->cache = $cacheManager->getFileCache(
00035 'helpmap', md5($this->filename),
00036 array(&$this, '_cacheMiss')
00037 );
00038
00039
00040 $cacheTime = $this->cache->getCacheTime();
00041 if ($cacheTime !== null && file_exists($this->filename) && $cacheTime < filemtime($this->filename)) {
00042
00043 $this->cache->flush();
00044 }
00045 }
00046 return $this->cache;
00047 }
00048
00049 function _cacheMiss(&$cache, $id) {
00050 $mappings = array();
00051
00052
00053 $notes =& Registry::get('system.debug.notes');
00054 $notes[] = array('debug.notes.helpMappingLoad', array('id' => $id, 'filename' => $this->filename));
00055
00056
00057 $xmlDao =& new XMLDAO();
00058 $data = $xmlDao->parseStruct($this->filename, array('topic'));
00059
00060 if (isset($data['topic'])) {
00061 foreach ($data['topic'] as $helpData) {
00062 $mappings[$helpData['attributes']['key']] = $helpData['attributes']['id'];
00063 }
00064 }
00065
00066 $cache->setEntireCache($mappings);
00067 return isset($mappings[$id])?$mappings[$id]:null;
00068 }
00069
00070 function map($key) {
00071 $cache =& $this->_getCache();
00072 return $cache->get($key);
00073 }
00074
00075 function containsToc($tocId) {
00076 return file_exists($this->getTocFilename($tocId));
00077 }
00078
00079 function containsTopic($topicId) {
00080 return file_exists($this->getTopicFilename($topicId));
00081 }
00082
00087 function getTocFilename($tocId) {
00088 fatalError('HelpMappingFile::getTocFilename should be overridden');
00089 }
00090
00095 function getTopicFilename($topicId) {
00096 fatalError('HelpMappingFile::getTopicFilename should be overridden');
00097 }
00098
00103 function getSearchPath($locale = null) {
00104 fatalError('HelpMappingFile::getSearchPath should be overridden');
00105 }
00106
00111 function getTopicIdForFilename($filename) {
00112 fatalError('HelpMappingFile::getSearchPath should be overridden');
00113 }
00114 }
00115
00116 ?>