pluck-cms / pluck

Central repo for pluck cms
http://www.pluck-cms.org
56 stars 39 forks source link

How to use php scripts in content #30

Closed la3rk closed 9 years ago

la3rk commented 9 years ago

I have some php scripts I would like to add in the content field and to be run when page is called. How to achieve this. Have tried via tinymce, but tinymce does not like scripts in the text field. Could of course write a new module, but this seems an overkill.

Any suggestions?

Olaf

filisko commented 9 years ago

Hello, Do you still need this feature?

la3rk commented 9 years ago

Currently my workaround is to point to a php script script which gives the html I want, but then the result is outside Pluck.

Ideally I would like to refer directly through the menu.

Script is used to show a number of pictures/videos created by an IP camera. Content varies dymamically.

Regards Olaf

On 11.24 27. August 2015, Filis wrote: Hello, Do you still need this feature?

— Reply to this email directly or view it on GitHub.

filisko commented 9 years ago

What you could do is:

  1. Create a folder called php_pages (or however you want to call it) in your pluck's root path.
  2. Create your PHP file inside, for example phpfile.php
  3. Go to pluck-cms/data/settings/pages/test.php (that file will be the page that will contain your just created PHP file in php_pages folder)
  4. test.php will probably containt four variables: title, seoname, content and hidden, the one that we need is content, put it's value to:
$content = include '/var/www/pluck-master/php_pages/phpfile.php';

/var/www/pluck-master/php_pages/phpfile.php must RETURN something, if not, it won't work as expected.

<?php
$var = 1;

if ($var == 0) {
    return "000000000000";
} else {
    return "111111111111";
}
?>

And what it returns will be displayed on your page without any problem. In this case you should see 111111111111.

I don't know if this will help you but by this way you can include an external php file in your pluck-cms page.

Regards, Filis

la3rk commented 9 years ago

Thanks. Will try. Seems like a logical solution. Not easy to figure out from the source code.

Regards Olaf

On 14.18 27. August 2015, Filis wrote: What you could do is: Create a folder called 'php_pages' (or however you want to call it) in your pluck's root path.Create your PHP file inside.Go to pluck-cms/data/settings/pages/test.php (test.php is the file that will contain your PHP file) test.php will probably containt four variables: title, seoname, content and hidden, the one that we need is content, put it's value to: $content = include '/var/www/pluck-master/php_pages/phpfile.php';

And your /var/www/pluck-master/php_pages/phpfile.php must return something.

<?php $var = 01; if ($var == 0) { return "000000000000"; } else { return "111111111111"; } ?>

And what it returns will be displayed on your page without any problem.

I don't know if this will help you but by this way you can include an external php file in your pluck-cms page.

Regards, Filis

— Reply to this email directly or view it on GitHub.

filisko commented 9 years ago

You're welcome!

Try it and tell us how it went.

Regards, Filis

la3rk commented 9 years ago

Seems to be close to get your proposal to work. Some problems of course. Firstly had to use include_once as I got errors due to reuse of some functions internally within the php script.

On the pages I now get the following error; Notice: Array to string conversion in /var/www/data/inc/functions.site.php on line 193 This text occurs just before the menu selection of the page and the menu selection seems now contains all the level 1 pages as subpages.

On the admin pages under pages I get the following errors; Warning: strpos() expects parameter 1 to be string, array given in /var/www/data/inc/functions.all.php on line 273

Notice: Array to string conversion in /var/www/data/inc/functions.all.php on line 275 The page title appears correctly.

It seems that the link to the page is somewhat different from the other pages, the normal form is www....../?file=forsiden. The new page reports as www....../?file=/bevegelser - note the slash.

These errors occur regardless of what I let the php script return.

Regards Olaf

Den 27.08.2015 14:55, skrev Filis:

You're welcome!

Try it and tell us how it went.

Regards, Filis

— Reply to this email directly or view it on GitHub https://github.com/pluck-cms/pluck/issues/30#issuecomment-135414232.

Regards

Olaf Devik M: +47 911 70 849 E: olaf.devik@mollefaret.no

la3rk commented 9 years ago

Forget the above - I had the same variable name in the php script which seems to have been picked up by pluck where a string was expected.

filisko commented 9 years ago

So, I get that everything is fine now?

la3rk commented 9 years ago

Sorry no. The intended text shows up in the admin pages, ie in the TinyMce edit form. But on the page itself nothing - its like everything is filtered out. No errors shown.

On 23.43 27. August 2015, Filis wrote: So, I get that everything is fine now?

— Reply to this email directly or view it on GitHub.

la3rk commented 9 years ago

And as an additional info. To show the result on the webpages, I have to use save from the admin menu ie any update will have to go through the admin page to get an update.

Regards Olaf

On 23.43 27. August 2015, Filis wrote: So, I get that everything is fine now?

— Reply to this email directly or view it on GitHub.

filisko commented 9 years ago

Could we have a look to your page file and the included one?

billcreswell commented 9 years ago

The most proper way is to write a plug-in. (https://github.com/pluck-cms/pluck/wiki/Module-guide). But you can hack it in the theme.php by adding

to main page content

<div id="content">
<h2><?php theme_pagetitle(); ?></h2>
<!-- Your Code here-->
<?php if(CURRENT_PAGE_SEONAME == 'home') {
       echo 'hello';
}?>
<!---->
 <?php theme_content(); ?>
 <?php theme_area('main'); ?>

or for sidebar

<div class='menu'>
<?php theme_menu('ul', 'li', 'current_page_item', 1, true); ?>
<?php theme_area('sidebar'); ?>
<!-- Your Code here-->
<?php if(CURRENT_PAGE_SEONAME == 'home') {
       echo 'hello';
}?>
<!---->

Replace 'home' with whatever page you want to replace it on, or skip the if statement altogether for your content to appear on all pages.

billcreswell commented 9 years ago

To illustrate how simple a module is: For a plugin called 'simple':

Create a directory called 'simple'.

File 1 is simple.php - contains the plugin info

<?php
//{plugin}_info
function simple_info() {
    $module_info = array(
        'name'          => 'My Simple Demo Module',
        'intro'         => 'The Simplest Module',
        'version'       => '0.1',
        'author'        => 'grwebguy',
        'website'       => 'http://twitter.com/grwebguy',
        'compatibility' => '4.7'
    );

File 2 is simple.site.php contains the code

<?php
defined('IN_PLUCK') or exit('Access denied!');
//{pluginname}_theme_main()
function simple_theme_main() {
    echo getMessage();
}
function getMessage() {
    return 'Hello Friends, this is my simple module';
}
la3rk commented 9 years ago

Thanks that did the trick. A simple example of a minimum module was all that was needed. I think I will abandon the approach earlier tried because that seems to be problematic. Thanks for all help.

Regards Olaf

Den 28.08.2015 13:16, skrev Bill Creswell:

To illustrate how simple a module is: For a plugin called 'simple':

Create a directory called 'simple'.

File 1 is simple.php - contains the plugin info

<?php //{plugin}_info function simple_info() { $module_info = array( 'name' => 'My Simple Demo Module', 'intro' => 'The Simplest Module', 'version' => '0.1', 'author' => 'grwebguy', 'website' => 'http://twitter.com/grwebguy', 'compatibility' => '4.7' );


File 2 is simple.site.php contains the code

```{php}
<?php
defined('IN_PLUCK') or exit('Access denied!');
//{pluginname}_theme_main()
function simple_theme_main() {
echo getMessage();
}
function getMessage() {
return 'Hello Friends, this is my simple module';
}

—
Reply to this email directly or view it on GitHub 
<https://github.com/pluck-cms/pluck/issues/30#issuecomment-135743379>.

Regards

Olaf Devik M: +47 911 70 849 E: olaf.devik@mollefaret.no

filisko commented 9 years ago

You welcome!

billcreswell commented 9 years ago

Good luck Olaf (la3rk), and thanks for all your input Filisko!