/[drupal]/contributions/modules/import_html/import_html_ui.inc
ViewVC logotype

Diff of /contributions/modules/import_html/import_html_ui.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.11.4.20, Tue Oct 6 13:57:15 2009 UTC revision 1.11.4.21, Tue Oct 6 14:09:02 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: import_html_ui.inc,v 1.11.4.19 2009/09/09 06:47:22 dman Exp $  // $Id: import_html_ui.inc,v 1.11.4.20 2009/10/06 13:57:15 dman Exp $
3  /**  /**
4   * @file   * @file
5   * Forms and UI functions for import_html.   * Forms and UI functions for import_html.
6   *   *
7   * The bulk is made up of the multistep import_html_prcess_form.   * The bulk is made up of the multistep import_html_prcess_form.
8   * This is made up of conditional includes of the per-stage subforms, and their   * This is made up of conditional includes of the per-stage subforms, and their
9   * respctive submit handlers.   * respctive submit handlers.
10   *   *
11   * TODO ajaxify?   * TODO ajaxify?
12   *   *
13   * @ingroup import_html Import HTML   * @ingroup import_html Import HTML
14   * @author Dan Morrison http://coders.co.nz/   * @author Dan Morrison http://coders.co.nz/
15   */   */
16    
17    
18  module_load_include('inc', 'import_html', 'import_html_process');  module_load_include('inc', 'import_html', 'import_html_process');
19    
20    
21  ///////////////////////////////////////////  ///////////////////////////////////////////
22  // SETTINGS and PROFILES  // SETTINGS and PROFILES
23    
24  /**  /**
25   * Display the import_html options and settings.   * Display the import_html options and settings.
26   *   *
27   * Settings menu callback   * Settings menu callback
28   *   *
29   * Display the default profile   * Display the default profile
30   */   */
31  function import_html_admin_settings($form_state) {  function import_html_admin_settings($form_state) {
# Line 33  function import_html_admin_settings($for Line 33  function import_html_admin_settings($for
33    $form = array();    $form = array();
34    // Check htmltidy is present and correct    // Check htmltidy is present and correct
35    module_load_include('inc', 'import_html', 'coders_php_library/tidy-functions');    module_load_include('inc', 'import_html', 'coders_php_library/tidy-functions');
36    $form['HTMLTidy'] = html_tidy_settings($form_state);    $form['HTMLTidy'] = html_tidy_settings($form_state);
37    
38    // Warn about known problem with open_basedir    // Warn about known problem with open_basedir
39    if ($open_basedir = ini_get('open_basedir')) {    if ($open_basedir = ini_get('open_basedir')) {
40      $form['open_basedir']=array(      $form['open_basedir']=array(
41        '#value' => t("        '#value' => t("
42          <p><strong>Warning:</strong>          <p><strong>Warning:</strong>
43          This server has open_basedir restrictions set [%open_basedir].          This server has open_basedir restrictions set [%open_basedir].
44          It's possible that external source directories may be inaccessible,          It's possible that external source directories may be inaccessible,
45          or that access to htmlTidy may be restricted.          or that access to htmlTidy may be restricted.
46          <a href='%help_url'>Check the help for more details</a>.</p>          <a href='%help_url'>Check the help for more details</a>.</p>
47        ",        ",
48        array(        array(
49          '%open_basedir' => $open_basedir,          '%open_basedir' => $open_basedir,
50          '%help_url' => url('admin/help/import_html', array('fragment' => 'open_basedir')))          '%help_url' => url('admin/help/import_html', array('fragment' => 'open_basedir')))
51        )        )
52      );      );
53    }    }
54    
55    // Warn, fix a known problem with large batch jobs.    // Warn, fix a known problem with large batch jobs.
56    import_html_check_max_allowed_packet();    import_html_check_max_allowed_packet();
57    
58    $profile_id = import_html_current_profile_id();    $profile_id = import_html_current_profile_id();
59    $form['default_profile'] = import_html_profile_settings($form_state, $profile_id);    $form['default_profile'] = import_html_profile_settings($form_state, $profile_id);
60    $form['#submit'][] = 'import_html_profile_settings_submit';    $form['#submit'][] = 'import_html_profile_settings_submit';
61    $form['#validate'][] = 'import_html_profile_settings_validate';    $form['#validate'][] = 'import_html_profile_settings_validate';
62    
63    
64    $form['import_html_proceed'] = array(    $form['import_html_proceed'] = array(
65      '#type' => 'submit',      '#type' => 'submit',
66      '#value' => t("Proceed to import"),      '#value' => t("Proceed to import"),
67      '#submit' => array('import_html_goto_process'),      '#submit' => array('import_html_goto_process'),
68      '#prefix' => '<br/>',      '#prefix' => '<br/>',
69      #'#attributes' => array('style' => 'font-size:2em;'),      #'#attributes' => array('style' => 'font-size:2em;'),
# Line 91  function import_html_goto_process() { Line 91  function import_html_goto_process() {
91   * This function attempts to analyse and repair your MySQL config.   * This function attempts to analyse and repair your MySQL config.
92   * It is highly likely the ability to do this will be restricted on shared   * It is highly likely the ability to do this will be restricted on shared
93   * hosts, but try anyway.   * hosts, but try anyway.
94   *   *
95   * This change will go away next time the MySQL gets reset, but that's OK.   * This change will go away next time the MySQL gets reset, but that's OK.
96   */   */
97  function import_html_check_max_allowed_packet() {  function import_html_check_max_allowed_packet() {
# Line 115  function import_html_check_max_allowed_p Line 115  function import_html_check_max_allowed_p
115        return TRUE;        return TRUE;
116      }      }
117    }    }
118    
119    drupal_set_message(t("    drupal_set_message(t("
120      <p><strong>Warning:</strong> This server has the      <p><strong>Warning:</strong> This server has the
121      database max_allowed_packet limited to %max_allowed_packet .      database max_allowed_packet limited to %max_allowed_packet .
122      Due to a limitation of the batch process, this is likely to cause      Due to a limitation of the batch process, this is likely to cause
123      problems on huge imports (several thousands of pages at once).<br/>      problems on huge imports (several thousands of pages at once).<br/>
124      If you <em>can</em>, please increase it in your database config (my.cnf).      If you <em>can</em>, please increase it in your database config (my.cnf).
125      At least %required_allowed_packet is recommmended.      At least %required_allowed_packet is recommmended.
126      See !doc_link,      See !doc_link,
127      If you can't, then set the advanced option '<b>Recursion behaviour</b>' to      If you can't, then set the advanced option '<b>Recursion behaviour</b>' to
128      '<b>recurse after</b>' and try to import your site only a few thousand      '<b>recurse after</b>' and try to import your site only a few thousand
129      pages at a time.</p>",      pages at a time.</p>",
130      array(      array(
131        '%max_allowed_packet' => format_size($row['Value']),        '%max_allowed_packet' => format_size($row['Value']),
132        '%required_allowed_packet' => format_size(IMPORT_HTML_REQUIRED_MAX_ALLOWED_PACKET * 1024 *1024),        '%required_allowed_packet' => format_size(IMPORT_HTML_REQUIRED_MAX_ALLOWED_PACKET * 1024 *1024),
133        '!doc_link' => l('MySQL docs', 'http://dev.mysql.com/doc/refman/5.1/en/packet-too-large.html'),        '!doc_link' => l('MySQL docs', 'http://dev.mysql.com/doc/refman/5.1/en/packet-too-large.html'),
134      )      )
# Line 173  function import_html_profile_settings(&$ Line 173  function import_html_profile_settings(&$
173    $profile = import_html_profile($profile_id);    $profile = import_html_profile($profile_id);
174    if (! $profile) {    if (! $profile) {
175      // Fill in defaults (should only be needed first time, if that      // Fill in defaults (should only be needed first time, if that
176      $profile = import_html_profile_defaults();      $profile = import_html_profile_defaults();
177    }    }
178    
179    $form = array();    $form = array();
180    if ($profile_id != 'new') {    if ($profile_id != 'new') {
181      $form['summary'] = array('#value' => import_html_profile_summary($profile));      $form['summary'] = array('#value' => import_html_profile_summary($profile));
182    }    }
# Line 188  function import_html_profile_settings(&$ Line 188  function import_html_profile_settings(&$
188    );    );
189    if ($profile_id != 'new') {    if ($profile_id != 'new') {
190      $form['profile_id']['#default_value'] = $profile_id;      $form['profile_id']['#default_value'] = $profile_id;
191      // It used to be that disabling this worked.      // It used to be that disabling this worked.
192      // Now doing so messes with validations      // Now doing so messes with validations
193      $form['profile_id']['#disabled'] = TRUE;      $form['profile_id']['#disabled'] = TRUE;
194      $form['profile_id']['#required'] = FALSE;      $form['profile_id']['#required'] = FALSE;
195    }    }
196    
197    $form['extraction'] = array(    $form['extraction'] = array(
198      '#type' => 'fieldset',      '#type' => 'fieldset',
199      '#title' => t('Import and Content Analysis Options'),      '#title' => t('Import and Content Analysis Options'),
200      '#collapsible' => TRUE,      '#collapsible' => TRUE,
201      '#collapsed' => TRUE,      '#collapsed' => TRUE,
202    );    );
203    $form['extraction'][] = array(    $form['extraction'][] = array(
204      '#value' => '<p>'. t("How the content is extracted from the source documents.") .'</p>',      '#value' => '<p>'. t("How the content is extracted from the source documents.") .'</p>',
205    );    );
206    
# Line 226  function import_html_profile_settings(&$ Line 226  function import_html_profile_settings(&$
226      "),      "),
227    );    );
228    
   
229    $form['extraction']['content_type'] = array(    $form['extraction']['content_type'] = array(
230      '#type' => 'select',      '#type' => 'select',
231      '#title' => t("Node Type for new pages"),      '#title' => t("Node Type for new pages"),
232      '#options' => node_get_types('names'),      '#options' => node_get_types('names'),
233      '#default_value' => $profile['content_type'],      '#default_value' => $profile['content_type'],
234      '#description' => t("      '#description' => t("
235        Note, if importing into a CCK content type, or anything that doesn't        Note, if importing into a CCK content type, or anything that doesn't
236        store its body in the node 'body', some customization will have to be        store its body in the node 'body', some customization will have to be
237        done on your XSL template.        done on your XSL template.
238      ")      ")
# Line 246  function import_html_profile_settings(&$ Line 245  function import_html_profile_settings(&$
245      '#default_value' => $profile['preferred_filter'],      '#default_value' => $profile['preferred_filter'],
246      '#options' => import_html_get_preferred_filter(TRUE),      '#options' => import_html_get_preferred_filter(TRUE),
247      '#description' => t("      '#description' => t("
248        After importing HTML, the end result may still have a standard Drupal        After importing HTML, the end result may still have a standard Drupal
249        filter applied to it internally.        filter applied to it internally.
250        Use 'Unfiltered HTML' if you want the content verbatim.        Use 'Unfiltered HTML' if you want the content verbatim.
251        'Full HTML' <em>may</em> be correct here, although it may create        'Full HTML' <em>may</em> be correct here, although it may create
252        unwanted hard breaks if the input is already word-wrapped internally.        unwanted hard breaks if the input is already word-wrapped internally.
253        Modify only if you want to strip the source right down, execute php,        Modify only if you want to strip the source right down, execute php,
254        or do other filter magic on the input.        or do other filter magic on the input.
255      "),      "),
# Line 275  function import_html_profile_settings(&$ Line 274  function import_html_profile_settings(&$
274      "),      "),
275    );    );
276    
277    
278    $form['extraction']['file_exclusions'] = array(    $form['extraction']['file_exclusions'] = array(
279      '#type' => 'textarea',      '#type' => 'textarea',
280      '#title' => t("File Exclusion Pattern"),      '#title' => t("File Exclusion Pattern"),
# Line 324  function import_html_profile_settings(&$ Line 323  function import_html_profile_settings(&$
323      '#return_value' => TRUE,      '#return_value' => TRUE,
324      '#default_value' => $profile['force_tidy'],      '#default_value' => $profile['force_tidy'],
325      '#description' => t("      '#description' => t("
326        Run HTML Tidy with all strict options over the input before        Run HTML Tidy with all strict options over the input before
327        parsing it as XML. Normally you want this on BUT turn it off        parsing it as XML. Normally you want this on BUT turn it off
328        if trying to read from non-HTML sources (like arbitrary XML)        if trying to read from non-HTML sources (like arbitrary XML)
329        or it will mutilate it.        or it will mutilate it.
330        <br/>        <br/>
331        Instead of using HTML input, you can feed in any <b>valid</b> XML        Instead of using HTML input, you can feed in any <b>valid</b> XML
332        and use XSL template to massage it into simple XHTML.        and use XSL template to massage it into simple XHTML.
333        But in that case disable this option and do NOT use HTML tidy.        But in that case disable this option and do NOT use HTML tidy.
334      "),      "),
335    );    );
336    
   
337    $form['replication'] = array(    $form['replication'] = array(
338      '#type' => 'fieldset',      '#type' => 'fieldset',
339      '#title' => t("Replication Options"),      '#title' => t("Replication Options"),
340      '#collapsible' => TRUE,      '#collapsible' => TRUE,
341      '#collapsed' => TRUE,      '#collapsed' => TRUE,
342    );    );
343    $form['replication'][] = array(    $form['replication'][] = array(
344      '#value' => '<p>'. t("How and where the imported content is reproduced on this site.") .'</p>',      '#value' => '<p>'. t("How and where the imported content is reproduced on this site.") .'</p>',
345    );    );
346    
# Line 386  function import_html_profile_settings(&$ Line 384  function import_html_profile_settings(&$
384        the new page will have no url_alias.        the new page will have no url_alias.
385      "),      "),
386    );    );
387    
388    $form['replication']['relink_files'] = array(    $form['replication']['relink_files'] = array(
389      '#type' => 'checkbox',      '#type' => 'checkbox',
390      '#title' => t("Try to Relink Files by discarding suffixes"),      '#title' => t("Try to Relink Files by discarding suffixes"),
# Line 421  function import_html_profile_settings(&$ Line 419  function import_html_profile_settings(&$
419        It's bad mojo to have spaces or non-alphanumeric characters        It's bad mojo to have spaces or non-alphanumeric characters
420        in your filenames and in your URLs. Normally I try to fix this        in your filenames and in your URLs. Normally I try to fix this
421        by replacing potentially damaging characters with an underscore.        by replacing potentially damaging characters with an underscore.
422        If, however you have to support legacy stuff like        If, however you have to support legacy stuff like
423        'Random filename #3 - & about what?.pdf' then we can try to leave them alone.        'Random filename #3 - & about what?.pdf' then we can try to leave them alone.
424        May not always work the way you expect.        May not always work the way you expect.
425      "),      "),
426    );    );
427    
# Line 436  function import_html_profile_settings(&$ Line 434  function import_html_profile_settings(&$
434        be stored. Images and suchlike will be put into a heirachy mirroring        be stored. Images and suchlike will be put into a heirachy mirroring
435        their old location, but all under this directory.        their old location, but all under this directory.
436        <br/>        <br/>
437        Effectively, this moves file storage towards the Drupal CMS way of        Effectively, this moves file storage towards the Drupal CMS way of
438        storing user files, although it does not enter them as 'attachments'.        storing user files, although it does not enter them as 'attachments'.
439      "),      "),
440      '#after_build' => array('system_check_directory'), // this works for the core, try it myself      '#after_build' => array('system_check_directory'), // this works for the core, try it myself
# Line 449  function import_html_profile_settings(&$ Line 447  function import_html_profile_settings(&$
447      '#default_value' => $profile['rewrite_links'],      '#default_value' => $profile['rewrite_links'],
448      '#description' => t("      '#description' => t("
449        As the actual files are being stored elsewhere, the HTML links need to be        As the actual files are being stored elsewhere, the HTML links need to be
450        rewritten to allow for that. This should be on by default.        rewritten to allow for that. This should be on by default.
451        Turn off only if you are intending to re-create a        Turn off only if you are intending to re-create a
452        messy site with files in old places and have set the file storage path to blank.        messy site with files in old places and have set the file storage path to blank.
453        See the transformation file        See the transformation file
454        <code>rewrite_href_and_src.xsl</code> for fine-tuning if there is trouble.        <code>rewrite_href_and_src.xsl</code> for fine-tuning if there is trouble.
455        <small>Only relative and site-relative links are rewritten.        <small>Only relative and site-relative links are rewritten.
456        Hard-coded, fully-justified (external) URLS are not messed with,        Hard-coded, fully-justified (external) URLS are not messed with,
457        even if they used to resolve to the same host.</small>        even if they used to resolve to the same host.</small>
458      ")      ")
459    );    );
460    
461    $form['replication']['import_site_prefix'] = array(    $form['replication']['import_site_prefix'] = array(
462      '#type' => 'textfield',      '#type' => 'textfield',
463      '#title' => t("Import Site Prefix"),      '#title' => t("Import Site Prefix"),
# Line 468  function import_html_profile_settings(&$ Line 466  function import_html_profile_settings(&$
466      '#maxlength' => 100,      '#maxlength' => 100,
467      '#description' => t("      '#description' => t("
468        Where, beneath siteroot, should extra imported <strong>pages</strong>        Where, beneath siteroot, should extra imported <strong>pages</strong>
469        <em>appear to be</em> served from?        <em>appear to be</em> served from?
470        This is a prefix that is applied to the generated URL-aliases.        This is a prefix that is applied to the generated URL-aliases.
471        <br/>        <br/>
472        If you wish to keep the imported        If you wish to keep the imported
# Line 493  function import_html_profile_settings(&$ Line 491  function import_html_profile_settings(&$
491      '#options' => $freetagging_vocabs,      '#options' => $freetagging_vocabs,
492      '#default_value' => $profile['freetag_vocab'],      '#default_value' => $profile['freetag_vocab'],
493      '#description' => t("      '#description' => t("
494         If chosen, any <b>meta keywords</b> or <b>dc:Subject</b> tags         If chosen, any <b>meta keywords</b> or <b>dc:Subject</b> tags
495         found in the source will be added as terms in the given vocabulary.         found in the source will be added as terms in the given vocabulary.
496         Works best with <em>freetagging vocabularies</em> that are associated         Works best with <em>freetagging vocabularies</em> that are associated
497         with the import node type.         with the import node type.
# Line 510  function import_html_profile_settings(&$ Line 508  function import_html_profile_settings(&$
508      '#collapsible' => TRUE,      '#collapsible' => TRUE,
509      '#collapsed' => TRUE,      '#collapsed' => TRUE,
510    );    );
511    
512    $form['advanced']["help"] = array(    $form['advanced']["help"] = array(
513     '#value' => '<p>'. t("How to handle problems when importing") .'</p>',     '#value' => '<p>'. t("How to handle problems when importing") .'</p>',
514    );    );
515    
516    $form['advanced']['handle_duplicates'] = array(    $form['advanced']['handle_duplicates'] = array(
517      '#type' => 'select',      '#type' => 'select',
518      '#title' => t("Duplicate Handling"),      '#title' => t("Duplicate Handling"),
519      '#default_value' => $profile['handle_duplicates'],      '#default_value' => $profile['handle_duplicates'],
520      '#options' => array(IMPORT_HTML_MERGE => 'overwrite/merge' , IMPORT_HTML_SKIP => 'skip'),      '#options' => array(IMPORT_HTML_MERGE => 'overwrite/merge' , IMPORT_HTML_SKIP => 'skip'),
521      '#description' => t("      '#description' => t("
522        If attempting to import a file into a path that already exists        If attempting to import a file into a path that already exists
523        in the system (such as by repeating an import process), do what?        in the system (such as by repeating an import process), do what?
524      "),      "),
525    );    );
526    
527    $form['advanced']['handle_no_title'] = array(    $form['advanced']['handle_no_title'] = array(
528      '#type' => 'select',      '#type' => 'select',
529      '#title' => t("No Title"),      '#title' => t("No Title"),
# Line 556  function import_html_profile_settings(&$ Line 554  function import_html_profile_settings(&$
554        When using this option, we can either scan those directories <em>before</em>        When using this option, we can either scan those directories <em>before</em>
555        or <em>during</em> the process.        or <em>during</em> the process.
556        <br/>        <br/>
557        Scanning and queuing everything first is more predictable, but may result in        Scanning and queuing everything first is more predictable, but may result in
558        a huge list being loaded into memory first.        a huge list being loaded into memory first.
559        <br/>        <br/>
560        Noting the directories to recurse into and only scanning them when it's time        Noting the directories to recurse into and only scanning them when it's time
561        <em>may</em> be easier on the memory for gigantic sites. The batch job will        <em>may</em> be easier on the memory for gigantic sites. The batch job will
562        keep extending until it is done.        keep extending until it is done.
563        <br/>I don't know which is better. The first is easy, but I'd recommend the second for        <br/>I don't know which is better. The first is easy, but I'd recommend the second for
564        tens of thousands of pages.        tens of thousands of pages.
565      "),      "),
566    );    );
# Line 574  function import_html_profile_settings(&$ Line 572  function import_html_profile_settings(&$
572      '#options' => array(0, 1, 2, 3),      '#options' => array(0, 1, 2, 3),
573      '#description' => t("      '#description' => t("
574        To trace and test the import process, increasing the debug level here        To trace and test the import process, increasing the debug level here
575        will produce a huge amount of process tracing,        will produce a huge amount of process tracing,
576        including dumps of the raw versions of the input files        including dumps of the raw versions of the input files
577        as it gets massaged into the end result.        as it gets massaged into the end result.
578        <br/>        <br/>
579        Note that enabling debug can itself introduce errors as the trace logs        Note that enabling debug can itself introduce errors as the trace logs
# Line 595  function import_html_profile_settings(&$ Line 593  function import_html_profile_settings(&$
593      "),      "),
594    );    );
595    
596    
597    $form['advanced']['import_html_other_logic'] = array(    $form['advanced']['import_html_other_logic'] = array(
598      '#value' => t("<p>      '#value' => t("<p>
599         Other logic, like whether to use the TITLE tag or the H1 tag found in a         Other logic, like whether to use the TITLE tag or the H1 tag found in a
# Line 636  function import_html_profile_summary($pr Line 634  function import_html_profile_summary($pr
634      $menu = menu_load($menu_name);      $menu = menu_load($menu_name);
635      $menu_title = $menu['title'];      $menu_title = $menu['title'];
636    }    }
637    
638    if (function_exists('dpm') && ($profile['debug_level'] > 0)) {    if (function_exists('dpm') && ($profile['debug_level'] > 0)) {
639      dpm($profile);      dpm($profile);
640    }    }
641    
642    $import_categories = array();    $import_categories = array();
643    foreach ((array)$profile['import_category'] as $tid) {    foreach ((array)$profile['import_category'] as $tid) {
644      if ($term = taxonomy_get_term($tid)) {      if ($term = taxonomy_get_term($tid)) {
645        $import_categories[$tid] = $term->name;        $import_categories[$tid] = $term->name;
646      }      }
647    }    }
648    
649    
650    $substitutions = array(    $substitutions = array(
651        '%import_html_source_siteroot' => variable_get('import_html_source_siteroot', "/var/www/htdocs/") ,        '%import_html_source_siteroot' => variable_get('import_html_source_siteroot', "/var/www/htdocs/") ,
652        '%import_html_current_subsection' => variable_get('import_html_current_subsection', ""),        '%import_html_current_subsection' => variable_get('import_html_current_subsection', ""),
653        '!dest_virtual_path' => l($dest_virtual_path, $dest_virtual_path ),        '!dest_virtual_path' => l($dest_virtual_path, $dest_virtual_path ),
654        '!dest_file_root' => l($dest_file_root, $dest_file_root),        '!dest_file_root' => l($dest_file_root, $dest_file_root),
655        '!settings_url' => url(IMPORT_HTML_ADMIN_PATH .'/settings'),        '!settings_url' => url(IMPORT_HTML_ADMIN_PATH .'/settings'),
656        '!translation_template' => l(basename($profile['translation_template']), $profile['translation_template']),        '!translation_template' => l(basename($profile['translation_template']), $profile['translation_template']),
657        '%default_document' => $profile['default_document'],        '%default_document' => $profile['default_document'],
658        '%create_menus' => $profile['create_menus']?'will':'will not',        '%create_menus' => $profile['create_menus']?'will':'will not',
659        '%menu_parent_name' => $menu_title,        '%menu_parent_name' => $menu_title,
# Line 665  function import_html_profile_summary($pr Line 663  function import_html_profile_summary($pr
663        '%import_promote' => $profile['import_promote']?'will':'will not',        '%import_promote' => $profile['import_promote']?'will':'will not',
664        '%import_categories' => join($import_categories, ', '),        '%import_categories' => join($import_categories, ', '),
665      );      );
666    
667    $summary = array();    $summary = array();
668    $summary[] = t("    $summary[] = t("
669        Source files will be scanned from        Source files will be scanned from
670        <br/><code>%import_html_source_siteroot%import_html_current_subsection</code>        <br/><code>%import_html_source_siteroot%import_html_current_subsection</code>
671      ", $substitutions);      ", $substitutions);
672    $summary[] = t("    $summary[] = t("
# Line 679  function import_html_profile_summary($pr Line 677  function import_html_profile_summary($pr
677    $summary[] = t("    $summary[] = t("
678      Import template for semantic data extraction is <code>!translation_template</code>      Import template for semantic data extraction is <code>!translation_template</code>
679      ", $substitutions);      ", $substitutions);
680    
681    $summary[] = $profile['rewrite_links']    $summary[] = $profile['rewrite_links']
682      ? t("Links found within the sources <b>will</b> be rewritten to try and allow for the new paths")      ? t("Links found within the sources <b>will</b> be rewritten to try and allow for the new paths")
683      : t("Links from within the imported pages will <b>not</b> be rewritten, and may get lost.");      : t("Links from within the imported pages will <b>not</b> be rewritten, and may get lost.");
684    
685    if ($profile['strip_scripts'])    if ($profile['strip_scripts'])
686      $summary[] = t("All script tags found in the source will be discarded");      $summary[] = t("All script tags found in the source will be discarded");
687    else    else
688      $summary[] = t("Script tags in the source will be left as-is (likely to break)");      $summary[] = t("Script tags in the source will be left as-is (likely to break)");
689    
690    $summary[] = t("Non-page files imported will be saved beneath <code>!dest_file_root %import_html_current_subsection</code> ", $substitutions);    $summary[] = t("Non-page files imported will be saved beneath <code>!dest_file_root %import_html_current_subsection</code> ", $substitutions);
# Line 706  function import_html_profile_summary($pr Line 704  function import_html_profile_summary($pr
704    $output = t("<p>These preferences and more are changeable <a href='!settings_url'>in the settings</a>.</p>", $substitutions);    $output = t("<p>These preferences and more are changeable <a href='!settings_url'>in the settings</a>.</p>", $substitutions);
705    
706    $title = t('%profile_label import profile:', array('%profile_label' => $profile['profile_id']));    $title = t('%profile_label import profile:', array('%profile_label' => $profile['profile_id']));
707    return theme('box', $title, theme("item_list", $summary) . $output );    return theme('box', $title, theme("item_list", $summary) . $output );
708  }  }
709    
710    
711    
712  /**  /**
# Line 724  function import_html_template_selector($ Line 722  function import_html_template_selector($
722      if (! $current_template) {      if (! $current_template) {
723        $current_template = drupal_get_path('module', 'import_html') ."/templates/html2simplehtml.xsl";        $current_template = drupal_get_path('module', 'import_html') ."/templates/html2simplehtml.xsl";
724      }      }
725    
726      return array(      return array(
727        '#type'    => 'select',        '#type'    => 'select',
728        '#title'   => t('Import template to use'),        '#title'   => t('Import template to use'),
729        '#options' => $options,        '#options' => $options,
730        '#default_value' => $current_template,        '#default_value' => $current_template,
# Line 734  function import_html_template_selector($ Line 732  function import_html_template_selector($
732        '#suffix'  => '</div>',        '#suffix'  => '</div>',
733        '#description' => t("        '#description' => t("
734          This file must be a valid XSL Template that can convert from your source          This file must be a valid XSL Template that can convert from your source
735          HTML to the simplified semantic XHTML schema (see docs and examples).          HTML to the simplified semantic XHTML schema (see docs and examples).
736          Templates should be placed in the import_html module <code>/templates/</code> directory.          Templates should be placed in the import_html module <code>/templates/</code> directory.
737          <br/>          <br/>
738          Sample import templates can be found in %module_dir.          Sample import templates can be found in %module_dir.
# Line 762  function import_html_profile_settings_su Line 760  function import_html_profile_settings_su
760    }    }
761    // trivial tidy-up, not worth complaining about    // trivial tidy-up, not worth complaining about
762    $form_state['values']['file_storage_path'] = ensure_trailing_slash($form_state['values']['file_storage_path']);    $form_state['values']['file_storage_path'] = ensure_trailing_slash($form_state['values']['file_storage_path']);
763    
764    // Save only the variables I care about    // Save only the variables I care about
765    $keys = array_keys(import_html_profile_defaults());    $keys = array_keys(import_html_profile_defaults());
766    foreach ($keys as $key) {    foreach ($keys as $key) {
# Line 791  function import_html_profile_settings_de Line 789  function import_html_profile_settings_de
789   * This is a subset of the general settings - these options are also reproduced   * This is a subset of the general settings - these options are also reproduced
790   * on later action pages where they can be tweaked closer to the action. So   * on later action pages where they can be tweaked closer to the action. So
791   * the form is saved in a block of its own.   * the form is saved in a block of its own.
792   *   *
793   * These options may be a little different occur per-pass, eg if importing   * These options may be a little different occur per-pass, eg if importing
794   * different directories within a global profile.   * different directories within a global profile.
795   */   */
796  function import_html_subsettings_form($profile) {  function import_html_subsettings_form($profile) {
797    $form=array();    $form=array();
798    
799    // Taxonomy box:    // Taxonomy box:
800    // note, this doesn't show up for vocabs with only one term. Sorta annoying'    // note, this doesn't show up for vocabs with only one term. Sorta annoying'
801    if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) {    if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) {
802      $form['import_category'] = array(      $form['import_category'] = array(
# Line 817  function import_html_subsettings_form($p Line 815  function import_html_subsettings_form($p
815        '#value' => t("<p><b>Taxonomy:</b> There are no vocabularies available to tag the imported content with. <a href='!add_vocab'>Create one</a> if you like.</p>", array('!add_vocab' => url('admin/content/taxonomy'))),        '#value' => t("<p><b>Taxonomy:</b> There are no vocabularies available to tag the imported content with. <a href='!add_vocab'>Create one</a> if you like.</p>", array('!add_vocab' => url('admin/content/taxonomy'))),
816      );      );
817    }    }
818    
819    // Status selection:    // Status selection:
820    $form['import_status'] = array(    $form['import_status'] = array(
821      '#type' => 'checkbox',      '#type' => 'checkbox',
822      '#title' => t('Imported nodes are Published?'),      '#title' => t('Imported nodes are Published?'),
823      '#default_value' => $profile['import_status'],      '#default_value' => $profile['import_status'],
824      '#description' => t("      '#description' => t("
825        Sets the node status.  Check to have nodes published.        Sets the node status.  Check to have nodes published.
826      "),      "),
827    );    );
828    
829    // promote selection:  added by L0rne    // promote selection:  added by L0rne
830    $form['import_promote'] = array(    $form['import_promote'] = array(
831      '#type' => 'checkbox',      '#type' => 'checkbox',
# Line 837  function import_html_subsettings_form($p Line 835  function import_html_subsettings_form($p
835        Sets whether or not imported nodes are promoted to the front page.        Sets whether or not imported nodes are promoted to the front page.
836      "),      "),
837    );    );
838    
839    global $user;    global $user;
840    $form['import_user'] = array(    $form['import_user'] = array(
841      '#type' => 'textfield',      '#type' => 'textfield',
842      '#title' => t('User to create nodes as'),      '#title' => t('User to create nodes as'),
843      '#maxlength' => 60,      '#maxlength' => 60,
844      '#autocomplete_path' => 'user/autocomplete',      '#autocomplete_path' => 'user/autocomplete',
845      '#default_value' => $profile['import_user'],      '#default_value' => $profile['import_user'],
846    );    );
847    
848    if (module_exists('menu')) {    if (module_exists('menu')) {
# Line 857  function import_html_subsettings_form($p Line 855  function import_html_subsettings_form($p
855      );      );
856      // Retrieve a select list of the entire menu tree      // Retrieve a select list of the entire menu tree
857      $menu_parent_options = menu_parent_options(menu_get_menus(), array('mlid' => 0));      $menu_parent_options = menu_parent_options(menu_get_menus(), array('mlid' => 0));
858    
859      $form["menu_parent_id"] = array(      $form["menu_parent_id"] = array(
860        '#type' => 'select',        '#type' => 'select',
861        '#title' => t('Menu Parent'),        '#title' => t('Menu Parent'),
862        '#default_value' => $profile['menu_parent_id'],        '#default_value' => $profile['menu_parent_id'],
863        '#options' => $menu_parent_options,        '#options' => $menu_parent_options,
864        '#description' => t("        '#description' => t("
865          Where in the menu system should the new heirachy          Where in the menu system should the new heirachy
866          of pages be built?          of pages be built?
867          <br/>          <br/>
868          If you leave this as 'Navigation' the new pages          If you leave this as 'Navigation' the new pages
869          may start to collide with your Admin menus,          may start to collide with your Admin menus,
870          so consider making a placeholder menu first.          so consider making a placeholder menu first.
871        "),        "),
872      );      );
# Line 877  function import_html_subsettings_form($p Line 875  function import_html_subsettings_form($p
875      $form["create_menus"] = array(      $form["create_menus"] = array(
876        '#type' => 'markup',        '#type' => 'markup',
877        '#value' => t("        '#value' => t("
878          Menu is not enabled, so the heirachical structure          Menu is not enabled, so the heirachical structure
879          of the imported files will NOT be retained.          of the imported files will NOT be retained.
880        "),        "),
881        '#description' => t("        '#description' => t("
882          <p>If you enable the menu.module,          <p>If you enable the menu.module,
883          the structure of the imported files can be imported as well.</p>          the structure of the imported files can be imported as well.</p>
884          <p>Note, that in order for this to work, all the apparent parents          <p>Note, that in order for this to work, all the apparent parents
885          of a page must have menu items as well. If importing a subsection,          of a page must have menu items as well. If importing a subsection,
886          Placeholders for the higher sections will be created, but they may be          Placeholders for the higher sections will be created, but they may be
887          hollow shells.</p>          hollow shells.</p>
888        ")        ")
889      );      );
890    }    }
891    return $form;    return $form;
892  }  }
893    
894    
895  function import_html_subsettings_submit($form, &$form_state) {  function import_html_subsettings_submit($form, &$form_state) {
896    // Handle incidental settings when submitted from other pages - like during the    // Handle incidental settings when submitted from other pages - like during the
897    // import process.    // import process.
898    
899    $profile = import_html_profile($form_state['values']['profile_id']);    $profile = import_html_profile($form_state['values']['profile_id']);
# Line 915  function import_html_subsettings_submit( Line 913  function import_html_subsettings_submit(
913      $profile[$v] = $form_state['values'][$v];      $profile[$v] = $form_state['values'][$v];
914     }     }
915    }    }
916    
917    import_html_profile($form_state['values']['profile_id'] , $profile);    import_html_profile($form_state['values']['profile_id'] , $profile);
918  }  }
919    
920  function import_html_profile_switcher_submit($form, &$form_state) {  function import_html_profile_switcher_submit($form, &$form_state) {
921    import_html_current_profile_id($form_state['values']['profile_id']);    import_html_current_profile_id($form_state['values']['profile_id']);
922  }  }
923    
924    
925    
926  ///////////////////////////////////////////  ///////////////////////////////////////////
# Line 935  function import_html_profile_switcher_su Line 933  function import_html_profile_switcher_su
933   * Step 2 - display files and select them   * Step 2 - display files and select them
934   * - submit that to run the import   * - submit that to run the import
935   * Step 3 - display summary of results.   * Step 3 - display summary of results.
936   *   *
937   * Parameters and return as per usual with FAPI   * Parameters and return as per usual with FAPI
938   */   */
939  function import_html_process_form(&$form_state) {  function import_html_process_form(&$form_state) {
# Line 943  function import_html_process_form(&$form Line 941  function import_html_process_form(&$form
941    $steps = 3;    $steps = 3;
942    
943    // Initialize multistep    // Initialize multistep
944    // D6 multistep example from    // D6 multistep example from
945    // http://www.andrewyager.com/content/view/51/27/    // http://www.andrewyager.com/content/view/51/27/
946    if (empty($form_state['storage']['step'])) {    if (empty($form_state['storage']['step'])) {
947      // we are coming in without a step, so default to step 1      // we are coming in without a step, so default to step 1
948      $form_state['storage']['step'] = 1;      $form_state['storage']['step'] = 1;
949    }    }
950    
951    $form['title'] = array('#value' => t('<h3>Step %step of %steps</h3>', array('%step' => $form_state['storage']['step'], '%steps' => $steps)));    $form['title'] = array('#value' => t('<h3>Step %step of %steps</h3>', array('%step' => $form_state['storage']['step'], '%steps' => $steps)));
952    
953    $profile_id = isset($form_state['values']['profile_id']) ? $form_state['values']['profile_id'] : import_html_current_profile_id();    $profile_id = isset($form_state['values']['profile_id']) ? $form_state['values']['profile_id'] : import_html_current_profile_id();
954    $profile = import_html_profile($profile_id);    $profile = import_html_profile($profile_id);
955    // Display this on every page - help knowing just what's happening    // Display this on every page - help knowing just what's happening
956    $form['profile_info'] = array(    $form['profile_info'] = array(
# Line 971  function import_html_process_form(&$form Line 969  function import_html_process_form(&$form
969  @dpm(array(  @dpm(array(
970    'Asked for the process form. profile is ' => $profile,    'Asked for the process form. profile is ' => $profile,
971    'Current step is ' => $form_state['storage']['step'],    'Current step is ' => $form_state['storage']['step'],
972    'Current submission is ' => $form_state['values'],    'Current submission is ' => $form_state['values'],
973    'Current POST is ' => $_POST,    'Current POST is ' => $_POST,
974    'Last time we were here, saved submission was ' => $form_state['storage']['values'][ $form_state['storage']['step'] ],    'Last time we were here, saved submission was ' => $form_state['storage']['values'][ $form_state['storage']['step'] ],
975    )    )
976  );  );
977  */  */
978    
979    // retrieve the last submitted values from storage to re-populate this form    // retrieve the last submitted values from storage to re-populate this form
980    if ( isset($form_state['storage']['values'][ $form_state['storage']['step'] ])) {    if ( isset($form_state['storage']['values'][ $form_state['storage']['step'] ])) {
# Line 991  function import_html_process_form(&$form Line 989  function import_html_process_form(&$form
989    }    }
990    
991    switch ($form_state['storage']['step']) {    switch ($form_state['storage']['step']) {
992    
993      case 1:      case 1:
994        // Display current options and path prior to filesystem scan        // Display current options and path prior to filesystem scan
995        $form['step1'] = import_html_select_source_form($form_state, $profile);        $form['step1'] = import_html_select_source_form($form_state, $profile);
# Line 1029  function import_html_process_form(&$form Line 1027  function import_html_process_form(&$form
1027        $form['action'] = array(        $form['action'] = array(
1028          '#value' => '<p>'. t("Either run the import now, or queue the selected files for processing later - may be required for large jobs") .'</p>',          '#value' => '<p>'. t("Either run the import now, or queue the selected files for processing later - may be required for large jobs") .'</p>',
1029        );        );
1030    
1031        // If these buttons are to do their thing and ALSO make an effect on the multistep        // If these buttons are to do their thing and ALSO make an effect on the multistep
1032        // and proceed, they need to have both behaviours attached as #submit actions.        // and proceed, they need to have both behaviours attached as #submit actions.
1033        $form['import'] = array(        $form['import'] = array(
# Line 1044  function import_html_process_form(&$form Line 1042  function import_html_process_form(&$form
1042          '#type' => 'submit',          '#type' => 'submit',
1043          '#value' => t('Batch Process Files'),          '#value' => t('Batch Process Files'),
1044          '#submit' => array(          '#submit' => array(
1045            'import_html_batch_import_files_submit',            'import_html_batch_import_files_submit',
1046            'import_html_process_form_next_button_submit'            'import_html_process_form_next_button_submit'
1047          ),          ),
1048        );        );
1049    
1050      break;      break;
1051    
1052      case 3:      case 3:
1053        // Files have been selected and submitted.        // Files have been selected and submitted.
1054    
1055        // To keep the state information fresh, (forward/back testing)        // To keep the state information fresh, (forward/back testing)
1056        // Make a quiet note of the recently selected checkboxes        // Make a quiet note of the recently selected checkboxes
1057        $import_files = (array)$form_state['values']['file_rel_path'];        $import_files = (array)$form_state['values']['file_rel_path'];
1058        $selected_files = array_filter($import_files);        $selected_files = array_filter($import_files);
# Line 1076  function import_html_process_form(&$form Line 1074  function import_html_process_form(&$form
1074    
1075      break;      break;
1076    }    }
1077    
1078    
1079    // Show step buttons.    // Show step buttons.
1080    if ($form_state['storage']['step'] > 1) {    if ($form_state['storage']['step'] > 1) {
1081      $form['previous'] = array(      $form['previous'] = array(
# Line 1094  function import_html_process_form(&$form Line 1092  function import_html_process_form(&$form
1092      );      );
1093    }    }
1094    return $form;    return $form;
1095    
1096  }  }
1097    
1098  /**  /**
1099   * Handle each step of the import process   * Handle each step of the import process
1100   * - by passing the form submit down to per-page handlers   * - by passing the form submit down to per-page handlers
1101   * , actually subforms with their own identity.   * , actually subforms with their own identity.
1102   */   */
1103  function import_html_process_form_validate($form, &$form_state) {  function import_html_process_form_validate($form, &$form_state) {
1104    // Massage the input to be forgiving and figure what we really mean    // Massage the input to be forgiving and figure what we really mean
1105    // Note these transient settings as variables.    // Note these transient settings as variables.
1106    // It's more convenient if they are remembered like this    // It's more convenient if they are remembered like this
1107    if ( isset($form_state['values']['source_siteroot']) ) {    if ( isset($form_state['values']['source_siteroot']) ) {
1108      $form_state['values']['source_siteroot'] = ensure_trailing_slash(foreslash($form_state['values']['source_siteroot'])); // win32 safe.      $form_state['values']['source_siteroot'] = ensure_trailing_slash(foreslash($form_state['values']['source_siteroot'])); // win32 safe.
# Line 1123  function import_html_process_form_valida Line 1121  function import_html_process_form_valida
1121  /**  /**
1122   * This function probably never runs. Remove it when all is well with the   * This function probably never runs. Remove it when all is well with the
1123   * multistep.   * multistep.
1124   *   *
1125   * Action buttons within import_html_process_form have their own handlers!   * Action buttons within import_html_process_form have their own handlers!
1126   *   *
1127   * The actual process that runs at the end of this form is   * The actual process that runs at the end of this form is
1128   * @see import_html_import_files_submit()   * @see import_html_import_files_submit()
1129   */   */
1130  function import_html_process_form_submit($form, &$form_state) {  function import_html_process_form_submit($form, &$form_state) {
1131    // I don't do anything useful.    // I don't do anything useful.
1132  }  }
1133    
1134  /**  /**
# Line 1168  function import_html_select_source_form( Line 1166  function import_html_select_source_form(
1166        or spider all the resources of a remote site.        or spider all the resources of a remote site.
1167      </p><p>      </p><p>
1168        <b>Note</b> Big sites <i>will</i> take a long time to process,        <b>Note</b> Big sites <i>will</i> take a long time to process,
1169        and processing may timeout.        and processing may timeout.
1170        You can either increase the php timeout value and wait around,        You can either increase the php timeout value and wait around,
1171        or just do sections at a time by using the subsection parameter above.        or just do sections at a time by using the subsection parameter above.
1172      </p>",      </p>",
1173      array(      array(
1174        '!demo_link' => url(IMPORT_HTML_ADMIN_PATH .'/demo'),        '!demo_link' => url(IMPORT_HTML_ADMIN_PATH .'/demo'),
1175      )      )
1176    ));    ));
# Line 1185  function import_html_select_source_form( Line 1183  function import_html_select_source_form(
1183    
1184    $form['htmlsource']['source_siteroot'] = array(    $form['htmlsource']['source_siteroot'] = array(
1185      '#type' => 'textfield',      '#type' => 'textfield',
1186      '#title' => t("Site Root on the Server"),      '#title' => t("Site Root on the Server"),
1187      '#default_value' => $profile['source_siteroot'],      '#default_value' => $profile['source_siteroot'],
1188      '#description' => t("      '#description' => t("
1189        Where to read from.        Where to read from.
1190        <br/><b>If the files are on the server</b> (local to Drupal)        <br/><b>If the files are on the server</b> (local to Drupal)
1191        Enter the absolute or drupal-root-relative location of the site to import.        Enter the absolute or drupal-root-relative location of the site to import.
1192        You must have access permissions.        You must have access permissions.
1193        Relative paths and aliases will be calculated from here.        Relative paths and aliases will be calculated from here.
1194        <br/>eg: <code>/var/www/old_site/htdocs</code>, or <code>sites/default/files/copy-of-old-site</code>        <br/>eg: <code>/var/www/old_site/htdocs</code>, or <code>sites/default/files/copy-of-old-site</code>
1195      "),      "),
# Line 1200  function import_html_select_source_form( Line 1198  function import_html_select_source_form(
1198    
1199    $form['htmlsource']['current_subsection'] = array(    $form['htmlsource']['current_subsection'] = array(
1200      '#type' => 'textfield',      '#type' => 'textfield',
1201      '#title' => t("Subsection to list"),      '#title' => t("Subsection to list"),
1202      '#default_value' => $profile['current_subsection'],      '#default_value' => $profile['current_subsection'],
1203      '#size' => 20,      '#size' => 20,
1204      '#description' => t("      '#description' => t("
# Line 1213  function import_html_select_source_form( Line 1211  function import_html_select_source_form(
1211    // Set a callback so these settings get saved generically, persistantly    // Set a callback so these settings get saved generically, persistantly
1212    $form['#submit'][] = 'import_html_subsettings_submit';    $form['#submit'][] = 'import_html_subsettings_submit';
1213    
1214    return $form;    return $form;
1215  }  }
1216    
1217  /**  /**
1218   * Check the submitted source path and subsection are valid   * Check the submitted source path and subsection are valid
1219   *   *
1220   * A FAPI #element_validate callback invoked on $form['source_siteroot']   * A FAPI #element_validate callback invoked on $form['source_siteroot']
1221   *   *
1222   * http://api.drupal.org/api/file/developer/topics/forms_api_reference. html#element_validate   * http://api.drupal.org/api/file/developer/topics/forms_api_reference. html#element_validate
1223   *   *
1224   * NOTE- use   * NOTE- use
1225   * form_error($element, $message)   * form_error($element, $message)
1226   * not   * not
1227   * form_set_error($element_name, message)   * form_set_error($element_name, message)
1228   */   */
1229  function import_html_source_siteroot_validate($element, &$form_state) {  function import_html_source_siteroot_validate($element, &$form_state) {
# Line 1252  function import_html_validate_trailing_s Line 1250  function import_html_validate_trailing_s
1250   * (html, resources like images and styles or other)   * (html, resources like images and styles or other)
1251   * based on suffix.   * based on suffix.
1252   * Enable handy multi-selections to enhance the form   * Enable handy multi-selections to enhance the form
1253   *   *
1254   * A form api form def used in step 2 of import_html_page()   * A form api form def used in step 2 of import_html_page()
1255   *   *
1256   * @param  $form_values array including 'source_siteroot' and   * @param  $form_values array including 'source_siteroot' and
1257   * 'current_subsection'   * 'current_subsection'
1258   *   *
1259   * @param $profile array including file exclusion patterns and scanning rules   * @param $profile array including file exclusion patterns and scanning rules
1260   *   *
1261   * @return Drupal form   * @return Drupal form
1262   */   */
1263  function import_html_list_filesystem($form_values, $profile, $max_depth = 0) {  function import_html_list_filesystem($form_values, $profile, $max_depth = 0) {
# Line 1276  function import_html_list_filesystem($fo Line 1274  function import_html_list_filesystem($fo
1274    drupal_set_message(t("    drupal_set_message(t("
1275      Listing contents of %source_siteroot %current_subsection ; %max_depth      Listing contents of %source_siteroot %current_subsection ; %max_depth
1276    ", array(    ", array(
1277      '%source_siteroot'  => $source_siteroot,      '%source_siteroot'  => $source_siteroot,
1278      '%current_subsection' => empty($current_subsection) ? '' : '['. $current_subsection .']',      '%current_subsection' => empty($current_subsection) ? '' : '['. $current_subsection .']',
1279      '%max_depth' => empty($max_depth) ? 'recursive' : 'maximum recursion depth:'. $max_depth,      '%max_depth' => empty($max_depth) ? 'recursive' : 'maximum recursion depth:'. $max_depth,
1280      )      )
# Line 1300  function import_html_list_filesystem($fo Line 1298  function import_html_list_filesystem($fo
1298    
1299        $count_files = count(file_scan_directory(trim_trailing_slash($working_path), ".*"));        $count_files = count(file_scan_directory(trim_trailing_slash($working_path), ".*"));
1300        $dir_structure = array( $working_path => (object)array(        $dir_structure = array( $working_path => (object)array(
1301          'filename' => $working_path,          'filename' => $working_path,
1302          'basename' => basename($working_path) ,          'basename' => basename($working_path) ,
1303          'child_count' => $count_files,          'child_count' => $count_files,
1304        ));        ));
# Line 1310  function import_html_list_filesystem($fo Line 1308  function import_html_list_filesystem($fo
1308        drupal_set_message(t("Too many items ($count_files) found. Reducing recursion depth and trying again"));        drupal_set_message(t("Too many items ($count_files) found. Reducing recursion depth and trying again"));
1309        // RECURSION HERE        // RECURSION HERE
1310        return import_html_list_filesystem($form_values, $profile, $max_depth);        return import_html_list_filesystem($form_values, $profile, $max_depth);
1311      }      }
1312    }    }
1313    if ($max_depth != 4) {    if ($max_depth != 4) {
1314      drupal_set_message(t("      drupal_set_message(t("
1315        Because this file listing contains more than %max files,        Because this file listing contains more than %max files,
1316        it is unreasonable to show all files in a browser treeview.        it is unreasonable to show all files in a browser treeview.
1317        The recursion depth is therefore being reduced to %max_depth.        The recursion depth is therefore being reduced to %max_depth.
1318        Content below that level can be selected in bulk        Content below that level can be selected in bulk
1319        by selecting the appropriate parent directory.        by selecting the appropriate parent directory.
1320        You may also try changing the 'current subsection'        You may also try changing the 'current subsection'
1321        to be more specific and just show files at that level.        to be more specific and just show files at that level.
1322      ", array(      ", array(
1323        '%max' => IMPORT_HTML_MAX_FILE_LISTING_COUNT,        '%max' => IMPORT_HTML_MAX_FILE_LISTING_COUNT,
1324        '%count' => $count_files,        '%count' => $count_files,
1325        '%max_depth' => $max_depth,        '%max_depth' => $max_depth,
1326        )        )
1327      ));      ));
1328    }    }
1329    
# Line 1343  function import_html_list_filesystem($fo Line 1341  function import_html_list_filesystem($fo
1341    $form['selectors'] = array(    $form['selectors'] = array(
1342      '#weight' => -2,      '#weight' => -2,
1343      '#value' => "<p id='import-html-selectors'>Select files to import<br/></p>",      '#value' => "<p id='import-html-selectors'>Select files to import<br/></p>",
1344    );    );
1345    
1346    // Need to convert the sructured tree into a structured form    // Need to convert the sructured tree into a structured form
1347    $tree_form = _import_html_tree_to_form($tree, "", "/", $form_values);    $tree_form = _import_html_tree_to_form($tree, "", "/", $form_values);
# Line 1359  function import_html_list_filesystem($fo Line 1357  function import_html_list_filesystem($fo
1357  /**  /**
1358   * The 'import files' button was pressed on the 'select files' form.   * The 'import files' button was pressed on the 'select files' form.
1359   * Go do it!   * Go do it!
1360   *   *
1361   */   */
1362  function import_html_import_files_submit($form, $form_state) {  function import_html_import_files_submit($form, $form_state) {
1363    
# Line 1384  function import_html_import_files_submit Line 1382  function import_html_import_files_submit
1382    
1383    if (count($selected_files)) {    if (count($selected_files)) {
1384      $results = import_html_import_files($selected_files, $form_state['values']);      $results = import_html_import_files($selected_files, $form_state['values']);
1385    }    }
1386    else {    else {
1387      drupal_set_message(t("No files or folders selected for import"));      drupal_set_message(t("No files or folders selected for import"));
1388    }    }
# Line 1395  function import_html_import_files_submit Line 1393  function import_html_import_files_submit
1393    
1394  /**  /**
1395   * A successor to import_html_import_files_submit.   * A successor to import_html_import_files_submit.
1396   *   *
1397   * Does the same thing, using the Drupal batch process.   * Does the same thing, using the Drupal batch process.
1398   */   */
1399  function import_html_batch_import_files_submit($form, $form_state) {  function import_html_batch_import_files_submit($form, $form_state) {
# Line 1420  function import_html_batch_import_files_ Line 1418  function import_html_batch_import_files_
1418    
1419    // Substitutions used for messages    // Substitutions used for messages
1420    $info = array(    $info = array(
1421      '%count_files' => count($selected_files),      '%count_files' => count($selected_files),
1422      '%count_dirs'  => count($selected_dirs),      '%count_dirs'  => count($selected_dirs),
1423      '!context'     => print_r($context, 1),      '!context'     => print_r($context, 1),
1424    );    );
1425    
# Line 1444  function import_html_batch_import_files_ Line 1442  function import_html_batch_import_files_
1442      $batch_instructions = import_html_import_files_batch_instructions($selected_files, $context, 'import_html_import_file_batch_job');      $batch_instructions = import_html_import_files_batch_instructions($selected_files, $context, 'import_html_import_file_batch_job');
1443      batch_set($batch_instructions);      batch_set($batch_instructions);
1444    }    }
1445    
1446    if (($profile['recursion_behaviour'] == IMPORT_HTML_RECURSE_AFTER) && !empty($selected_dirs)) {    if (($profile['recursion_behaviour'] == IMPORT_HTML_RECURSE_AFTER) && !empty($selected_dirs)) {
1447      // Also batch queue folders - individual batches      // Also batch queue folders - individual batches
1448      $batch_instructions = import_html_import_files_batch_instructions($selected_dirs, $context, 'import_html_import_directory_batch_job');      $batch_instructions = import_html_import_files_batch_instructions($selected_dirs, $context, 'import_html_import_directory_batch_job');
1449      batch_set($batch_instructions);      batch_set($batch_instructions);
1450    }    }
1451    
1452    import_html_debug("Batch process (%count_dirs dirs, %count_files files) items) is queued", $info, WATCHDOG_INFO);    import_html_debug("Batch process (%count_dirs dirs, %count_files files) items) is queued", $info, WATCHDOG_INFO);
1453  }  }
# Line 1459  function import_html_batch_import_files_ Line 1457  function import_html_batch_import_files_
1457  /**  /**
1458   * From a flat list of file defs, build a tree structure, and annotate it like   * From a flat list of file defs, build a tree structure, and annotate it like
1459   * the forms API does.   * the forms API does.
1460   *   *
1461   * @param $dir_structure list of file names and file details, as returned from   * @param $dir_structure list of file names and file details, as returned from
1462   * file_scan_directory.   * file_scan_directory.
1463   *   *
1464   * @return an array structure that is almost, but not quite a FAPI form   * @return an array structure that is almost, but not quite a FAPI form
1465   * definition.   * definition.
1466   */   */
# Line 1491  function import_html_sort_list_into_tree Line 1489  function import_html_sort_list_into_tree
1489          $twig['#type'] = 'tree_branch';          $twig['#type'] = 'tree_branch';
1490          $twig['#value']= $path;          $twig['#value']= $path;
1491          $twig['#description']= "";          $twig['#description']= "";
1492          $twig['#filename']   = $source_siteroot . $path;          $twig['#filename']   = $source_siteroot . $path;
1493    
1494          $twig[$dad] = array();          $twig[$dad] = array();
1495          $count++;          $count++;
# Line 1501  function import_html_sort_list_into_tree Line 1499  function import_html_sort_list_into_tree
1499      }      }
1500      $twig['#type']       = is_dir($file_path) ? 'tree_branch' : 'tree_item';      $twig['#type']       = is_dir($file_path) ? 'tree_branch' : 'tree_item';
1501      $twig['#description']= $file_info->basename;      $twig['#description']= $file_info->basename;
1502      $twig['#filename']   = $file_path;      $twig['#filename']   = $file_path;
1503      $twig['#value']      = $rel_path;      $twig['#value']      = $rel_path;
1504    
1505      // Misc data that MAY have been set when we scanned.      // Misc data that MAY have been set when we scanned.
# Line 1509  function import_html_sort_list_into_tree Line 1507  function import_html_sort_list_into_tree
1507        $twig['#description'] = $file_info->child_count ." items";        $twig['#description'] = $file_info->child_count ." items";
1508      }      }
1509    }    }
1510    return $tree;    return $tree;
1511  }  }
1512    
1513    
1514  /**  /**
1515   * Recursive form construction function to format a tree-like structure   * Recursive form construction function to format a tree-like structure
1516   * of heirarchical filenames into a Form API nested tree of checkboxes.   * of heirarchical filenames into a Form API nested tree of checkboxes.
1517   *   *
1518   * The function is self-referentially recursive - depth-first formatting of a tree menu.   * The function is self-referentially recursive - depth-first formatting of a tree menu.
# Line 1522  function import_html_sort_list_into_tree Line 1520  function import_html_sort_list_into_tree
1520   * @param $tree array The tree layout so far;   * @param $tree array The tree layout so far;
1521   * @param $name string The human name of the item were are adding right now   * @param $name string The human name of the item were are adding right now
1522   * @param $prefix string The path so far;   * @param $prefix string The path so far;
1523   *   *
1524   * @return form object   * @return form object
1525   */   */
1526  function _import_html_tree_to_form($tree, $name, $prefix = "", $form_values ) {  function _import_html_tree_to_form($tree, $name, $prefix = "", $form_values ) {
# Line 1530  function _import_html_tree_to_form($tree Line 1528  function _import_html_tree_to_form($tree
1528    $id = "ID_" . preg_replace("/[^\w]/", "", $path);    $id = "ID_" . preg_replace("/[^\w]/", "", $path);
1529    // $id is a safe name - a unique id derived from the item path    // $id is a safe name - a unique id derived from the item path
1530    // -- OK, these are becoming stupidly long - any reason not to just use a counter?    // -- OK, these are becoming stupidly long - any reason not to just use a counter?
1531    
1532    // Although the form is presented in a tree, the form values are to come back in a list.    // Although the form is presented in a tree, the form values are to come back in a list.
1533    //    //
1534    // To sorta-but-not-really 'tree' and allow multiple values for identically named checkboxes,    // To sorta-but-not-really 'tree' and allow multiple values for identically named checkboxes,
1535    // we keep a running list of numbers.    // we keep a running list of numbers.
1536    // We cheat by setting the '#parents' manually before rendering, and using a counter of our own    // We cheat by setting the '#parents' manually before rendering, and using a counter of our own
1537    static $checkbox_count;    static $checkbox_count;
1538    
1539    
1540    $element = array();    $element = array();
1541    
1542    if ($tree['#type'] == 'tree_branch') {    if ($tree['#type'] == 'tree_branch') {
1543      // tree_branch is our own pseudo form element item      // tree_branch is our own pseudo form element item
1544      // I wanted to re-use 'fieldset' and just render it specially myself      // I wanted to re-use 'fieldset' and just render it specially myself
# Line 1556  function _import_html_tree_to_form($tree Line 1554  function _import_html_tree_to_form($tree
1554      );      );
1555    
1556      // checkbox toggle for the children of this item      // checkbox toggle for the children of this item
1557      //      //
1558      // If this was a folder that displays children,      // If this was a folder that displays children,
1559      // the children will be submitted as individual entries in the UI      // the children will be submitted as individual entries in the UI
1560      // this means that we can ignore its state for the purposes of importing,      // this means that we can ignore its state for the purposes of importing,
1561      // otherwise we would queue both the folder (recursive) and its children (individuals)      // otherwise we would queue both the folder (recursive) and its children (individuals)
1562      // which would produce double-ups      // which would produce double-ups
1563      // Give the checkbox a different form element name.      // Give the checkbox a different form element name.
# Line 1574  function _import_html_tree_to_form($tree Line 1572  function _import_html_tree_to_form($tree
1572        // Need to allow multiples, but they are essentially flat, not tree-d        // Need to allow multiples, but they are essentially flat, not tree-d
1573        '#parents'      => array($checkbox_name, $tree['#value']),        '#parents'      => array($checkbox_name, $tree['#value']),
1574      );      );
1575    }    }
1576    else {    else {
1577      // Normal file      // Normal file
1578      $element = array(      $element = array(
# Line 1601  function _import_html_tree_to_form($tree Line 1599  function _import_html_tree_to_form($tree
1599    $element['#item-path'] = $item_type; // made-up attribute to pass to theme    $element['#item-path'] = $item_type; // made-up attribute to pass to theme
1600    $element['#attributes']['class'] .= ' '. $item_type;    $element['#attributes']['class'] .= ' '. $item_type;
1601    
1602    
1603    // Construct the content    // Construct the content
1604    
1605    if (element_children($tree)) {    if (element_children($tree)) {
# Line 1631  function theme_import_html_list_filesyst Line 1629  function theme_import_html_list_filesyst
1629    
1630  /**  /**
1631   * Basically the theme_checkbox, but without form-item div cruft.   * Basically the theme_checkbox, but without form-item div cruft.
1632   *   *
1633   * Does have some extra css classes though.   * Does have some extra css classes though.
1634   *   *
1635   * @return HTML containing a form checkbox   * @return HTML containing a form checkbox
1636   */   */
1637  function theme_import_html_filesystem_tree_item($element) {  function theme_import_html_filesystem_tree_item($element) {
# Line 1665  function theme_tree_branch($element) { Line 1663  function theme_tree_branch($element) {
1663    $item_checkbox = "<input type='checkbox' name='{$toggle_button['#name']}' id='{$toggle_button['#id']}' value='{$toggle_button['#return_value']}' $checked $atts />";    $item_checkbox = "<input type='checkbox' name='{$toggle_button['#name']}' id='{$toggle_button['#id']}' value='{$toggle_button['#return_value']}' $checked $atts />";
1664    $item = "<label>$item_checkbox {$element['#title']}</label>";    $item = "<label>$item_checkbox {$element['#title']}</label>";
1665    
1666    $children = empty($element['children']) ? '' :    $children = empty($element['children']) ? '' :
1667      '<div'. drupal_attributes($element['children']['#attributes']) .'>'      '<div'. drupal_attributes($element['children']['#attributes']) .'>'
1668      . drupal_render($element['children'] )      . drupal_render($element['children'] )
1669      .'</div>'      .'</div>'
1670      ;      ;
1671    
1672    return    return
1673      '<fieldset'. drupal_attributes($element['#attributes']) .'>'      '<fieldset'. drupal_attributes($element['#attributes']) .'>'
1674    ."<legend class=\"{$element['#item-type']}-label\">{$item}</legend>"    ."<legend class=\"{$element['#item-type']}-label\">{$item}</legend>"
1675    . (isset($element['#description']) && $element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '')    . (isset($element['#description']) && $element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '')
1676    . $children    . $children
1677    . (isset($element['#value']) ? $element['#value'] : '')    . (isset($element['#value']) ? $element['#value'] : '')
1678    ."</fieldset>\n";    ."</fieldset>\n";
1679    
1680  }  }
# Line 1688  function import_html_results($severity = Line 1686  function import_html_results($severity =
1686    $last_import_timestamp = variable_get('import_html_last_import_timestamp', 0);    $last_import_timestamp = variable_get('import_html_last_import_timestamp', 0);
1687    
1688    $output = "Results from the last import process - ". format_date($last_import_timestamp);    $output = "Results from the last import process - ". format_date($last_import_timestamp);
1689    
1690    // We will use the watchdog to do most of our logging - but then have to retrieve it ourself as the watchdog reports are tedious.    // We will use the watchdog to do most of our logging - but then have to retrieve it ourself as the watchdog reports are tedious.
1691    // Code adapted from dblog.admin.inc    // Code adapted from dblog.admin.inc
1692    $filter = array(    $filter = array(
# Line 1735  function import_html_results($severity = Line 1733  function import_html_results($severity =
1733    
1734    return $output;    return $output;
1735    
1736    
1737  }  }
1738    
1739  /////////////////////////////////////////////  /////////////////////////////////////////////
# Line 1806  function import_html_demo_form_submit($f Line 1804  function import_html_demo_form_submit($f
1804    
1805        // divide the path into two halves (avoiding glue_url()) to provide a context and a rel_path        // divide the path into two halves (avoiding glue_url()) to provide a context and a rel_path
1806        $split_at = strrpos($source_path, $url_parts['path']) +1;        $split_at = strrpos($source_path, $url_parts['path']) +1;
1807    
1808        $form_state['values']['source_siteroot'] = substr($source_path, 0, $split_at);        $form_state['values']['source_siteroot'] = substr($source_path, 0, $split_at);
1809        $rel_path = substr($source_path, $split_at);        $rel_path = substr($source_path, $split_at);
1810    
1811        // Grab the current default settings.        // Grab the current default settings.
1812        $context = import_html_profile();        $context = import_html_profile();
1813    
# Line 1825  function import_html_demo_form_submit($f Line 1823  function import_html_demo_form_submit($f
1823            break;            break;
1824          }          }
1825          $node = $file['node'];          $node = $file['node'];
1826    
1827          // Dummy up a node edit form          // Dummy up a node edit form
1828          module_load_include('inc', 'node', 'node.pages');          module_load_include('inc', 'node', 'node.pages');
1829    
# Line 1834  function import_html_demo_form_submit($f Line 1832  function import_html_demo_form_submit($f
1832    
1833          // Previewing alters $node so it needs to be cloned.          // Previewing alters $node so it needs to be cloned.
1834          $cloned_node = drupal_clone($node);          $cloned_node = drupal_clone($node);
1835    
1836          // Unset this because the 'trimmed version' is unhelpful          // Unset this because the 'trimmed version' is unhelpful
1837          $cloned_node->teaser = trim($cloned_node->body);          $cloned_node->teaser = trim($cloned_node->body);
1838    
1839          $output = theme('node_preview', $cloned_node);          $output = theme('node_preview', $cloned_node);
1840    
1841          if (function_exists('dpm') && ($context['debug_level'] > 0)) {          if (function_exists('dpm') && ($context['debug_level'] > 0)) {
1842            dpm($node);            dpm($node);
1843          }          }
# Line 1849  function import_html_demo_form_submit($f Line 1847  function import_html_demo_form_submit($f
1847    
1848          // Note there is also a hook in import_html_form_alter that adjusts this page_node_form and makes it work.          // Note there is also a hook in import_html_form_alter that adjusts this page_node_form and makes it work.
1849          print theme('page', $output);          print theme('page', $output);
1850        }        }
1851        else {        else {
1852          print theme('page', t("For whatever reason, the request to %rel_path on %source_siteroot) failed to return a result. You'll have to enable debugging to find out why.", array('%rel_path' => $rel_path, '%source_siteroot' => $source_siteroot)) );          print theme('page', t("For whatever reason, the request to %rel_path on %source_siteroot) failed to return a result. You'll have to enable debugging to find out why.", array('%rel_path' => $rel_path, '%source_siteroot' => $source_siteroot)) );
1853        }        }
1854        break;        break;
1855    
1856      case 'page_node_form':      case 'page_node_form':
1857        drupal_execute('page_node_form', $form_state['values']);        drupal_execute('page_node_form', $form_state['values']);
1858        break;        break;

Legend:
Removed from v.1.11.4.20  
changed lines
  Added in v.1.11.4.21

  ViewVC Help
Powered by ViewVC 1.1.2