/[drupal]/contributions/modules/phpfreechat/handler.php
ViewVC logotype

Contents of /contributions/modules/phpfreechat/handler.php

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


Revision 1.6 - (show annotations) (download) (as text)
Fri Dec 7 20:22:30 2007 UTC (23 months, 3 weeks ago) by owahab
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +87 -9 lines
File MIME type: text/x-php
Merging from DRUPAL-5
1 <?php
2 // $Id: handler.php,v 1.3.2.10 2007/12/07 19:35:55 owahab Exp $
3
4 // Original implementation of locating Drupal root from dursh module by Moshe Weitzman.
5 define('PHPFREECHAT_DRUPAL_BOOTSTRAP', 'includes/bootstrap.inc');
6
7 /**
8 * Exhaustive depth-first search to try and locate the Drupal root directory.
9 * This makes it possible to run drush from a subdirectory of the drupal root.
10 */
11 function _phpfreechat_locate_root() {
12 $path = getcwd();
13 // Convert windows paths.
14 $path = str_replace('\\','/', $path);
15 // Check the current path.
16 if (file_exists($path . '/' . PHPFREECHAT_DRUPAL_BOOTSTRAP)) {
17 return $path;
18 }
19 // Move up dir by dir and check each.
20 while ($path = _phpfreechat_locate_root_moveup($path)) {
21 if (file_exists($path . '/' . PHPFREECHAT_DRUPAL_BOOTSTRAP)) {
22 return $path;
23 }
24 }
25 return FALSE;
26 }
27
28 function _phpfreechat_locate_root_moveup($path) {
29 if (empty($path)) {
30 return FALSE;
31 }
32 $path = explode('/', $path);
33 // Move one directory up.
34 array_pop($path);
35 return implode($path, '/');
36 }
37
38 /**
39 * Bootstrap Drupal.
40 */
41 // Change to Drupal root dir.
42 chdir(_phpfreechat_locate_root());
43 // Drupal will probably miscalculate the base_url if we're bootstrapping from
44 // handler.php
45 if (!isset($base_url)) {
46 $base_root = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
47 // As $_SERVER['HTTP_HOST'] is user input, ensure it only contains
48 // characters allowed in hostnames.
49 $base_url = $base_root .= '://'. preg_replace('/[^a-z0-9-:._]/i', '', $_SERVER['HTTP_HOST']);
50 // $_SERVER['SCRIPT_NAME'] can, in contrast to $_SERVER['PHP_SELF'], not
51 // be modified by a visitor.
52 // Also use $_SERVER['HTTP_REFERRER'] to correlate with original bootstrap
53 $base_path = explode('/', $_SERVER['HTTP_REFERER']);
54 $script_path = explode('/', $_SERVER['SCRIPT_NAME']);
55 $base_url .= implode('/', array_intersect($base_path, $script_path));
56 }
57 // Bootstrap Drupal.
58 require_once './includes/bootstrap.inc';
59 drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
60 // Initialize configuration variables, using values from settings.php if available.
61 $conf = variable_init(isset($conf) ? $conf : array());
62 // Add file.inc for various file functions used in phpfreechat
63 require_once './includes/file.inc';
64 // Add common.inc to be able to use drupal_get_path later
65 require_once './includes/common.inc';
66 // Add user module to handle user permissions in phpfreechat
67 require_once drupal_get_path('module', 'user') .'/user.module';
68 // Starting phpfreechat module
69 require_once drupal_get_path('module', 'phpfreechat') .'/phpfreechat.module';
70 // Load global params
71 $params = phpfreechat_load_params();
72 // We will need to load the current node
73 if (!function_exists('arg')) {
74 // Use HTTP_REFERER to extract the node ID
75 $path = str_replace(array($base_url .'/', '/?q='), '', $_SERVER['HTTP_REFERER']);
76 // Get the real path from the current request
77 require_once './includes/path.inc';
78 $args = explode('/', drupal_get_normal_path($path));
79 $node = db_fetch_object(db_query('SELECT * FROM {node} n INNER JOIN {phpfreechat} pfc ON pfc.nid = n.nid WHERE n.nid = %d', $args[1]));
80 if ($_SESSION['drupal_user']) {
81 $user =& $_SESSION['drupal_user'];
82 }
83 }
84 // Prepare params for current node
85 $params = phpfreechat_prepare_params($params, $node, $user);
86 // Start/resume a chat room
87 require_once drupal_get_path('module', 'phpfreechat') .'/phpfreechat/src/phpfreechat.class.php';
88 $chat = new phpFreeChat($params);
89 ?>

  ViewVC Help
Powered by ViewVC 1.1.2