CakePHP emailFormat('both') vs emailFormat('html') and emailFormat('text') - cakephp

In cakephp documentation it is stated that you can use both text and html template files if you set up like this :
$email = new Email();
$email
->template('welcome', 'fancy')
->emailFormat('both')
->to('bob#example.com')
->from('app#domain.com')
->send();
This would use the following template files:
src/Template/Email/text/welcome.ctp
src/Template/Layout/Email/text/fancy.ctp
src/Template/Email/html/welcome.ctp
src/Template/Layout/Email/html/fancy.ctp
How does it use both html and text files here? Does it check both text files and html files when creating a view? What if there are differences in those templates?

When setting emailFormat to both, CakePHP will put both templates in email, and set Content-type header of message to multipart/alternative. With this behavior, receiving end will be provided with two versions of the same message and will be able to choose which to use.
That means you can provide rich and flashy HTML version of your email to users that can display it, and also provide simple plaintext version of your message which will be used by email clients that can not (or refuse to) render HTML emails.
For more info, please look at this question and answer, as well as at RFC.

Related

How can I download a PDF file from a form using UI designer?? Bonita

The thing is I have found how upload a document and after that downolad it. But I just want to download it. I want to do it using the UI designer but I dont know how to do it.
Thanks :)
I dont know which tool are you using to design your UI, anyway this is concerning functionality, not design. In that point, i need to know wich language do you want (or can) use. For example, in PHP, it's very simple, you can make something like:
(create php file) downloadpdf.php
1st: (if you want to generate pdf "on the fly":
<?php
function download($foo){
content headers (type, force-download, etc)
database select to get data or harcode it.
echo data
}
?>
and call this function with some id to select from database or something (ignore if you want to hardcode it)
Other option to download a file, if it's stored on server is making a link to this file (statically or dyamically). If you wanna take control to file downloads, check this post:
http://www.media-division.com/the-right-way-to-handle-file-downloads-in-php/
I don't mean that it can be done with UI designer tools, and it's not concerned if it's from a form or not.
Cheers!
You should create link and variable which type is javascript expression. On Variable value write
return "/bonita/portal/" + $data.context.mainDoc_ref.url;
On link URL write your variable and to text
Download: {{context.mainDoc_ref.fileName}}
Here you can find excellent example for this case

CakePHP - read file from outside webroot

I have a model in /app/Model/User.php where I would like to read a file.
The file is located in /app/View/Emails/html/welcome.html:
$message = file_get_contents('../View/Emails/html/welcome.html');
This works locally but not online. What to change?
You do it wrong, what you try is already covered by the framework. See this, "Sending templated emails". Reading the book is always a good idea. Copy and paste from the book:
Emails are often much more than just a simple text message. In order
to facilitate that, CakePHP provides a way to send emails using
CakePHP’s view layer.
The templates for emails reside in a special folder in your
applications View directory called Emails. Email views can also use
layouts, and elements just like normal views:
$Email = new CakeEmail();
$Email->template('welcome', 'fancy')
->emailFormat('html')
->to('bob#example.com')
->from('app#domain.com')
->send();
The above would use app/View/Emails/html/welcome.ctp for the view, and
app/View/Layouts/Emails/html/fancy.ctp for the layout. You can send
multipart templated email messages as well:

HTMLPurifier custom filter configuration

I've seen many posts on various sites which talk about adding "to your HTML Purifier config", like Sonny's excellent response to this question: HTMLPurifier iframe Vimeo and Youtube video
However, try as I might, I can't seem to discover exactly how to set up my HTML Purifier config. I'm actually trying to add a custom filter a la Sonny's comment, but the closest I can come to discovering how to set up my HTML purifier config in my Drupal 7 environment is from /sites/all/modules/htmlpurifier/config/sample.php:
<?php
/**
* #file
* This file is a sample advanced PHP configuration file for the HTML Purifier
* filter module. In reality, this file would be named N.php, where N is the
* integer identifying the filter this is configuring. The configure page
* for HTML Purifier (advanced) will tell you what file to copy this to.
*
* See this URI:
*
* http://htmlpurifier.org/live/configdoc/plain.html
*
* For full information about permitted directives. The most interesting ones
* for custom configuration are ones with the 'mixed' type, as they cannot
* be configured using the webform.
But this hasn't helped me at all - I don't see anything on the HTML Purifier (advanced) configure page (on the text filter config page? I don't see anything there...), and the doc at the URI above didn't help, either.
Edit: much thanks to #Chris for his answer to my original question. I subsequently found that creating the filtered_html.php file removes the ability for me to configure HTML Purifier for Filtered HTML from the UI! Is this supposed to happen?
All that I see from the UI when looking at HTML Purifier (Advanced) is the checkbox for "Display help text". (I already added this as a comment below, but I thought I'd modify my question as well in the hopes that more people would see this...)
First, make sure you have the HTML purifier library installed as show in the INSTALL.txt file. The status report page will show you the version if it's installed correctly.
In Drupal 7 the filter system now uses string keys rather than integer. So to create a configuration file for the format "Filtered HTML" under sites/all/modules/htmlpurifier/config/, copy sample.php to filtered_html.php, and update the hook function name like this:
function htmlpurifier_config_filtered_html($config) {
The rest of the tutorial above worked for me, and now my preFilter and postFilter functions are being called.
I thought you could do this through the UI, but it looks like the "Filters" custom configuration box is not evaluated as PHP.

Drupal Attachments (FileField) file path

What function in Drupal gets file attachment path?
Edit: the attachments provided by Upload module in system section. But since you mentioned there may be another way around it. Maybe I could achieve may goals using FileField module so if you could tell me how to get a direct link of a file uploaded by FileField module that may also be very helpful.
Edit 2:
Ok I will start from my main and final objective:
It is to get an image linking to a file which visibility I could be managed using CCK module.
I am doing this step by step. So now I have written a code which generates the needed image and I have added that image to one of content types teaser. I found a way to warp my image in a tag and I had dug up simple attachments url. So my next step is to advance from simple upload attachment to the one added by FileFields and from odd looking HTML pace in all PHP document into beautifully managed CCK field.
How to fetch file path of a file uploaded FileFields?
Some plain and at the same time rich tutorials for making custom fields for CCK module.
Assuming you know how to get the $node object for a node containing a file attachment, this is super easy:
Upload (core)
$file = upload_load($node);
echo $file[1]->filepath;
Where 1 is the index of the file. Upload can let you upload more than one file, so file 2 would have an index of 2 and so on. If there's only one file, it'll always be 1.
More info: upload_load() API reference.
FileField
echo $node->field_fieldname[0]['filepath'];
Where field_filename is the short name you've used for the field, and 0 is the index of the field. CCK fields let you have multiple values in one field, so 0 would be the first, 1 would be the second, etc. If you only have one value, it'll always be 0.
Note: if you want to get the rendered output of the FileField using its formatters, you can just use $field_fieldname in your node template, or if you want to store the rendered output, you can use:
echo content_format('field_fieldname', $node->field_fieldname[0]);
More info: content_format() API reference.
Upload is a sad little module, and has been completely replaced with a core implementation of FileField in Drupal 7. If you have the option to use FileField, you should.
Don't direct links of file attachments appear below the uploaded file for the core Upload module?
Since you are trying to use images, you should use http://drupal.org/project/imagefield CCK module in order to add images to specified content type. After that using the Display fields tab in Content type configuration you can specify how image would be presented (as a link, image, image with link to node...) both in teaser and body view.

Receive multi file post with google app engine

I want to receive multi file post from image uploader.(i use this)
Most examples show how to receive one image from post.
I tried many ways but never got the results.
For example
self.request.POST['Filename']
gives only first filename.
What to do when there are multiple files/images in post?
The reason for this is to resize before upload images, that are too big for google app engine
to upload.
EDIT:
self.request.POST.multi.__dict__
shows
{'_items':
[('Filename', 'camila1.jpg'),
('Filedata[]', FieldStorage('Filedata[]', 'camila1.jpg')),
('Upload', 'Submit Query\r\n--negpwjpcenudkacqrxpleuuubfqqftwm----negpwjpcenudkacqrxpleuuubfqqftwm\r\nContent-Disposition: form-data; name="Filename"\r\n\r\nbornToBeWild1.jpg'),
('Filedata[]', FieldStorage('Filedata[]', 'bornToBeWild1.jpg')),
('Upload', 'Submit Query')]}
Your flash uploader is designed to work with PHP and sends multiple Filedata[] fields (php interprets this as an array for easy access)
So you need to iterate and get them all:
def post(self):
for file_data in self.request.POST.getall('Filedata[]'):
logging.info(file_data.filename)
data should be file_data.value
Are you using the Django libraries available to you? If so, check this out.
Call self.request.POST.getall('Filename') to get a list of FieldStorage objects; each one contains one file. You can access the file data with .value, the name with .name, and the mimetype with .type.
I have no idea how that multi uploader works, I have made one in the past however and I just added a number on the end of input field name, then hide it. Then add a new file input field to add another file. The reason for this is that they don't let you play around with input file fields to much because you could make it upload files they didn't want you uploading.
Using my conventions, in your example the 2 files in your example would be "Filename0" and "Filename1". You could also use firebug to see what it renaming the input file fields to.
Edit: I had a look, and it's using flash. So i have no idea how it works.

Resources