Mint =& $Mint; $this->plugin_id = $plugin_id; // Used to display info about this plug-in $this->info['developer'] = "Marc A. Garrett"; $this->info['plugin'] = "Parsel"; $this->info['description'] = "

Find out which languages your visitors use. This is version 0.0.5. If you have any problems please email me. Parsel should be stable but you install at your own risk.

How to Read the Results

Here's a typical result:

English (United Kingdom), English, q=0.5

This results means "I prefer British English, but I will accept other forms of English as well." The "q" value assigns a preference weight for secondary languages.

For more information on the Accept-Language Header see w3.org.

"; $this->info['developer_url'] = "http://since1968.com/"; $this->info['documentation'] = "http://since1968.com/"; // Used internally $this->info['src'] = "since1968/parsel/"; $this->info['class'] = "since1968_Parsel"; // Panes used to keep track of the data displayed by this plug-in and // for ordering preferences $this->panes['Languages'] = array('Most Common','Most Recent'); } /************************************************************************** install() This function will be called by the Mint plug-in installer It may add columns to the Mint table but the onRecord/onJavaScript event handlers must provide and validate the necessary data **************************************************************************/ function install() { $query = " ALTER TABLE {$this->Mint->db['tblprefix']}visit ADD since1968_language VARCHAR( 100 ) NOT NULL default ''"; if (mysql_query($query)) { // Do not change this line $this->Mint->registerPlugIn($this->info['src'],$this->info['class'],$this->panes); } } /************************************************************************** uninstall() This function will be called by the Mint plug-in remover Should delete any columns or additional tables added by $this->install(). Mint will take care of deleting any associated preferences or data Need to: - Reconsider this as other plug-ins may form dependancies on these non-standard columns **************************************************************************/ function uninstall() { $query = "ALTER TABLE {$this->Mint->db['tblprefix']}visit DROP since1968_language"; mysql_query($query); } /************************************************************************** onRecord() Operates on existing $_GET values, values generated as a result of the JavaScript output below or existing $_SERVER variables and returns an associative array with a column name as the index and the value to be stored in that column as the value. **************************************************************************/ function onRecord() { if (empty($_GET)) { return array(); } $language = ''; // get the user's language $language = $_SERVER['HTTP_ACCEPT_LANGUAGE']; // trim to 100 characters so string isn't too long for database // (this is probably overkill) $language = substr($language, 0, 100); // put field name and value in array for insert into table return array('since1968_language'=>$language); } /************************************************************************** onJavaScript() Returns a JavaScript string responsible for extracting the necessary values (if any) necessary for this plug-in. Should follow format of the new SI Object() **************************************************************************/ function onJavaScript() { } /************************************************************************** onDisplay() Produces what the user sees when they are browsing their Mint install Returns an associative array of associative arrays that contain an HTML string for each display unit this plug-in is responsible for, plus a formal display name and the containing element's id (for ordering in preferences and anchor linking) **************************************************************************/ function onDisplay($pane,$tab,$column='',$sort='') { $html = ''; // load language array from separate file include_once("{$this->Mint->siteroot}{$this->Mint->cfg['install_dir']}pepper/{$this->info['src']}languages.php"); switch($pane) { /* Visitors ***********************************************************/ case 'Languages': switch($tab) { /* Most Common ************************************************/ case 'Most Common': $html .= $this->getHTML_LanguagesCommon($since1968_languages); break; /* Most Recent ************************************************/ case 'Most Recent': $html .= $this->getHTML_LanguagesRecent($since1968_languages); break; } break; } return $html; } /************************************************************************** onWidget() **************************************************************************/ function onWidget() { } /************************************************************************** onDisplayPreferences() Should return an assoicative array (indexed by pane name) that contains the HTML contents of that pane's preference. Preferences used by all panes in this plug-in should be indexed as 'global'. Any pane that isn't represeneted by an index in the return array will simply display the string "This pane does not have any preferences" (or similar). **************************************************************************/ function onDisplayPreferences() { } /************************************************************************** onSavePreferences() **************************************************************************/ function onSavePreferences() { } /************************************************************************** onCustom() **************************************************************************/ function onCustom() { } /************************************************************************** getHTML_LanguagesRecent() This function expects an array of language abbreviations (key) and language names (value). **************************************************************************/ function getHTML_LanguagesRecent($since1968_languages) { $html = ''; $tableData['table'] = array('id'=>'','class'=>''); $tableData['thead'] = array( // display name, CSS class(es) for each column array('value'=>'Language Combinations','class'=>'stacked-rows'), array('value'=>'When','class'=>'') ); $query = "SELECT `since1968_language`, `dt` FROM `{$this->Mint->db['tblprefix']}visit` WHERE `since1968_language`!='' ORDER BY `dt` DESC LIMIT 0,{$this->Mint->cfg['preferences']['rows']}"; if ($result = mysql_query($query)) { while ($r = mysql_fetch_array($result)) { $dt = $this->Mint->formatDateTimeRelative($r['dt']); $language_row = $this->Mint->abbr(stripslashes($r['since1968_language'])); // here are some sample strings: // en-us,th;q // es-uy // de;q=1.0,e // en,ja;q=0. // replace semi-colons with commas $language_row = str_replace(';', ',', $language_row); // explode list of abbreviations into an array $language_row_exploded = explode(',', $language_row); // create a new, empty array to hold readable language names $language_row_readable = array(); // loop through language abbreviations. For each abbreviation, look up in $a_languages // If found, add human readable name to array. If not found, add original abbreviation to array // Implode and print when done. foreach ($language_row_exploded as $lang) { if(array_key_exists($lang, $since1968_languages)) { $language_row_readable[] = $since1968_languages[$lang]; } else { $language_row_readable[] = $lang; } } $language_row_final = implode(', ', $language_row_readable); $tableData['tbody'][] = array( $language_row_final, $dt ); } } $html = $this->Mint->generateTable($tableData); return $html; } /************************************************************************** getHTML_LangugesCommon() This function expects an array of language abbreviations (key) and language names (value). **************************************************************************/ function getHTML_LanguagesCommon($since1968_languages) { $html = ''; $tableData['table'] = array('id'=>'','class'=>''); $tableData['thead'] = array( // display name, CSS class(es) for each column array('value'=>'Language Combinations','class'=>'stacked-rows'), array('value'=>'Hits','class'=>'') ); $query = "SELECT `since1968_language`, COUNT(`since1968_language`) as `total`, `dt` FROM `{$this->Mint->db['tblprefix']}visit` WHERE `since1968_language`!='' GROUP BY `since1968_language` ORDER BY `total` DESC, `dt` DESC LIMIT 0,{$this->Mint->cfg['preferences']['rows']}"; if ($result = mysql_query($query)) { while ($r = mysql_fetch_array($result)) { $language_row = $this->Mint->abbr(stripslashes($r['since1968_language'])); // here are some sample strings: // en-us,th;q // es-uy // de;q=1.0,e // en,ja;q=0. // replace semi-colons with commas $language_row = str_replace(';', ',', $language_row); // explode list of abbreviations into an array $language_row_exploded = explode(',', $language_row); // find members of array matching q= and remove // create a new, empty array to hold readable language names $language_row_readable = array(); // loop through language abbreviations. For each abbreviation, look up in $a_languages // If found, add human readable name to array. If not found, add original abbreviation to array // Implode and print when done. foreach ($language_row_exploded as $lang) { if(array_key_exists($lang, $since1968_languages)) { $language_row_readable[] = $since1968_languages[$lang]; } else { $language_row_readable[] = $lang; } } $language_row_final = implode(', ', $language_row_readable); $tableData['tbody'][] = array( $language_row_final, $r['total'] ); } } $html = $this->Mint->generateTable($tableData); return $html; } } ?>