Links obtained by ajax are aimed to root

Discussion forum for MOD Writers regarding MOD Development.
Locked
Senky
Extension Customisations
Extension Customisations
Posts: 2162
Joined: Thu Apr 30, 2009 8:49 pm
Name: Jakub
Contact:

Links obtained by ajax are aimed to root

Post by Senky » Tue Mar 09, 2010 9:01 pm

Hello,
I have done one my MOD - statistics and registered users online o the index page are reloaded by ajax. The files which obtains strings are in includes/ajax (simple functions, like get_username_string, obtain_users_online_string, ...). If I navigate to includes/ajax/file.php, it will generate what I want and it looks I want - also with links in correct directory. But after I get it through ajax, the links are changed into root directory of the domain. I really do not know the reason and why are links in one directory correct and in another not.
Can someone explain me or tell me how to fix this problem?
Thanks in advance...

User avatar
Marc
Development Team Leader
Development Team Leader
Posts: 5413
Joined: Tue Oct 30, 2007 10:57 pm
Location: Munich, Germany
Name: Marc
Contact:

Re: Links obtained by ajax are aimed to root

Post by Marc » Tue Mar 09, 2010 10:48 pm

Have you included the files with phpbb_root_path? It might help if you post your script here. ;)

Senky
Extension Customisations
Extension Customisations
Posts: 2162
Joined: Thu Apr 30, 2009 8:49 pm
Name: Jakub
Contact:

Re: Links obtained by ajax are aimed to root

Post by Senky » Wed Mar 10, 2010 11:56 am

Okay, my files which outputs strings:
this is for statistics:

Code: Select all

<?php
/**
*
* @package newest_member_ajax
* @version $Id: statistics.php.php 2010-02-20 22:40:00Z Senky $
* @copyright (c) 2010 Senky
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

define('IN_PHPBB', true);

$phpbb_root_path = '../../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

$user->session_begin();
$auth->acl($user->data);
$user->setup();

$l_total_user_s = ($config['num_users'] == 0) ? 'TOTAL_USERS_ZERO' : 'TOTAL_USERS_OTHER';
$l_total_post_s = ($config['num_posts'] == 0) ? 'TOTAL_POSTS_ZERO' : 'TOTAL_POSTS_OTHER';
$l_total_topic_s = ($config['num_topics'] == 0) ? 'TOTAL_TOPICS_ZERO' : 'TOTAL_TOPICS_OTHER';

echo sprintf($user->lang[$l_total_post_s], $config['num_posts']) . ' &bull; ';
echo sprintf($user->lang[$l_total_topic_s], $config['num_topics']) . ' &bull; ';
echo sprintf($user->lang[$l_total_user_s], $config['num_users']) . ' &bull; ';
echo sprintf($user->lang['NEWEST_USER'], get_username_string('full', $config['newest_user_id'], $config['newest_username'], $config['newest_user_colour']));

?>
and this for the online user list:

Code: Select all

<?php
/**
*
* @package newest_member_ajax
* @version $Id: statistics.php.php 2010-02-20 22:40:00Z Senky $
* @copyright (c) 2010 Senky
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

define('IN_PHPBB', true);

$phpbb_root_path = '../../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

$user->session_begin();
$auth->acl($user->data);
$user->setup();

$online_users = obtain_users_online(0, 'forum');
$user_online_strings = obtain_users_online_string($online_users, 0, 'forum');

echo $user_online_strings['online_userlist'];

?>
Both generates all correct, and in includes/ajax/statistics.php are links correct, but in index.php are not... Will be the edits of all used functions required, or can it be changed somehow in that files?
Thanks...

User avatar
m157y
Registered User
Posts: 482
Joined: Mon Apr 30, 2007 9:39 am
Location: Russia, Moscow, Khimki
Contact:

Re: Links obtained by ajax are aimed to root

Post by m157y » Wed Mar 10, 2010 1:12 pm

It's simple...
Your $phpbb_root_path is ../../... And it's works correct if you'll access directly to your scripts, but via ajax you're placed, for example at ./index.php and it tries to go up on two folders (because $phpbb_root_path from your script is ../../..
PS
If you know links at functions, which are you using, generated by this standard append_sid("{$phpbb_root_path}SCRIPTNAME.$phpEx", "ADDITIONAL_PARAMS") as you can see $phpbb_root_path is here...
But if you don't know this, and as i see, you don't... maybe it'll be better if you'll read some docs about phpbb before any developments for it?
m157y aka Misty
NO SUPPORT VIA PM
KarmaMOD for phpBB 3.0.x | bbAJAX
Follow me on twitter

Senky
Extension Customisations
Extension Customisations
Posts: 2162
Joined: Thu Apr 30, 2009 8:49 pm
Name: Jakub
Contact:

Re: Links obtained by ajax are aimed to root

Post by Senky » Mon Mar 15, 2010 1:49 pm

Ah I am such an idiot... And, yes I have read almost all docs about developing ;) . Hmm, just thinking about how to get it. Maybe to parse generate_board_url() and fetch only num of directories and by that num generate $phpbb_root_path. Or maybe not use $phpbb_root_path to include functions and set it to "./". Fine, thanks, I will play with it a little bit more...

Oleg
Former Team Member
Posts: 1221
Joined: Sat Jan 30, 2010 4:42 pm
Location: NYC
Contact:

Re: Links obtained by ajax are aimed to root

Post by Oleg » Mon Mar 15, 2010 2:08 pm

You should not have entry points under include directory.

Any php file that users may request, either directly or indirectly, should be at the top level (same place where e.g. viewtopic.php is). This way you are not going to have discrepancies between phpbb root definition, and your layout would be consistent with phpbb's own layout.
Participate in phpBB development: Get involved | Issue tracker | Report a bug | Development board | [url=irc://chat.freenode.net/phpbb-dev]Development IRC chat[/url]
My stuff: mindlinkgame.com

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 21034
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: Links obtained by ajax are aimed to root

Post by RMcGirr83 » Mon Mar 15, 2010 2:18 pm

Why not just leave the files at root?
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

Senky
Extension Customisations
Extension Customisations
Posts: 2162
Joined: Thu Apr 30, 2009 8:49 pm
Name: Jakub
Contact:

Re: Links obtained by ajax are aimed to root

Post by Senky » Tue Mar 16, 2010 12:50 pm

Okay, as I see, I will leave it in phpbb root and probably change into one file. Thanks for the help...

Locked

Return to ‚Äú[3.0.x] MOD Writers Discussion‚ÄĚ