Include in the page

autosurf

Active Member
Hi,

I would like to change my version of VL but for the moment, I use during my creation of pages, the possibility to add a PHP treatment in my pages with the function include.
To be done on my page, I have the code: {include "https://www.classement.com/test.php"} for example in which I have a PHP treatment on my test page. This allows me to get a dynamic page and that corresponds to my needs.
example of page: https://www.classement.pro/prochains-supprimes/

I tested the new version of VL and it does not interpret the accolages: /

Is there a possibility to activate this or fix this in the new version of VL?

Thank you in advance for your assistance
 

Basti

Administrator
Staff member
hmm that functionality hasnt changed since its creation.

Does your error log gives any hint?
 

autosurf

Active Member
Hi,

in the file sources/misc/skin.php (VL 1.6) , i have so
function parse($skin) {
global $LNG, $TMPL, $n, $parse_time;

if(!empty($_GET['a']) || !empty($_GET['cat'])) {$TMPL['front_page_top'] = '';}

// Include tag
$skin = preg_replace_callback('/{include \"(.+?)\"}/i', function($matches) {

return file_get_contents($matches[1]);
}, $skin);

// Language tags
$skin = preg_replace_callback('/{\$lng->(.+?)}/i', function($matches) {
global $LNG;

return $LNG[$matches[1]];
}, $skin);

// Template tags + optional limit text output
$skin = preg_replace_callback('/{\$(.+?)((?:,\s?length=)([0-9]+?))?}/i', function($matches) {
global $TMPL;

if(isset($matches[3])) {
$limit = $matches[3];
if (mb_strlen($TMPL[$matches[1]]) > $limit) {
$TMPL[$matches[1]] = mb_substr($TMPL[$matches[1]], 0, mb_strrpos(mb_substr($TMPL[$matches[1]], 0, $limit), " ")) . "...";
}
}

return isset($TMPL[$matches[1]]) ? $TMPL[$matches[1]] : "";
}, $skin);


// Front page (page 1) only tag
$skin = preg_replace_callback('/{isfront}(.+?){\/isfront}/is', function($matches) {
global $FORM;

if(empty($FORM["a"]) && empty($FORM["method"]) && empty($FORM["cat"])) {
return $matches[1];
}
else {}
}, $skin);

//Ampersand Validation purpose only, does not affect any URLs
$skin = str_replace(' & ', ' & ', $skin);

return $skin;
}
and for this function, i have (0.9)
function parse($skin) {
global $LNG, $TMPL, $n, $parse_time;

if(!empty($_GET['a']) || !empty($_GET['cat'])) {$TMPL['front_page_top'] = '';}

// Language tags
$skin = preg_replace_callback('/{\$lng->(.+?)}/i', create_function('$matches', 'global $LNG; return $LNG[$matches[1]];'), $skin);

// Limit text created by template tags
$skin = preg_replace_callback('/{\$(.+?)((?:,\s?length=)([0-9]+?))?}/i', create_function('$matches', 'global $TMPL;
if(isset($matches[3])) {
$limit = $matches[3];
if (mb_strlen($TMPL[$matches[1]]) > $limit) {
$TMPL[$matches[1]] = mb_substr($TMPL[$matches[1]], 0, mb_strrpos(mb_substr($TMPL[$matches[1]], 0, $limit), " ")) . "...";
}
}
return $TMPL[$matches[1]];
'), $skin);

// Include tag
$skin = preg_replace_callback('/{include \"(.+?)\"}/i', create_function('$matches', 'return file_get_contents($matches[1]);'), $skin);

// Front page (page 1) only tag
$skin = preg_replace_callback('/{isfront}(.+?){\/isfront}/is', create_function('$matches', 'global $FORM;
if(empty($FORM["a"]) && empty($FORM["method"]) && empty($FORM["cat"])) {
return $matches[1];
} else {}
'), $skin);

//Ampersand Validation purpose only, does not affect any URLs
$skin = str_replace(' & ', ' & ', $skin);

return $skin;
}
With this last code (0.9), the {include} is OK when i include this in my page

i just read "create_function" is "Warning This function has been DEPRECATED as of PHP 7.2.0. Relying on this function is highly discouraged."

would it be possible to have a function compatible with the current versions of PHP that works with the include in a personal page?

Thank
 

Mark

Administrator
Staff member
I just tested on PHP 7.2 and 7.3 in both cases the {include "https://mydomain/testscript.php"} worked as expected. Can you check your error_log for more details?

Edit: there is no "create_function" in 1.6, we are already 7.2+ ready
 

autosurf

Active Member
I don't have any error, i have just in my test page : {include "https://mydomain/testscript.php"}

it's just that it does not interpret the inclusion command but displays it as if it were text to display

And i have try with php 7.1.33 and php 7.2.24 the result is the same
 

autosurf

Active Member
I try with parabola (defaut) and with other, the problem is the same.

When i put my include in : /index.php?a=admin&b=edit_page&id=test
with the V0.9, it's interpretate and i can see the generate page
with the V1.6, it's only text => {include "https://mydomain/testscript.php"}
 

Mark

Administrator
Staff member
Those tags only work in the skin templates, not inside the content of custom pages.

I'll see if we can make that work for you.
 

autosurf

Active Member
thank you mark, in fact my problem comes only custom pages from the beginning, sorry not to have been precise enough in my request.

It works well with version 0.9 however, as stated in the message above.
and if I replace the function parse ($ skin) of the V1.6 by the function parse ($ skin) of the V0.9, the include works well on the pages custom but the function create_function is depreciated with php 7: /

I hope you'll find a solution, this ability to include is very convenient for custom pages, it can make them dynamic (for example, including php or readings in the database)
 

Basti

Administrator
Staff member
Do not edit skin.php or any core file. This is quite easy to integrate into the page.php file using a similar function
Ill post a updated page.php in a few minutes, though untested, cause lack of time
 

Basti

Administrator
Staff member
make a backup of sources/page.php

This is for VL 1.6
in that file find the following

Code:
    $TMPL['meta_description'] = !empty($description) ? $description : $TMPL['meta_description'];
Right above on a new line, add the following code
Code:
    // Include tag
    $TMPL['content'] = preg_replace_callback('/{include \"(.+?)\"}/i', function($matches) {
       
        return file_get_contents($matches[1]);
    }, $TMPL['content']);
 

autosurf

Active Member
The solution that Basti proposed works very well. You are Great

Thank you Basti and Mark for your research and your work !
 

Mark

Administrator
Staff member
make a backup of sources/page.php

This is for VL 1.6
in that file find the following

Code:
    $TMPL['meta_description'] = !empty($description) ? $description : $TMPL['meta_description'];
Right above on a new line, add the following code
Code:
    // Include tag
    $TMPL['content'] = preg_replace_callback('/{include \"(.+?)\"}/i', function($matches) {
      
        return file_get_contents($matches[1]);
    }, $TMPL['content']);
Nice, we should probably roll this into 1.7?
 
Top