/[drupal]/contributions/modules/social_statistics/social_statistics.module
ViewVC logotype

Contents of /contributions/modules/social_statistics/social_statistics.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Fri May 11 16:37:40 2007 UTC (2 years, 6 months ago) by njt1982
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
File MIME type: text/x-php
Initial commit of Social Statistics
1 <?php
2 // $Id: $
3
4 /**
5 * Implementation of hook_help().
6 */
7 function social_statistics_help($section) {
8 switch ($section) {
9 case 'admin/modules#description':
10 $output = t("Provides statistics about any given URL for a set of 'Web 2.0' websites.");
11 break;
12 case 'admin/help#social_statistics':
13 $output = t('<p>Provides statistics from pluggable modules which access Web 2.0 sites such as Del.icio.us and Digg and gather statistics about the current URL.</p>');
14 break;
15 case 'admin/settings/social-statistics':
16 $output = t('Use this page to configure all your Social Statistics Settings.');
17 }
18 return $output;
19 }
20
21
22 /*
23 * Implementation of hook_block()
24 */
25 function social_statistics_block($op = 'list', $delta = 0, $edit = array()) {
26 switch($op) {
27 case 'list' :
28 $blocks[0] = array(
29 'info' => t('Social Statstics'),
30 'weight' => 0,
31 'enabled' => 1,
32 'region' => 'left');
33 return $blocks;
34 case 'view' :
35 $url = social_statistics_current_url();
36
37 drupal_add_css(drupal_get_path('module', 'social_statistics') . '/social_statistics.css');
38 drupal_add_js("var ss_url = " . drupal_to_js($url) . ";", 'inline');
39 drupal_add_js(drupal_get_path('module', 'social_statistics') .'/social_statistics.js');
40
41 $block_results = module_invoke_all('social_stats_api', 'view', $url);
42
43 $block_contents = implode("\n\n", $block_results);
44 $block_contents .= "\n<div style=\"clear: both;\"><!-- --></div>\n\n";
45
46 return array(
47 'title' => t('Social Statistics'),
48 'content' => $block_contents,
49 );
50 }
51 }
52
53
54 /*
55 * Implementation of hook_menu()
56 */
57 function social_statistics_menu($may_cache) {
58 $items = array();
59
60 if(!$may_cache) {
61 $items[] = array(
62 'type' => MENU_CALLBACK,
63 'path' => 'social_statistics/block/'.arg(2),
64 'callback' => 'social_statistics_generate',
65 'callback arguments' => array(arg(2), $_POST['url']),
66 'access' => TRUE,
67 );
68 $items[] = array(
69 'path' => 'admin/settings/social-statistics',
70 'title' => t('Social Statistics'),
71 'description' => t('Control settings such as cache time for social statistics.'),
72 'callback' => 'drupal_get_form',
73 'callback arguments' => array('social_statistics_admin_settings'),
74 'access' => user_access('administer site configuration'),
75 'type' => MENU_NORMAL_ITEM,
76 );
77 }
78
79 return $items;
80 }
81
82
83
84 /*
85 * This function simply "returns" a number on a blank page. This used for the AHAH callback.
86 */
87 function social_statistics_generate($module, $url = NULL) {
88 echo module_invoke($module, 'social_stats_api', 'count', $url);
89 exit();
90 }
91
92
93
94 /*
95 * Admin Settings page - also uses social_statistics API to get any settings each module NEEDS.
96 */
97 function social_statistics_admin_settings() {
98 //Get the settings (for default values)
99 $settings = variable_get('social_statistics', array());
100
101 //Need to tree the form so all settings go in one entry in the table
102 $form['social_statistics'] = array(
103 '#tree' => TRUE,
104 '#type' => 'fieldset',
105 '#title' => t('Social Statistic Settings'),
106 );
107
108 //Core form element - cache time!
109 $form['social_statistics']['cache_time'] = array(
110 '#title' => t('Cache period'),
111 '#description' => t('<em><a href="http://api.drupal.org/api/5/constant/CACHE_TEMPORARY">CACHE_TEMPORARY</a></em> will cache something until the cache is flushed. <em><a href="http://api.drupal.org/api/5/constant/CACHE_PERMANENT">CACHE_PERMANENT</a></em> will cache something until drupal explicitly tells it to be removed. If you set a time, then the item will be cached for that long at which point it takes the role of CACHE_TEMPORARY.'),
112 '#default_value' => $settings['cache_time'],
113 '#type' => 'select',
114 '#options' => array(
115 CACHE_PERMANENT => t('Permenently Cache'),
116 CACHE_TEMPORARY => t('Temporarily Cache'),
117 60 => t('1 Minute'),
118 3600 => t('1 Hour'),
119 7200 => t('2 Hours'),
120 10800 => t('3 Hours'),
121 21600 => t('6 Hours'),
122 43200 => t('12 Hours'),
123 86400 => t('1 Day'),
124 604800 => t('1 Week'),
125 ),
126 );
127
128 //Now merge in any other settings.
129 $other_forms = module_invoke_all('social_stats_api', 'settings');
130
131 $form['social_statistics'] = array_merge($form['social_statistics'], $other_forms);
132
133 return system_settings_form($form);
134 }
135
136
137
138 /*
139 * Code to get the current URL
140 * 'borrowed' from: http://www.webcheatsheet.com/php/get_current_page_url.php
141 */
142 function social_statistics_current_url() {
143 $pageURL = 'http';
144
145 if ($_SERVER["HTTPS"] == 'on') {
146 $pageURL .= 's';
147 }
148
149 $pageURL .= '://';
150
151 if ($_SERVER['SERVER_PORT'] != '80') {
152 $pageURL .= $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'];
153 } else {
154 $pageURL .= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
155 }
156
157 return $pageURL;
158 }
159
160
161
162 /*
163 * Theme a stat entry - each stat has an image, title/link and a counter
164 */
165 function theme_social_statistic($img, $title, $stat) {
166 $output = "<div class=\"img\">{$img}</div><div class=\"title\">{$title}</div><div class=\"stat\">{$stat}</div>\n";
167 return $output;
168 }
169
170
171
172 /*
173 * Theme function for a ajax loading image.
174 */
175 function theme_social_statistics_loading() {
176 return theme('image', drupal_get_path('module', 'social_statistics') .'/ajax-loader.gif', 'Loading');
177 }

  ViewVC Help
Powered by ViewVC 1.1.2