Submitted by Eric Weik on Tue, 07/07/2009 - 21:04.
In cases where your site uses clean urls, and your script exists in a directory outside of the Drupal directory, relative links in your view may not be formatted properly. Relative links passed through Drupal's url() function will include the path to the directory your script exists in (e.g. "node/99" will link to "/path/to/script/node/99") which likely will not work properly.
Here is an updated version of the above script to run a search and replace on such links:
<?php // If Drupal is installed in a subdirectory under DOCUMENT_ROOT, specify it // here in the form /path/to/drupal/ define('DRUPAL_SUBDIR','/content/');
// Change to Drupal root directory chdir($_SERVER["DOCUMENT_ROOT"].DRUPAL_SUBDIR);
// Turn on error reporting during development (turn off for production sites) // error_reporting(E_ALL);
// Bootstrap Drupal
require_once './includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// Views 2 output via views_embed_view() $rawfeed = views_embed_view('recent_blog_posts');
// Replace relative links which may be broken by calls to url() $search = "href=\"{$base_path}"; $replace = "href=\"{$base_root}".DRUPAL_SUBDIR; print str_ireplace($search,$replace,$rawfeed);
// To fetch nodes without views, see use something like: // $results = db_query('select nid from node where type="story"'); // while ($result = db_fetch_object($results)) { // $node = node_load($result->nid); // echo "Debug (node): <pre>";print_r($node);echo "</pre>"; // } ?>
Hello! My name is Eric Weik. I am a computer scientist, photographer, musician, and occasional blogger. New Rivers Digital is my software consulting business. I am dedicated to using open source software and open data standards for Web development and applications integration. In particular, I am an ardent Drupal fan and specialize in Drupal module development, theming, and data architecture integration.
Reply to comment
#1 A Few Updates
Submitted by Eric Weik on Tue, 07/07/2009 - 21:04.
In cases where your site uses clean urls, and your script exists in a directory outside of the Drupal directory, relative links in your view may not be formatted properly. Relative links passed through Drupal's url() function will include the path to the directory your script exists in (e.g. "node/99" will link to "/path/to/script/node/99") which likely will not work properly.
Here is an updated version of the above script to run a search and replace on such links:
<?php// If Drupal is installed in a subdirectory under DOCUMENT_ROOT, specify it
// here in the form /path/to/drupal/
define('DRUPAL_SUBDIR','/content/'); // Change to Drupal root directory
chdir($_SERVER["DOCUMENT_ROOT"].DRUPAL_SUBDIR); // Turn on error reporting during development (turn off for production sites)
// error_reporting(E_ALL);
// Bootstrap Drupal
require_once './includes/bootstrap.inc';drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); // Views 2 output via views_embed_view()
$rawfeed = views_embed_view('recent_blog_posts'); // Replace relative links which may be broken by calls to url()
$search = "href=\"{$base_path}";
$replace = "href=\"{$base_root}".DRUPAL_SUBDIR;
print str_ireplace($search,$replace,$rawfeed); // To fetch nodes without views, see use something like:
// $results = db_query('select nid from node where type="story"');
// while ($result = db_fetch_object($results)) {
// $node = node_load($result->nid);
// echo "Debug (node): <pre>";print_r($node);echo "</pre>";
// }
?>
Reply
About
Hello! My name is Eric Weik. I am a computer scientist, photographer, musician, and occasional blogger. New Rivers Digital is my software consulting business. I am dedicated to using open source software and open data standards for Web development and applications integration. In particular, I am an ardent Drupal fan and specialize in Drupal module development, theming, and data architecture integration.
Contact Details
Lancaster, VA 22503
Content Tags
Abstract B&W Celestial Clouds Drupal 6 Drupal Recipes Drupal Sites Estuary Etsy Government Grasses HDR Long Exposure Macro New Rivers Digital Orton Photoblog Photo Expedition Photoset Renderblog RGB Sketchbook Snow Storm Structure Synth Sunflow Sunset Theming Webform.module Wide Angle Zen Zen ThemingRecent comments
Popular content
Today's:
All time:
Activity Stream
Sun, 01/29/2012 - 22:31
Mon, 01/16/2012 - 10:43
Fri, 01/06/2012 - 07:54
Powered by Drupal & Genesis | Valid XHTML 1.0 Strict |
RSS Feed
© 2010 New Rivers Digital | PO Box 784 | Lancaster, Virginia 22503 | +1-804-577-8526 | Contact Form