It seems related to cacheing because it doesn't happen every time

From my php log:
PHP Fatal error: Call to undefined function base_path() in C:\apache2triad\htdocs\drupal\drupal-5.1\modules\pageear\pageear.module on line 289

I assume it has to do with drupal boot strapping to different levels depending on caching or not?

This is a super cool module - and I would really like it to work.

Comments

manfer’s picture

At first look something really strange as base_path is a drupal API function. I don't know what that undefine function error.

And yes it seems related to caching. I have been able to reproduce it. Still don't know why.

I would have to ask myself to try to know how can that happen because it seems to appear with normal caching.

manfer’s picture

A research have pointed me to the problem, in drupal5 hook_init of modules is called for cached pages and common.inc is not included.

As base_path is a function inside common.inc it is not defined.

The problem, base_path issue is easy to solve just changing base_path calls with its return value $GLOBALS['base_path'], but I'm using some other functions in hook_init that are defined in common.inc so I have to ask for the best way to solve those issues.

That's for the report. I'll try to solve it as soon as possible.

manfer’s picture

Assigned: Unassigned » manfer
Status: Active » Needs work

Well, I have yet to confirm but I think I got the solution.

Just I have to get totally rid of hook_init function and set all that code to hook_menu(!$may_cache).

So Just deleting the function pageear_init in pageear.module and editing pageear_menu($may_cache) as follows:

/**
 * Implementation of hook_menu().
 */
function pageear_menu($may_cache) {

  $items = array();

  if ($may_cache) {

    $items[] = array(
      'path' => 'admin/build/pageear',
      'title' => t('Pageears'),
      'description' => t('Configure pageears, how they look and where they appear on the site.'),
      'callback' => 'pageear_admin_display',
      'access' => user_access('administer pageears'),
    );
    $items[] = array(
      'path' => 'admin/build/pageear/list',
      'title' => t('List'),
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'weight' => -10,
    );
    $items[] = array(
      'path' => 'admin/build/pageear/add',
      'title' => t('Add pageear'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array('pageear_admin_configure', 'add', NULL),
      'access' => user_access('administer pageears'),
      'type' => MENU_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'admin/build/pageear/configure',
      'title' => t('Configure pageear'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array('pageear_admin_configure', 'configure'),
      'access' => user_access('administer pageears'),
      'type' => MENU_CALLBACK,
    );
    $items[] = array(
      'path' => 'admin/build/pageear/clone',
      'title' => t('Clone pageear'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array('pageear_admin_configure', 'clone'),
      'access' => user_access('administer pageears'),
      'type' => MENU_CALLBACK,
    );
    $items[] = array(
      'path' => 'admin/build/pageear/delete',
      'title' => t('Delete pageear'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array('pageear_admin_delete'),
      'access' => user_access('administer pageears'),
      'type' => MENU_CALLBACK,
    );
    $items[] = array(
      'path' => 'admin/build/pageear/disable',
      'title' => t('Disables pageear'),
      'callback' => 'pageear_admin_disable',
      'access' => user_access('administer pageears'),
      'type' => MENU_CALLBACK,
    );
    $items[] = array(
      'path' => 'admin/build/pageear/enable',
      'title' => t('Enables pageear'),
      'callback' => 'pageear_admin_enable',
      'access' => user_access('administer pageears'),
      'type' => MENU_CALLBACK,
    );

  } else {

    // Add the JS only if we have any active pageear.
    // Test if pageear must be displayed in this node
    // and prepare it for hook_footer.
    $num_active = variable_get('numEnabledPageears', 0);

    if ($num_active) {

      // Fetch all active pageears.
      // TODO: cache?
      $pageears = array();
      $result = db_query("SELECT * FROM {pageears} WHERE status = 1");
      while ($row = db_fetch_object($result)) {
        $pageears[] = $row;
      }

      global $user;
      global $locale;
      $rids = array_keys($user->roles);
      $lang_name = $locale;

      $output = '';

      // Pageear for the current path/role/language. If more than one are configured
      // for this path/role/language, only first would be presented.
      foreach ($pageears as $pageear) {

        // Get the settings
        $vis_languages = explode(',', $pageear->languages);
        $vis_roles = explode(',', $pageear->roles);
        $vis_vis = $pageear->visibility;
        $vis_pages = $pageear->pages;

        // Match languages
        if (module_exists('locale') && count(array_filter($vis_languages))) {
          $lang_enabled = in_array($lang_name, $vis_languages);
        }
        else {
          $lang_enabled = TRUE;
        }

        // Match roles
        if (count(array_filter($vis_roles))) {
          $role_enabled = count(array_intersect($vis_roles, $rids)) ? TRUE : FALSE;
        }
        else {
          $role_enabled = TRUE;
        }

        // Match path if necessary
        if ($vis_pages) {
          if ($vis_vis < 2) {
            $path = drupal_get_path_alias($_GET['q']);
            $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($vis_pages, '/')) .')$/';
            // Compare with the internal and path alias (if any).
            $page_match = preg_match($regexp, $path);
            if ($path != $_GET['q']) {
              $page_match = $page_match || preg_match($regexp, $_GET['q']);
            }
            // When $vis_vis has a value of 0, the pageear is displayed on
            // all pages except those listed in $vis_pages. When set to 1, it
            // is displayed only on those pages listed in $vis_pages.
            $page_match = !($vis_vis xor $page_match);
          }
          else {
            $page_match = drupal_eval($vis_pages);
          }
        }
        else {
          $page_match = TRUE;
        }

        // Generate pageear if enabled for current path, role and language
        if ($lang_enabled === TRUE && $role_enabled === TRUE && $page_match) {

          // Prepare the pageear object to adjust it to pageTurn javascript variable needs
          // and store it on persistent variable currentPageear
          variable_set('current_pageear', pageear_prepare($pageear));

          // Include on page javascript files needed to make pageear work
          $path = drupal_get_path('module', 'pageear');
          drupal_add_js($path .'/pageturn/AC_RunActiveContent.js');
          drupal_add_js($path .'/pageturn/pageTurn.js');
        
          return;
        }
      }

      // There is no pageear enabled for this node
      variable_set('current_pageear', FALSE);

    } else {
      // There is no pageear enabled at all
      variable_set('current_pageear', FALSE);
    }
  }

  return $items;
}

should do the trick. I think the module has to be disable and reenable so this change takes effect (configured pageears if there were any have to be reenable in pageears administration page because disabling the module disables all pageears, they are not deleted just disabled).

For those following this bug they can notice another change. I included another bug fix, a bug that was reported to 6.x version and I think was present in 5.x too. When no pageear was enabled at all sometimes a js error appears. That is solved with the code I just included in this change almost at the end of the function:

    } else {
      // There is no pageear enabled at all
      variable_set('current_pageear', FALSE);
    }

I would commit the changes as soon as possible when I have confirmed it is the best solution.

And as soon as the 6.x-2.1 version is finished (probably I could just tag it as 2.1 version by now) I can start to include new features to a 5.x-2.1 version too.

manfer’s picture

I have just finished changes to include on 5.x version all new features. I have commited all the changes and as soon as the package system packages it, it would be available in the project pages as a development snapshot for 5.x.

That 5.x-2.x-dev version has all the new features and this cache bug fixed.

It would be of great help if you could test it and provide me feedback. I tested and it seems it is working but more opinions and tests would be apreciated. If it is working fine I could make it the 5.x-2.1-RC version and set it as the recommended version for drupal 5.

I don't know exactly when is the next packaging job programmed but I suppose at most in 12 hours it would be available in project page. I will notice here when it is available.

Thanks for the report again and I hope it works now.

manfer’s picture

The 5.x dev package is by now available in the project page.

If you could test if it works for you with that version it would be very helpful.

Thanks.

manfer’s picture

Priority: Normal » Critical
Status: Needs work » Fixed

Fixed on dev version.

With my tests the last 5.x version is not presenting any issues but I would wait a while before deciding to make it available as a 5.x-2.1-RC release.

If you test it please provide feedback.

Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.