--- hof.module~ Sat May 7 04:08:39 2005 +++ hof.module Mon Aug 15 09:34:55 2005 @@ -1,6 +1,6 @@ ' . t('Introduction') . ''; - $html .= '

' . t('Hall of Fame (HOF) offers a concise summary of site statistics on a read-only basis. Unlike the built-in statistical features of Drupal itself, HOF is intended for public consumption rather than [mostly] for administrators. The module can display its output in sections such as "Most Popular Content", "Most Active Contributors", etc., or it can make a single large page with the combined output of all sections, or it can produce a sparse table-of-contents page with links to each section.'); - $html .= '

' . t('Administrators can determine what roles have permission to view the HOF pages, who can change the module\'s settings, and some behaviors of the module (such as which output section is the default).'); - $html .= '

' . t('HOF is aware of the weblink and scheduler modules, and if they are installed, it adds specific reporting features related to these, as explained below.'); - $html .= '

' . t('Statistical Computations') . '

'; - $html .= '

' . t('Overall statistics include, among others:') . '

'; - $html .= '
' . t('Date of first publication, and time since that date') . '
' . t('Computed by looking for the earliest creation date of any node'); - $html .= '
' . t('Number of active user accounts') . '
' . t('Computed by looking for an update date greater than the creation date of the account, an attempt to ignore accounts which are created but never used.'); - $html .= '
' . t('Weblinks in directory') . '
' . t('If the weblink module is installed, this statistic reports how many weblinks have been published.'); - $html .= '
' . t('Items in queue awaiting approval') . '
' . t('Tallies all unpublished nodes. If the scheduler module is installe, nodes that have been scheduled for future publication are not counted in this number.'); - $html .= '
' . t('Items awaiting scheduled release') . '
' . t('If the scheduler module is installed, this statistic indicates how many nodes have been scheduled for release in the future.'); - $html .= '

' . t('Other statistics are computed for the past week, the past month, the past year, and for all time since the site\'s creation. These include:') . '

'; - $html .= '
' . t('Most active contributors') . '
' . t('Computed by looking at the user who created each node.'); - $html .= '
' . t('Most popular content') . '
' . t('Computed by tallying the number of reads for each node.'); - $html .= '
' . t('Stories published') . '
' . t('In this context, "stories" really means "promoted nodes", the concept being intended as "things that are announced on the default main page as newsworthy" as opposed to regular pages that may include static-ish content, terms of service, privacy policy, and so on.'); - $html .= '
' . t('Total articles published') . '
' . t('This is simply a count of all published nodes on the site, regardless of type.'); - $html .= '
'; + $html = '

'. t('Introduction') .'

'; + $html .= '

'. t('Hall of Fame (HOF) offers a concise summary of site statistics on a read-only basis. Unlike the built-in statistical features of Drupal itself, HOF is intended for public consumption rather than [mostly] for administrators. The module can display its output in sections such as "Most Popular Content", "Most Active Contributors", etc., or it can make a single large page with the combined output of all sections, or it can produce a sparse table-of-contents page with links to each section.'); + $html .= '

'. t('Administrators can determine what roles have permission to view the HOF pages, who can change the module\'s settings, and some behaviors of the module (such as which output section is the default).'); + $html .= '

'. t('HOF is aware of the weblink and scheduler modules, and if they are installed, it adds specific reporting features related to these, as explained below.'); + $html .= '

'. t('Statistical Computations') .'

'; + $html .= '

'. t('Overall statistics include, among others:') .'

'; + $html .= '
'. t('Date of first publication, and time since that date') .'
'. t('Computed by looking for the earliest creation date of any node'); + $html .= '
'. t('Number of active user accounts') .'
'. t('Computed by looking for an update date greater than the creation date of the account, an attempt to ignore accounts which are created but never used.'); + $html .= '
'. t('Weblinks in directory') .'
'. t('If the weblink module is installed, this statistic reports how many weblinks have been published.'); + $html .= '
'. t('Items in queue awaiting approval') .'
'. t('Tallies all unpublished nodes. If the scheduler module is installe, nodes that have been scheduled for future publication are not counted in this number.'); + $html .= '
'. t('Items awaiting scheduled release') .'
'. t('If the scheduler module is installed, this statistic indicates how many nodes have been scheduled for release in the future.'); + $html .= '

'. t('Other statistics are computed for the past week, the past month, the past year, and for all time since the site\'s creation. These include:') .'

'; + $html .= '
'. t('Most active contributors') .'
'. t('Computed by looking at the user who created each node.'); + $html .= '
'. t('Most popular content') .'
'. t('Computed by tallying the number of reads for each node.'); + $html .= '
'. t('Stories published') .'
'. t('In this context, "stories" really means "promoted nodes", the concept being intended as "things that are announced on the default main page as newsworthy" as opposed to regular pages that may include static-ish content, terms of service, privacy policy, and so on.'); + $html .= '
'. t('Total articles published') .'
'. t('This is simply a count of all published nodes on the site, regardless of type.'); + $html .= '

'; return $html; } } @@ -54,9 +54,9 @@ unset($sections['all']); $perms = array('access hof'); foreach ($sections as $section=>$title) { - if (array_search($section,$enabled) !== FALSE) { - $title = strtolower(preg_replace('/\W+/',' ',$title)); - $perm = 'access hof '.$title; + if (array_search($section, $enabled) !== FALSE) { + $title = strtolower(preg_replace('/\W+/', ' ', $title)); + $perm = 'access hof '. $title; $perms[] = $perm; } } @@ -73,21 +73,21 @@ unset($sections['all']); $sections2 = hof_get_sections(); // For selecting default display, do not remove toc and all - $group = form_checkboxes(t('Enable HOF sections'),'hof_enable_sections',variable_get('hof_enable_sections', array_keys($sections)), $sections, t('Check or uncheck each option to enable or disable that section of the Hall of Fame')); + $group = form_checkboxes(t('Enable HOF sections'), 'hof_enable_sections', variable_get('hof_enable_sections', array_keys($sections)), $sections, t('Check or uncheck each option to enable or disable that section of the Hall of Fame')); $sections = hof_get_sections(); unset($sections['default']); // Not applicable here - $group .= form_select(t('Default HOF section'),'hof_default_section',variable_get('hof_default_section', 'all'), $sections2, t('Select the page that will display at the top-level Hall of Fame URL')); - $html .= form_group(t('Hall of Fame Sections'),$group); - $group = form_select(t('TOC position'),'hof_toc_position',variable_get('hof_toc_position','bottom'), array('top'=>t('Above report'), 'bottom'=>t('Below report'), 'none'=>t('No automatic TOC')), t('Select the position of a table-of-contents, or link to the table of contents, to display on all pages except for the TOC page itself.')); - $group .= form_select(t('TOC mode'),'hof_toc_mode',variable_get('hof_toc_mode','link'), array('link'=>t('Link to TOC page'), 'full'=>t('Show full TOC in pages')), t('Should the embedded table-of-contents be just a link to the TOC page, or should all the links to individual pages be listed? This affects only the TOC embedded in other pages, not the TOC on its own dedicated page.')); - $group .= form_checkbox(t('Include HOF TOC in embedded TOC'),'hof_toc_in_toc',1,variable_get('hof_toc_in_toc',TRUE),t('If the embedded table-of-contents is enabled, this setting controls whether that TOC will include a link to the full-page TOC. You can disable that link if it is redundant because of your choice of theme and other Hall of Fame settings.')); - $html .= form_group(t('Table of Contents (TOC) Settings'),$group); - $numbers = array('3'=>3, '5'=>5, '10'=>10, '15'=>15, '20'=>20); - $group = form_select(t('Users Per Activity Period'),'hof_active_user_count',variable_get('hof_active_user_count',5), $numbers, t('For reports where the most-active users are listed for given time periods, this setting determines how many users will be listed (maximum) for each time period. The actual displayed list may be shorter if not enough users qualify to be listed.')); - $group .= form_select(t('Items Per Activity Period'),'hof_item_count',variable_get('hof_item_count',5), $numbers, t('For reports where items are ranked (such as by popularity) for given time periods, this setting determines how many items will be listed (maximum) for each time period. The actual displayed list may be shorter if not enough items qualify to be listed.')); - $group .= form_textfield(t('Label for promoted nodes'),'hof_promoted_label',variable_get('hof_promoted_label',t('Promoted Nodes')),30,40,t('When reporting statistics for promoted nodes, this is the user-friendly title that will be used to describe these nodes. It should be plural and should be formatted with appropriate capitalization for use as a title. Suggested examples would be "Promoted Nodes" (the default), "News Items", and so forth. This option should be decided based on your site\'s policy for promoting nodes.'),NULL,TRUE); - $group .= form_textfield(t('Alternative for "nodes"'),'hof_node_label',variable_get('hof_node_label',t('nodes')),20,20,t('When reporting statistics for all nodes, this is the user-friendly term that is used in place of Drupal\'s internal term, "nodes". It should be plural. Suggested examples would be "nodes" (the default), "articles", and so forth.'),NULL,TRUE); - $html .= form_group(t('Report Settings'),$group); + $group .= form_select(t('Default HOF section'), 'hof_default_section', variable_get('hof_default_section', 'all'), $sections2, t('Select the page that will display at the top-level Hall of Fame URL')); + $html .= form_group(t('Hall of Fame Sections'), $group); + $group = form_select(t('TOC position'), 'hof_toc_position', variable_get('hof_toc_position', 'bottom'), array('top' => t('Above report'), 'bottom' => t('Below report'), 'none' => t('No automatic TOC')), t('Select the position of a table-of-contents, or link to the table of contents, to display on all pages except for the TOC page itself.')); + $group .= form_select(t('TOC mode'), 'hof_toc_mode', variable_get('hof_toc_mode', 'link'), array('link' => t('Link to TOC page'), 'full' => t('Show full TOC in pages')), t('Should the embedded table-of-contents be just a link to the TOC page, or should all the links to individual pages be listed? This affects only the TOC embedded in other pages, not the TOC on its own dedicated page.')); + $group .= form_checkbox(t('Include HOF TOC in embedded TOC'), 'hof_toc_in_toc', 1, variable_get('hof_toc_in_toc', TRUE), t('If the embedded table-of-contents is enabled, this setting controls whether that TOC will include a link to the full-page TOC. You can disable that link if it is redundant because of your choice of theme and other Hall of Fame settings.')); + $html .= form_group(t('Table of Contents (TOC) Settings'), $group); + $numbers = array('3' => 3, '5' => 5, '10' => 10, '15' => 15, '20' => 20); + $group = form_select(t('Users Per Activity Period'), 'hof_active_user_count', variable_get('hof_active_user_count', 5), $numbers, t('For reports where the most-active users are listed for given time periods, this setting determines how many users will be listed (maximum) for each time period. The actual displayed list may be shorter if not enough users qualify to be listed.')); + $group .= form_select(t('Items Per Activity Period'), 'hof_item_count', variable_get('hof_item_count', 5), $numbers, t('For reports where items are ranked (such as by popularity) for given time periods, this setting determines how many items will be listed (maximum) for each time period. The actual displayed list may be shorter if not enough items qualify to be listed.')); + $group .= form_textfield(t('Label for promoted nodes'), 'hof_promoted_label', variable_get('hof_promoted_label', t('Promoted Nodes')), 30, 40, t('When reporting statistics for promoted nodes, this is the user-friendly title that will be used to describe these nodes. It should be plural and should be formatted with appropriate capitalization for use as a title. Suggested examples would be "Promoted Nodes" (the default), "News Items", and so forth. This option should be decided based on your site\'s policy for promoting nodes.'), NULL, TRUE); + $group .= form_textfield(t('Alternative for "nodes"'), 'hof_node_label', variable_get('hof_node_label', t('nodes')), 20, 20, t('When reporting statistics for all nodes, this is the user-friendly term that is used in place of Drupal\'s internal term, "nodes". It should be plural. Suggested examples would be "nodes" (the default), "articles", and so forth.'), NULL, TRUE); + $html .= form_group(t('Report Settings'), $group); return $html; } @@ -98,23 +98,34 @@ $items = array(); if ($may_cache) { // Nothing - } else { - $items[] = array('path'=>'hof','title'=>t('Hall of Fame'), - 'callback'=>'hof_page','access'=>user_access('access hof'), - 'type'=>MENU_CALLBACK); + } + else { + $items[] = array( + 'path' => 'hof', + 'title' => t('Hall of Fame'), + 'callback' => 'hof_page', + 'access' => user_access('access hof'), + 'type' => MENU_CALLBACK + ); $sections = hof_get_sections(); - foreach($sections as $section=>$title) { + foreach ($sections as $section=>$title) { if ($section == 'default' || $section == 'all' || $section == 'toc') { $acc = user_access('access hof'); - } else { + } + else { $acc1 = user_access('access hof'); - $acc2 = user_access('access hof '.strtolower(preg_replace('/\W+/',' ',$title))); + $acc2 = user_access('access hof '. strtolower(preg_replace('/\W+/', ' ', $title))); $acc = $acc1 && $acc2; } $weight = ($section == 'all') ? 10 : 0; - $items[] = array('path'=>'hof/'.$section, 'title'=>$title, - 'callback'=>'hof_page', 'type'=>MENU_CALLBACK, - 'access'=>$acc, 'weight'=>$weight); + $items[] = array( + 'path' => 'hof/'. $section, + 'title' => $title, + 'callback' => 'hof_page', + 'type' => MENU_CALLBACK, + 'access' => $acc, + 'weight' => $weight + ); } } return $items; @@ -125,12 +136,12 @@ */ function hof_get_sections() { $sections = array( - 'site'=>t('Site Statistics'), - 'contrib'=>t('Most Active Contributors'), - 'node'=>t('Most Popular Content'), - 'comment'=>t('Most Active Commentors'), - 'all'=>t('All Statistics'), - 'toc'=>t('HOF Table of Contents') + 'site' => t('Site Statistics'), + 'contrib' => t('Most Active Contributors'), + 'node' => t('Most Popular Content'), + 'comment' => t('Most Active Commentors'), + 'all' => t('All Statistics'), + 'toc' => t('HOF Table of Contents') ); return $sections; } @@ -150,9 +161,9 @@ $enabled = variable_get('hof_enable_sections', $sections); foreach ($sections as $section=>$title) { if ($section != 'toc' && $section != 'all' && $section != 'default') { - $title = strtolower(preg_replace('/\W+/',' ',$title)); - $perm = 'access hof '.$title; - if (array_search($section,$enabled) === FALSE) { + $title = strtolower(preg_replace('/\W+/', ' ', $title)); + $perm = 'access hof '. $title; + if (array_search($section, $enabled) === FALSE) { unset($sections[$section]); } if (! user_access($perm)) { @@ -171,8 +182,12 @@ $GLOBALS['hof_last_week'] = strtotime("-1 week"); $GLOBALS['hof_last_month'] = strtotime("-1 month"); $GLOBALS['hof_last_year'] = strtotime("-1 year"); - $GLOBALS['hof_intervals'] = array(t('week')=>$GLOBALS['hof_last_week'], t('month')=>$GLOBALS['hof_last_month'], - t('year')=>$GLOBALS['hof_last_year'], t('epoch')=>0); + $GLOBALS['hof_intervals'] = array( + t('week') => $GLOBALS['hof_last_week'], + t('month') => $GLOBALS['hof_last_month'], + t('year') => $GLOBALS['hof_last_year'], + t('epoch') => 0 + ); } @@ -181,27 +196,28 @@ */ function hof_page() { _hof_constants(); - $toc_position = variable_get('hof_toc_position','none'); - $default_section = variable_get('hof_default_section','toc'); + $toc_position = variable_get('hof_toc_position', 'none'); + $default_section = variable_get('hof_default_section', 'toc'); $html = '
'; $section = arg(1); $section = empty($section) ? 'default' : $section; if ($section == 'toc' || ($default_section == 'toc' && $section == 'default')) { $need_toc = FALSE; - } else { + } + else { $need_toc = TRUE; } - $function = '_hof_page_section_'.$section; + $function = '_hof_page_section_'. $section; if (function_exists($function)) { if ($need_toc) { $sections = hof_get_sections(); - drupal_set_title(t('Hall of Fame: ').$sections[$section]); + drupal_set_title(t('Hall of Fame: '). $sections[$section]); if ($toc_position == 'top') { $html .= _hof_embedded_toc(); } } $args = array_shift(func_get_args()); - $html .= "

" . t("Statistics for ") . variable_get('site_name',t("this site")) . t(" as of ") . format_date(time(), "long") . "

\n"; + $html .= "

". t('Statistics for ') . variable_get('site_name', t('this site')) . t(' as of ') . format_date(time(), "long") ."

\n"; $html .= call_user_func_array($function, $args); if ($need_toc) { if ($toc_position == 'bottom') { @@ -209,8 +225,9 @@ } } $html .= '
'; - print(theme('page',$html)); - } else { + print(theme('page', $html)); + } + else { drupal_not_found(); } } @@ -220,13 +237,14 @@ */ function _hof_page_section_default() { // return("

Default

"); - $default_section = variable_get('hof_default_section','toc'); - $function = '_hof_page_section_'.$default_section; + $default_section = variable_get('hof_default_section', 'toc'); + $function = '_hof_page_section_'. $default_section; if (function_exists($function)) { $args = func_get_args(); return call_user_func_array($function, $args); - } else { - drupal_set_message('Internal error: HOF tried to call function ' . $function); + } + else { + drupal_set_message('Internal error: HOF tried to call function '. $function); return "Internal error"; } } @@ -240,10 +258,9 @@ $sections = hof_get_allowed_sections(); unset($sections['toc']); foreach ($sections as $section=>$title) { - $function = '_hof_page_section_'.$section; + $function = '_hof_page_section_'. $section; if ($section != 'toc' && $section != 'default' && function_exists($function)) { - $html .= "\n

" . l($title, 'hof/'.$section) . "

\n"; - $html .= "

"; + $html .= "\n

". l($title, 'hof/'. $section) ."

\n"; } } return $html; @@ -258,18 +275,18 @@ if (! variable_get('hof_toc_in_toc', TRUE)) { unset($sections['toc']); } - $mode = variable_get('hof_toc_mode','link'); - $html = '

'; + $mode = variable_get('hof_toc_mode', 'link'); + $html = '

'; switch ($mode) { case 'full': $links = array(); foreach ($sections as $section=>$title) { - $links[] = l($title, 'hof/'.$section); + $links[] = l($title, 'hof/'. $section); } - $html .= '[ ' . implode(' | ',$links) . ' ]'; + $html .= '[ '. implode(' | ', $links) .' ]'; break; default: - $html .= '[ ' . l(t('Hall of Fame Table of Contents'),'hof/toc') . ' ]'; + $html .= '[ '. l(t('Hall of Fame Table of Contents'), 'hof/toc') .' ]'; } $html .= "

\n"; return $html; @@ -283,11 +300,10 @@ $sections = hof_get_allowed_sections(); unset($sections['toc']); // Don't display the TOC as part of the "all" display foreach ($sections as $section=>$title) { - $function = '_hof_page_section_'.$section; + $function = '_hof_page_section_'. $section; if ($section != 'all' && $section != 'default' && function_exists($function)) { - $html .= "\n

" . l($title, 'hof/'.$section) . "

\n"; + $html .= "\n

". l($title, 'hof/'. $section) ."

\n"; $html .= call_user_func($function); - $html .= "

"; } } return $html; @@ -297,65 +313,68 @@ * Site statistics (general summary) */ function _hof_page_section_site() { - $sql="select min(created) from {node} where status=1"; + $sql = "SELECT min(created) FROM {node} where status=1"; $first_tstmp = db_result(db_query($sql)); $founded = format_date($first_tstmp, "long"); - $duration = format_interval(time()-$first_tstmp, 3); - $sql="select count(*) from {node} where type in ('story','webstory') and status=1"; + $duration = format_interval(time() - $first_tstmp, 3); + $sql = "SELECT count(*) FROM {node} where type in ('story', 'webstory') and status=1"; $count = db_result(db_query($sql)); - $html = "