? port_6_beginning_not_working_1,patch
? port_6_beginning_not_working_1.patch
Index: path_image.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/path_image/path_image.info,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 path_image.info
--- path_image.info	30 Oct 2006 11:40:34 -0000	1.1.2.1
+++ path_image.info	29 Dec 2008 23:07:54 -0000
@@ -1,2 +1,4 @@
+; $Id$
 name = path_image
 description = A module to provide an image file within a block dependant upon the Drupal path
+core = 6.x
Index: path_image.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/path_image/path_image.install,v
retrieving revision 1.2.2.1
diff -u -p -r1.2.2.1 path_image.install
--- path_image.install	8 Jan 2007 23:15:46 -0000	1.2.2.1
+++ path_image.install	29 Dec 2008 23:07:54 -0000
@@ -5,31 +5,53 @@
  * @file
  */
 
+/**
+ * Implementation of hook_install().
+ */
 function path_image_install() {
-  global $db_type;
-
-  switch ($db_type) {
-    case 'mysql':
-    case 'mysqli':
-      db_query("CREATE TABLE IF NOT EXISTS {path_image_data} (".
-               "pid INT(10) NOT NULL,".
-               "path VARCHAR(128) NOT NULL,".
-               "image_file VARCHAR(32) NOT NULL,".
-               "PRIMARY KEY(pid),".
-               "INDEX(path(32)))");
-      break;
-    case 'pgsql':
-      db_query("CREATE TABLE {path_image_data} (".
-               "pid INT(10) NOT NULL,".
-               "path VARCHAR(128) NOT NULL,".
-               "image_file VARCHAR(32) NOT NULL,".
-               "PRIMARY KEY(pid))");
-      db_query("CREATE INDEX {path_image_data}_path_idx ON {path_image_data} (path)");
-               
-      break;
-  }
+  drupal_install_schema('path_image');
 
   db_query('update system set weight=5 WHERE name="path_image"');
 }
 
+/**
+ * Implementation of hook_uninstall().
+ */
+function path_image_uninstall() {
+  drupal_uninstall_schema('path_image');
+}
+
+/**
+ * Implementation of hook_schema().
+ */
+function path_image_schema() {
+  $schema['path_image_data'] = array(
+    'description' => t('Table for storing images by path'),
+    'fields' => array(
+      'pid' => array(
+        'description' => t('path image id'),
+        'type' => 'serial',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+      ),
+      'path' => array(
+        'description' => t('path image path'),
+        'type' => 'varchar',
+        'length' => 128,
+        'not null' => TRUE,
+      ),
+      'image_file' => array(
+        'description' => t('path image filepath'),
+        'type' => 'varchar',
+        'length' => 32,
+        'not null' => TRUE,
+      ),
+    ),
+    'indexes' => array(
+      'path' => array('path'),
+    ),
+    'primary key' => array('pid'),
+  );
 
+  return $schema;
+}
Index: path_image.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/path_image/path_image.module,v
retrieving revision 1.4.2.4
diff -u -p -r1.4.2.4 path_image.module
--- path_image.module	8 Jan 2007 23:15:46 -0000	1.4.2.4
+++ path_image.module	29 Dec 2008 23:07:55 -0000
@@ -46,10 +46,10 @@ function path_image_perm() {
 /**
  * Implementation of hook_help()
  */
-function path_image_help($section) {
-  _path_image_debug("path_image_help('$section')");
+function path_image_help($path, $args) {
+  _path_image_debug("path_image_help('$path')");
   
-  switch ($section) {
+  switch ($path) {
     case 'admin/modules#description':
       return t('Provides an block containing an image dependent upon the URL path');
   }
@@ -58,46 +58,60 @@ function path_image_help($section) {
 }
 
 /**
+ * Implementation of hook_theme().
+ */
+function path_image_theme() {
+  return array(
+    'path_image_form_wrapper' => array(
+      'arguments' => array(
+       'arg' => NULL,
+       'params' => array(),
+      ),
+    ),
+    'path_image_block_0' => array(
+      'arguments' => array(
+        'params' => NULL,
+      ),
+    ),
+  );
+}
+
+/**
  * Implementation of hook_menu()
  */
-function path_image_menu($may_cache) {
+function path_image_menu() {
 
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/settings/path_image',
-      'title' => t('Path image'),
-      'access' => user_access('Path image admin'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => '_path_image_settings_form',
-      'description' => t('Provides an block containing an image dependent upon the URL path'),
-      'type' => MENU_NORMAL_ITEM
-    );
-  }
+  $items['admin/settings/path_image'] = array(
+    'title' => 'Path image',
+    'access arguments' => array('Path image admin'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('_path_image_settings_form'),
+    'description' => 'Provides an block containing an image dependent upon the URL path',
+    'type' => MENU_NORMAL_ITEM
+  );
   
   return $items;
 }
 
 /**
- * Implementation of hook_form_alter()
+ * Implementation of hook_form_[block_admin_configure]_alter()
  */
-function path_image_form_alter($form_id, &$form) {
-  _path_image_debug("path_image_form_alter('$form_id')");
+function path_image_form_block_admin_configure_alter(&$form, $form_state) {
+  _path_image_debug("path_image_form_alter('block_admin_configure')");
   
-  if ('block_admin_configure' == $form_id) {
     if (isset($form['module']['#value']) && 'path_image' == $form['module']['#value']) {
-      $form['path_image'] = array(
-        '#type' => 'fieldset',
-        '#title' => t('Block content set-up'),
-        '#collapsible' => TRUE,
-        '#weight' => -100
-      );
-      $form['path_image']['markup_help'] = array(
-        '#type' => 'markup',
-        '#value' => t('This section allows you to control the block\'s visibility. '.
-                      'To administer the block\'s content please visit the block\'s '.
-                      l('administration section', 'admin/settings/path_image'))
-      );  
-    }
+    $form['path_image'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Block content set-up'),
+      '#collapsible' => TRUE,
+      '#weight' => -100
+    );
+    $form['path_image']['markup_help'] = array(
+      '#type' => 'markup',
+      '#value' => t('This section allows you to control the block\'s visibility. '.
+                    'To administer the block\'s content please visit the block\'s '.
+                    l('administration section', 'admin/settings/path_image'))
+    );  
   }
 }
 
@@ -174,7 +188,7 @@ function _path_image_block_main() {
   // for the first numeric component... REDIRECT_URL
   // $path_parts = explode('/', drupal_get_path_alias($_GET['q']));
   
-  $path = trim($_SERVER['REDIRECT_URL'], '/');
+  $path = trim($_SERVER['REDIRECT_URI'], '/');
   
   if (!strlen($path) || strpos(drupal_set_header(), '403 Forbidden')) {
       if (variable_get('path_image_homepage_use', 0)) {
@@ -219,6 +233,7 @@ function _path_image_block_main() {
  
     // now we can search the database for possible matches
     foreach ($search_paths as $path) {
+      dsm($path);
       $sql = 'SELECT image_file, LENGTH(path) AS path_len '.
              'FROM {path_image_data} '.
              'WHERE path LIKE "%s%%" '.
@@ -227,9 +242,10 @@ function _path_image_block_main() {
       _path_image_expand_sql($sql, $path);
     
       $r = db_query($sql, $path);
-      if (db_num_rows($r)) {
+
+      // get just the first match if multiple return (see ORDER BY)
+      if ($row = db_fetch_array($r)) {
         // we have a match!
-        $row = db_fetch_array($r); // get just the first match if multiple return (see ORDER BY)
         $params = array(
           'image_file' => $row['image_file'],
           'image_repos' => variable_get('path_image_repository', 'files/images'),
@@ -431,58 +447,55 @@ function _path_image_settings_form() {
 
   $sql = 'SELECT * FROM {path_image_data} ORDER BY path ASC';
   $result = db_query($sql);
-  $num_of_rows = db_num_rows($result);
-  if ($num_of_rows > 0) {
-    $form['path_image']['existing_entries'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Existing path %x', array('%x' => format_plural($num_of_rows, 'entry', 'entries'))),
-      '#tree' => TRUE,  
-    );
-    $row_counter = 0;
-    while ($row = db_fetch_object($result)) {
-      if (count($files)) {
-        $form['path_image']['existing_entries'][$row_counter]['pid'] = array(
-          '#type' => 'hidden',
-          '#default_value' => $row->pid,
-        );
-        $form['path_image']['existing_entries'][$row_counter]['path'] = array(
-          '#type' => 'textfield',
-          '#title' => t('Alter a path'),
-          '#default_value' => $row->path,
-          '#size' => 50,
-          '#description' => t('Amend the path. <em>Note, no leading / (slash)</em>'),
-          '#prefix' => theme('path_image_form_wrapper', 'cell_first_prefix', array('cell' => array('valign' => 'top'))), 
-          '#suffix' => theme('path_image_form_wrapper', 'cell_first_suffix')         
-        );
-        $form['path_image']['existing_entries'][$row_counter]['image_file'] = array(
-          '#type' => 'select',
-          '#title' => t('Select an image'),
-          '#default_value' => $row->image_file,
-          '#options' => $files,
-          '#prefix' => theme('path_image_form_wrapper', 'cell_middle_prefix', array('cell' => array('valign' => 'top'))),
-          '#suffix' => theme('path_image_form_wrapper', 'cell_middle_suffix')        
-        );    
-        $form['path_image']['existing_entries'][$row_counter]['delete'] = array(
-          '#type' => 'checkbox',
-          '#title' => t('Delete'),
-          '#prefix' => theme('path_image_form_wrapper', 'cell_last_prefix', array('cell' => array('valign' => 'middle'))), 
-          '#suffix' => theme('path_image_form_wrapper', 'cell_last_suffix')            
-        );    
-      }
-      else {
-        $form['path_image']['existing_entries'][$row_counter]['path_markup'] = array(
-          '#type' => 'markup',
-          '#value' => check_plain($row->path),
-          '#suffix' => '&nbsp; -- &nbsp;'    
-        );      
-        $form['path_image']['existing_entries'][$row_counter]['image_file_markup'] = array(
-          '#type' => 'markup',
-          '#value' => t('No files available for selection'),
-          '#suffix' => theme('path_image_form_wrapper', 'new_line')
-        );
-      }
-      $row_counter++;
+  $row_counter = 0;
+  while ($row = db_fetch_object($result)) {
+    if (count($files)) {
+      $form['path_image']['existing_entries'][$row_counter]['pid'] = array(
+        '#type' => 'hidden',
+        '#default_value' => $row->pid,
+      );
+      $form['path_image']['existing_entries'][$row_counter]['path'] = array(
+        '#type' => 'textfield',
+        '#title' => t('Alter a path'),
+        '#default_value' => $row->path,
+        '#size' => 50,
+        '#description' => t('Amend the path. <em>Note, no leading / (slash)</em>'),
+        '#prefix' => theme('path_image_form_wrapper', 'cell_first_prefix', array('cell' => array('valign' => 'top'))), 
+        '#suffix' => theme('path_image_form_wrapper', 'cell_first_suffix')         
+      );
+      $form['path_image']['existing_entries'][$row_counter]['image_file'] = array(
+        '#type' => 'select',
+        '#title' => t('Select an image'),
+        '#default_value' => $row->image_file,
+        '#options' => $files,
+        '#prefix' => theme('path_image_form_wrapper', 'cell_middle_prefix', array('cell' => array('valign' => 'top'))),
+        '#suffix' => theme('path_image_form_wrapper', 'cell_middle_suffix')        
+      );    
+      $form['path_image']['existing_entries'][$row_counter]['delete'] = array(
+        '#type' => 'checkbox',
+        '#title' => t('Delete'),
+        '#prefix' => theme('path_image_form_wrapper', 'cell_last_prefix', array('cell' => array('valign' => 'middle'))), 
+        '#suffix' => theme('path_image_form_wrapper', 'cell_last_suffix')            
+      );    
+    }
+    else {
+      $form['path_image']['existing_entries'][$row_counter]['path_markup'] = array(
+        '#type' => 'markup',
+        '#value' => check_plain($row->path),
+        '#suffix' => '&nbsp; -- &nbsp;'    
+      );      
+      $form['path_image']['existing_entries'][$row_counter]['image_file_markup'] = array(
+        '#type' => 'markup',
+        '#value' => t('No files available for selection'),
+        '#suffix' => theme('path_image_form_wrapper', 'new_line')
+      );
     }
+    $row_counter++;
+  }
+  if ($row_counter > 0) {
+    $form['path_image']['existing_entries']['#type'] = 'fieldset';
+    $form['path_image']['existing_entries']['#title'] = t('Existing path %x', array('%x' => format_plural($num_of_rows, 'entry', 'entries')));
+    $form['path_image']['existing_entries']['#tree'] = TRUE;
   }
 
   $form['path_image']['submit'] = array(
@@ -496,11 +509,11 @@ function _path_image_settings_form() {
 /**
  * Form validation function for the _settings page
  */
-function _path_image_settings_form_validate($form_id, $form_values) {
+function _path_image_settings_form_validate($form, &$form_state) {
   
   $return_value = TRUE;
   
-  if ($form_values['default_image'] == 'no image selected') {
+  if ($form_state['values']['default_image'] == 'no image selected') {
     form_set_error(
       'default_image', 
       t('You must set this even if you do not intend to use it'));
@@ -513,7 +526,8 @@ function _path_image_settings_form_valid
 /**
  * Form submit function for the _settings page
  */
-function _path_image_settings_form_submit($form_id, $form_values) {
+function _path_image_settings_form_submit($form, $form_state) {
+  $form_values = $form_state['values'];
 
   variable_set('path_image_block_subject', $form_values['block_subject']);
   variable_set('path_image_repository', $form_values['repos']);
@@ -534,12 +548,10 @@ function _path_image_settings_form_submi
   if (strlen($form_values['new_entry']['new_path']) &&
       strlen($form_values['new_entry']['new_image'])) {
     
-    $pid = db_next_id('{path_image_data}');  
     $sql = 'INSERT INTO {path_image_data} SET ' .
-           ' pid = %d, '.
            ' path = "%s", '.
            ' image_file = "%s"';
-    db_query($sql, $pid, $form_values['new_entry']['new_path'], $form_values['new_entry']['new_image']);
+    db_query($sql, $form_values['new_entry']['new_path'], $form_values['new_entry']['new_image']);
   }
   
   if (isset($form_values['existing_entries']) && is_array($form_values['existing_entries'])) {
@@ -623,11 +635,10 @@ function _path_image_get_image_files() {
   
   $file_types = variable_get('path_image_file_types', array('gif', 'jpg', 'png'));
   
-  $dir = $_SERVER['DOCUMENT_ROOT'] . '/' . 
-         file_directory_path() . '/' . 
-         variable_get('path_image_repository', 'images');
-         
-  if (is_dir($dir)) {
+  $dir = file_directory_path() .'/'.  variable_get('path_image_repository', 'images');
+  // output is: sites/default/files/images
+
+  if (file_exists($dir)) {
     if ($dh = opendir($dir)) {
       while (($file = readdir($dh)) !== false) {
         $file_info = pathinfo($file);
