Jump to content

Is there any way to execute PHP loaded from textarea fields?


DZoneRick
 Share

Recommended Posts

To add an image to TinyMCE, make sure the template has an images field - that will be your local library for the page, if you like.

Upload what ever images you want.

To insert into TinyMCE, click on the TinyMCE images button - a bespoke images popup will open listing all the images from your image field (Note: you can also browse images from other pages).

Select an image and resize to suit (an automatic thumbnail will be created).

Choose your alignment, and click the box if you want the image to link to the original version.

Insert, and there you go.

NOTE:

If you would like those images to open in a lightbox (for instance colorbox or fancybox), Install and set up the jquery plugin (making sure you also installed JQuery, of course) and then you can use a bit of jquery to automatically add the required images for any <img> tag that is surrounded by an <a> tag. Probably limit it to the container where your articles appear, for safety.

The image system in PW means that when ever you dictate sizes, whether that is via TinyMCE (and CKEditor in a day or so), or set sizes when rendering images in your template files, thumbnails are cached of the right size without you actually having to tell it to do so.

And if you are using image fields (rather than inserting via TinyMCE), there is also a superb Thumbnails module that allows you to preset multiple thumbnail sizes and comes with a Crop function so you can customize each one.

  • Like 1
Link to comment
Share on other sites

Just had a look at Desk.com and it would be no problem to put that together with ProcessWire at all.

OK, it's encouraging that you and others here feel that producing such a site wouldn't be a problem with PW. The fact is, after all, that I have decided to invest time, money and energy in adopting PW because it really seems to be the best of the available options.

I'll tell you guys truly, though, that it's a damned shame there's not a killer PW gallery of killer PW sites. Nothing I have seen in the examples promoted on the PW website comes close to the tour-de-force range of that Desk.com site. It would have been super helpful to be able to browse through a lot more examples of PW sites, and managing such a gallery is precisely where PW excels!

Link to comment
Share on other sites

To add an image to TinyMCE, make sure the template has an images field - that will be your local library for the page, if you like.

Upload what ever images you want.

To insert into TinyMCE, click on the TinyMCE images button - a bespoke images popup will open listing all the images from your image field (Note: you can also browse images from other pages).

OK, I immediately went and tried it out, and the TinyMCE image plugin is merely hard-coding the path into the underlying html, which totally defeats the purpose. Here's an example of the html created by the TinyMCE plugin:

<img src="/site/assets/files/1062/answerhub-logo-230x60.png" width="230" height="60" alt="AnswerHub" />

Hard-coding the path will only work UNTIL the site gets moved or the path changes, and then you're up a creek without a paddle. I'm looking for a simple, safe, reliable way to access $config->urls->templates and use it in markup stored in text fields. The TinyMCE plugin is not producing the outcome I was aiming for.

Link to comment
Share on other sites

Currently, most people develop so that paths don't change (root on their local server solution and then root on the final site)

If you are developing in a sub-domain, it is a couple of minutes work to do a search and replace in the database to change the path.

But, and this is a big but, I think if most of us were designing a site like desk.com, we would not be relying on a wysiwyg editor, but using simple fields (text, textarea, image) and leaving the construction to the template files and assoiciated CSS in style sheets. When you look at the source of Desk.com. that is how they have done it.

Desk.com is controlled by a 17,000 line style sheet (looks like it started as Bootstrap somewhere in the past) with huge amounts of overrides to deal with every version of IE, sort out all the responsive side and so on. That includes all of the background images. 

And it looks like they are loading most of the JS on every page.

It may be to your advantage to change the way you were thinking of designing this and keep the database for what it is good at (storing the site data and relationships) and work on some really storming template files that give you exactly what you want.

I think you may well end up with a much better site that is much easier to maintain for the long term.

Link to comment
Share on other sites

OK, I immediately went and tried it out, and the TinyMCE image plugin is merely hard-coding the path into the underlying html, which totally defeats the purpose. Here's an example of the html created by the TinyMCE plugin:

<img src="/site/assets/files/1062/answerhub-logo-230x60.png" width="230" height="60" alt="AnswerHub" />

Hard-coding the path will only work UNTIL the site gets moved or the path changes, and then you're up a creek without a paddle. I'm looking for a simple, safe, reliable way to access $config->urls->templates and use it in markup stored in text fields. The TinyMCE plugin is not producing the outcome I was aiming for.

Ok, this thread has gotten a little bit out of control in regards to the original question and where it went from there. It's not even about the possibility of putting PHP into text(area) fields perse, but the ability to use variables or tags inside text fields. In your example something for $config->urls->templates.

Like Soma said: "Pw has no template tag language and will never have in core level. However this is an easy task and would make a simple textformatter module. Basicly what wanze does but more convenient."

I was thinking you could maybe use http://processwire.com/talk/topic/1819-markupshortcodes/ to map $config->urls->templates to [urltemplates]. Then you could just use [urltemplates] anywhere in text fields of your choosing. The sky is the limit, you can define as many tags as you like representing every combination of php/js/html you wish.

  • Like 4
Link to comment
Share on other sites

Then you could just use [urltemplates] anywhere in text fields of your choosing. The sky is the limit, you can define as many tags as you like representing every combination of php/js/html you wish.

That's really interesting. Could this also be used for a simple javascript [slideshow] or [news-scroller] ?
Link to comment
Share on other sites

I was thinking you could maybe use http://processwire.com/talk/topic/1819-markupshortcodes/ to map $config->urls->templates to [urltemplates]. Then you could just use [urltemplates] anywhere in text fields of your choosing. The sky is the limit, you can define as many tags as you like representing every combination of php/js/html you wish.

Very cool module, and it looks like it can do exactly what I want. My original question about php in fields was driven by my specific need to use the value of $config->urls->templates inside markup fields. It looks like MarkupShortcodes makes this relatively easy. Thanks!

  • Like 1
Link to comment
Share on other sites

That's really interesting. Could this also be used for a simple javascript [slideshow] or [news-scroller] ?

I don't see why not. Mind you, i haven't actually used  Nico's module so if you have questions post them in the corresponding module thread.

Link to comment
Share on other sites

OK, I immediately went and tried it out, and the TinyMCE image plugin is merely hard-coding the path into the underlying html, which totally defeats the purpose. Here's an example of the html created by the TinyMCE plugin:

The PageLinkAbstractor module will abstract those URLs to something that will work regardless of where you place it. Though I'm actually looking to make the PageLinkAbstractor module useless, by having the core take care of this abstraction instead. That way we don't have to search/replace when going from our development site subdirectory to production site at root (search/replace is what I do on the DB dump file when migrating a site). 

There has been one instance on I site I developed where I needed values from $config in one of my textarea fields. The way I solved it was to place something like the following at the top of my first include file (in that case, it was _init.php): 

// these are just examples of tag replacements I've used
// but they could be anything...
$replacements = array(
  '{config.urls.root}' => $config->urls->root,
  '{config.urls.templates}' => $config->urls->templates,
  '{url}' => $page->url,
  '{id}' => $page->id, 
  ); 

// perform the tag-to-value replacements
$page->body = str_replace(array_keys($replacements), array_values($replacements), $page->body); 
 
Link to comment
Share on other sites

Same stuff as Ryan posted with using my module:

<?php

$shortcode = $modules->get('MarkupShortcodes');

$shortcode->add('config.urls.root', function($atts){
	return $config->urls->root;
});

$shortcode->add('config.urls.templates', function($atts){
	return $config->urls->templates;
});

$shortcode->add('url', function($atts){
	return $page->url;
});

$shortcode->add('id', function($atts){
	return $page->id;
});

echo $shortcode->render($page->body);

?>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...