[ Index ] |
|
Code source de Serendipity 1.2 |
1 <?php # $Id: serendipity_plugin_entrylinks.php 1140 2006-04-21 12:44:55Z garvinhicking $ 2 3 // Probe for a language include with constants. Still include defines later on, if some constants were missing 4 $probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php'; 5 if (file_exists($probelang)) { 6 include $probelang; 7 } 8 9 include dirname(__FILE__) . '/lang_en.inc.php'; 10 11 class serendipity_plugin_entrylinks extends serendipity_plugin 12 { 13 var $title = PLUGIN_ENTRYLINKS_NAME; 14 15 function introspect(&$propbag) 16 { 17 global $serendipity; 18 19 $this->title = $this->get_config('title', $this->title); 20 21 $propbag->add('name', PLUGIN_ENTRYLINKS_NAME); 22 $propbag->add('description', PLUGIN_ENTRYLINKS_BLAHBLAH); 23 $propbag->add('stackable', false); 24 $propbag->add('author', 'Garvin Hicking'); 25 $propbag->add('version', '1.01'); 26 $propbag->add('requirements', array( 27 'serendipity' => '0.8', 28 'smarty' => '2.6.7', 29 'php' => '4.1.0' 30 )); 31 $propbag->add('groups', array('FRONTEND_ENTRY_RELATED')); 32 $propbag->add('configuration', array('title', 'newwin', 'markup', 'wordwrap', 'show_exits', 'show_referers', 'maxref', 'orderby')); 33 } 34 35 function introspect_config_item($name, &$propbag) 36 { 37 switch($name) { 38 case 'title': 39 $propbag->add('type', 'string'); 40 $propbag->add('name', TITLE); 41 $propbag->add('description', TITLE); 42 $propbag->add('default', ''); 43 break; 44 45 case 'newwin': 46 $propbag->add('type', 'boolean'); 47 $propbag->add('name', PLUGIN_ENTRYLINKS_NEWWIN); 48 $propbag->add('description', PLUGIN_ENTRYLINKS_NEWWIN_BLAHBLAH); 49 $propbag->add('default', 'false'); 50 break; 51 52 case 'markup': 53 $propbag->add('type', 'boolean'); 54 $propbag->add('name', DO_MARKUP); 55 $propbag->add('description', DO_MARKUP_DESCRIPTION); 56 $propbag->add('default', 'true'); 57 break; 58 59 case 'show_exits': 60 $propbag->add('type', 'boolean'); 61 $propbag->add('name', TOP_EXITS); 62 $propbag->add('description', SHOWS_TOP_EXIT); 63 $propbag->add('default', 'true'); 64 break; 65 66 case 'show_referers': 67 $propbag->add('type', 'boolean'); 68 $propbag->add('name', TOP_REFERRER); 69 $propbag->add('description', SHOWS_TOP_SITES); 70 $propbag->add('default', ''); 71 break; 72 73 case 'maxref': 74 $propbag->add('type', 'string'); 75 $propbag->add('name', PLUGIN_ENTRYLINKS_MAXREF); 76 $propbag->add('description', PLUGIN_ENTRYLINKS_MAXREF_BLAHBLAH); 77 $propbag->add('default', 15); 78 break; 79 80 case 'wordwrap': 81 $propbag->add('type', 'string'); 82 $propbag->add('name', PLUGIN_ENTRYLINKS_WORDWRAP); 83 $propbag->add('description', PLUGIN_ENTRYLINKS_WORDWRAP_BLAHBLAH); 84 $propbag->add('default', 30); 85 break; 86 87 case 'orderby': 88 $select = array('day' => PLUGIN_ENTRYLINKS_ORDERBY_DAY, 'fullcount' => PLUGIN_ENTRYLINKS_ORDERBY_FULLCOUNT); 89 $propbag->add('type', 'select'); 90 $propbag->add('name', PLUGIN_ENTRYLINKS_ORDERBY); 91 $propbag->add('description', PLUGIN_ENTRYLINKS_ORDERBY_BLAHBLAH); 92 $propbag->add('select_values', $select); 93 $propbag->add('default', 'fullcount'); 94 break; 95 96 default: 97 return false; 98 } 99 return true; 100 } 101 102 function generate_content(&$title) 103 { 104 global $serendipity; 105 106 $title = $this->get_config('title', $this->title); 107 108 if (!isset($serendipity['GET']['id']) || !is_numeric($serendipity['GET']['id'])) { 109 return false; 110 } else { 111 $id = serendipity_db_escape_string($serendipity['GET']['id']); 112 } 113 114 $target = ''; 115 $newwin = $this->get_config('newwin', 'false'); 116 $wordwrap = $this->get_config('wordwrap', 30); 117 $maxref = $this->get_config('maxref', 15); 118 $orderby = $this->get_config('orderby', 'fullcount'); 119 120 if ($newwin == 'true') { 121 $target = ' target="_blank" '; 122 } 123 124 125 $counter = array(); 126 127 if ($this->get_config('show_exits', 'true') == 'true') { 128 $exits = serendipity_db_query("SELECT SUM(count) as fullcount, scheme, host, port, path, query, " . serendipity_db_concat("scheme, '://', host, ':', port, path, '?', query") . " AS fulllink FROM {$serendipity['dbPrefix']}exits WHERE entry_id = " . $id . " GROUP BY scheme,host,port,path,query"); 129 if (is_array($exits)) { 130 foreach($exits AS $key => $row) { 131 $url = sprintf('%s://%s%s%s%s', 132 $row['scheme'], 133 $row['host'], 134 (!empty($row['port']) ? ':' . $row['port'] : ''), 135 $row['path'], 136 (!empty($row['query']) ? '?' . $row['query'] : '') 137 ); 138 139 $counter[$url] = $row['fullcount']; 140 } 141 } 142 } 143 144 $references = serendipity_db_query("SELECT link, max(name) as name FROM {$serendipity['dbPrefix']}references WHERE entry_id = " . $id . " AND type = '' GROUP BY link"); 145 if (is_array($references)) { 146 $links = '<ul style="margin: 5px; padding: 10px; text-align: left">'; 147 foreach($references AS $key => $row) { 148 if (empty($row['name']) || empty($row['link'])) { 149 continue; 150 } 151 $count = ''; 152 if (isset($counter[$row['link']])) { 153 $count = '<br /><div style="text-align: right; margin: 0px">[' . $counter[$row['link']] . ']</div>'; 154 } 155 $link_name = $wordwrap < 1? $row['name']: wordwrap($row['name'], $wordwrap, "<br />", 1); 156 $links .= '<li><a href="' . $row['link'] . '" ' . $target . '>' . $link_name . "</a>$count</li>"; 157 } 158 $links .= '</ul>'; 159 160 if ($this->get_config('markup', 'true') == 'true') { 161 $entry = array('html_nugget' => $links, 'entry_id' => $id); 162 serendipity_plugin_api::hook_event('frontend_display', $entry); 163 echo $entry['html_nugget']; 164 } else { 165 echo $links; 166 } 167 } 168 169 if ($this->get_config('show_referers', 'true') == 'true') { 170 $ref = serendipity_db_query("SELECT SUM(count) as fullcount, scheme, host, port, path, query, " . serendipity_db_concat("scheme, '://', host, ':', port, path, '?', query") . " AS fulllink FROM {$serendipity['dbPrefix']}referrers WHERE entry_id = " . $id . " GROUP BY scheme,host,port,path,query ORDER BY $orderby DESC LIMIT $maxref"); 171 if (is_array($ref)) { 172 echo PLUGIN_ENTRYLINKS_REFERERS . '<ul style="margin: 5px; padding: 10px; text-align: left">'; 173 foreach($ref AS $key => $row) { 174 $url = sprintf('%s://%s%s%s%s', 175 $row['scheme'], 176 $row['host'], 177 (!empty($row['port']) ? ':' . $row['port'] : ''), 178 $row['path'], 179 (!empty($row['query']) ? '?' . $row['query'] : '') 180 ); 181 182 echo '<li><a href="' . $url . '" ' . $target . '>' . wordwrap($row['host'], $wordwrap, "<br />", 1) . '</a><br /><div style="text-align: right; margin: 0px;">[' . $row['fullcount'] . "]</div></li>"; 183 } 184 echo '</ul>'; 185 } 186 } 187 } 188 } 189 190 /* vim: set sts=4 ts=4 expandtab : */
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 |
![]() |