<?php
// $Id: savetoftp.module,v 1.0 2008/08/05 11:00:00 kevin Exp $
/**
* Lets users save nodes to an FTP server.
* Adds text boxes for logging into FTP server in order to save.
*/
/**
* Implementation of hook_nodeapi().
*/
function savetoftp_nodeapi(&$node, $op, $teaser, $page) {
switch ($op) {
case 'view':
if ($user->uid == 0) {
break;
}
$node->
content['savetoftp'] =
array(
'#weight' => 10
);
}
}
/**
* Implementation of hook_form_alter. Define the form for saving to ftp.
*/
function savetoftp_form_alter($form_id, &$form) {
if ($form_id == $form['#node']->type .'_node_form') {
$form['savetoftp'] =
array(
'#type' => 'fieldset',
'#title' =>
t('FTP Server settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => 30,
);
$form['savetoftp']['ftp_server'] =
array(
'#type' => 'textfield',
'#default_value' =>
variable_get('ftp_server',
'www.sfsu.edu'),
'#maxlength' => 50,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' =>
t('Enter your FTP Server'),
);
$form['savetoftp']['ftp_username'] =
array(
'#type' => 'textfield',
'#maxlength' => 50,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' =>
t('Enter your FTP Username'),
);
$form['savetoftp']['ftp_password'] =
array(
'#type' => 'password',
'#maxlength' => 50,
'#size' => 15,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' =>
t('Enter your FTP Password'),
);
$form['savetoftp']['ftp_directory'] =
array(
'#type' => 'textfield',
'#default_value' =>
variable_get('ftp_directory',
'public_html'),
'#maxlength' => 50,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' =>
t('Enter your default directory, this will most likely be public_html or blank'),
);
$form['#submit']['savetoftp'] =
array(
);
}
}
function save_to_ftp($form, &$form_values) {
/** Code added to save node to a file and then send it to ftp server */
$html_title = $form_values['title'];
$html_header = $form_values['field_header'][0][value];
$html_leftsidebar = $form_values['field_leftsidebar'][0][value];
$html_rightsidebar = $form_values['field_rightsidebar'][0][value];
$html_body = $form_values['body'];
$html_footer = $form_values['field_footer'][0][value];
$file_name = $html_title.'.html';
$file =
fopen($file_name,
"w");
fwrite($file,
$html_leftsidebar);
fwrite($file,
$html_rightsidebar);
$ftpserver = $form_values['ftp_server'];
$ftp_uname = $form_values['ftp_username'];
$ftp_pass = $form_values['ftp_password'];
$targetDir = 'public_html/noindex/';
{
die('Connection failed');
}
{
}
{
die ('Unable to change directory to: ' .
$targetDir);
}
$fileholder = 'C:/web/xampp/htdocs/drupal-5.7/'.$file_name;
$remote_file = $file_name;
$filetobemoved =
fopen($fileholder,
"r");
if(!
ftp_fput($fp,
$remote_file,
$filetobemoved, FTP_BINARY
))
{
$errorMessage .= "&error-unable-ftp-fput;";
}
/** end of custom code add */
}