1 Mint =& $Mint; 54 $this->plugin_id = $plugin_id; 55 56 // Used to display info about this plug-in 57 $this->info['developer'] = "Marc A. Garrett"; 58 $this->info['plugin'] = "Parsel"; 59 $this->info['description'] = "Find out which languages your visitors use. I wish I knew how to write snappy copy. This is version 0.0.2."; 60 $this->info['developer_url'] = "http://since1968.com/"; 61 $this->info['documentation'] = "http://since1968.com/"; 62 63 // Used internally 64 $this->info['src'] = "since1968/parsel/"; 65 $this->info['class'] = "since1968_Parsel"; 66 67 // Panes used to keep track of the data displayed by this plug-in and 68 // for ordering preferences 69 $this->panes['Languages'] = array('Most Common','Most Recent'); 70 } 71 72 /************************************************************************** 73 install() 74 This function will be called by the Mint plug-in installer 75 76 It may add columns to the Mint table but the onRecord/onJavaScript event 77 handlers must provide and validate the necessary data 78 79 **************************************************************************/ 80 function install() { 81 $query = "ALTER TABLE {$this->Mint->db['tblprefix']}visit 82 ADD since1968_language VARCHAR( 10 )"; 83 if (mysql_query($query)) { 84 // Do not change this line 85 $this->Mint->registerPlugIn($this->info['src'],$this->info['class'],$this->panes); 86 } 87 } 88 89 /************************************************************************** 90 uninstall() 91 This function will be called by the Mint plug-in remover 92 93 Should delete any columns or additional tables added by $this->install(). 94 Mint will take care of deleting any associated preferences or data 95 96 Need to: 97 - Reconsider this as other plug-ins may form dependancies on these 98 non-standard columns 99 100 **************************************************************************/ 101 function uninstall() { 102 $query = "ALTER TABLE {$this->Mint->db['tblprefix']}visit 103 DROP since1968_language"; 104 mysql_query($query); 105 } 106 107 /************************************************************************** 108 onRecord() 109 Operates on existing $_GET values, values generated as a result of the 110 JavaScript output below or existing $_SERVER variables and returns an 111 associative array with a column name as the index and the value to be 112 stored in that column as the value. 113 **************************************************************************/ 114 115 function onRecord() { 116 if (empty($_GET)) { 117 return array(); 118 } 119 120 // get the user's language 121 $language = $_SERVER['HTTP_ACCEPT_LANGUAGE']; 122 return array('since1968_language'=>$language); 123 } 124 125 /************************************************************************** 126 onJavaScript() 127 Returns a JavaScript string responsible for extracting the necessary values 128 (if any) necessary for this plug-in. 129 130 Should follow format of the new SI Object() 131 **************************************************************************/ 132 function onJavaScript() { } 133 134 /************************************************************************** 135 onDisplay() 136 Produces what the user sees when they are browsing their Mint install 137 138 Returns an associative array of associative arrays that contain an HTML 139 string for each display unit this plug-in is responsible for, plus a formal 140 display name and the containing element's id (for ordering in preferences 141 and anchor linking) 142 143 **************************************************************************/ 144 function onDisplay($pane,$tab,$column='',$sort='') { 145 $html = ''; 146 147 // load language array from separate file 148 include_once("{$this->Mint->siteroot}{$this->Mint->cfg['install_dir']}pepper/{$this->info['src']}languages.php"); 149 150 151 switch($pane) { 152 /* Visitors ***********************************************************/ 153 case 'Languages': 154 switch($tab) { 155 /* Most Common ************************************************/ 156 case 'Most Common': 157 $html .= $this->getHTML_LanguagesCommon($since1968_languages); 158 break; 159 /* Most Recent ************************************************/ 160 case 'Most Recent': 161 $html .= $this->getHTML_LanguagesRecent($since1968_languages); 162 break; 163 } 164 break; 165 } 166 return $html; 167 } 168 169 /************************************************************************** 170 onWidget() 171 172 **************************************************************************/ 173 function onWidget() { } 174 175 /************************************************************************** 176 onDisplayPreferences() 177 178 Should return an assoicative array (indexed by pane name) that contains the 179 HTML contents of that pane's preference. Preferences used by all panes in 180 this plug-in should be indexed as 'global'. Any pane that isn't represeneted 181 by an index in the return array will simply display the string "This pane 182 does not have any preferences" (or similar). 183 184 **************************************************************************/ 185 function onDisplayPreferences() { } 186 187 /************************************************************************** 188 onSavePreferences() 189 190 **************************************************************************/ 191 function onSavePreferences() { } 192 193 /************************************************************************** 194 onCustom() 195 196 **************************************************************************/ 197 function onCustom() { } 198 199 200 /************************************************************************** 201 getHTML_LanguagesRecent() 202 203 This function expects an array of language abbreviations (key) and language 204 names (value). 205 206 **************************************************************************/ 207 function getHTML_LanguagesRecent($since1968_languages) { 208 $html = ''; 209 210 $tableData['table'] = array('id'=>'','class'=>''); 211 $tableData['thead'] = array( 212 // display name, CSS class(es) for each column 213 array('value'=>'Languages','class'=>'stacked-rows'), 214 array('value'=>'When','class'=>'') 215 ); 216 217 $query = "SELECT `since1968_language`, `dt` 218 FROM `{$this->Mint->db['tblprefix']}visit` 219 WHERE 220 `since1968_language`!='' 221 ORDER BY `dt` DESC 222 LIMIT 0,{$this->Mint->cfg['preferences']['rows']}"; 223 224 if ($result = mysql_query($query)) { 225 while ($r = mysql_fetch_array($result)) { 226 $dt = $this->Mint->formatDateTimeRelative($r['dt']); 227 $language_row = $this->Mint->abbr(stripslashes($r['since1968_language'])); 228 229 // here are some sample strings: 230 // en-us,th;q 231 // es-uy 232 // de;q=1.0,e 233 // en,ja;q=0. 234 235 // replace semi-colons with commas 236 $language_row = str_replace(';', ',', $language_row); 237 238 // explode list of abbreviations into an array 239 $language_row_exploded = explode(',', $language_row); 240 241 // create a new, empty array to hold readable language names 242 $language_row_readable = array(); 243 // loop through language abbreviations. For each abbreviation, look up in $a_languages 244 // If found, add human readable name to array. If not found, add original abbreviation to array 245 // Implode and print when done. 246 foreach ($language_row_exploded as $lang) { 247 if(array_key_exists($lang, $since1968_languages)) { 248 $language_row_readable[] = $since1968_languages[$lang]; 249 } else { 250 $language_row_readable[] = $lang; 251 } 252 } 253 254 $language_row_final = implode(', ', $language_row_readable); 255 256 $tableData['tbody'][] = array( 257 $language_row_final, 258 $dt 259 ); 260 } 261 } 262 263 $html = $this->Mint->generateTable($tableData); 264 return $html; 265 } 266 267 /************************************************************************** 268 getHTML_LangugesCommon() 269 This function expects an array of language abbreviations (key) and language 270 names (value). 271 272 **************************************************************************/ 273 function getHTML_LanguagesCommon($since1968_languages) { 274 $html = ''; 275 276 $tableData['table'] = array('id'=>'','class'=>''); 277 $tableData['thead'] = array( 278 // display name, CSS class(es) for each column 279 array('value'=>'Language','class'=>'stacked-rows'), 280 array('value'=>'Hits','class'=>'') 281 ); 282 283 $query = "SELECT `since1968_language`, COUNT(`since1968_language`) as `total`, `dt` 284 FROM `{$this->Mint->db['tblprefix']}visit` 285 WHERE 286 `since1968_language`!='' 287 GROUP BY `since1968_language` 288 ORDER BY `total` DESC, `dt` DESC 289 LIMIT 0,{$this->Mint->cfg['preferences']['rows']}"; 290 if ($result = mysql_query($query)) { 291 while ($r = mysql_fetch_array($result)) { 292 $language_row = $this->Mint->abbr(stripslashes($r['since1968_language'])); 293 294 // here are some sample strings: 295 // en-us,th;q 296 // es-uy 297 // de;q=1.0,e 298 // en,ja;q=0. 299 300 // replace semi-colons with commas 301 $language_row = str_replace(';', ',', $language_row); 302 303 // explode list of abbreviations into an array 304 $language_row_exploded = explode(',', $language_row); 305 306 // create a new, empty array to hold readable language names 307 $language_row_readable = array(); 308 // loop through language abbreviations. For each abbreviation, look up in $a_languages 309 // If found, add human readable name to array. If not found, add original abbreviation to array 310 // Implode and print when done. 311 foreach ($language_row_exploded as $lang) { 312 if(array_key_exists($lang, $since1968_languages)) { 313 $language_row_readable[] = $since1968_languages[$lang]; 314 } else { 315 $language_row_readable[] = $lang; 316 } 317 } 318 319 $language_row_final = implode(', ', $language_row_readable); 320 321 $tableData['tbody'][] = array( 322 $language_row_final, 323 $r['total'] 324 ); 325 } 326 } 327 328 $html = $this->Mint->generateTable($tableData); 329 return $html; 330 } 331 332 } 333 334 ?>