Index: contribs/weblinks_checker/weblinks_checker.admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/weblinks/contribs/weblinks_checker/weblinks_checker.admin.inc,v retrieving revision 1.1.2.13 diff -u -r1.1.2.13 weblinks_checker.admin.inc --- contribs/weblinks_checker/weblinks_checker.admin.inc 31 Aug 2009 18:57:03 -0000 1.1.2.13 +++ contribs/weblinks_checker/weblinks_checker.admin.inc 17 Sep 2009 14:05:16 -0000 @@ -25,27 +25,27 @@ '#options' => array(1 => t('Yes'), 0 => t('No'), 2 => t('Warn')), '#description' => t('This check is performed at link creation time. Most users will not want to allow duplicate URLs.'), '#prefix' => '
', + '#suffix' => '', ); $form['weblinks_validate_check'] = array( '#type' => 'radios', '#options' => $yesno, - '#prefix' => '', '#title' => t('Check if link is valid when entered'), '#default_value' => (int) variable_get('weblinks_validate_check', FALSE), '#description' => t('If enabled, the module will attempt to use the URL to contact the site when the link is created or updated. If the link returns any error, the add/update will fail.'), + '#prefix' => '', ); $form['weblinks_checker_enabled'] = array( '#type' => 'radios', '#options' => $yesno, - '#prefix' => '', '#title' => t('Enable link validity checker'), '#description' => t('Do you want to check the links on a schedule?'), '#default_value' => (int) variable_get('weblinks_checker_enabled', FALSE), + '#prefix' => '', ); $form['basic'] = array( Index: contribs/weblinks_checker/weblinks_checker.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/weblinks/contribs/weblinks_checker/weblinks_checker.install,v retrieving revision 1.1.2.5 diff -u -r1.1.2.5 weblinks_checker.install --- contribs/weblinks_checker/weblinks_checker.install 3 Aug 2009 15:16:13 -0000 1.1.2.5 +++ contribs/weblinks_checker/weblinks_checker.install 17 Sep 2009 00:31:58 -0000 @@ -18,6 +18,25 @@ } /** + * Implementation of hook_update_N(). + * Fix url. http://drupal.org/node/575512 + */ +function weblinks_checker_update_6001() { + $ret = array(); + + $result = db_query("SELECT nid, vid, url FROM {weblinks} GROUP BY nid ORDER BY nid ASC, vid DESC"); + while ($row = db_fetch_object($result)) { + $new = rawurldecode(_weblinks_checker_fix_url($row->url)); + if ($new != $row->url) { + $urlhash = md5($new); + $ret[] = update_sql("UPDATE {weblinks} SET url='$new', urlhash='$urlhash' WHERE nid=$row->nid AND vid=$row->vid"); + } + } + + return $ret; +} + +/** * Implementation of hook_uninstall(). */ function weblinks_checker_uninstall() { Index: contribs/weblinks_checker/weblinks_checker.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/weblinks/contribs/weblinks_checker/weblinks_checker.module,v retrieving revision 1.1.2.16 diff -u -r1.1.2.16 weblinks_checker.module --- contribs/weblinks_checker/weblinks_checker.module 16 Sep 2009 15:33:04 -0000 1.1.2.16 +++ contribs/weblinks_checker/weblinks_checker.module 17 Sep 2009 14:08:36 -0000 @@ -137,12 +137,13 @@ /** * Implementation of hook_form_alter(). - * Adds validation to the node add/edit form. + * Adds validation and submit to the node add/edit form. */ function weblinks_checker_form_alter(&$form, $form_state, $form_id) { if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) { if ($form['type']['#value'] == 'weblinks') { $form['#validate'][] = 'weblinks_checker_validate'; + $form['#submit'][] = 'weblinks_checker_submit'; } } } @@ -155,20 +156,16 @@ return ''; } - // This is needed for WYSIWYG editors. - $url = strip_tags(trim($form_state['values']['url'])); - - // Note that we have to try to bypass a core bug in valid_url(). See http://drupal.org/node/295021. - $y = parse_url($url); - $new = ($y['scheme'] ? $y['scheme'] .'://' : NULL) . $y['host'] . $y['path'] . ($y['query'] ? '&'. rawurlencode($y['query']) : NULL); + $new = _weblinks_checker_fix_url($form_state['values']['url']); if (!valid_url($new, TRUE)) { form_set_error('url', t('"@url" does not look like a valid URL.', array('@url' => $new))); } $allow_dupes = variable_get('weblinks_allow_dupes', FALSE); if ($allow_dupes != 1) { - $urlhash = md5($url); - $url_exists_nid = db_result(db_query("SELECT nid FROM {weblinks} l WHERE l.urlhash='%s' AND l.url='%s'", $urlhash, $url)); + // See if this url is already in the database. + $urlhash = md5($new); + $url_exists_nid = db_result(db_query("SELECT nid FROM {weblinks} l WHERE l.urlhash='%s' AND l.url='%s'", $urlhash, $new)); if ($url_exists_nid) { if ($form['#node']->nid != $url_exists_nid) { if (!$allow_dupes) { @@ -201,6 +198,31 @@ } /** + * Helper function for URLs. + */ +function _weblinks_checker_fix_url($url) { + // This is needed for WYSIWYG editors. + $url = strip_tags(trim($url)); + + // Note that we have to try to bypass a core bug in valid_url(). See http://drupal.org/node/295021. + $y = parse_url($url); + return ($y['scheme'] ? $y['scheme'] .'://' : NULL) + . $y['host'] + . ($y['port'] ? (':'. $y['port']) : '') + . ($y['path'] ? '' : '/') + . $y['path'] + . ($y['query'] ? '?'. rawurlencode($y['query']) : NULL); +} + +/** + * Implementation of hook_submit(). + * This function corrects the URL before it gets saved. + */ +function weblinks_checker_submit($form, &$form_state) { + $form_state['values']['url'] = rawurldecode(_weblinks_checker_fix_url($form_state['values']['url'])); +} + +/** * Implementation of hook_nodeapi(). */ function weblinks_checker_nodeapi(&$node, $op, $a3, $a4) { Index: weblinks_node_view.tpl.php =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/weblinks/weblinks_node_view.tpl.php,v retrieving revision 1.5.2.7.2.4 diff -u -r1.5.2.7.2.4 weblinks_node_view.tpl.php --- weblinks_node_view.tpl.php 30 Apr 2009 17:11:42 -0000 1.5.2.7.2.4 +++ weblinks_node_view.tpl.php 16 Sep 2009 23:32:44 -0000 @@ -14,8 +14,10 @@ switch (variable_get('weblinks_view_as', 'url')) { case 'url': if (variable_get('weblinks_strip', FALSE)) { + // Note this also strips a port. $parts = parse_url($node->url); - $url = str_replace('www.', '', $parts['host']) . $parts['path']; + $parts['host'] = str_replace('www.', '', $parts['host']); + $url = $parts['host'] . ($parts['path'] == '/' ? '' : $parts['path']); } else { $url = $node->url;