diff --git a/epub_export.install b/epub_export.install index 3051406..16becf1 100644 --- a/epub_export.install +++ b/epub_export.install @@ -35,7 +35,7 @@ function epub_export_field_schema($field) { } /** - * Implements hook_field_schema(). + * Implements hook_schema(). */ function epub_export_schema() { $schema['epub_export'] = array( diff --git a/epub_export.module b/epub_export.module index 021b150..34c89d3 100644 --- a/epub_export.module +++ b/epub_export.module @@ -127,6 +127,7 @@ function epub_export_build_epub_worker($data) { */ function epub_export_get_filename($entity) { $directory = file_default_scheme() . '://epub/'; + file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); $basename = $entity->title . '.epub'; return file_create_filename($basename, $directory); } @@ -145,8 +146,8 @@ function epub_export_set_entity_field($entity_type, $entity_id, $settings = arra $fields = epub_export_get_epub_fields($entity_type, $entity); if (!empty($entity)) { - foreach($fields as $field_name => $field) { - foreach(array('fid', 'version', 'status') as $column) { + foreach ($fields as $field_name => $field) { + foreach (array('fid', 'version', 'status') as $column) { if (isset($settings[$column])) { // @todo if fid... increment file usage counter $entity->{$field_name}[LANGUAGE_NONE][0][$column] = $settings[$column]; @@ -171,7 +172,7 @@ function epub_export_get_epub_fields($entity_type, $entity) { $fields = field_read_fields(array('type' => 'epub_export_epub')); if (!empty($entity)) { - foreach($fields as $field_name => $field) { + foreach ($fields as $field_name => $field) { if (isset($entity->$field_name)) { $return[$field_name] = $field; } @@ -186,7 +187,7 @@ function epub_export_get_epub_fields($entity_type, $entity) { function epub_export_clear_file_usage($entity_type, $entity) { list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity); $fields = epub_export_get_epub_fields($entity_type, $entity); - foreach($fields as $field_name => $field) { + foreach ($fields as $field_name => $field) { if (!empty($entity->{$field_name}[LANGUAGE_NONE][0]['fid'])) { $file = file_load($entity->{$field_name}[LANGUAGE_NONE][0]['fid']); if (!empty($file)) { @@ -262,7 +263,7 @@ function epub_export_node_update($node) { // corresponding entities to rebuild $referenced = epub_export_get_referenced_entities($node); if (!empty($referenced)) { - foreach($referenced as $item) { + foreach ($referenced as $item) { db_insert('epub_export') ->fields(array( 'entity_type' => 'node', @@ -297,7 +298,7 @@ function epub_export_get_entities_by_field_status($states = array(EPUB_EXPORT_ST EPUB_EXPORT_STATUS_NEEDS_REBUILD)) { $fields = field_read_fields(array('type' => 'epub_export_epub')); - foreach(array_keys($fields) as $field) { + foreach (array_keys($fields) as $field) { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node') ->fieldCondition($field, 'status', $states, 'IN'); @@ -319,7 +320,7 @@ function epub_export_get_assets($node) { else { $query = db_select('epub_export') ->fields(array('ref_entity_type', 'ref_entity_id')); - foreach($query->execute as $row) { + foreach ($query->execute as $row) { $referenced[$node->nid] = $row; } } @@ -334,7 +335,7 @@ function epub_export_get_referenced_entities($node) { if (!empty($export)) { $export->findAssets(); $export->parseAssets(); - foreach($export->getAssets() as $uri => $asset) { + foreach ($export->getAssets() as $uri => $asset) { if (!empty($asset['ref_entity_type'])) { $return[] = array( 'ref_entity_type' => $asset['ref_entity_type'], diff --git a/includes/EPUBExport.inc b/includes/EPUBExport.inc index e655ee1..3f5beaf 100644 --- a/includes/EPUBExport.inc +++ b/includes/EPUBExport.inc @@ -93,7 +93,7 @@ class EPUBExport { * @see http://us2.php.net/manual/en/domnode.removechild.php */ public function load() { - switch($this->entity_type) { + switch ($this->entity_type) { case 'node': $this->alias = drupal_get_path_alias('node/' . $this->etid); $parts = explode('/', $this->alias); @@ -104,7 +104,8 @@ class EPUBExport { } // load the requested entity - $this->data = array_pop(entity_load($this->entity_type, array($this->etid))); + $entities = entity_load($this->entity_type, array($this->etid)); + $this->data = array_pop($entities); if (empty($this->data)) { throw new Exception('Unable to load type: ' . $this->typeinfo(), EPUB_EXPORT_NOLOAD); } @@ -121,7 +122,8 @@ class EPUBExport { $function = $this->entity_type . '_view'; if (function_exists($function)) { if (!empty($this->data)) { - $this->rendered = drupal_render($function($this->data)); + $data = $function($this->data); + $this->rendered = drupal_render($data); } } else { @@ -194,7 +196,7 @@ class EPUBExport { } } - foreach($this->tag_map() as $tag => $attribute) { + foreach ($this->tag_map() as $tag => $attribute) { $elements = $this->dom->getElementsByTagName($tag); foreach ($elements as $element) { $asset = $element->attributes->getNamedItem($attribute)->nodeValue; @@ -219,6 +221,7 @@ class EPUBExport { */ public function parseAssets() { global $base_url; + //global $base_path; if (!empty($this->assets)) { foreach ($this->assets as $asseturi => $asset) { @@ -241,6 +244,13 @@ class EPUBExport { $path = substr_replace($path, '', 0, strlen($base_url)); } + /* + // replace base path if it is present + if (strpos($path, $base_path) === 0) { + $path = substr_replace($path, '', 0, strlen($base_path)); + } + */ + // strip a leading / if available if (strpos($path, '/') === 0) { $path = substr_replace($path, '', 0, 1); @@ -280,7 +290,7 @@ class EPUBExport { ->fields('fm') ->condition('uri', file_default_scheme() . '://' . $path); - foreach($query->execute() as $row) { + foreach ($query->execute() as $row) { $asset['ref_entity_type'] = 'file'; $asset['ref_entity_id'] = $row->fid; } @@ -294,7 +304,7 @@ class EPUBExport { else { if ($item = menu_get_item($path)) { $asset['title'] = $item['title']; - if (!in_array($item['path'], $this->getPrunedPaths())) { + if (!in_array($item['path'], $this->getPrunedPaths()) && isset($item['load_functions'][1])) { // @todo there has to be a better way of recovering item type etc. $type = str_replace('_load', '', $item['load_functions'][1]); $keys = epub_export_supported_types(); @@ -313,7 +323,8 @@ class EPUBExport { $parts = explode('/', $asset['dest']); // give other modules a chance to modify our exported assets - drupal_alter('epub_export_asset', $asset, $this->context()); + $context = $this->context(); + drupal_alter('epub_export_asset', $asset, $context); // store the asset in our assets list if (!empty($asset)) { @@ -323,7 +334,8 @@ class EPUBExport { } // give other modules an opportunity to alter all of our assets - drupal_alter('epub_export_assets', $this->assets, $this->context()); + $context = $this->context(); + drupal_alter('epub_export_assets', $this->assets, $context); } /** @@ -350,7 +362,8 @@ class EPUBExport { ); // give other modules an opportunity to alter the tag map - drupal_alter('epub_export_tag_map', $map, $this->context()); + $context = $this->context(); + drupal_alter('epub_export_tag_map', $map, $context); return $map; } @@ -372,10 +385,12 @@ class EPUBExport { 'meta submitted', 'field-type-epub-export-epub', 'submitted', + 'comment_forbidden', // "Log in or register to post comments" ); // give other modules an opportunity to alter the css classes that are removed - drupal_alter('epub_export_strip_classes', $classes, $this->context()); + $context = $this->context(); + drupal_alter('epub_export_strip_classes', $classes, $context); return $classes; } @@ -389,10 +404,12 @@ class EPUBExport { 'node/%/delete', 'node/%/edit', 'user/%', + 'filter/tips', ); // give other modules an opportunity to alter the paths we consider assets - drupal_alter('epub_export_prune_paths', $paths, $this->context()); + $context = $this->context(); + drupal_alter('epub_export_prune_paths', $paths, $context); return $paths; } @@ -408,7 +425,7 @@ class EPUBExport { if (!empty($this->assets)) { $xpath = new DOMXpath($this->dom); foreach ($this->assets as $uri => $asset) { - foreach($this->tag_map() as $tag => $attribute) { + foreach ($this->tag_map() as $tag => $attribute) { $query = "//" . $tag . "[@" . $attribute . "='" . $uri . "']"; $entries = $xpath->query($query); if (!empty($entries)) { @@ -458,7 +475,7 @@ class EPUBExport { $epub = new FMEPub; } - foreach($this->getAssets() as $uri => $asset) { + foreach ($this->getAssets() as $uri => $asset) { if (empty($gathered[$asset['dest']])) { $gathered[$asset['dest']] = TRUE; $id = str_replace(array('/','.'), '-', $asset['cleaned']); @@ -520,7 +537,7 @@ class EPUBExport { '; - $epub->manifestAddItem('nav', 'nav.html', 'application/xhtml+xml', 'inline', $toc, NULL, array('nav')); + $epub->manifestAddItem('nav', 'fmnav.html', 'application/xhtml+xml', 'inline', $toc, NULL, array('nav')); //$test->dump(); $zipname = drupal_tempnam(file_directory_temp(), 'epub-build-') . '.epub'; diff --git a/includes/epub_export.field.inc b/includes/epub_export.field.inc index 33fa8d0..1d0856c 100644 --- a/includes/epub_export.field.inc +++ b/includes/epub_export.field.inc @@ -105,8 +105,8 @@ function epub_export_field_widget_form(&$form, &$form_state, $field, $instance, function epub_export_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array(); if ($display['type'] == 'epub_export_epub_formatter') { - foreach($items as $delta => $item) { - switch($item['status']) { + foreach ($items as $delta => $item) { + switch ($item['status']) { case EPUB_EXPORT_STATUS_NOT_BUILT: $element[$delta] = array('#markup' => 'EPUB not built yet.'); break;