$myFile = "path_to_dir/test.(EXTENSION)EG jpg,js";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Contents to display";
fwrite($fh, $stringData);
fclose($fh);
if (file_exists($myFile)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($myFile));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($myFile));
ob_clean();
flush();
readfile($myFile);
exit;
}
Please follow this blog if u feel the blog content is useful to you
Tuesday, June 21, 2011
Example with l of in drupal
l('TITLE','node/33');
Output:
<a href="/?q=node/33">TITLE</a>
l('TITLE','node/33',array('attributes'=>array('target'=>"_blank")));
Output :
<a href="/?q=node/33" target="_blank">TITLE</a>
l('TITLE','node/33',array('query'=>array('disp'=>4),'attributes'=>array
('target'=>"_blank")));
Output :
<a href="/?q=node/33&disp=4" target="_blank">TITLE</a>
l('TITLE','node/33',array('attributes'=>array('target'=>"_blank")),'fragment'=>'comment-
1');
Output :
<a href="/?q=node/33#comment-1" target="_blank">TITLE</a>
l('TITLE','node/33',array('query'=>array('disp'=>4),'attributes'=>array
('target'=>"_blank")),'fragment'=>'comment-1');
Output :
<a href="/?q=node/33&disp=4#comment-1" target="_blank">TITLE</a>
Output:
<a href="/?q=node/33">TITLE</a>
l('TITLE','node/33',array('attributes'=>array('target'=>"_blank")));
Output :
<a href="/?q=node/33" target="_blank">TITLE</a>
l('TITLE','node/33',array('query'=>array('disp'=>4),'attributes'=>array
('target'=>"_blank")));
Output :
<a href="/?q=node/33&disp=4" target="_blank">TITLE</a>
l('TITLE','node/33',array('attributes'=>array('target'=>"_blank")),'fragment'=>'comment-
1');
Output :
<a href="/?q=node/33#comment-1" target="_blank">TITLE</a>
l('TITLE','node/33',array('query'=>array('disp'=>4),'attributes'=>array
('target'=>"_blank")),'fragment'=>'comment-1');
Output :
<a href="/?q=node/33&disp=4#comment-1" target="_blank">TITLE</a>
Create translation js file based on the po file content imported in database
//Pass the language code.
function custom_translation_create_js($language) {
// Get information about the locale.
$languages = language_list();
$language = $languages[$language];
// Construct the array for JavaScript translations.
// We sort on plural so that we have all plural forms before singular forms.
$result = db_query("SELECT s.lid, s.source, t.plid, t.plural, t.translation FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE t.language = '%s' ORDER BY t.plural DESC", $language->language);
$translations = $plurals = array();
while ($data = db_fetch_object($result)) {
// Only add this to the translations array when there is actually a translation.
if (!empty($data->translation)) {
if ($data->plural) {
// When the translation is a plural form, first add it to another array and
// wait for the singular (parent) translation.
if (!isset($plurals[$data->plid])) {
$plurals[$data->plid] = array($data->plural => $data->translation);
}
else {
$plurals[$data->plid] = array($data->plural => $data->translation);
}
}
elseif (isset($plurals[$data->lid])) {
// There are plural translations for this translation, so get them from
// the plurals array and add them to the final translations array.
$translations[$data->source] = array($data->plural => $data->translation) + $plurals[$data->lid];
unset($plurals[$data->lid]);
}
else {
// There are no plural forms for this translation, so just add it to
// the translations array.
$translations[$data->source] = $data->translation;
}
}
}
// Only operate when there are translations.
if (!empty($translations)) {
// Construct the JavaScript file.
$data = "Drupal.locale = { ";
if (!empty($language->formula)) {
$data .= "'pluralFormula': function(\$n) { return Number({$language->formula}); }, ";
}
$data .= "'strings': ". drupal_to_js($translations) ." };";
$data_hash = md5($data);
// Construct the directory where JS translation files are stored.
// There is (on purpose) no front end to edit that variable.
$dir = file_create_path(variable_get('locale_js_directory', 'languages'));
// Only create a new file if the content has changed.
if ($language->javascript != $data_hash) {
if (!empty($language->javascript)) {
// We are recreating the new file, so delete the old one.
file_delete(file_create_path($dir .'/'. $language->language .'_'. $language->javascript .'.js'));
$language->javascript = '';
}
else {
// The directory might not exist when there has not been a translation
// file before, so create it.
file_check_directory($dir, TRUE);
}
$str = "trans";
// The file name of the new JavaScript translation file.
$dest = $dir .'/'. $language->language .'_'. $str .'.js';
$path = file_save_data($data, $dest);
db_query("UPDATE {languages} SET javascript = '%s' WHERE language = '%s'", $path ? $data_hash : '', $language->language);
// Only report updated or creation when there is actually a file created.
if ($path) {
// There has already been a translation file before.
if (!empty($language->javascript)) {
watchdog('locale', t('Updated JavaScript translation file for the language %language.', array('%language' => t($language->name))));
}
else {
watchdog('locale', t('Created JavaScript translation file for the language %language.', array('%language' => t($language->name))));
}
}
else {
watchdog('locale', t('An error occured during creation of the JavaScript translation file for the language %language.', array('%language' => t($language->name))));
}
}
}
// There are no strings for JavaScript translation. However, if there is a file,
// delete it and reset the database.
elseif (!empty($language->javascript)) {
// Delete the old JavaScript file
file_delete(file_create_path(variable_get('locale_js_directory', 'languages') .'/'. $language->language .'_'. $language->javascript .'.js'));
db_query("UPDATE {languages} SET javascript = '' WHERE language = '%s'", $language->language);
watchdog('locale', t('Deleted JavaScript translation file for the locale %language.', array('%language' => t($language->name))));
}
}
function custom_translation_create_js($language) {
// Get information about the locale.
$languages = language_list();
$language = $languages[$language];
// Construct the array for JavaScript translations.
// We sort on plural so that we have all plural forms before singular forms.
$result = db_query("SELECT s.lid, s.source, t.plid, t.plural, t.translation FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE t.language = '%s' ORDER BY t.plural DESC", $language->language);
$translations = $plurals = array();
while ($data = db_fetch_object($result)) {
// Only add this to the translations array when there is actually a translation.
if (!empty($data->translation)) {
if ($data->plural) {
// When the translation is a plural form, first add it to another array and
// wait for the singular (parent) translation.
if (!isset($plurals[$data->plid])) {
$plurals[$data->plid] = array($data->plural => $data->translation);
}
else {
$plurals[$data->plid] = array($data->plural => $data->translation);
}
}
elseif (isset($plurals[$data->lid])) {
// There are plural translations for this translation, so get them from
// the plurals array and add them to the final translations array.
$translations[$data->source] = array($data->plural => $data->translation) + $plurals[$data->lid];
unset($plurals[$data->lid]);
}
else {
// There are no plural forms for this translation, so just add it to
// the translations array.
$translations[$data->source] = $data->translation;
}
}
}
// Only operate when there are translations.
if (!empty($translations)) {
// Construct the JavaScript file.
$data = "Drupal.locale = { ";
if (!empty($language->formula)) {
$data .= "'pluralFormula': function(\$n) { return Number({$language->formula}); }, ";
}
$data .= "'strings': ". drupal_to_js($translations) ." };";
$data_hash = md5($data);
// Construct the directory where JS translation files are stored.
// There is (on purpose) no front end to edit that variable.
$dir = file_create_path(variable_get('locale_js_directory', 'languages'));
// Only create a new file if the content has changed.
if ($language->javascript != $data_hash) {
if (!empty($language->javascript)) {
// We are recreating the new file, so delete the old one.
file_delete(file_create_path($dir .'/'. $language->language .'_'. $language->javascript .'.js'));
$language->javascript = '';
}
else {
// The directory might not exist when there has not been a translation
// file before, so create it.
file_check_directory($dir, TRUE);
}
$str = "trans";
// The file name of the new JavaScript translation file.
$dest = $dir .'/'. $language->language .'_'. $str .'.js';
$path = file_save_data($data, $dest);
db_query("UPDATE {languages} SET javascript = '%s' WHERE language = '%s'", $path ? $data_hash : '', $language->language);
// Only report updated or creation when there is actually a file created.
if ($path) {
// There has already been a translation file before.
if (!empty($language->javascript)) {
watchdog('locale', t('Updated JavaScript translation file for the language %language.', array('%language' => t($language->name))));
}
else {
watchdog('locale', t('Created JavaScript translation file for the language %language.', array('%language' => t($language->name))));
}
}
else {
watchdog('locale', t('An error occured during creation of the JavaScript translation file for the language %language.', array('%language' => t($language->name))));
}
}
}
// There are no strings for JavaScript translation. However, if there is a file,
// delete it and reset the database.
elseif (!empty($language->javascript)) {
// Delete the old JavaScript file
file_delete(file_create_path(variable_get('locale_js_directory', 'languages') .'/'. $language->language .'_'. $language->javascript .'.js'));
db_query("UPDATE {languages} SET javascript = '' WHERE language = '%s'", $language->language);
watchdog('locale', t('Deleted JavaScript translation file for the locale %language.', array('%language' => t($language->name))));
}
}
Language translation for Drupal JavaScript files.
1. Make sure that you have entered Drupal.t () function before all the text.
2. You have to create a js file (fr-trans.js) like below u for corresponding language
Drupal.locale = {‘strings’: {"Certification":"Certification","Required":"Requis"}};
In my example I have given for French language.
3. Include the js file based on user language
2. You have to create a js file (fr-trans.js) like below u for corresponding language
Drupal.locale = {‘strings’: {"Certification":"Certification","Required":"Requis"}};
In my example I have given for French language.
3. Include the js file based on user language
Language translation in Drupal Based on user language or based on website
1. Make sure that you have entered t() function before all the text.
2. Install the locale module.
3. In admin settings to Languages Link add languages which you need.
4. Click on configure you can see language negotiation you have to select”
Path prefix with language fallback. "(You have to do this if you want language translation
based on user selected language in his my account page) Or In admin setting languages Click the default language for the webpage to change page to corresponding language(This will change the language of webpage)
5. Download the default po file provided by drupal from this link
http://localize.drupal.org/ for testing purpose. (Note: You need to create a po file
based on your content of you website )
6. Go to Translate interface link in site building
7. Click on the import link & select the language & import the selected language po file
8. Check for a particular user by changing his language
2. Install the locale module.
3. In admin settings to Languages Link add languages which you need.
4. Click on configure you can see language negotiation you have to select”
Path prefix with language fallback. "(You have to do this if you want language translation
based on user selected language in his my account page) Or In admin setting languages Click the default language for the webpage to change page to corresponding language(This will change the language of webpage)
5. Download the default po file provided by drupal from this link
http://localize.drupal.org/ for testing purpose. (Note: You need to create a po file
based on your content of you website )
6. Go to Translate interface link in site building
7. Click on the import link & select the language & import the selected language po file
8. Check for a particular user by changing his language
Saturday, May 7, 2011
Put a pipe symbol in between primary link
1.Pu this code in the template.php file of your theme folder
2.Check the class of primary links in the page.tpl or page-front.tpl matches with class condition check indie this function if this function doesn't work
function youthemename_links($links, $attributes = array('class' => 'links')) {
$output = '';
// Change the way primary links are rendered
if($attributes['class'] == 'links primary-links') {
$linklist = array();
foreach ((array)$links as $key => $link) {
$linklist[] = l($link['title'], $link['href'], $link);
}
// Return the links joined by a '|' character
return join(' | ', $linklist);
}
// Normal theming continued below:
if (count($links) > 0) {
$output = '<ul'. drupal_attributes($attributes) .'>';
$num_links = count($links);
$i = 1;
foreach ($links as $key => $link) {
$class = $key;
// Add first, last and active classes to the list of links to help out themers.
if ($i == 1) {
$class .= ' first';
}
if ($i == $num_links) {
$class .= ' last';
}
if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '' && drupal_is_front_page()))) {
$class .= ' active';
}
$output .= '<li class="'. $class .'">';
if (isset($link['href'])) {
// Pass in $link as $options, they share the same keys.
$output .= l($link['title'], $link['href'], $link);
}
else if (!empty($link['title'])) {
// Some links are actually not links, but we wrap these in for adding title and class attributes
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset($link['attributes'])) {
$span_attributes = drupal_attributes($link['attributes']);
}
$output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
}
$i++;
$output .= "</li>\n";
}
$output .= '</ul>';
}
return $output;
}
2.Check the class of primary links in the page.tpl or page-front.tpl matches with class condition check indie this function if this function doesn't work
function youthemename_links($links, $attributes = array('class' => 'links')) {
$output = '';
// Change the way primary links are rendered
if($attributes['class'] == 'links primary-links') {
$linklist = array();
foreach ((array)$links as $key => $link) {
$linklist[] = l($link['title'], $link['href'], $link);
}
// Return the links joined by a '|' character
return join(' | ', $linklist);
}
// Normal theming continued below:
if (count($links) > 0) {
$output = '<ul'. drupal_attributes($attributes) .'>';
$num_links = count($links);
$i = 1;
foreach ($links as $key => $link) {
$class = $key;
// Add first, last and active classes to the list of links to help out themers.
if ($i == 1) {
$class .= ' first';
}
if ($i == $num_links) {
$class .= ' last';
}
if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '
$class .= ' active';
}
$output .= '<li class="'. $class .'">';
if (isset($link['href'])) {
// Pass in $link as $options, they share the same keys.
$output .= l($link['title'], $link['href'], $link);
}
else if (!empty($link['title'])) {
// Some links are actually not links, but we wrap these in for adding title and class attributes
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset($link['attributes'])) {
$span_attributes = drupal_attributes($link['attributes']);
}
$output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
}
$i++;
$output .= "</li>\n";
}
$output .= '</ul>';
}
return $output;
}
Remove formating text & split summary cursor button in drupal
You should put this is code inside hook_alter of any your custom module
-----------------------------------------------------------------------------------------------------------
$form['body_field']['format'] = array();
$form['body_field']['teaser_include'] = array('#type' => 'value','#value' => TRUE,);
-----------------------------------------------------------------------------------------------------------
$form['body_field']['format'] = array();
$form['body_field']['teaser_include'] = array('#type' => 'value','#value' => TRUE,);
Subscribe to:
Posts (Atom)