php print file_get_contents

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
duivelken
Forum Members
Forum Members
Posts: 10
Joined: Wed Jul 18, 2018 1:01 pm

php print file_get_contents

Post 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

----------------------------------------------
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1809
Joined: Wed Feb 25, 2009 4:25 am

Re: php print file_get_contents

Post 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)
Not getting the answer you need? CMSMS support options
duivelken
Forum Members
Forum Members
Posts: 10
Joined: Wed Jul 18, 2018 1:01 pm

Re: php print file_get_contents

Post by duivelken »

Thx, gonna give it a try :-)
duivelken
Forum Members
Forum Members
Posts: 10
Joined: Wed Jul 18, 2018 1:01 pm

Re: php print file_get_contents

Post 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.
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: php print file_get_contents

Post by Rolf »

- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: php print file_get_contents

Post 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}
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1809
Joined: Wed Feb 25, 2009 4:25 am

Re: php print file_get_contents

Post by DIGI3 »

It's also protected by cloudflare so it may have to be explicitly allowed by IP or something.
Not getting the answer you need? CMSMS support options
duivelken
Forum Members
Forum Members
Posts: 10
Joined: Wed Jul 18, 2018 1:01 pm

Re: php print file_get_contents

Post 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 :-)
duivelken
Forum Members
Forum Members
Posts: 10
Joined: Wed Jul 18, 2018 1:01 pm

Re: php print file_get_contents

Post 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 :-((((((
duivelken
Forum Members
Forum Members
Posts: 10
Joined: Wed Jul 18, 2018 1:01 pm

Re: php print file_get_contents

Post 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 :(
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1809
Joined: Wed Feb 25, 2009 4:25 am

Re: php print file_get_contents

Post 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.
Not getting the answer you need? CMSMS support options
duivelken
Forum Members
Forum Members
Posts: 10
Joined: Wed Jul 18, 2018 1:01 pm

Re: php print file_get_contents

Post 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.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: php print file_get_contents

Post 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)
Post Reply

Return to “Modules/Add-Ons”