I’m working on the Darkscribes site, trying to build it up and improve what I have as I go. I’m also trying to get the sites old fiction archive up and online slowly by hand. It’s not easy at all, but I’m slowly getting there. One of the things I’m working on is themeing. I’m trying to get an Omega based theme for Darkscribes that resembles the old Coldstar themes look and feel. Hopefully as I do I can get a better feel for Drupal CSS coding. But it’s a long task. Part of it involved cleaning up the old css in order for it to be human readable. That took up almost five hours there.
Part of what I’m doing is trying to figure out how to get the sites capabilities online. Things like document upload, story construction, and chapter organization. It’s been difficult and I’m no where near done. I just wish I could find an easy way to fix the issues. But slow and stead won the race. I’ve got some code provided by popupman from FFN that works ok, but could use some work.
/**
* @file
* A module which integrates with the Book module allowing file uploads
*/
/**
* Implements hook_help.
*
* Displays help and module information.
*
* @param path
* Which path of the site we’re using to display help
* @param arg
* Array that holds the current path as returned from arg() function
*/
function book_uploader_help($path, $arg) {
switch($path) {
case “admin/help#book_uploader”:
return ‘
‘. t(“Allows users to upload files when creating a new Book Page”) .’
‘;
break;
}
}
/**
* Alter the node form to include a file upload field
*/
function node_uploader_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == ‘book_node_form’) {
$form['book-node-form']['page_content_file'] = array(
‘#type’ => ‘file’,
‘#title’ => t(‘Or upload Content (supports txt/html/docx/odt)’)
);
$form['#validate'][] = ‘book_uploader_custom_validate’;
}
}
/**
* In this function we attempt to load the uploaded file. If it exists,
* we then convert it to HTML if it is docx or odt, and then replace its
* contents into the body of the saved Book Page, before finally deleting
* the temporary file
*/
function book_uploader_custom_validate($form, &$form_state) {
$file = file_save_upload(‘page_content_file’, array(‘file_validate_extensions’ => array(‘txt html docx’)));
if ($file) {
$form_state['storage']['page_content_file'] = $file;
$is_docx = file_validate_extensions($file, ‘docx’);
if(empty($is_docx)) {
$wrapper = file_stream_wrapper_get_instance_by_uri($file->uri);
$content = book_uploader_docx2html($wrapper->realpath());
}
else {
$content = file_get_contents($file->uri);
}
$content = mb_convert_encoding($content, ‘UTF-8′);
$form_state['values']['body']['und'][0]['value'] = $content;
file_delete($file);
}
}
/**
* @param file
* Path to the docx file to convert to html
*/
function book_uploader_docx2html($file) {
$output = “”;
try {
$path = book_uploader_docx2text($file);
foreach(qp($path, ‘w|p’) as $qp) {
$qr = $qp->branch();
$output .= book_uploader_format($qr->find(‘w|r:first’), ‘w|r:first’);
$qp->find(‘w|r:first’);
while($qp->next(‘w|r’)->html() != null) {
$qr = $qp->branch();
$output .= book_uploader_format($qr->find(‘w|r’), ‘w|r’);
}
$output .= “r”;
}
return $output;
}
catch (Exception $e) {
return $output;
}
return $output;
}
function book_uploader_format($qp, $findSelector = null) {
// Create a new branch for printing later.
$qr = $qp->branch();
$text = “”;
$text = $qr->find($findSelector)->find(‘w|t’)->text();
$text = (book_uploader_checkUnderline($qp->branch())) ? ‘‘.$text.’‘ : $text;
$text = (book_uploader_checkBold($qp->branch())) ? ‘‘.$text.’‘ : $text;
$text = (book_uploader_checkItalics($qp->branch())) ? ‘‘.$text.’‘ : $text;
return $text;
}
/**
*
* @param QueryPath $qp
* @return String
*/
function book_uploader_checkBold($qp) {
$qp->children(“w|rPr”);
return ($qp->children(‘w|b’)->html()) ? true : false;
}
/**
*
* @param QueryPath $qp
* @return String
*/
function book_uploader_checkUnderline($qp) {
$qp->children(“w|rPr”);
return ($qp->children(‘w|u’)->html()) ? true : false;
}
function book_uploader_checkItalics($qp) {
$qp->children(“w|rPr”);
return ($qp->children(‘w|i’)->html()) ? true : false;
}
function book_uploader_docx2text($file) {
return book_uploader_readZippedXML($file, ‘word/document.xml’);
}
function book_uploader_readZippedXML($archiveFile, $dataFile) {
if (!class_exists(‘ZipArchive’, false)) {
return “ZipArchive Class Doesn’t Exist.”;
}
$zip = new ZipArchive;
if (true === $zip->open($archiveFile, ZipArchive::CREATE)) {
if (($index = $zip->locateName($dataFile)) !== false) {
$data = $zip->getFromIndex($index);
$zip->close();
return $data;
}
$zip->close();
}
return false;
}
I found a site post that had some useful code I think but I have no idea how to integrate it or anything of that here.
All the While I’m trying to figure out ideas as well for my own stories and actually write them. It’s not easy to work all the time in to do all of this and it’s kicking my ass in a lot of ways. I just wish I knew if I was getting closer to done really.