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

Contents of /contributions/modules/google_pr/google_pr.module

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


Revision 1.6 - (show annotations) (download) (as text)
Sun May 3 06:54:48 2009 UTC (6 months, 3 weeks ago) by deekayen
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +2 -2 lines
File MIME type: text/x-php
fix access argument callback spelling problem that breaks all access to google_pr except uid 1
1 <?php
2 // $Id: google_pr.module,v 1.5 2008/08/14 12:28:40 deekayen Exp $
3
4 /**
5 * @file
6 * This module provides visitors to your web site a way to find the Google PageRank of sites chosen by them.
7 */
8
9 /**
10 * Implementation of hook_help().
11 */
12 function google_pr_help($path, $args) {
13 switch ($path) {
14 case 'google_pr':
15 return '<p>'. variable_get('google_pr_description', t('<strong>Google PageRank</strong> is a general representation of an internet page\'s popularity; it is primarily based on link popularity. Commonly the websites with a high PageRank value tend to have more traffic and higher positions in search engines (although many other factors are also taken into consideration).')) .'</p>';
16 }
17 }
18
19 /**
20 * Implementation of hook_menu().
21 */
22 function google_pr_menu() {
23 $items = array();
24 $items['admin/settings/google_pr'] = array(
25 'title' => 'Google PageRank',
26 'description' => 'Change how Google PageRank behaves.',
27 'page callback' => 'drupal_get_form',
28 'page arguments' => array('google_pr_admin_settings'),
29 'access callback' => 'user_access',
30 'access arguments' => array('administer site configuration')
31 );
32 $items['google_pr'] = array(
33 'title' => 'Google PageRank',
34 'page callback' => 'google_pr_page',
35 'access callback' => 'user_access',
36 'access arguments' => array('get pagerank'),
37 'weight' => 0
38 );
39 return $items;
40 }
41
42 /**
43 * Define the settings form.
44 */
45 function google_pr_admin_settings() {
46 $form = array();
47
48 $form['google_pr_max'] = array(
49 '#type' => 'select',
50 '#title' => t('Maximum number of simultaneous URL addresses'),
51 '#default_value' => variable_get('google_pr_max', '5'),
52 '#options' => array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'),
53 '#description' => t('This is to prevent abuse of the system.'),
54 );
55
56 $form['google_pr_description'] = array(
57 '#type' => 'textarea',
58 '#title' => t('Description on top of page'),
59 '#default_value' => variable_get('google_pr_description', t('<strong>Google PageRank</strong> is a general representation of an internet page\'s popularity; it is primarily based on link popularity. Commonly the websites with a high PageRank value tend to have more traffic and higher positions in search engines (although many other factors are also taken into consideration).')),
60 '#cols' => 70,
61 '#rows' => 7,
62 '#description' => t('This text will be displayed at the top of the Google PageRank page. You can use HTML code.'),
63 );
64
65 $form['google_pr_watchdog'] = array(
66 '#type' => 'checkbox',
67 '#title' => t('Log all requests for Google PageRank.'),
68 '#default_value' => variable_get('google_pr_watchdog', 0),
69 );
70 return system_settings_form($form);
71 }
72
73 /**
74 * Implementation of hook_perm().
75 */
76 function google_pr_perm() {
77 return array(
78 'get pagerank' => t('Use the query form to request PageRank values from Google.')
79 );
80 }
81
82 // Display the form
83 function google_pr_form() {
84 $form = array();
85 $max = variable_get('google_pr_max', 5);
86 $form['urls'] = array(
87 '#type' => 'textarea',
88 '#title' => t("URLs ($max max)"),
89 '#default_value' => $urls,
90 '#cols' => 50,
91 '#rows' => 5,
92 '#maxlength' => 100,
93 '#description' => t('URLs separated by newline. Example: www.example.com'),
94 );
95
96 $form['#redirect'] = FALSE;
97
98 $form['submit'] = array(
99 '#type' => 'submit',
100 '#value' => t('Get Google PageRank')
101 );
102
103 return $form;
104 }
105
106 /**
107 * Handle post-validation form submission.
108 */
109 function google_pr_form_submit($form, &$form_state) {
110
111 }
112
113 function google_pr_page() {
114 $urls = $_POST['urls'];
115 $urls = explode("\n", $urls);
116 $urls = array_map('trim', $urls);
117 $urls = array_filter($urls, 'strlen');
118 $urls = array_slice($urls, 0, variable_get('google_pr_max', 5));
119 $header = array(t('URL'), t('Google Pagerank'));
120 $rows = array();
121 $path_module = drupal_get_path('module', 'google_pr');
122 $output .= drupal_get_form('google_pr_form', $form_values);
123
124 if ($_POST['op'] == t('Get Google PageRank')) {
125 include_once($path_module .'/PageRankXor32.php');
126 $pagerank_object = new PageRankXor32();
127 foreach ($urls as $url) {
128 $urlpr = google_pr_get($url);
129 $rows[] = array($url, $urlpr);
130 $urls_dog[] = $url .' : '. $urlpr;
131 }
132 $output .= '<p>&nbsp;</p><p>'. theme('table', $header, $rows) .'</p>';
133 if (variable_get('google_pr_watchdog', '0') == 1) {
134 foreach ($urls_dog as $url_dog) {
135 $msg .= $url_dog .'<br />';
136 }
137 watchdog('google_pr', $msg, NULL, WATCHDOG_INFO);
138 }
139
140 }
141 return $output;
142 }
143
144 function google_pr_get($url) {
145 $url = trim($url);
146 $path_module = drupal_get_path('module', 'google_pr');
147 include_once($path_module .'/PageRankXor32.php');
148 $pagerank_object = new PageRankXor32();
149 $result = db_query("SELECT COUNT(pagerank) FROM {google_pr} where url = '%s'", $url);
150 if (db_result($result) == 0) {
151 $urlpr = $pagerank_object->getRank($url);
152 if ($urlpr != '-1') {
153 db_query("INSERT INTO {google_pr} (url, pagerank, timestamp) VALUES ('%s', %d, %d)", $url, $urlpr, time());
154 }
155 }
156 else {
157 $urlpr = db_result(db_query_range("SELECT pagerank FROM {google_pr} where url = '%s'", $url, 0, 1));
158 }
159 return $urlpr != '-1' ? '<img src="'. base_path() . $path_module .'/pr-'. $urlpr .'.gif" width="58" height="28" alt="'. $urlpr .'" />' : t('Not a valid URL');
160 }
161
162 /**
163 * Implementation of hook_requirements().
164 *
165 * Show the pagerank of the current site in the status report.
166 */
167 function google_pr_requirements($phase) {
168 $requirements = array();
169 $t = get_t();
170 if ($phase == 'runtime') {
171 $pr = google_pr_get(url('<front>', array('absolute' => TRUE)));
172 $requirements['google_pr_rank'] = array(
173 'title' => $t('Google Pagerank'),
174 'value' => $pr,
175 'severity' => REQUIREMENT_INFO
176 );
177 }
178 return $requirements;
179 }

  ViewVC Help
Powered by ViewVC 1.1.2