[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH.'class/view/smartyview.class.php' ); 4 lt_include( PLOG_CLASS_PATH.'class/plugin/pluginmanager.class.php' ); 5 6 /** 7 * default date format used for the archive links 8 */ 9 define( "ARCHIVE_DEFAULT_DATE_FORMAT", '%B %Y' ); 10 11 /** 12 * \ingroup View 13 * 14 * Extends the SmartyView class to provide support for common operations, for example 15 * to automatically add support for locale. It is recommended 16 * that all classes that generate a view extend from this unless strictly necessary. 17 */ 18 class BlogView extends SmartyView 19 { 20 21 var $_pm; 22 var $_pageTitle; 23 var $_locale; 24 25 /** 26 * @see SmartyView 27 */ 28 function BlogView( $blogInfo, $template, $cachingEnabled = SMARTY_VIEW_CACHE_CHECK, $data = Array()) 29 { 30 // the SmartyView will generate the right Template object for us 31 $this->SmartyView( $blogInfo, $template, $cachingEnabled, $data ); 32 33 $this->_pm =& PluginManager::getPluginManager(); 34 $this->_pm->setBlogInfo( $this->_blogInfo ); 35 36 // set the character set in the request based on the blog locale 37 $this->_locale = $this->_blogInfo->getBlogLocale(); 38 $this->setCharset( $this->_locale->getCharset()); 39 40 // set the initial page title 41 $this->_pageTitle = $blogInfo->getBlog(); 42 } 43 44 /** 45 * Generates an html calendar based on the posts for the given month 46 * 47 * @param year 48 * @param month 49 * @private 50 */ 51 function generateCalendar( $year = null, $month = null ) 52 { 53 lt_include( PLOG_CLASS_PATH.'class/data/plogcalendar.class.php' ); 54 55 $monthPosts = $this->getValue( 'monthposts' ); 56 57 $calendar = new PlogCalendar( $monthPosts, $this->_blogInfo, $this->_locale ); 58 59 $this->setValue( 'calendar', $calendar->getMonthView( $month, $year )); 60 } 61 62 /** 63 * notifies of a throwable event 64 * 65 * @param eventType The code of the event we're throwing 66 * @param params Array with the event parameters 67 */ 68 function notifyEvent( $eventType, $params = Array()) 69 { 70 $params[ 'from' ] = get_class( $this ); 71 72 return $this->_pm->notifyEvent( $eventType, $params ); 73 } 74 75 /** 76 * Fetches the stats for the archives 77 * 78 * @private 79 */ 80 function _getArchives() 81 { 82 lt_include( PLOG_CLASS_PATH.'class/dao/archivelink.class.php' ); 83 lt_include( PLOG_CLASS_PATH.'class/data/timestamp.class.php' ); 84 85 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" ); 86 $articles = new Articles(); 87 $archiveStats = $articles->getNumberPostsPerMonth( $this->_blogInfo->getId()); 88 89 if( $archiveStats == '' ) 90 return false; 91 92 $links = Array(); 93 $urls = $this->_blogInfo->getBlogRequestGenerator(); 94 95 // format of dates used in the archive, but it defaults to '%B %Y' if none specified 96 $archiveDateFormat = $this->_locale->tr( 'archive_date_format' ); 97 // need to check whether we got the same thing back, since that's the way Locale::tr() works instead of 98 // returning an empty string 99 if( $archiveDateFormat == "archive_date_format" ) $archiveDateFormat = ARCHIVE_DEFAULT_DATE_FORMAT; 100 101 foreach( $archiveStats as $yearName => $year) { 102 foreach( $year as $monthName => $month ) { 103 // we can use the Timestamp class to help us with this... 104 $t = new Timestamp(); 105 $t->setYear( $yearName ); 106 $t->setMonth( $monthName ); 107 $archiveUrl = $urls->getArchiveLink( $t->getYear().$t->getMonth()); 108 $linkName = $this->_locale->formatDate( $t, $archiveDateFormat ); 109 $link = new ArchiveLink( $linkName, '', $archiveUrl, $this->_blogInfo->getId(), 0, $month, 0); 110 $links[] = $link; 111 } 112 } 113 114 return $links; 115 } 116 117 /** 118 * Retrieves the most recent posts 119 * 120 * @private 121 */ 122 function _getRecentPosts() 123 { 124 lt_include( PLOG_CLASS_PATH.'class/dao/recentarticles.class.php' ); 125 lt_include( PLOG_CLASS_PATH."class/config/siteconfig.class.php" ); 126 127 $blogSettings = $this->_blogInfo->getSettings(); 128 129 $hardLimit = SiteConfig::getHardRecentPostsMax(); 130 $amount = $blogSettings->getValue( "recent_posts_max", 15 ); 131 if( $amount > $hardLimit ) $amount = $hardLimit; 132 133 $recent = new RecentArticles(); 134 $recentPosts = $recent->getRecentArticles( $this->_blogInfo->getId(), $amount ); 135 $this->_pm->notifyEvent( EVENT_POSTS_LOADED, Array( 'articles' => &$recentPosts )); 136 137 return $recentPosts; 138 } 139 140 /** 141 * Retrieves all the posts for the current month 142 * 143 * @private 144 */ 145 function _getMonthPosts() 146 { 147 lt_include( PLOG_CLASS_PATH.'class/data/timestamp.class.php' ); 148 149 $t = new Timestamp(); 150 $blogSettings = $this->_blogInfo->getSettings(); 151 // the values for the month and the year have been included in the session 152 $month = $this->getValue( 'Month' ); 153 $year = $this->getValue( 'Year' ); 154 155 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" ); 156 $articles = new Articles(); 157 return( $articles->getDaysWithPosts( $this->_blogInfo->getId(), $year, $month )); 158 } 159 160 /** 161 * Retrieves the links 162 * 163 * @private 164 */ 165 function _getLinkCategories() 166 { 167 lt_include( PLOG_CLASS_PATH.'class/dao/mylinkscategories.class.php' ); 168 169 $blogSettings = $this->_blogInfo->getSettings(); 170 $linkCategoriesOrder = $blogSettings->getValue( 'link_categories_order', MYLINKS_CATEGORIES_NO_ORDER ); 171 $myLinksCategories = new MyLinksCategories(); 172 $blogLinksCategories = $myLinksCategories->getMyLinksCategories( $this->_blogInfo->getId(), $linkCategoriesOrder); 173 $this->notifyEvent( EVENT_LINK_CATEGORIES_LOADED, Array( 'linkcategories' => &$blogLinksCategories )); 174 175 return $blogLinksCategories; 176 } 177 178 /** 179 * Fetches the article categories for the given blog 180 * 181 * @private 182 */ 183 function _getArticleCategories() 184 { 185 lt_include( PLOG_CLASS_PATH.'class/dao/articlecategories.class.php' ); 186 187 $blogSettings = $this->_blogInfo->getSettings(); 188 $categoryOrder = $blogSettings->getValue( 'categories_order' ); 189 $categories = new ArticleCategories(); 190 // we want a list with all the categories, sorted in the way that was configured 191 $categories = $categories->getBlogCategories( $this->_blogInfo->getId(), false, $categoryOrder ); 192 193 return $categories; 194 } 195 196 /** 197 * @see Smartyview::preProcessViewContents() 198 * 199 * This reimplementation of this method adds support for events that can be caught in a plugin. This can be used 200 * for for example in a plugin that processes the output of a template in order to add ads or do some other 201 * dynamic operation with the content. 202 * 203 * @param content 204 * @return The content 205 */ 206 function preProcessViewContents( $content ) 207 { 208 // pass the content and the name of the template file as a parameter to the event 209 $this->notifyEvent( EVENT_PROCESS_BLOG_TEMPLATE_OUTPUT, Array( 'content' => &$content, 'template' => $this->_templateName )); 210 211 return( $content ); 212 } 213 214 /** 215 * This method must be implemented by child classes and it is meant 216 * to return the title for the current page, to make it easier for template 217 * designers to automatically provide meaningful page titles 218 * 219 * @return A string containing the appropriate page title 220 */ 221 function getPageTitle() 222 { 223 return( $this->_pageTitle ); 224 } 225 226 /** 227 * This method sets the page title and can be called by action classes 228 * instantiating this view to set a meaningful page title. 229 * 230 * @param title A string containing the appropriate page title 231 */ 232 function setPageTitle( $title ) 233 { 234 $this->_pageTitle = $title; 235 } 236 237 /** 238 * Sets some in this case, we leave it all up to the child classes to reimplement 239 * this and by default call View::render() 240 * 241 * @returns always true 242 */ 243 function render() 244 { 245 if( !$this->isCached() ) { 246 lt_include( PLOG_CLASS_PATH.'class/data/plogcalendar.class.php' ); 247 lt_include( PLOG_CLASS_PATH.'class/misc/version.class.php' ); 248 lt_include( PLOG_CLASS_PATH.'class/xml/rssparser/rssparser.class.php' ); 249 lt_include( PLOG_CLASS_PATH.'class/data/timestamp.class.php' ); 250 251 // and then add our stuff to the view... 252 $this->setValue( 'archives', $this->_getArchives()); 253 $this->setValue( 'recentposts', $this->_getRecentPosts()); 254 $this->setValue( 'mylinkscategories', $this->_getLinkCategories()); 255 $this->setValue( 'monthposts', $this->_getMonthPosts()); 256 $this->setValue( 'articlecategories', $this->_getArticleCategories()); 257 $this->generateCalendar( $this->getValue( 'Year' ), $this->getValue( 'Month' )); 258 259 $this->setValue( 'url', $this->_blogInfo->getBlogRequestGenerator()); 260 $this->setValue( 'utils', $this->_blogInfo->getBlogRequestGenerator()); 261 $this->setValue( 'rss', new RssParser()); 262 $this->setValue( 'version', Version::getVersion()); 263 $this->setValue( 'now', new Timestamp()); 264 265 // page title 266 $this->setValue( "pageTitle", $this->getPageTitle()); 267 268 // also, let's not forget about the plugins... 269 // put the plugins in the context 270 $plugins = $this->_pm->getPlugins(); 271 foreach( $plugins as $name => $plugin ) { 272 $this->setValue( $name, $plugin ); 273 } 274 } 275 276 // 277 // these things can go in since they do not mean much overhead when generating the view... 278 // 279 280 $this->setValue( 'locale', $this->_locale ); 281 $this->setValue( 'blog', $this->_blogInfo ); 282 $this->setValue( 'blogsettings', $this->_blogInfo->getSettings()); 283 $this->setValue( 'misctemplatepath', TemplateSetStorage::getMiscTemplateFolder()); 284 285 // ask the parent to do something, if needed 286 parent::render(); 287 } 288 } 289 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |