Showing posts with label drupal 6. Show all posts
Showing posts with label drupal 6. Show all posts

Wednesday, April 21, 2010

Drupal: Drush + CCK Import Module Code

I was trying to figure out if there are any modules which I can download for the Drupal 6 and try to use Drush command to do an CCK Import of a file which has been exported thru CCK Export. After a hard dig around, I couldn't find any one, so I started writing my own. Don't worry I have shared the code below. Anyway talks apart, below is the code which you put in a file called drush/commands/cck_import/cck_import.drush.inc




// $Id: cck_import.drush.inc,v 1.1 2010/04/21 03:03:39 kishore Exp $

/**
* @file
* Drush support for cck_import.
*/

/**
* Implementation of hook_drush_command().
*/
function cck_import_drush_command() {
$items = array();

$items['cck_import-import'] = array(
'callback' => 'cck_import_drush_callback_import',
'description' => "Import node code from a previous export.",
'options' => array(
'--uid' => "Uid of user to save nodes as. If not given will use 1. You may specify 0 for the Anonymous user.",
),
'examples' => array(
'drush cck_import import < filename' =>
'Import nodes from given filename.',
),
);

return $items;
}

/**
* Implementation of hook_drush_help().
*
* This function is called whenever a drush user calls
* 'drush help '
*
* @param
* A string with the help section (prepend with 'drush:')
*
* @return
* A string with the help text for your command.
*/
function cck_import_drush_help($section) {
switch ($section) {
case 'drush:cck_import-import':
return dt("Imports nodes that have been exported. Usage: 'drush cck_import import < filename'.");
}
}

/**
* Drush command callback.
*
*/
function cck_import_drush_callback_export() {
$commands = func_get_args();

$nids = array_filter($commands, 'is_numeric');

$data = cck_import_node_bulk($nids, TRUE);

$filename = drush_get_option('file');

if ($filename) {
// Output data to file. Note this only takes a flat filename for the current directory.
// If file exists, ask for whether to overwrite
if (file_exists($filename)) {
if (!drush_confirm(dt('File ' . $filename . ' exists. Do you really want to overwrite?'))) {
return;
}
}
// Write the file.
file_put_contents($filename, $data);
}
else {
// Print to terminal.
drush_print_r($data);
}
}

/**
* Drush command callback.
*
* Import nodes from data.
*/
function cck_import_drush_callback_import() {
$commands = func_get_args();

// Switch to admin or the specified user so imported nodes are not anonymous.
$uid = drush_get_option('uid');
// Test on NULL so uid may be given as 0.
if (is_null($uid)) {
$uid = 1;
}
// uid 0 is already loaded.
if ($uid != 0) {
global $user;
$user = user_load($uid);
}

$values = array();
$values['type_name'] = '';
$values['macro'] = file_get_contents("php://stdin", "r");
$form_state = array();
$form_state['values'] = $values;
if (!empty($form_state)) {
$result = drupal_execute("content_copy_import_form", $form_state);
if ($result === FALSE) {
// There was a problem with types?
drush_set_error('DRUSH_NOT_COMPLETED', 'Problem found with the import file. Check the node types exist.');
}
}

}




After saving this file, try to execute the below command



$ drush cck_import-import < filename.content



note filename.content should contain something which has been exported from the CCK Export.

Hope this would have solved your issues, I am in the process of developing the CCK Import / Export thru Drush commands and might update you soon with other version of the code. Not sure where to publish but thought of publishing in my own blog and in future might publish in a proper particular location where everybody gets benefited.

Feel free to ask me any queries.

Thursday, August 20, 2009

Easy Steps to remove "Read More" , Published by author - Drupal 6

One of the ticket raised in Drupal community was, how to remove the "Read More" link & "Published by Author" with date for a story / page while listing the stories in the website. I just digged the code for exactly 1 min and found an easy solution. Drupal 6 is as good as you think good. But really speaking its really damn good. I went to the garland folder present in the themes folder. I just removed the below two blocks and saved the node.tpl.php file.


<?php if ($submitted): ?>
<span class="submitted"><?php print $submitted; ?></span>
<?php endif; ?>


<?php if ($links): ?>
<div class="links"><?php print $links; ?></div>
<?php endif; ?>


I definitely hope that this might have solve his issue who has raised it in Drupal Themes community. If you feel any issues, please let me know I will try to help as much as possible.

Tuesday, July 28, 2009

Basic SCiTE configuration for Drupal

Suppose you are working on Drupal and new to SCiTE editor and you want to customize then try this little below trick to help your eyes feel cool. The below info will help you to colorize little. This is just a start and would let you guys know how easy to do the stuff. I know most of the guys working in Ubuntu + SCiTE + Drupal for their projects.

In the SCiTE editor click Options Menu then click "Open User Options File"

copy paste the below settings

# PHP
style.php.118=fore:#CD1C69,back:#25272B,eolfilled
# Matching braces
style.php.34=fore:#E21E1E,back:#25272B,font=Monospace,size:12
# Not maching braces
style.php.35=fore:#FF0000,back:#25272B,font=Monospace,size:12
# Double quoted String
style.php.119=fore:#E17C4A,back:#25272B
# Single quoted string
style.php.120=fore:#F6E443,back:#25272B
# Keyword
style.php.121=fore:#FCFDFA,back:#25272B
# Number
style.php.122=fore:#CC9900,back:#25272B,
# Variable
style.php.123=fore:#53B6F0,back:#25272B
# Comment
style.php.124=fore:#999999,$(font.comment),back:#25272B,eolfilled
# One line comment
style.php.125=fore:#929394,$(font.comment),back:#25272B
# PHP variable in double quoted string
style.php.126=fore:#00007F,italics,back:#25272B
# PHP operator
style.php.127=fore:#FCFDFA,back:#25272B

# File patterns
file.patterns.php=*.php;*.php4;*.inc;*.module;*.info;*.install;*.views.inc;*.admin.inc;

if PLAT_GTK
selection.alpha=90
selection.back=#C0CCCC
find.files=*.php *.inc *.module *.views.inc *.admin.inc *.info *.install

#SCiTE Cursor Config
caret.fore=#FF0000
caret.width=2
caret.line.back=#FFFED8
caret.line.back.alpha=33
caret.period=310


Just Save an you will feel the difference when you open the Drupal's / PHP code file. Please let me know if you need more.

Wednesday, March 18, 2009

Show enable/disable rich text toggle link has no effect

If you use WYSIWYG module in a drupal and notice that "Show enable/disable rich text toggle link doesnt work", here is the patch which will make it work.

Or you can edit the wysiwyg.js file and add an if condition to solve this.

if (Drupal.settings['wysiwyg']['showToggle']) {
Drupal.wysiwygAttachToggleLink(context, params);
}



instead of

Drupal.wysiwygAttachToggleLink(context, params);


Please let me know if it doesnt works for you.