[ Index ] |
|
Code source de Claroline 188 |
1 <?php // $Id: rss.write.lib.php,v 1.18 2007/02/14 14:18:47 mathieu Exp $ 2 if ( count( get_included_files() ) == 1 ) die( '---' ); 3 /** 4 * CLAROLINE 5 * 6 * @version 1.8 $Revision: 1.18 $ 7 * 8 * @copyright (c) 2001-2006 Universite catholique de Louvain (UCL) 9 * 10 * @license http://www.gnu.org/copyleft/gpl.html (GPL) GENERAL PUBLIC LICENSE 11 * 12 * @package CLRSS 13 * @since 1.8 14 * 15 * @author Claro Team <cvs@claroline.net> 16 * 17 * @see http://www.stervinou.com/projets/rss/ 18 * @see http://feedvalidator.org/ 19 * @see http://rss.scripting.com/ 20 */ 21 22 23 /** 24 * This lib use 25 * * cache lite 26 * * rssendar/class.rss.inc.php 27 * 28 */ 29 30 if ((bool) stristr($_SERVER['PHP_SELF'], basename(__FILE__))) die('---'); 31 32 define('RSS_FILE_EXT', 'xml'); 33 34 include_once claro_get_conf_repository() . 'CLKCACHE.conf.php'; 35 include_once claro_get_conf_repository() . 'rss.conf.php'; 36 37 function build_rss($context) 38 { 39 if (is_array($context) && count($context) > 0) 40 { 41 include_once dirname(__FILE__) . '/pear/XML/Serializer.php'; 42 43 $rssRepositoryCacheSys = get_path('rootSys') . get_conf('rssRepositoryCache','tmp/cache/rss/'); 44 if (!file_exists($rssRepositoryCacheSys)) 45 { 46 require_once dirname(__FILE__) . '/fileManage.lib.php'; 47 claro_mkdir($rssRepositoryCacheSys, CLARO_FILE_PERMISSIONS, true); 48 if (!file_exists($rssRepositoryCacheSys)) 49 return claro_failure::set_failure('CANT_CREATE_RSS_DIR'); 50 } 51 52 $options = array( 53 'indent' => ' ', 54 'linebreak' => "\n", 55 'typeHints' => FALSE, 56 'addDecl' => TRUE, 57 'encoding' => get_conf('charset'), 58 'rootName' => 'rss', 59 'defaultTagName' => 'item', 60 'rootAttributes' => array('version' => '2.0', 'xmlns:dc'=>'http://purl.org/dc/elements/1.1/') 61 ); 62 63 $rssFilePath = $rssRepositoryCacheSys . '/' ; 64 if (array_key_exists(CLARO_CONTEXT_COURSE,$context)) 65 { 66 $rssFilePath .= $context[CLARO_CONTEXT_COURSE] . '.'; 67 68 $_course = claro_get_course_data($context[CLARO_CONTEXT_COURSE]); 69 $rssTitle = '[' . get_conf('siteName') . '] '.$_course['officialCode']; 70 $rssDescription = $_course['name']; 71 $rssEmail = $_course['email'] == '' ? get_conf('administrator_email') : $_course['email']; 72 $rssLink = get_path('rootWeb') . get_path('coursesRepositoryAppend') . claro_get_course_path(); 73 if (array_key_exists(CLARO_CONTEXT_GROUP,$context)) 74 { 75 $rssFilePath .= 'g'.$context[CLARO_CONTEXT_GROUP] . '.'; 76 $rssTitle .= '[' . get_lang('Group') . $context[CLARO_CONTEXT_GROUP] . ']'; 77 $rssDescription .= get_lang('Group') . $context[CLARO_CONTEXT_GROUP]; 78 } 79 } 80 else 81 { 82 $rssEmail = ''; 83 } 84 85 $rssFilePath = $rssFilePath . RSS_FILE_EXT; 86 87 88 $data['channel'] = array( 89 'title' => $rssTitle, 90 'description' => $rssDescription, 91 'link' => $rssLink, 92 'generator' => 'Claroline-PEARSerializer', 93 'webMaster' => get_conf('administrator_email'), 94 'managingEditor' => $rssEmail, 95 'language' => get_locale('iso639_1_code'), 96 'docs' => 'http://blogs.law.harvard.edu/tech/rss', 97 'pubDate' => date("r",time()) 98 ); 99 100 $toolLabelList = rss_get_tool_compatible_list(); 101 foreach ($toolLabelList as $toolLabel) 102 { 103 $rssToolLibPath = get_module_path($toolLabel) . '/connector/rss.write.cnr.php'; 104 $rssToolFuncName = $toolLabel . '_write_rss'; 105 if ( file_exists($rssToolLibPath) 106 ) 107 { 108 include_once $rssToolLibPath; 109 if (function_exists($rssToolFuncName)) 110 { 111 $rssItems = call_user_func($rssToolFuncName, $context ); 112 $data['channel'] = array_merge($data['channel'], $rssItems); 113 } 114 } 115 } 116 117 foreach ($data['channel'] as $itemKey => $item) 118 { 119 // $data['channel'][$itemKey][x] = filter($item[x]); 120 $data['channel'][$itemKey]['title'] = trim(strip_tags($item['title'])); 121 $data['channel'][$itemKey]['title'] = (empty($data['channel'][$itemKey]['title'])?get_lang('Item').':'.$itemKey:$data['channel'][$itemKey]['title'] ); 122 } 123 124 $serializer = new XML_Serializer($options); 125 126 if ($serializer->serialize($data)) 127 { 128 if(is_writable($rssFilePath) || (!file_exists($rssFilePath) && is_writable(dirname($rssFilePath)))) 129 { 130 if( false !== $fprss = fopen($rssFilePath, 'w')) 131 { 132 fwrite($fprss, 133 //str_replace('//','/', 134 // str_replace(get_conf('urlAppend'), 135 // get_path('rootWeb'), 136 $serializer->getSerializedData() 137 // ) 138 // ) 139 ); 140 fclose($fprss); 141 } 142 else 143 { 144 return claro_failure::set_failure('CANT_OPEN_RSS_FILE'); 145 } 146 } 147 else 148 { 149 return claro_failure::set_failure('CANT_OPEN_RSS_FILE_READ_ONLY'); 150 } 151 152 } 153 return $rssFilePath; 154 155 } 156 return false; 157 158 } 159 160 161 /** 162 * Build the list of claro label of tool having a rss creator. 163 * 164 * @return array of claro_label 165 * 166 * This function use 2 level of cache. 167 * - memory Cache to compute only one time the list by script execution 168 * - if enabled : use cache lite 169 */ 170 function rss_get_tool_compatible_list() 171 { 172 static $rssToolList = null; 173 if (is_null($rssToolList)) 174 { 175 if(get_conf('rssUseCache',true)) 176 { 177 include_once PEAR_LIB_PATH . '/Lite.php'; 178 179 // Cache_lite setting & init 180 $cache_options = array( 181 'cacheDir' => get_path('rootSys') . get_conf('rssRepositoryCache','tmp/cache/rss/') . 'sources/', 182 'lifeTime' => get_conf('rssCacheLifeTime', get_conf('cache_lifeTime', 10)), 183 'automaticCleaningFactor' => 500, 184 ); 185 if (get_conf('CLARO_DEBUG_MODE',false) ) 186 { 187 $cache_options ['pearErrorMode'] = CACHE_LITE_ERROR_DIE; 188 $cache_options ['lifeTime'] = 60; 189 $cache_options ['automaticCleaningFactor'] = 10; 190 } 191 192 if (! file_exists($cache_options['cacheDir']) ) 193 { 194 include_once dirname(__FILE__) . '/fileManage.lib.php'; 195 claro_mkdir($cache_options['cacheDir'],CLARO_FILE_PERMISSIONS,true); 196 if (! file_exists($cache_options['cacheDir']) ) 197 return claro_failure::set_failure('CANT_CREATE_CACHE_RSS_SOURCE_LIST'); 198 } 199 200 $rssToolListCache = new Cache_Lite($cache_options); 201 202 if (false === ($rssToolListSerialized = $rssToolListCache->get('rssToolList'))) 203 { 204 $toolList = $GLOBALS['_courseToolList']; 205 foreach ($toolList as $tool) 206 { 207 $toolLabel = trim($tool['label'],'_'); 208 $rssToolLibPath = get_module_path($toolLabel) . '/connector/rss.write.cnr.php'; 209 $rssToolFuncName = $toolLabel . '_write_rss'; 210 if ( file_exists($rssToolLibPath) 211 ) 212 { 213 require_once $rssToolLibPath; 214 if (function_exists($rssToolFuncName)) 215 { 216 $rssToolList[] = $toolLabel; 217 } 218 } 219 220 } 221 $rssToolListSerialized = serialize($rssToolList); 222 $rssToolListCache->save($rssToolListSerialized, 'rssToolList'); 223 } 224 else 225 $rssToolList = unserialize($rssToolListSerialized); 226 227 } 228 else 229 $rssToolList = array(); 230 231 } // if is_null $rssToolList -> if not use static 232 233 return $rssToolList; 234 } 235 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 14:38:42 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |