1

Topic: can't include common.php

Hi,

I'm trying to import punbb into cakephp.

I have defined PUN_ROOT and included the file include/common.php

But a php fatal error jumps at me

Fatal error: Call to a member function query() on a non-object in ..../include/functions.php on line 125

I have var_dump($db) before line 120 on common.php
and its show me an object reference, but inside check_cookie() i get NULL.

For some odd reason the global $db doesn't work (also other global like $pun_user,$pun_config ....).
When overriding cakephp and running index.php or defining PUN_ROOT inside common.php and running it i get no error

Any idea why?

Thanks,

Assaf

Re: can't include common.php

I'm not familiar with cakephp, so could you post some example code of how you're implementing this?

3

Re: can't include common.php

here is sample code

class ForumsController extends AppController
{

    function index(){
        define('PUN_ROOT', dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'webroot'.DIRECTORY_SEPARATOR.'forum'.DIRECTORY_SEPARATOR);
        require PUN_ROOT.'include'.DIRECTORY_SEPARATOR.'common.php';
    }

}


here is a crude debug report after manualy hacking the global $db

please note in the end how the array lose their data becuase the checked againt $pun_config which is null
becuase declared global $pun_config

smarty:you can delete this post after reading becuase its take lot of space and i don't know how clear it is for readers smile

pun user  -> var_dump()
array(11) { ["id"]=> string(2) "24" ["user_name"]=> string(4) "test" ["email_address"]=> string(18) "sufinoon@gmail.com" ["full_name"]=> string(3) "ass" ["password"]=> string(32) "e10adc3949ba59abbe56e057f20f883e" ["show_name"]=> string(1) "0" ["created"]=> string(19) "2007-05-15 09:45:12" ["user_profile_id"]=> string(2) "16" ["email_authenticated"]=> string(1) "1" ["email_token"]=> NULL ["email_token_expires"]=> NULL }
hihiobject(DBLayer)#13 (5) { ["prefix"]=> string(0) "" ["link_id"]=> object(mysqli)#14 (0) { } ["query_result"]=> NULL ["saved_queries"]=> array(0) { } ["num_queries"]=> int(0) }
in the middle (common.php line 116)


before check cookie (common.php line 140)

var_dump($db) ->
object(DBLayer)#13 (5) { ["prefix"]=> string(0) "" ["link_id"]=> object(mysqli)#14 (0) { } ["query_result"]=> NULL ["saved_queries"]=> array(0) { } ["num_queries"]=> int(0) }

******
* in check user *
********** (functions.php line 37)

NULL -> var_dump($db);
*****
default users
**** (functions.php line 143)


pun_config (functions.php line 157)

NULL  -> var_dump($pun_config);
in set_default_user (functions.php line 166)

array(56) { ["id"]=> string(1) "1" ["group_id"]=> string(1) "3" ["username"]=> string(5) "Guest" ["password"]=> string(5) "Guest" ["email"]=> string(0) "" ["title"]=> NULL ["realname"]=> string(0) "" ["url"]=> NULL ["jabber"]=> NULL ["icq"]=> NULL ["msn"]=> NULL ["aim"]=> NULL ["yahoo"]=> NULL ["location"]=> NULL ["use_avatar"]=> string(1) "0" ["signature"]=> NULL ["disp_topics"]=> NULL ["disp_posts"]=> NULL ["email_setting"]=> string(1) "1" ["save_pass"]=> string(1) "1" ["notify_with_post"]=> string(1) "0" ["show_smilies"]=> string(1) "1" ["show_img"]=> string(1) "1" ["show_img_sig"]=> string(1) "1" ["show_avatars"]=> string(1) "1" ["show_sig"]=> string(1) "1" ["timezone"]=> string(1) "0" ["language"]=> string(7) "English" ["style"]=> string(6) "Oxygen" ["num_posts"]=> string(1) "0" ["last_post"]=> NULL ["registered"]=> string(1) "0" ["registration_ip"]=> string(7) "0.0.0.0" ["last_visit"]=> string(1) "0" ["admin_note"]=> NULL ["activate_string"]=> NULL ["activate_key"]=> NULL ["g_id"]=> string(1) "3" ["g_title"]=> string(5) "Guest" ["g_user_title"]=> NULL ["g_read_board"]=> string(1) "1" ["g_post_replies"]=> string(1) "0" ["g_post_topics"]=> string(1) "0" ["g_post_polls"]=> string(1) "0" ["g_edit_posts"]=> string(1) "0" ["g_delete_posts"]=> string(1) "0" ["g_delete_topics"]=> string(1) "0" ["g_set_title"]=> string(1) "0" ["g_search"]=> string(1) "1" ["g_search_users"]=> string(1) "1" ["g_edit_subjects_interval"]=> string(1) "0" ["g_post_flood"]=> string(1) "0" ["g_search_flood"]=> string(1) "0" ["g_pm"]=> string(1) "1" ["g_pm_limit"]=> string(2) "20" ["logged"]=> string(10) "1179213445" }

**********
AFTER defaukt init
************

(functions.php line 197)

array(57) { ["id"]=> string(1) "1" ["group_id"]=> string(1) "3" ["username"]=> string(5) "Guest" ["password"]=> string(5) "Guest" ["email"]=> string(0) "" ["title"]=> NULL ["realname"]=> string(0) "" ["url"]=> NULL ["jabber"]=> NULL ["icq"]=> NULL ["msn"]=> NULL ["aim"]=> NULL ["yahoo"]=> NULL ["location"]=> NULL ["use_avatar"]=> string(1) "0" ["signature"]=> NULL ["disp_topics"]=> NULL ["disp_posts"]=> NULL ["email_setting"]=> string(1) "1" ["save_pass"]=> string(1) "1" ["notify_with_post"]=> string(1) "0" ["show_smilies"]=> string(1) "1" ["show_img"]=> string(1) "1" ["show_img_sig"]=> string(1) "1" ["show_avatars"]=> string(1) "1" ["show_sig"]=> string(1) "1" ["timezone"]=> NULL ["language"]=> NULL ["style"]=> NULL ["num_posts"]=> string(1) "0" ["last_post"]=> NULL ["registered"]=> string(1) "0" ["registration_ip"]=> string(7) "0.0.0.0" ["last_visit"]=> string(1) "0" ["admin_note"]=> NULL ["activate_string"]=> NULL ["activate_key"]=> NULL ["g_id"]=> string(1) "3" ["g_title"]=> string(5) "Guest" ["g_user_title"]=> NULL ["g_read_board"]=> string(1) "1" ["g_post_replies"]=> string(1) "0" ["g_post_topics"]=> string(1) "0" ["g_post_polls"]=> string(1) "0" ["g_edit_posts"]=> string(1) "0" ["g_delete_posts"]=> string(1) "0" ["g_delete_topics"]=> string(1) "0" ["g_set_title"]=> string(1) "0" ["g_search"]=> string(1) "1" ["g_search_users"]=> string(1) "1" ["g_edit_subjects_interval"]=> string(1) "0" ["g_post_flood"]=> string(1) "0" ["g_search_flood"]=> string(1) "0" ["g_pm"]=> string(1) "1" ["g_pm_limit"]=> string(2) "20" ["logged"]=> string(10) "1179213445" ["is_guest"]=> bool(true) }
after check cookie (common.php line 145)

array(57) { ["id"]=> string(1) "1" ["group_id"]=> string(1) "3" ["username"]=> string(5) "Guest" ["password"]=> string(5) "Guest" ["email"]=> string(0) "" ["title"]=> NULL ["realname"]=> string(0) "" ["url"]=> NULL ["jabber"]=> NULL ["icq"]=> NULL ["msn"]=> NULL ["aim"]=> NULL ["yahoo"]=> NULL ["location"]=> NULL ["use_avatar"]=> string(1) "0" ["signature"]=> NULL ["disp_topics"]=> NULL ["disp_posts"]=> NULL ["email_setting"]=> string(1) "1" ["save_pass"]=> string(1) "1" ["notify_with_post"]=> string(1) "0" ["show_smilies"]=> string(1) "1" ["show_img"]=> string(1) "1" ["show_img_sig"]=> string(1) "1" ["show_avatars"]=> string(1) "1" ["show_sig"]=> string(1) "1" ["timezone"]=> NULL ["language"]=> NULL ["style"]=> NULL ["num_posts"]=> string(1) "0" ["last_post"]=> NULL ["registered"]=> string(1) "0" ["registration_ip"]=> string(7) "0.0.0.0" ["last_visit"]=> string(1) "0" ["admin_note"]=> NULL ["activate_string"]=> NULL ["activate_key"]=> NULL ["g_id"]=> string(1) "3" ["g_title"]=> string(5) "Guest" ["g_user_title"]=> NULL ["g_read_board"]=> string(1) "1" ["g_post_replies"]=> string(1) "0" ["g_post_topics"]=> string(1) "0" ["g_post_polls"]=> string(1) "0" ["g_edit_posts"]=> string(1) "0" ["g_delete_posts"]=> string(1) "0" ["g_delete_topics"]=> string(1) "0" ["g_set_title"]=> string(1) "0" ["g_search"]=> string(1) "1" ["g_search_users"]=> string(1) "1" ["g_edit_subjects_interval"]=> string(1) "0" ["g_post_flood"]=> string(1) "0" ["g_search_flood"]=> string(1) "0" ["g_pm"]=> string(1) "1" ["g_pm_limit"]=> string(2) "20" ["logged"]=> string(10) "1179213445" ["is_guest"]=> bool(true) }
in !isset (common.php line 150)

array(57) { ["id"]=> string(1) "1" ["group_id"]=> string(1) "3" ["username"]=> string(5) "Guest" ["password"]=> string(5) "Guest" ["email"]=> string(0) "" ["title"]=> NULL ["realname"]=> string(0) "" ["url"]=> NULL ["jabber"]=> NULL ["icq"]=> NULL ["msn"]=> NULL ["aim"]=> NULL ["yahoo"]=> NULL ["location"]=> NULL ["use_avatar"]=> string(1) "0" ["signature"]=> NULL ["disp_topics"]=> NULL ["disp_posts"]=> NULL ["email_setting"]=> string(1) "1" ["save_pass"]=> string(1) "1" ["notify_with_post"]=> string(1) "0" ["show_smilies"]=> string(1) "1" ["show_img"]=> string(1) "1" ["show_img_sig"]=> string(1) "1" ["show_avatars"]=> string(1) "1" ["show_sig"]=> string(1) "1" ["timezone"]=> NULL ["language"]=> NULL ["style"]=> NULL ["num_posts"]=> string(1) "0" ["last_post"]=> NULL ["registered"]=> string(1) "0" ["registration_ip"]=> string(7) "0.0.0.0" ["last_visit"]=> string(1) "0" ["admin_note"]=> NULL ["activate_string"]=> NULL ["activate_key"]=> NULL ["g_id"]=> string(1) "3" ["g_title"]=> string(5) "Guest" ["g_user_title"]=> NULL ["g_read_board"]=> string(1) "1" ["g_post_replies"]=> string(1) "0" ["g_post_topics"]=> string(1) "0" ["g_post_polls"]=> string(1) "0" ["g_edit_posts"]=> string(1) "0" ["g_delete_posts"]=> string(1) "0" ["g_delete_topics"]=> string(1) "0" ["g_set_title"]=> string(1) "0" ["g_search"]=> string(1) "1" ["g_search_users"]=> string(1) "1" ["g_edit_subjects_interval"]=> string(1) "0" ["g_post_flood"]=> string(1) "0" ["g_search_flood"]=> string(1) "0" ["g_pm"]=> string(1) "1" ["g_pm_limit"]=> string(2) "20" ["logged"]=> string(10) "1179213445" ["is_guest"]=> bool(true) }
Attempt to load the common language file (common.php line 155)

There is no valid language pack '' installed. Please reinstall a language of that name.

Re: can't include common.php

Try declaring the variables like $db, $pun_config, etc to be global in your function.

5

Re: can't include common.php

Smartys: you the man !!

Now i have found new problems sad

First because i'm in another page (within cake) i want only what comes between  <body> ans </body> tags.
Do i need to change the templates directly?
Can you please tell me were to find them?

Second does the script terminates in exit() or die() after displaying the templates?
The cake page doesnt load and the way cake works its loads the view (templates) after finishing execution in the controller (the index function above)

Thanks again Smartys,

Assaf

Re: can't include common.php

Yes, you need to change the templates. Templates are in include/templates/main.tpl
And yes, footer.php (and several functions) do terminate with exits. Remove them at your peril: http://punbb.org/forums/viewtopic.php?id=11984
As Rickard said there, we're open to ways to improve the current system

7

Re: can't include common.php

ok thanks,

last question (i hope) before diving into code
Does the css link on top of the page is relative to the PUN_ROOT or something like PUN_WEBROOT?
If it's not i think it would be a good practice to support not native punbb platforms by helping them find relevant files like css,js and images used by punbb

p.s i do have another question smile
How do i enable root member and moderators after installation?
Or in another way how the system recognize a user to be admin/moderator? because i'm using diffrent login system which updates punbb users tables

Assaf

Re: can't include common.php

last question (i hope) before diving into code
Does the css link on top of the page is relative to the PUN_ROOT or something like PUN_WEBROOT?
If it's not i think it would be a good practice to support not native punbb platforms by helping them find relevant files like css,js and images used by punbb

Yes, 1.3 uses the base URL for stylesheets, smilies, etc. 1.2, however, does not: you would need to manually edit that yourself.
And what's PUN_WEBROOT?

p.s i do have another question smile
How do i enable root member and moderators after installation?
Or in another way how the system recognize a user to be admin/moderator? because i'm using diffrent login system which updates punbb users tables

group_id on the users table.

9

Re: can't include common.php

PUN_WEBROOT?

PUN_WEBROOT can be used if the server document root is different then the installation of punbb.
Usually when Apache redirect you according to RewriteRules to places outside document_root

Hope it's clear,
Assaf

Re: can't include common.php

No, my point is that PunBB doesn't define anything like that wink

11

Re: can't include common.php

Well i know that it is not implanted yet.
You have asked for improvements didn't you,
So here is my first one PUN_WEBROOT wink

Now for more questions smile

How come i get an error on that query

SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.redirect_url FROM categories AS c INNER JOIN forums AS f ON c.id=f.cat_id LEFT JOIN forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=4) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position

defined in serach.php line 708

when running inside the script the var_dump result in bool false hence the error message.

But when running on my mysql client i get 2 rows?

mysql> use punbb;
Database changed
mysql> SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.redirect_url
FROM categories AS c INNER JOIN forums AS f ON c.id=f.cat_id LEFT JOIN forum_pe
rms AS fp ON (fp.forum_id=f.id AND fp.group_id=4) WHERE (fp.read_forum IS NULL O
R fp.read_forum=1) AND f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.
disp_position;
+-----+----------+-----+------------+--------------+
| cid | cat_name | fid | forum_name | redirect_url |
+-----+----------+-----+------------+--------------+
|   1 | test     |   1 | wibizz     | NULL         |
|   2 | assaf    |   2 | New forum  | NULL         |
+-----+----------+-----+------------+--------------+
2 rows in set (0.00 sec)

Re: can't include common.php

I don't know, you should check the nice error that PunBB gives you ;)
And I didn't realize you were suggesting a new feature, you were asking a question :P
The webroot is really unnecessary I think, I can't think of an example where it would be useful (or rather, where PUN_ROOT wouldn't work and base URL wouldn't work).