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

Contents of /contributions/modules/urllist/urllist.module

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


Revision 1.17 - (show annotations) (download) (as text)
Thu Mar 5 01:55:35 2009 UTC (8 months, 3 weeks ago) by deekayen
Branch: MAIN
Changes since 1.16: +41 -37 lines
File MIME type: text/x-php
updates to support Drupal 7
1 <?php
2 // $Id: urllist.module,v 1.16 2009/01/13 05:08:06 deekayen Exp $
3
4 /**
5 * @file
6 * Creates a list of URLs for search engines to index.
7 *
8 * @version $Id: urllist.module,v 1.16 2009/01/13 05:08:06 deekayen Exp $
9 * @author David Kent Norman
10 * @link http://deekayen.net/
11 */
12
13 /**
14 * Implementation of hook_menu().
15 *
16 * @return array
17 */
18 function urllist_menu() {
19 $items = array();
20
21 $items['urllist.txt'] = array(
22 'page callback' => 'theme',
23 'page arguments' => array('urllist'),
24 'type' => MENU_CALLBACK,
25 'access callback' => 'user_access',
26 'access arguments' => array('access content')
27 );
28 $items['urllist'] = array(
29 'page callback' => 'theme',
30 'page arguments' => array('urllist'),
31 'type' => MENU_CALLBACK,
32 'access callback' => 'user_access',
33 'access arguments' => array('access content')
34 );
35 $items['admin/settings/urllist'] = array(
36 'title' => 'URL list',
37 'description' => 'Toggle access log for URL list and edit Yahoo! API information.',
38 'page callback' => 'drupal_get_form',
39 'page arguments' => array('urllist_admin_settings'),
40 'access callback' => 'user_access',
41 'access arguments' => array('administer site configuration'),
42 'type' => MENU_NORMAL_ITEM
43 );
44
45 /* since this would get skipped on during the module install
46 a _submit() hook was added to the settings form to force
47 a menu rebuild so this can be captured if a Yahoo verification
48 URL was added. */
49 if ($yahoo_link = variable_get('urllist_yahoo_auth_link', '')) {
50 $items[$yahoo_link] = array(
51 'title' => 'Yahoo! authentication',
52 'page callback' => 'urllist_verify_yahoo',
53 'type' => MENU_CALLBACK,
54 'access callback' => 'user_access',
55 'access arguments' => array('access content')
56 );
57 }
58
59 return $items;
60 }
61
62 /**
63 * Implementation of hook_settings().
64 *
65 * @return array
66 */
67 function urllist_admin_settings() {
68 $form = array();
69 $form['urllist_logacc'] = array(
70 '#type' => 'checkbox',
71 '#title' => 'Log accesses',
72 '#default_value' => variable_get('urllist_logacc', 0),
73 '#description' => t('If enabled, a watchdog entry will be made each time the URL list is accessed, containing information about the requestor.')
74 );
75 $form['url_submit_yahoo'] = array(
76 '#type' => 'fieldset',
77 '#title' => t('Yahoo! Update Notification API'),
78 '#collapsible' => TRUE,
79 '#collapsed' => TRUE,
80 '#description' => t('The Yahoo! Update Notification service requires a <strong>generic</strong> application ID, which can be obtained from applying for one at <a href="https://developer.yahoo.com/wsregapp/index.php">https://developer.yahoo.com/wsregapp/index.php</a>.')
81 );
82 $form['url_submit_yahoo']['urllist_yahoo_submit'] = array(
83 '#type' => 'checkbox',
84 '#title' => t('Submit URL list when updated'),
85 '#return_value' => 1,
86 '#default_value' => variable_get('urllist_yahoo_submit', 0),
87 '#description' => t('If enabled, the sitemap will be submitted to Yahoo! via HTTP request each time it is updated.'),
88 );
89 $form['url_submit_yahoo']['urllist_yahoo_cron_submit'] = array(
90 '#type' => 'checkbox',
91 '#title' => t('Submit URL list on cron runs'),
92 '#return_value' => 1,
93 '#default_value' => variable_get('urllist_yahoo_cron_submit', 0),
94 '#description' => t('If enabled, the sitemap will be submitted to Yahoo! via HTTP request each time the cron job is run.'),
95 );
96 $form['url_submit_yahoo']['urllist_yahoo_rss_submit'] = array(
97 '#type' => 'checkbox',
98 '#title' => t('Submit RSS feed'),
99 '#return_value' => 1,
100 '#default_value' => variable_get('urllist_yahoo_rss_submit', 0),
101 '#description' => t('If enabled, the front page RSS feed will be submitted to Yahoo! via HTTP along with the URL list'),
102 );
103 $form['url_submit_yahoo']['urllist_yahoo_appid'] = array(
104 '#type' => 'textfield',
105 '#title' => t('Yahoo! application ID'),
106 '#return value' => '',
107 '#default_value' => variable_get('urllist_yahoo_appid', '')
108 );
109 $form['auth'] = array(
110 '#type' => 'fieldset',
111 '#title' => t('Yahoo! Site Explorer Authentication'),
112 '#collapsible' => TRUE,
113 '#collapsed' => TRUE,
114 '#description' => l('Yahoo! Site Explorer', 'https://siteexplorer.search.yahoo.com/')
115 );
116 $form['auth']['urllist_yahoo_auth_link'] = array(
117 '#type' => 'textfield',
118 '#title' => t('Authentication file name'),
119 '#return value' => '',
120 '#default_value' => variable_get('urllist_yahoo_auth_link', ''),
121 '#description' => t('In order to view stats, Yahoo! will ask you to verify that you control this site by creating a page with a certain name. Enter that name here and the urllist module will hook that filename. Note that this will only work if you have clean URLs enabled.'),
122 );
123 $form['auth']['urllist_yahoo_auth_content'] = array(
124 '#type' => 'textfield',
125 '#title' => t('Authentication file content'),
126 '#return value' => '',
127 '#default_value' => variable_get('urllist_yahoo_auth_content', ''),
128 '#description' => t('The authentication file has a specific string of random characters Yahoo! will look for inside the above file name when it revalidates your site ownership.'),
129 );
130
131 /* While it is cleaner in the code to just add the extra
132 submit handler first and return system_settings_form($form),
133 the system_settings_form() information needs to be first
134 so the information is saved to the urllist_yahoo_auth_link
135 variable before menu_rebuild() is called so hook_menu() can
136 add it to the menu tables in the database since hook_menu()
137 is no longer called on every page load as of Drupal 6. */
138 $form = system_settings_form($form);
139 $form['#submit'][] = 'urllist_admin_settings_submit';
140
141 return $form;
142 }
143
144 /**
145 * Capture any Yahoo! verification link URLs so
146 * the menu can know to react to them when requested.
147 */
148 function urllist_admin_settings_submit() {
149 menu_rebuild();
150 drupal_set_message(t('The URL List module re-built the menu information to check for a URL for Yahoo! authentication.'), 'status');
151 }
152
153 /**
154 * Implmentation of hook_nodeapi_insert().
155 */
156 function urllist_nodeapi_insert(&$node, $teaser = NULL, $page = NULL) {
157 if (variable_get('urllist_yahoo_submit', 0) && $node->status) {
158 watchdog('urllist', "Submitting URL list to Yahoo! because node %node_id was inserted or deleted.", array('%node_id' => $node->nid), WATCHDOG_DEBUG);
159 _urllist_submit_yahoo();
160 }
161 }
162
163 /**
164 * Implmentation of hook_nodeapi_delete().
165 */
166 function urllist_nodeapi_delete(&$node, $teaser = NULL, $page = NULL) {
167 urllist_nodeapi_insert($node, $teaser, $page);
168 }
169
170 /**
171 * Implmentation of hook_nodeapi_update().
172 */
173 function urllist_nodeapi_update(&$node, $teaser = NULL, $page = NULL) {
174 if (variable_get('urllist_yahoo_submit', 0) && ($node->status || $oldnode->status)) {
175 watchdog('urllist', "Submitting URL list to Yahoo! because node %node_id was updated.", array('%node_id' => $node->nid), WATCHDOG_DEBUG);
176 _urllist_submit_yahoo();
177 }
178 }
179
180 function urllist_cron() {
181 if (variable_get('urllist_yahoo_cron_submit', 0)) {
182 watchdog('urllist', 'Submitting URL list to Yahoo! from cron job.', NULL, WATCHDOG_DEBUG);
183 _urllist_submit_yahoo();
184 }
185 }
186
187 /**
188 * Print list of URLs in plaintext format
189 */
190 function theme_urllist() {
191 if (!ini_get('safe_mode')) {
192 set_time_limit(240);
193 }
194 header('Content-type: text/plain');
195 print url('', array('absolute' => TRUE)) . "\n";
196 $result = db_query("SELECT n.nid, n.type, n.status, n.promote, n.changed, u.dst FROM {node} n LEFT JOIN {url_alias} u ON u.src=CONCAT('node/',CAST(n.nid as CHAR))");
197 while ($node = $result->fetchObject()) {
198 if ($node->status) { // add check for if the node type is disabled or not
199 if (isset($node->dst)) { // alias is named
200 print url($node->dst, array('absolute' => TRUE)) . "\n";
201 }
202 else {
203 print url('node/' . $node->nid, array('absolute' => TRUE)) . "\n";
204 }
205 }
206 }
207 if (module_exists('taxonomy')) {
208 $result = db_query('SELECT d.tid FROM {taxonomy_term_data} d');
209 while ($topic = $result->fetchObject()) {
210 print url('taxonomy/term/' . $topic->tid, array('absolute' => TRUE)) . "\n";
211 }
212 }
213 if (module_exists('search')) {
214 print url('search', array('absolute' => TRUE)) . "\n";
215 }
216 if (module_exists('image')) {
217 print url('image', array('absolute' => TRUE)) . "\n";
218 }
219 if (module_exists('randomizer')) {
220 print url('randomizer', array('absolute' => TRUE)) . "\n";
221 }
222 if (module_exists('blog')) {
223 print url('blog', array('absolute' => TRUE)) . "\n";
224 }
225 if (variable_get('urllist_logacc', 0)) {
226 watchdog('urllist', 'URL list downloaded by ' . getenv('HTTP_USER_AGENT') . ' at ' . getenv('REMOTE_ADDR') . '.', NULL, WATCHDOG_INFO);
227 }
228 }
229
230 /**
231 * Prints a string for Yahoo Site Explorer authentication
232 */
233 function urllist_verify_yahoo() {
234 die(variable_get('urllist_yahoo_auth_content', ''));
235 }
236
237 /**
238 * Submits the urllist to Yahoo Site Explorer
239 * Requires a generic Yahoo! Developer Network Appid
240 *
241 * @link https://developer.yahoo.com/wsregapp/index.php
242 * @link https://developer.yahoo.com/wsregapp/index.php?view
243 */
244 function _urllist_submit_yahoo() {
245 $result = drupal_http_request('http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=' . variable_get('urllist_yahoo_appid', '') . '&url=' . url('urllist.txt', array('absolute' => TRUE)));
246 if ($result->code == 200) {
247 watchdog('urllist', 'URL list successfully submitted to Yahoo!', NULL, WATCHDOG_INFO);
248 }
249 else {
250 watchdog('urllist', 'Error occurred submitting URL list to Yahoo!: @code: @data', array('@code' => $result->code, '@data' => $result->data), WATCHDOG_ERROR);
251 }
252 if (variable_get('urllist_yahoo_rss_submit', 0)) {
253 $result = drupal_http_request('http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=' . variable_get('urllist_yahoo_appid', '') . '&url=' . url('rss.xml', array('absolute' => TRUE)));
254 if ($result->code == 200) {
255 watchdog('urllist', 'RSS feed successfully submitted to Yahoo!.', NULL, WATCHDOG_INFO);
256 }
257 else {
258 watchdog('urllist', 'Error occurred submitting RSS feed to Yahoo!: @code: @data', array('@code' => $result->code, '@data' => $result->data), WATCHDOG_ERROR);
259 }
260 }
261 }
262
263 /**
264 * Implementation of hook_theme().
265 *
266 * @return array
267 */
268 function urllist_theme() {
269 return array(
270 'urllist' => array()
271 );
272 }

  ViewVC Help
Powered by ViewVC 1.1.2