createSection(); $html_dom = new simple_html_dom(); $html_dom->load($html); $html_dom_array = $html_dom->find('html',0)->children(); $paths = htmltodocx_paths(); $initial_state = array( 'phpword_object' => &$phpword_object, // Must be passed by reference. 'base_root' => $paths['base_root'], 'base_path' => $paths['base_path'], 'current_style' => array('size' => '11'), // The PHPWord style on the top element. 'parents' => array(0 => 'body'), // Our parent is body. 'list_depth' => 0, // This is the current depth of any current list. 'context' => 'section', // Possible values - section, footer or header. 'pseudo_list' => TRUE, // NOTE: Word lists not yet supported (TRUE is the only option at present). 'pseudo_list_indicator_font_name' => 'Wingdings', // Bullet indicator font. 'pseudo_list_indicator_font_size' => '7', // Bullet indicator size. 'pseudo_list_indicator_character' => 'l ', // Gives a circle bullet point with wingdings. 'table_allowed' => TRUE, // Note, if you are adding this html into a PHPWord table you should set this to FALSE: tables cannot be nested in PHPWord. 'treat_div_as_paragraph' => FALSE, // If set to TRUE, each new div will trigger a new line in the Word document. 'style_sheet' => htmltodocx_styles(), // This is an array (the "style sheet") from styles.inc /* I added these to fix a bug for images not showing up in docx converted files */ 'download_img_path' => elgg_get_data_path(), 'download_img_tmp' => &$file_takeout_tmp_files, ); htmltodocx_insert_html($section, $html_dom_array[0]->nodes, $initial_state); $html_dom->clear(); unset($html_dom); $objWriter = PHPWord_IOFactory::createWriter($phpword_object, 'Word2007'); // Word2007 is the only option :-( $objWriter->save($file_path); } // Save a few lines of code and use this helper function to grab all Elgg entities by owner and subtype (file, blog, page_top, bookmarks) function get_all_entities($guid, $subtype) { $options = array( 'type' => 'object', 'subtype' => $subtype, 'container_guid' => $guid, 'limit' => '', ); return elgg_get_entities($options); } // Sanitize file names function sanitize_file_name($filename) { $filename_array = explode('.', $filename); if (count($filename_array) > 2) { $filename = implode('', $filename_array); } $strip = array("‘", "’", "“", "”", "–", "—", "'", "~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "=", "+", "[", "{", "]", "’", "}", "\\", "|", ";", ":", "\"", "'", "—", "–", ",", "<", ">", "/", "?"); $clean = trim(str_replace($strip, "", $filename)); $clean = preg_replace('/\s+/', "_", $clean); return $clean; } function create_files_from_entities($entities, $entity_type, $subtype, $guid, &$zip, &$file_takeout_tmp_files) { if (count($entities) > 0) { $user = elgg_get_logged_in_user_entity(); $user_guid = $user->getGUID(); $export_type = ''; if ($entity_type == 'file') { $export_type = elgg_get_plugin_user_setting('file_takeout_file_meta_export_type', $user_guid, 'file_takeout'); } else { $export_type = elgg_get_plugin_user_setting('file_takeout_export_type', $user_guid, 'file_takeout'); } if ($export_type == '') { $export_type = 'html'; } $area = '
  • ...' . $entity_type . '/entries.xml
  • '; $group_entity = get_entity($guid); $url = elgg_get_site_url() . $entity_type . '/group' . '/' . $guid . '/all'; set_input('view', 'rss'); $contents = <<<__HTML <![CDATA[$group_entity->name]]> $url __HTML; $options = array( 'type' => 'object', 'subtype' => $subtype, 'container_guid' => $guid, 'limit' => '', ); $contents .= elgg_list_entities($options); $contents .= <<<__HTML __HTML; set_input('view', 'default'); $zip->addFromString($entity_type . '/entries.xml', $contents); // create a file for each entry foreach ($entities as $entity) { $author = get_entity($entity->owner_guid)->name; $pubdate = date('r', $entity->time_created); $filedate = date('Y-m-d', $entity->time_created); if ($entity_type == 'bookmarks') { $description = $entity->description.'

    Address of bookmark: '.$entity->address.'

    '; } else if ($entity_type == 'file') { $description = $entity->description.'

    File: '.sanitize_file_name($entity->originalfilename).'

    '; } else { $description = $entity->description; } $content = ''; $content .= <<<__HTML __HTML; if ($export_type != 'docx') { $content .= <<<__HTML __HTML; } $content .= <<<__HTML

    $entity->title

    By $author on $pubdate

    $description __HTML; if ($entity->countComments() > 0) { $comments = $entity->getAnnotations('generic_comment'); $content .= <<<__HTML

    Comments

    __HTML; foreach ($comments as $comment) { $comment_author = get_entity($comment->owner_guid)->name; $comment_pubdate = date('r', $comment->time_created); $content .= <<<__HTML

    By $comment_author on $comment_pubdate

    $comment->value
    __HTML; } $content .= <<<__HTML
    __HTML; } $content .= <<<__HTML
    __HTML; if ($export_type == 'aspx') { $content .= <<<__HTML

    < Back to file listing

    __HTML; } $file_name = sanitize_file_name($filedate . '-' . $entity->title) . '.' . $export_type; $area .= '
  • ...' . $entity_type . '/' . $file_name . '
  • '; if ($export_type == 'docx') { $docx_filepath = elgg_get_data_path() . $file_name; generate_docx($content, $docx_filepath, $file_takeout_tmp_files); $zip->addFile($docx_filepath, $entity_type . '/' . $file_name); $file_takeout_tmp_files[] = $docx_filepath; } else { $zip->addFromString($entity_type . '/' . $file_name, $content); } } return $area; } } // // Logic to do the work ... // // Create the ZIP archive and make it available for download if ($guid_from_path != 'file_takeout') { $files = get_all_entities($guid_from_path, 'file'); $blogs = get_all_entities($guid_from_path, 'blog'); $pages = get_all_entities($guid_from_path, 'page_top'); $bookmarks = get_all_entities($guid_from_path, 'bookmarks'); if (count($files) > 0 || count($blogs) > 0 || count($pages) > 0 || count($bookmarks) > 0) { $area .= '

    ' . get_entity($guid_from_path)->name . '

    '; $area .= '

    Zipping the following files...

    '; $area .= ''; $area .= '

    ZIP file created successfully.

    Download this ZIP file to your computer and extract the contents to any folder.

    '; } } else { $area .= '

    No files to export.

    '; } $area .= '
    < Back to File Takeout'; } // Display a listing of all groups that contain files else { $area = '

    This tool exports files from a group (which you own) into a ZIP archive. -- Configure Settings

    '; $all_groups = elgg_get_entities(array("type" => "group", "limit" => "")); $my_groups = 0; $sort_array = array(); foreach ($all_groups as $group) { if (!isset($sort_array[$group->getOwnerEntity()->guid])) { $sort_array[$group->getOwnerEntity()->guid] = array(); } $sort_array[$group->getOwnerEntity()->guid][] = $group; } foreach ($sort_array as $key => $val) { if ($key == $logged_in_user->guid || $logged_in_user->isAdmin() ) { $user = get_user($key); $area .= '

    Group Owner: ' . $user->name . '

    '; $area .= '
    '; } } if ($my_groups == 0) { $area .= '

    You do not own any groups.


    '; } $user_files = get_all_entities($logged_in_user->guid, 'file'); $area .= '

    You may also download all your personal files (' . count($user_files) . ' files)'; if (elgg_is_active_plugin('blog')) { $user_blogs = get_all_entities($logged_in_user->guid, 'blog'); $area .= '(' . count($user_blogs) . ' blogs)'; } if (elgg_is_active_plugin('pages')) { $user_pages = get_all_entities($logged_in_user->guid, 'page_top'); $area .= '(' . count($user_pages) . ' pages)'; } if (elgg_is_active_plugin('bookmarks')) { $user_bookmarks = get_all_entities($logged_in_user->guid, 'bookmarks'); $area .= '(' . count($user_bookmarks) . ' bookmarks)'; } $area .= ' -- Download Archive

    '; } // Format page $body = elgg_view_layout('one_column', array('content' => $title . $area)); // Draw it echo elgg_view_page("File Takeout", $body); ?>