How to resize civicrm images(uploaded via webform) in Drupal views.
The images are getting displayed but the width and height are of the size when they upload images..
2 solutions come to mind
Use css to give each image a max-width property. This will make images appear correctly, but won't save bandwidth as the full image will be downloaded and scaled client-side.
Use a drupal module such as Image Resize Filter
If you need more advanced resizing / image transformation options, you can create a custom template file for the image URL field and use drupal image style (admin/config/media/image-styles) to define the required conversion.
As CiviCRM is protecting the files (we don't have the files urls in the database since 4.4.4 ?), you need to use imagecache_external (didn't manage to make image_style_url work). The drawback of this module is that the image is duplicated in drupal.
Anyway, to make this work :
install imagecache_external, go to the configuration page (http://YOUR_SITE/admin/config/media/imagecache_external) and add YOUR_SITE to the white list
create a style http://YOUR_SITE/admin/config/media/image-styles/add
configure the view as needed and add the CiviCRM Image URL field
Edit the view -> Advanced -> Information
Find the file name corresponding to the field you want to customize and create the file with this file name in YOUR_THEME/templates/
Paste the following code (replace 'thumbnail' with the style name you have created) :
<?php
if ($row->{$field->field_alias} != '') {
print theme('imagecache_external', array(
'path' => $row->{$field->field_alias},
'style_name'=> 'thumbnail'));
}
?>
back to Edit the view -> Advanced -> Information -> Rescan templates file and then save the view.
This didn't quite work on a drupal 7 / CiviCRM 5.10+ system (don't know if it still works on earlier).
To make it work put this in the template file:
<?php
$path = $field->render($row);
if (!empty($path)) {
print theme('imagecache_external', array(
'path' => $path,
'style_name'=> 'thumbnail'));
}
?>
Related
I have a plugin installed that has its own layout overrides for different controllers. However I'm having trouble understanding the mechanism for modifying the paths.
In the plug-in controller if I tell it to use my layout
$this->layout = 'default_dashboard';
Which is in app/Views/Layout and references an image in app/webroot/default_images.
All the relative links work fine to default_images when I do this, but would like to use some of the Plugin template overides for other actions.
However if I modify the default.cpt file to include some of the images, like say a logo that is used in default_dashboard.ctp. It is unable to map to the same image location.
For example in default.ctp:
echo $this->Html->image('default_images/logo.png',array('alt' =>
'Logo','width'=>'284','height'=>'82'));
produces a path to /img/default_images/logo.png. The Plugin is configured to use the /img location, whereas I want to direct to /default_images in this case. I could make this ../default_images/logo.png, but this isn't very clean.
In addition I have js and css which is having a similar problem. Can someone please explain the mechanism for using a site-wide default.ctp so that it works with inherited plugin templates?
From hard coding the links into the template not using the Html Helper, I see that the browser's relative path is confused because of the routing. For example the first one works with the root specified, the second doesn't.
<img src="/default_images/logo.png" alt="works" width='284' height='82'>
<img src="default_images/logo.png" alt="lost" width='284' height='82'>
What's the best way to make sure that the Plugin layouts and non-plugin layouts can all find the correct path to /default_images ?
Following are the steps that you can follow to resolve relative path problem:
Create a file abc_constants.php in app\Config folder.
Include the file in app\Config\bootstrap.php
require_once(abc_constants.php);
abc_constants.php should contain:
define('HTTP_HOST', "http://" . $_SERVER['HTTP_HOST'].'/');
define('SITE_URL', HTTP_HOST.'your_app_name/');
define('IMAGE_HTTP_PATH', SITE_URL.'app/webroot/default_images/');
Use these constants in your view file accordingly.
<?php echo $this->Html->image(IMAGE_HTTP_PATH.'logo.png',array('alt' => 'Logo','width'=>'284','height'=>'82'));
It looks a bit lengthy process at first time, but once implemented, you can use these constants in Ajax calls in view files, controller's code etc.
I have a Wordpress blog and I'm developing a backend application using Cakephp.
I want to develop the blog's contact form using cake (since the entered information will be available from the backend app).
Right now, I tried including the cake view into wp using ajax. The problem with this approach is that I either use a Js->submit, which makes attaching files to the form quite complicated, or I use a Form->submit, which makes displaying validation errors problematic. Also, it creates problems with the recaptcha plugin not showing up.
Is there a way of integrating the form using php? I don't need authentication (it is a public form), but I need to be able to show validation errors on the form and upload files on the form.
Actually, you can load any website into a string using CURL, if you load en empty page with a placeholder from your wordpress, you can then use it as your layout
<?php
$url = "http://www.yourdomain.com/emptypage";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($curl);
curl_close($curl)
$placeholder = "{{CONTENT}}"
$placeholderPos = strpos($output,$placeholder);
$beginning = substr($output,0,$placeholderPos);
$end = substr($output,$placeholderPos+strlen($placeholder));
echo $beginning;
////// your form //////
echo $end;
?>
You may have to deal with relative path after that, but this should get you started.
So, I finally found a way I think is the best since it uses cake classes.
I created a file new_file.php on webroot that is basically a copy of index.php but instead of using a generic request it requests the specific page I'm looking for:
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(new CakeRequest('CONTROLLER/ACTION'), new CakeResponse(array('charset' => Configure::read('App.encoding'))));
Of course, you'll have to change 'CONTROLLER/ACTION' to whatever your controller is.
After that, you only have to include the file in a WordPress plugin.
There is only one more change. There are some methods that conflict with WP declarations. PHP will complain when you include the above file. You have to find those method and wrap them into an if to make sure the method is not redeclared. This can break some functionality like localization (function __()) but it is ok if what you are including is not a very complex cake application.
if (!function_exists('methodName')) {
Hopefully the last issue will be solved once Cake 3 is out with namespaces support.
I'm making a website in drupal 7 and need some help.
I created a content type called Itenary where user will upload information and five images.
The images I have taken as Image1, Image2.... Image5 as fields of type image pf the itenary content type.
Now I wish to show these images as something like this
So I go to the views module -> add new view
Now when I had tried this before, I had selected
Show content of type itenary
And it didn't work as I hoped.
So this time, I chose
Show File of type Image
I hope this is the right option for my need.
Then I went to create a block, gave it a name.
Now my dilema is how do I bring those fields of Image1 Image2 .. Image5 into this block ?
The fields it shows by default are related to files and not the field of my content type.
Make sure you have the following steps checked.
1- Try to download jQuery cycle plugin.
2- Create a folder a new folder sites/all/libraries/jquery.cycle and place jquery.cycle.all.js file inside it.
3- Go and test the results :).
Hope this works... Muhammad.
I have added the following to my template.php file, in the [themename]_preprocess_page function:
<?php
if ($variables['is_front'])
{
$variables['theme_hook_suggestions'] = array();
$variables['theme_hook_suggestions'][] = 'page__index';
}
if (isset($variables['node'])) {
// If the node type is "blog" the template suggestion will be "page--blog.tpl.php".
$variables['theme_hook_suggestions'][] = 'page__'. str_replace('_', '--', $variables['node']->type);
}
If I run a var_dump on the $variables array, I can see that, on my front page, the 'theme_hook_suggestions' is set to only use 'page__index'. I have a file named 'page--index.tpl.php'. Drupal still uses page.tpl.php.
I also commented out the code above, and renamed the file to 'page--front.tpl.php' and it still used page.tpl.php. I clear the caches after every change.
What am I missing?
Edit: To help clarify, I want to override the entire design of the page for the front - no columns or sidebars, different graphics, different backgrounds on some of the div's, etc. I don't want to override the 'node--' template files (yet).
In the end, I need to have a static front page with a different design than the rest of the site, then a custom node template for each content type.
I worked with the awesome folks on the #drupal IRC channel and found the issue. Not sure if this is a bug in the code or on purpose - but you cannot use the word 'index' for those theme suggestions. I changed the content type's name to 'homepage' and voila!
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.