Page 1 of 1

php print file_get_contents

Posted: Mon Oct 12, 2020 6:53 pm
by duivelken
Hi,

maybe this is a very stupid question, but I'm quite the noob when it comes down to this.

So basically, I have a site running CMSMS and totally love how I can do almost anything with it without having to be a programmer :D

My site is about ceramics and workshops, and the idea is customers can subscribe to a workshop via the system (I found a partner for this).

So I want to to integrate a calendar in my cmsms installation, and the partner gives several options. One is an iframe, but that's totally ugly.

The other one is with this:

<?php print file_get_contents('https://www.myreservations.nl/calendar. ... 7e01dc7079'); ?>

Now I tried to modify a template (I made a copy of an existing one and am working on this copy.

So in the block content I tried doing this:

{block name='content'}
<div class="column row text-center">
<h3>{title}</h3>
<?php print file_get_contents('https://www.myreservations.nl/calendar. ... 7e01dc7079'); ?>
</div>
{/block}

which if probably totally idiotic, I know, but it was worth a shot.

Anyone of you know how I would be able to integrate this into my website and not having to resort to an iframe?

Thank you very much in advance.

This is the info I find in my cmsms installation:



----------------------------------------------

Cms Version: 2.2.7

Installed Modules:

AdminSearch: 1.0.4
CGCalendar: 2.5.1
CGExtensions: 1.61.5
CGGoogleMaps2: 1.1.1
CGSimpleSmarty: 2.2.1
CGSmartImage: 1.22.2
CMSContentManager: 1.1.6
CMSMailer: 6.2.14
Captcha: 1.0
CmsJobManager: 0.1.2
DesignManager: 1.1.4
FileManager: 1.6.6
FilePicker: 1.0.2
FormBuilder: 1.0.2
Gallery: 2.4.2
LISE: 1.3.1
MenuManager: 1.50.3
MicroTiny: 2.2.2
ModuleManager: 2.1.3
Navigator: 1.0.8
News: 2.51.3
Search: 1.51.4


Config Information:

php_memory_limit:
max_upload_size: 256000000
url_rewriting: mod_rewrite
page_extension:
query_var: page
auto_alias_content: true
locale:
set_names: true
timezone: Europe/Brussels
permissive_smarty: false


Php Information:

phpversion: 7.1.33
md5_function: Aan (Waar)
json_function: Aan (Waar)
gd_version: 2
tempnam_function: Aan (Waar)
magic_quotes_runtime: Uit (Onwaar)
E_ALL: 32759
E_STRICT: 2048
E_DEPRECATED: 8192
test_file_timedifference: Geen tijdsverschillen gevonden
test_db_timedifference: Geen tijdsverschillen gevonden
create_dir_and_file: 1
memory_limit: 128M
max_execution_time: 300
register_globals: Uit (Onwaar)
output_buffering: Aan
disable_functions: symlink
open_basedir: /data/sites/web/kreamiekbe2538:/usr/local/php-7.1/lib/php:/usr/bin:/tmp:/data/vendor-scripts:/data/sites/web/disabled:/etc/ssl/certs
test_remote_url: Succes
file_uploads: Aan (Waar)
post_max_size: 256M
upload_max_filesize: 256M
session_save_path: Geen controle omdat 'open_basedir' actief is
session_use_cookies: Aan (Waar)
xml_function: Aan (Waar)
xmlreader_class: Aan (Waar)
check_ini_set: Aan (Waar)
curl: Aan


Performance Information:

allow_browser_cache: Aan (Waar)
browser_cache_expiry: 60
php_opcache: Aan (Waar)
smarty_cache: Uit (Onwaar)
smarty_compilecheck: Uit (Onwaar)
auto_clear_cache_age: Aan (Waar)

Server Information:

Server Software: Apache
Server Api: fpm-fcgi
Server Os: Linux 4.19.140-combell Aan x86_64
Server Db Type: MySQL (mysqli)
Server Db Version: 5.7.31
Server Db Grants: Er is een "GRAND ALL" permissie gevonden, alles lijkt in orde.


Permission Information:

tmp: /data/sites/web/kreamiekbe2538/www/tmp (0755)
tmp_cache: /data/sites/web/kreamiekbe2538/www/tmp/cache (0755)
templates_c: /data/sites/web/kreamiekbe2538/www/tmp/templates_c (0755)
modules: /data/sites/web/kreamiekbe2538/www/modules (0755)
uploads: /data/sites/web/kreamiekbe2538/www/uploads (0755)
Bestandscreatiemasker (umask): /data/sites/web/kreamiekbe2538/www/tmp/cache (0755)
config_file: 0444

----------------------------------------------

Re: php print file_get_contents

Posted: Tue Oct 13, 2020 12:44 am
by DIGI3
Ideally the partner would provide an api that you could integrate through, but if that's not an option perhaps try {fetch} https://www.smarty.net/docs/en/language ... .fetch.tpl . You'll need to use permissive_smarty mode (https://docs.cmsmadesimple.org/configur ... ive_smarty)

Re: php print file_get_contents

Posted: Tue Oct 13, 2020 7:50 am
by duivelken
Thx, gonna give it a try :-)

Re: php print file_get_contents

Posted: Tue Oct 13, 2020 11:04 am
by duivelken
Hello again,

so this is what I did:

1)
I added to config.php =>

$config['permissive_smarty'] = 1;

2)
I went to Settings/Global/Smarty and put both on yes.

3)
I adapted the template to have this:
{block name='content'}
<div class="column row text-center">
<h3>{title}</h3>
{fetch file='https://www.myreservations.nl/calendar. ... b33#loaded'}
</div>
{/block}

Which results in to this:


Error: at line 212 in file /data/sites/web/kreamiekbe2538/www/lib/smarty/plugins/function.fetch.php:

Message:

{fetch} cannot read resource 'https://www.myreservations.nl/calendar. ... b33#loaded'

Close Full Trace ↑

#0 /data/sites/web/kreamiekbe2538/www/tmp/templates_c/e9445e6db6d3460ed1cafc6fb67c78ec5bb8b120_0.tpl_body.72.php(195): smarty_function_fetch(Array, Object(CMS_Smarty_Template))
#1 /data/sites/web/kreamiekbe2538/www/lib/smarty/sysplugins/smarty_internal_runtime_inheritance.php(238): Block_14026048255f85882f0e7cc2_16508018->callBlock(Object(CMS_Smarty_Template))
#2 /data/sites/web/kreamiekbe2538/www/lib/smarty/sysplugins/smarty_internal_runtime_inheritance.php(170): Smarty_Internal_Runtime_Inheritance->callBlock(Object(Block_14026048255f85882f0e7cc2_16508018), Object(CMS_Smarty_Template))
#3 /data/sites/web/kreamiekbe2538/www/lib/smarty/sysplugins/smarty_internal_runtime_inheritance.php(144): Smarty_Internal_Runtime_Inheritance->process(Object(CMS_Smarty_Template), Object(Block_14026048255f85882f0e7cc2_16508018))
#4 /data/sites/web/kreamiekbe2538/www/tmp/templates_c/e9445e6db6d3460ed1cafc6fb67c78ec5bb8b120_0.tpl_body.72.php(68): Smarty_Internal_Runtime_Inheritance->instanceBlock(Object(CMS_Smarty_Template), 'Block_140260482...', 'content')
#5 /data/sites/web/kreamiekbe2538/www/lib/smarty/sysplugins/smarty_template_resource_base.php(128): content_5f85882f1091e5_09165163(Object(CMS_Smarty_Template))
#6 /data/sites/web/kreamiekbe2538/www/lib/smarty/sysplugins/smarty_template_compiled.php(172): Smarty_Template_Resource_Base->getRenderedTemplateCode(Object(CMS_Smarty_Template))
#7 /data/sites/web/kreamiekbe2538/www/lib/smarty/sysplugins/smarty_internal_template.php(206): Smarty_Template_Compiled->render(Object(CMS_Smarty_Template))
#8 /data/sites/web/kreamiekbe2538/www/lib/smarty/sysplugins/smarty_internal_templatebase.php(216): Smarty_Internal_Template->render(false, 0)
#9 /data/sites/web/kreamiekbe2538/www/lib/smarty/sysplugins/smarty_internal_templatebase.php(107): Smarty_Internal_TemplateBase->_execute(Object(CMS_Smarty_Template), 'p42', NULL, NULL, 0)
#10 /data/sites/web/kreamiekbe2538/www/lib/classes/internal/class.CMS_Smarty_Template.php(20): Smarty_Internal_TemplateBase->fetch(NULL, 'p42', NULL, NULL)
#11 /data/sites/web/kreamiekbe2538/www/index.php(158): CMS_Smarty_Template->fetch()
#12 {main}

From what I understand, at CMSMS side everything is correct now and I should go check with myreservations.nl ? Or am I mistaken.

Thank you once again for you help.

Re: php print file_get_contents

Posted: Tue Oct 13, 2020 2:05 pm
by Rolf

Re: php print file_get_contents

Posted: Tue Oct 13, 2020 2:21 pm
by velden
Not sure caching a calendar is a good idea. Depends if the bookings get visible real time, or a date can be disabled if it's fully booked etc.

For the record: I can't get it to work either with this url on my local (xampp) install. It might have something to do with the fact it's https.

However, on my real hosting I managed to get it to work using an UDT (too lazy to set permissive_smarty)
2020-10-13 16_18_57-Window.png

Code: Select all

$res = file_get_contents('https://www.myreservations.nl/calendar.php?custid=938ebf418db6527134d43c7e01dc7079');
echo $res;
Where you want to the calendar to be displayed use:

Code: Select all

{get_calendar}

Re: php print file_get_contents

Posted: Tue Oct 13, 2020 3:20 pm
by DIGI3
It's also protected by cloudflare so it may have to be explicitly allowed by IP or something.

Re: php print file_get_contents

Posted: Tue Oct 13, 2020 3:33 pm
by duivelken
Rolf wrote: Tue Oct 13, 2020 2:05 pm Might be useful
http://dev.cmsmadesimple.org/projects/cacheremotefile
Thx Rolf, but what I understand from the explanation, this is for creating content that can then be displayed on another website. What I would like to do is display external dynamic content on my cmsms site without having to resort to iframes :-)

Will give this a try however and let you know if it works :-)

Re: php print file_get_contents

Posted: Tue Oct 13, 2020 3:42 pm
by duivelken
velden wrote: Tue Oct 13, 2020 2:21 pm Not sure caching a calendar is a good idea. Depends if the bookings get visible real time, or a date can be disabled if it's fully booked etc.

For the record: I can't get it to work either with this url on my local (xampp) install. It might have something to do with the fact it's https.

However, on my real hosting I managed to get it to work using an UDT (too lazy to set permissive_smarty)

2020-10-13 16_18_57-Window.png

Code: Select all

$res = file_get_contents('https://www.myreservations.nl/calendar.php?custid=938ebf418db6527134d43c7e01dc7079');
echo $res;
Where you want to the calendar to be displayed use:

Code: Select all

{get_calendar}
Thx.

First of all, loving the support I am getting, great to see what a superb team there is trying to help noobs like me.

Secondly: I followed your instruction step by step, and eventhough it works on your live hosting, I can't get it to work :-(.

I disabled permissive_smarty to see if this would make a difference, but nope. Tried clearing website cache, no difference neither.

I really don't want to resort to iframes but I'm afraid the options are running out :-((((((

Re: php print file_get_contents

Posted: Tue Oct 13, 2020 3:45 pm
by duivelken
DIGI3 wrote: Tue Oct 13, 2020 3:20 pm It's also protected by cloudflare so it may have to be explicitly allowed by IP or something.
no idea what this is and how I could overcome this :(

Re: php print file_get_contents

Posted: Tue Oct 13, 2020 3:47 pm
by DIGI3
I tried Velden's suggestion and the error log shows connection 403 - forbidden. You might want to ask the calendar provider if there's a whitelist or other method to allow your server's IP or similar. Not sure how Velden got through but probably coincidental.

Re: php print file_get_contents

Posted: Tue Oct 13, 2020 3:57 pm
by duivelken
DIGI3 wrote: Tue Oct 13, 2020 3:47 pm I tried Velden's suggestion and the error log shows connection 403 - forbidden. You might want to ask the calendar provider if there's a whitelist or other method to allow your server's IP or similar. Not sure how Velden got through but probably coincidental.
Maybe only Dutch IP's are allowed... Not sure where Velden has his hosting off course, but that might be an explanation.

Re: php print file_get_contents

Posted: Tue Oct 13, 2020 5:43 pm
by velden
Yes, my hosting is in NL (Neostrada).

That said, the url just works in my browser too but not in my local xampp install. So not sure it's IP restricted.

Actually I suspect it's the https part which may play a role. You could just try a random non https url (e.g. http://www.cmsmadesimple.org/robots.txt)