A lot of database-related questions from a complete newbie

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Rogerjwilkinson
Registered User
Posts: 33
Joined: Wed Jan 17, 2018 2:42 pm

Re: A lot of database-related questions from a complete newbie

Post by Rogerjwilkinson »

Ufft so I deicded to take a break from all of this and come back to the bbcode bollocks later, and decided to get around to adding mChat (with external integration - yippee!)... So back to all the "creating an external page" wiki entries I went, and try as I might I just can't make any sense of any of it. So I went back to my "mishmash coding" and found the following two pieces of code for trying to achieve this mChat task as well.

There was this from 2016, which went unanswered in the forums (no one could figure it out I think?), which try as I might, I couldn't manipulate into anything useful whatsoever. Blank white page standalone, and does nothing when put into my index.php, doesn't throw up any errors that I can tell

Code: Select all

<?php

 define('IN_PHPBB', true);

 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forum/';
 $phpEx = substr(strrchr(__FILE__, '.'), 1);

 include($phpbb_root_path . 'common.' . $phpEx);
 

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

 $html='<html><head><link href="'.$phpbb_root_path.'ext/dmzx/mchat/styles/prosilver/theme/mchat.css" rel="stylesheet" /></head><body>';
 $html.='<script type="text/javascript" src="'.$phpbb_root_path.'assets/javascript/editor.js"></script>';
 $html.='<script type="text/javascript" src="'.$phpbb_root_path.'assets/javascript/jquery.min.js"></script>';
 $html.='<script type="text/javascript" src="'.$phpbb_root_path.'styles/prosilver/template/ajax.js"></script>';
 $html.='<script type="text/javascript">
// <![CDATA[
   var root_path = "'.$phpbb_root_path.'";
// ]]>   
  </script>';
  echo $html;

 $mchat_installed = (!empty($config['mchat_version']) && !empty($config['mchat_enable'])) ? true : false;
 if ($mchat_installed && $auth->acl_get('u_mchat_view'))
 {
     
   if(!defined('MCHAT_INCLUDE') && $config['mchat_on_index'] && !empty($user->data['user_mchat_index']))
   {
      define('MCHAT_INCLUDE', true);
      $mchat_include_index = true;
      include($phpbb_root_path . 'ext/dmzx/mchat/controller/mchat.' . $phpEx);
   }   

   //$user->add_lang('mods/mchat_lang');

   $template->assign_vars(array(
         'ROOT_PATH'   => $phpbb_root_path,   
   ));

   $template->set_filenames(array('body' => 'ext/dmzx/mchat/styles/prosilver/template/mchat_body.html'));

   $template->display('body');
 }

 echo '</body></html>';
?>

And there was this lovely bit of code from the fellas over on phpmodders, and I had what I THOUGHT was a little more success, but either way my end result has been "nadda". I at least think I understand the issue in this code a little better?

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path.'common.'.$phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

// Start session management.
$user->session_begin();
$auth->acl($user->data);
$user->setup();


// BEGIN mChat Mod
$mchat_installed = (!empty($config['mchat_version']) && !empty($config['mchat_enable'])) ? true : false;
if ($mchat_installed && $auth->acl_get('u_mchat_view'))
{
   if(!defined('MCHAT_INCLUDE') && $config['mchat_on_index'] && !empty($user->data['user_mchat_index']))
   {
      define('MCHAT_INCLUDE', true);
      $mchat_include_index = true;
      include($phpbb_root_path . 'ext/dmzx/mchat/core/mchat.' . $phpEx);
   }   

   if (!empty($config['mchat_stats_index']) && !empty($user->data['user_mchat_stats_index']))
   {
      if (!function_exists('mchat_users'))
      {
         include($phpbb_root_path . 'ext/dmzx/mchat/core/functions.' . $phpEx);
      }
      // Add lang file
      $user->add_lang('ext/dmzx/mchat/language/en/mchat' . $phpEx);
      // stats display
      $mchat_session_time = !empty($config_mchat['timeout']) ? $config_mchat['timeout'] : 3600;// you can change this number to a greater number for longer chat sessions
      $mchat_stats = mchat_users($mchat_session_time);
      $template->assign_vars(array(
         'MCHAT_INDEX_STATS'   => true,
         'MCHAT_INDEX_USERS_COUNT'   => $mchat_stats['mchat_users_count'],
         'MCHAT_INDEX_USERS_LIST'   => $mchat_stats['online_userlist'],
         'L_MCHAT_ONLINE_EXPLAIN'   => $mchat_stats['refresh_message'],   
      ));
   }
}   
// END mChat Mod
// Output page
page_header($user->lang['MCHAT_TITLE']);

$template->set_filenames(array(
   'body' => 'mchat_body2.html')
);

page_footer();
?>
This code at least responds to me a little better, but far from ideal. I also don't know if the modifications I made to it from the original code were correct. It seems extension pathing and whatnot has been completely overhauled from previous versions? So not only is there surprisingly little "easy to understand" information on all this stuff, what there is, is becoming increasingly outdated :lol:

I think the issue with this code is I don't know how to either declare, or override WHERE it looks for

Code: Select all

$template->set_filenames(array(
   'body' => 'mchat_body2.html')
);
because when I run the code like that as it in a file called "mchat.php" on it's own, it throws up errors about being unable to find the required template in the standard locations (***/forum/styles/prosilver/template and ***/forum/styles/prosilver/theme), if I copy those files out of the ext/dmzx/mchat/styles/prosilver/template directory and into the normal templates path, it stops throwing up errors, and shows a page with the required forms and chatboxes and whathaveyou in it, but they don't work - I'm ASSUMING because it needs the templates relative locations or w/e?

I really don't know. I'mma keep tacking away at this, see if I can get ANY response whatsoever. I feel like maybe if I can figure this craziness out, I'll be one step closer to either integrating comments into my webpage PROPERlY, or at least, understanding why I can't seem to figure out PROPER integration? :lol: Anyone got any ideas to point me in the right direction(s) here?

Thanks so much in advance for everyone's time :mrgreen:
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: A lot of database-related questions from a complete newbie

Post by mrgoldy »

How many headers do you have? You should only have one header per page.
If you want to include a file, in this case the includes/functions_content.php, you can do so by:

include_once()

Code: Select all

include_once($phpbb_root_path . 'includes/functions_content.' . $phpEx);
Or using the function_exists()

Code: Select all

if (!function_exists('generate_text_for_display'))
{
	include($phpbb_root_path . 'includes/functions_content.' . $phpEx);
}
Then you have to set up (in your case hard code it) the $bbcode_options. BBCode options is a number from 0 till 7 (both these numbers included). If you want to enable bbcodes, you count +1, if you want to enable smilies you count +2 and if you want to automatically parse url's you count +4.
So if BBCode options are set to 5 (4 + 1), this means BBCodes and URL's are parsed and smilies are not.
Set to 7 to enable/parse everything and 0 to disable everything / parse nothing.
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
Rogerjwilkinson
Registered User
Posts: 33
Joined: Wed Jan 17, 2018 2:42 pm

Re: A lot of database-related questions from a complete newbie

Post by Rogerjwilkinson »

Hmm, my index.php alone calls on 3-4 headers (the ones I posted before).... I guess there's a big part of my issue heh. And to think I thought I at least understood that part. This is probably why I've never managed to get anything to work externally, including mchat now.

I'm gonna keep bashing my head against the wall, googling obscure bits of code in-between " " with "phpbb" at the end, and HOPEFULLY, I can start making some sense of it..... or get lucky ;)

fwiw, I did figure out the bbcode stuff from the indented comments (see post earlier :lol: ) so that's a small boost of confidence at least. Playing around with the if statement for the header atm, but I think there's just too many clashes with all my headers, going to have to do a lot of research to figure out which "one" I can cut back to on index.php. It seems strange though, if functions_content is already included (or the part I need from it anyway), wouldn't my problem that needs functions_content included not exist? :lol: bloody computers, all too complicated.
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: A lot of database-related questions from a complete newbie

Post by mrgoldy »

Just to clarify, an 'include' on those phpBB functions is not a header.
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
Rogerjwilkinson
Registered User
Posts: 33
Joined: Wed Jan 17, 2018 2:42 pm

Re: A lot of database-related questions from a complete newbie

Post by Rogerjwilkinson »

Alright, so I'm trying very very hard again with getting mchat to display on an external page, or at the very least, display on a CUSTOM page, and I'll work through it step-by-step if I can at least get that far. I have this

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../../../';  // This makes no difference, I was simply trying it in the ext/dmzx/mchat path for this scenario to see if that would do it
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path.'common.'.$phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

// Start session management.
$user->session_begin();
$auth->acl($user->data);
$user->setup();


// BEGIN mChat Mod
$mchat_installed = (!empty($config['mchat_version']) && !empty($config['mchat_enable'])) ? true : false;
if ($mchat_installed && $auth->acl_get('u_mchat_view'))
{
   if(!defined('MCHAT_INCLUDE') && $config['mchat_on_index'] && !empty($user->data['user_mchat_index']))
   {
      define('MCHAT_INCLUDE', true);
      $mchat_include_index = true;
      include($phpbb_root_path . 'ext/dmzx/mchat/core/mchat.' . $phpEx);
   }   

   if (!empty($config['mchat_stats_index']) && !empty($user->data['user_mchat_stats_index']))
   {
      if (!function_exists('mchat_users'))
      {
         include($phpbb_root_path . 'ext/dmzx/mchat/core/functions.' . $phpEx);
      }
      // Add lang file
      $user->add_lang('ext/dmzx/mchat/language/en/mchat' . $phpEx);
      // stats display
      $mchat_session_time = !empty($config_mchat['timeout']) ? $config_mchat['timeout'] : 3600;// you can change this number to a greater number for longer chat sessions
      $mchat_stats = mchat_users($mchat_session_time);
      $template->assign_vars(array(
         'MCHAT_INDEX_STATS'   => true,
         'MCHAT_INDEX_USERS_COUNT'   => $mchat_stats['mchat_users_count'],
         'MCHAT_INDEX_USERS_LIST'   => $mchat_stats['online_userlist'],
         'L_MCHAT_ONLINE_EXPLAIN'   => $mchat_stats['refresh_message'],   
      ));
   }
}   
// END mChat Mod
// Output page
page_header($user->lang['MCHAT_TITLE']);

$template->set_filenames(array(
   'body' => 'mchat_body.html')
);

page_footer();
?>

And it returns errors

"
Fatal error: Uncaught exception 'Twig_Error_Loader' with message 'Unable to find template "mchat_body2.html" (looked into: /var/www/html/forum/styles/prosilver/template, /var/www/html/forum/styles/prosilver/theme, /var/www/html/forum/styles/all/template)."

how on earth do I tell either IT, or PHPBB as a whole to ALSO look in the /ext/dmzx/mchat/styles/prosilver/template directory, because I THINK that's the error? I'm also going to open a new post over on the mchat thread, maybe they got better ideas.
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: A lot of database-related questions from a complete newbie

Post by mrgoldy »

Not sure if it works on a custom page, but try:

Code: Select all

$template->set_filenames(array(
   'body' => '@dmzx_mchat/mchat_body.html')
);
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
Rogerjwilkinson
Registered User
Posts: 33
Joined: Wed Jan 17, 2018 2:42 pm

Re: A lot of database-related questions from a complete newbie

Post by Rogerjwilkinson »

Excellent, that did work. It put me in the same boat I was in copy and pasting the templates over (I now have a form box, "MCHAT_OK" and "Cancel" buttons that do nothing, "MCHAT_NOMESSAGE, MCHAT_USESOUND" and a tick-box that does nothing, all white background) but it worked all the same. I *THINK* my issue here is now, I need to find a way to incorporate the javascript and ajax pulls like the first code has

Code: Select all

 $html='<html><head><link href="'.$phpbb_root_path.'ext/dmzx/mchat/styles/prosilver/theme/mchat.css" rel="stylesheet" /></head><body>';
 $html.='<script type="text/javascript" src="'.$phpbb_root_path.'assets/javascript/editor.js"></script>';
 $html.='<script type="text/javascript" src="'.$phpbb_root_path.'assets/javascript/jquery.min.js"></script>';
 $html.='<script type="text/javascript" src="'.$phpbb_root_path.'styles/prosilver/template/ajax.js"></script>';
 $html.='<script type="text/javascript">

so essentially combine the two codes in a way I guess. Which is gonna be tricky because IF I understand it, one is using java and one is using straight PHP? Hmmm. Closer and closer, can feel it within reach now. Thanks again.
Rogerjwilkinson
Registered User
Posts: 33
Joined: Wed Jan 17, 2018 2:42 pm

Re: A lot of database-related questions from a complete newbie

Post by Rogerjwilkinson »

Bump. Just copy and pasting the lines in didn't work (surprise surprise).

Anyone please got some ideas? This just shouldn't be this hard. I've even begun looking at seeing how myBB and others handling <?php include = "target?> because this is just ludicrous.
Post Reply

Return to “phpBB Custom Coding”