[ Index ] |
|
Code source de Serendipity 1.2 |
1 <?php # $Id: serendipity_plugin_recententries.php 1719 2007-06-11 10:15:01Z garvinhicking $ 2 3 // Contributed by Christian Machmeier <cm@redsplash.de> 4 // Randomizing contributed by Christian Brabandt <cb@256bit.org> 5 6 // Probe for a language include with constants. Still include defines later on, if some constants were missing 7 $probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php'; 8 if (file_exists($probelang)) { 9 include $probelang; 10 } 11 12 include dirname(__FILE__) . '/lang_en.inc.php'; 13 14 class serendipity_plugin_recententries extends serendipity_plugin { 15 var $title = PLUGIN_RECENTENTRIES_TITLE; 16 17 function introspect(&$propbag) { 18 $this->title = $this->get_config('title', $this->title); 19 20 $propbag->add('name', PLUGIN_RECENTENTRIES_TITLE); 21 $propbag->add('description', PLUGIN_RECENTENTRIES_BLAHBLAH); 22 $propbag->add('stackable', true); 23 $propbag->add('author', 'Christian Machmeier, Christian Brabandt'); 24 $propbag->add('version', '1.7'); 25 $propbag->add('requirements', array( 26 'serendipity' => '0.8', 27 'smarty' => '2.6.7', 28 'php' => '4.1.0' 29 )); 30 $propbag->add('configuration', array('title', 'number', 'number_from', 'dateformat', 'category', 'randomize')); 31 $propbag->add('groups', array('FRONTEND_VIEWS')); 32 } 33 34 function introspect_config_item($name, &$propbag) { 35 switch($name) { 36 case 'title': 37 $propbag->add('type', 'string'); 38 $propbag->add('name', TITLE); 39 $propbag->add('description', TITLE_FOR_NUGGET); 40 $propbag->add('default', PLUGIN_RECENTENTRIES_TITLE); 41 break; 42 43 case 'number': 44 $propbag->add('type', 'string'); 45 $propbag->add('name', PLUGIN_RECENTENTRIES_NUMBER); 46 $propbag->add('description', PLUGIN_RECENTENTRIES_NUMBER_BLAHBLAH); 47 $propbag->add('default', 10); 48 break; 49 50 case 'number_from': 51 $propbag->add('type', 'radio'); 52 $propbag->add('name', PLUGIN_RECENTENTRIES_NUMBER_FROM); 53 $propbag->add('description', PLUGIN_RECENTENTRIES_NUMBER_FROM_DESC); 54 $propbag->add('radio', array( 55 'value' => array('all', 'skip'), 56 'desc' => array(PLUGIN_RECENTENTRIES_NUMBER_FROM_RADIO_ALL, PLUGIN_RECENTENTRIES_NUMBER_FROM_RADIO_RECENT) 57 )); 58 $propbag->add('default', 'all'); 59 break; 60 61 case 'randomize': 62 $propbag->add('type', 'radio'); 63 $propbag->add('name', PLUGIN_RECENTENTRIES_RANDOMIZE); 64 $propbag->add('description', PLUGIN_RECENTENTRIES_RANDOMIZE_DESC); 65 $propbag->add('radio', array( 66 'value' => array('yes', 'no'), 67 'desc' => array(YES, NO) 68 )); 69 $propbag->add('default', 'no'); 70 break; 71 72 case 'dateformat': 73 $propbag->add('type', 'string'); 74 $propbag->add('name', GENERAL_PLUGIN_DATEFORMAT); 75 $propbag->add('description', sprintf(GENERAL_PLUGIN_DATEFORMAT_BLAHBLAH, '%A, %B %e %Y')); 76 $propbag->add('default', '%A, %B %e %Y'); 77 break; 78 79 case 'category': 80 $cats = serendipity_fetchCategories($serendipity['authorid']); 81 if (!is_array($cats)) { 82 return false; 83 } 84 85 $catlist = serendipity_generateCategoryList($cats, array(0), 4, 0, 0, '', ' . '); 86 $tmp_select_cats = explode('@@@', $catlist); 87 88 if (!is_array($tmp_select_cats)) { 89 return false; 90 } 91 92 $select_cats = array(); 93 $select_cats['none'] = ALL_CATEGORIES; 94 foreach($tmp_select_cats as $cidx => $tmp_select_cat) { 95 $select_cat = explode('|||', $tmp_select_cat); 96 if (!empty($select_cat[0]) && !empty($select_cat[1])) { 97 $select_cats[$select_cat[0]] = $select_cat[1]; 98 } 99 } 100 101 $propbag->add('type', 'multiselect'); 102 $propbag->add('select_values', $select_cats); 103 $propbag->add('select_size', 5); 104 $propbag->add('name', CATEGORY); 105 $propbag->add('description', CATEGORIES_TO_FETCH); 106 $propbag->add('default', 'none'); 107 break; 108 109 default: 110 return false; 111 } 112 return true; 113 } 114 115 function generate_content(&$title) { 116 global $serendipity; 117 118 $number = $this->get_config('number'); 119 $dateformat = $this->get_config('dateformat'); 120 $category = $this->get_config('category', 'none'); 121 $title = $this->get_config('title', $this->title); 122 $number_from_sw = $this->get_config('number_from'); 123 $randomize = ($this->get_config('randomize') == "yes") ? true : false ; 124 125 $sql_join = ''; 126 $sql_where = ''; 127 if ($category != 'none') { 128 $sql_join = 'LEFT OUTER JOIN ' . $serendipity['dbPrefix'] . 'entrycat AS ec ON id = ec.entryid 129 LEFT OUTER JOIN ' . $serendipity['dbPrefix'] . 'category AS c ON ec.categoryid = c.categoryid'; 130 131 $sql_categories = array(); 132 if (is_numeric($category)) { 133 $sql_categories[] = $category; 134 } else { 135 $sql_categories = explode('^', $category); 136 } 137 138 $category_parts = array(); 139 foreach($sql_categories AS $sql_category) { 140 $category_parts[] = "\n" . implode(' AND ', serendipity_fetchCategoryRange($sql_category)); 141 } 142 143 $sql_where = ' AND (c.category_left BETWEEN ' . implode(' OR c.category_left BETWEEN ', $category_parts) . ')'; 144 } 145 146 if (!$number || !is_numeric($number) || $number < 1) { 147 $number = 10; 148 } 149 150 $sql_number = serendipity_db_limit_sql($number); 151 $db = $serendipity['dbType']; 152 153 switch($number_from_sw) { 154 case 'skip': 155 $sql_number = serendipity_db_limit_sql(serendipity_db_limit($serendipity['fetchLimit'], $number)); 156 break; 157 } 158 159 if (!$dateformat || strlen($dateformat) < 1) { 160 $dateformat = '%A, %B %e %Y'; 161 } 162 if ($randomize) { 163 if ($db == 'mysql' || $db == 'mysqli') { 164 $sql_order = "ORDER BY RAND()"; 165 } else { 166 // SQLite and PostgreSQL support this, hooray. 167 $sql_order = "ORDER BY RANDOM()"; 168 } 169 } else { 170 $sql_order = "ORDER BY timestamp DESC "; 171 } 172 173 $entries_query = "SELECT DISTINCT id, 174 title, 175 timestamp 176 FROM {$serendipity['dbPrefix']}entries 177 $sql_join 178 WHERE isdraft = 'false' AND timestamp <= " . time() . " 179 $sql_where 180 $sql_order 181 $sql_number"; 182 $entries = serendipity_db_query($entries_query); 183 184 if (isset($entries) && is_array($entries)) { 185 foreach ($entries as $k => $entry) { 186 $entryLink = serendipity_archiveURL( 187 $entry['id'], 188 $entry['title'], 189 'serendipityHTTPPath', 190 true, 191 array('timestamp' => $entry['timestamp']) 192 ); 193 194 if (empty($entry['title'])) { 195 $entry['title'] = '#' . $entry['id']; 196 } 197 198 echo '<a href="' . $entryLink . '" title="' . htmlspecialchars($entry['title']) . '">' . $entry['title'] . '</a><br />' 199 . '<div class="serendipitySideBarDate">' 200 . htmlspecialchars(serendipity_strftime($dateformat, $entry['timestamp'])) 201 . '</div><br />'; 202 } 203 } 204 } 205 } 206 207 /* vim: set sts=4 ts=4 smartindent autoindent : */
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Nov 24 09:00:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |