Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.

Answers to questions

Can someone answer the questions I have asked in #8 and #9 from this subject: https://www.php-fusion.co.uk/infusions/forum/viewthread.php?thread_id=38455 ?

Quote

I don know why this information needs to be inserted twice in the same table, maybe someone can explain this?

Every message is stored twice because one is in your archive, if the message is deleted and saved in archive it can still be read due to this.

Quote

In PHP-Fusion-9, for display on all pages, this value needs to be set to 3.

A lot changed in 9 including a re-write of panels, that is how it was done at that time for 9.
Every PM, there will be 2 rows insert because in v9 we introduced outbox.

When a message is being sent, contrary to v7 where just one message will be recorded (https://github.com/php-fusion/PHP-Fus...s.php#L181), we will log 2 rows instead and the indicator for the message ownership is by message_user column.

During a PM sent by another person to you, these will happen:
One message was sent to you - you are the owner of that row. It will be on your inbox.
One message was kept by the sender - he is the owner of that row. It will be on his outbox.

Now, assuming if both sender and receiver shares 1 row only. If either one of you delete that row will cause an issue. Where was my inbox message? Where was my outbox message? kind of situation.

Also, since the PM is MVCT capable, someone could always come up with a template for "Chat or Conversation" based PM templates anytime. Our source code is open, and if you feel like there is a need to change, you can address them and let us know your solution in either Github, or in this forum.
Ok, What do you mean with MVCT capable?
I don´t know what this mans
Model View Template ( Custom Skinning ), A default style override on theme level is possible.
I'm glad you ask, and if anyone wants to know what exactly is MVCT. It is a concept for getting the most optimized environment for development as it allows you to grow your code segregated, clean and extensible at the same time. In this CMS, we use this to enhance our capabilities beyond the core codes to modules, submodules, panels, addons, without recoding the whole chunk entirely again.

The following is an example I spent some 15 min to explain. You probably need half amount of time to understand. Ready?

In MVCT, we will draft 4 files, each respectively for Model, View, Control all at base core, and Template in our theme.php file to provide customization. Let's say we want to build a forum. This is how we will do it.

Model.php - This file will control data. It is used to interact with MYSQL. No other file will handle MYSQL except this file.
CodeDownload  
function forum_query() {
 return dbquery("SELECT * FROM ".DB_FORUMS);
}

// Model.php
function thread_query() {
 return dbquery("SELECT * FROM ".DB_FORUM_THREADS);
}
function more_thread_info($item) {
 return $item + array(
 "thread_special_link" => "....",
 "user_avatar_with_modal" => "...",
 "colorbox" => "...."
 );
}



Control.php - This file is for reading URL and provide the relevant output. It controls output.
CodeDownload  
function control() {
 $list = array();
 $thread = false;
 $result = forum_query();
 if ($thread_id = get("viewthread")) { // Where $_GET['viewthread'] exist.
 $result = thread_query();
 $thread = true;
 }
 if (dbrows($result)) {
 while ($data = dbarray($result)) {
 $list[] = $data;
 }
 }
 return view_everything($list, $thread);
}



View.php - This file for your skinning infomation. It controls what the user will see and returns what we will see on screen.
CodeDownload  
function view_everything($items, $is_thread_view = FALSE) {
 if ($is_thread_view) {
 return render_thread($items);
 }
 return render_forum($items);
}
if (!defined("render_forum")) {
 function render_form($data) {
 return 'default forum view';
 }
}
if (!defined("render_thread")) {
 function render_thread($data) {
 return 'default thread view';
 }
}



Theme.php - Custom HTML skinning, theming. If we declare the same function, the one in view.php will not be used since it has been defined.
CodeDownload  
function render_forum($data) {
 // Custom capability
 return 'Custom forum view';
}
function render_thread($data) {
 // Custom thread view
 return 'Custom thread view';
}



And in forum/index.php - It will be just 1 line of code.
CodeDownload  
echo control();



Direct Benefits
✔️ Scope - It will give you a clear scope of what and which file went wrong during debugging.

✔️ Simple - It is the most simplified form of development. You will not spend hours fixing this part and figured that another part, in which you will guaranteed to have if it is coded inline, jumbled up, mixed into a single exposed non function file like what we have in v7.

✔️ Simplicity - File size will also significantly drop since there are no duplicates.

✔️ Secure - All variables will not bind together and variable mutation will absolutely not happen.

Variable Mutation:
CodeDownload  
$result= dbquery("");
if (dbrows($result)) {
 while ($data = dbarray($result);
 // this is mutation.
 $data = dbarray(dbquery($result));
}



✔️ Extensible - With the function, Templates are being extended. All controlled at developer's finger tips.

This is basic a MVCT technique explanation. And it is what made v9. Well, at least down in all the core infusions, haha. Except maincore.php, right.
I'm adding further answers to templating..

In templating here, we have 2 more workflow to adopt. Just one if you're following the v9.03.6 adaptation, but if you follow Github, there are 2.

What is Templating?
A template is a piece of "skin" drafted in other language other than PHP. PHP is designed to be a logical parser. It was never intended to be used for "print". Echo is insecure and also will slow down TTFB a lot. Oh yes, after making eval a bad thing, now echo is next in line.

What they are saying is, keep .php file PHP. Do not use it for HTML output. There is something else that should do that.
I looked into google, read more articles regarding how people fix this and why such rule exist in the first place. There must be a reason, objectively speaking. If we are to forbid HTML code in PHP Files, about 100% of our addons will be invalid.

Justification for a change:

What happened to us was basically our public repository is tied to a Code Quality Checker Enterprise application called "Codacy" https://www.codacy.com/. What happens is when we commit our files into repository for a change, it will first send that commit to Codacy for review. Now, one of the primary rule checker is that if any of the code contains echo will be considered a bad practise, and if that is unfixed, Codacy code quality ratings will drop... and .. It is counted 1 error, per line of echo. What...the.. Really -.- ??? Just say, my emotions were in roller coaster, the decline for 900 ft when I got the email from them about it.

Quote

echo "<div>"; // drop rating -1
echo "<div class='this'>"; // drop rating -1


To fix this Codacy errors, we need to readapt. In v9.03.50 on, months back, our answer to that is as following: Template Class. PHPFusion Andromeda supports this. https://github.com/php-fusion/PHP-Fus...mplate.inc

Back then it was like this

Old v7 Approach
CodeDownload  
function render_forum($data) {
echo "<div>"
}



So to fix codacy errors it should work like this instead

Template Engine - Better
CodeDownload  
function render_forum($data) {
$tpl = Template::getInstance('forum');
$tpl->set_template("path-to-template-folder".DIRECTORY_SEPERATOR."template.html");
$tpl->set_tag("block_1", $data["forum_name"]);
return $tpl->get_output();
}



template.html
CodeDownload  
<div class="forum"><h4>{%block_1%}</h4></div>



And obviously, we got really deep into it, adding more customization ideas into Template, but we're stuck with some really bad nested item rendering. If I increment Template engine codes, I'm afraid it will definitely slow down the site even more, and we had a meeting some among the core devs. There will be probably no need to document on this. The main reason is we dropped this due to its limitations and decided not to pursue further development on it.

Now in Babylon we do this:

Twig - v10 and above
CodeDownload  
function render_forum($data) {
return fusion_render("path-to-template-folder", "template.twig", $data);
}



The whole turn over took Core Developers roughly 8 months to overcome. It's fast enough of a change considering, well our team size factors. Despite that, our test reveals that Twig is better, stronger, and faster than echo a lot and template class as well. Why? well... my mind just got blown out the window when I saw the site render speed and memory usage results. It uses cache, and we do not need PHP to render anything. It's like the Op_Cache of HTML.

So look into them when you are interested as well or working with Babylon.
Thread Information
Author
Posted In
Replies
7 posts
Views
70 times
Last Post
Last updated on 4 days ago
You can view all discussion threads in this forum.
You can start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You can download attachments in this forum.
Users who participated in discussion: Falk, Chan, douwe_yntema