b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (0.9.x) [ class tree: admin ] [ index: admin ] [ all elements ]

Source for file import-mt.php

Documentation is available at import-mt.php

  1. <?php
  2. /**
  3.  * This file implements importing of Movable Type entries into b2evolution.
  4.  *
  5.  * {@internal 
  6.  * TODO:
  7.  *  - Wrap this by an abstract import class!
  8.  *  - list of all posts, editable (overkill?)
  9.  *  - assign comment_author_ID to comments if user exist?! }}}
  10.  *
  11.  *
  12.  * This script was developed and tested with b2evolution 0.9.0.4 (on Sourceforge CVS)
  13.  * and Movable Type 2.64 and 2.661.
  14.  * It should work quite alright with b2evo 0.9 and later though.
  15.  *
  16.  * This file is part of the b2evolution/evocms project - {@link http://b2evolution.net/}.
  17.  * See also {@link http://sourceforge.net/projects/evocms/}.
  18.  *
  19.  * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}.
  20.  *  Parts of this file are copyright (c)2004-2005 by Daniel HAHLER - {@link http://thequod.de/contact}.
  21.  *  Credits go to the WordPress team (@link http://wordpress.org), where I got the basic
  22.  *  import-mt.php script with most of the core functions. Thank you!
  23.  *
  24.  * @license http://b2evolution.net/about/license.html GNU General Public License (GPL)
  25.  *  {@internal 
  26.  *  b2evolution is free software; you can redistribute it and/or modify
  27.  *  it under the terms of the GNU General Public License as published by
  28.  *  the Free Software Foundation; either version 2 of the License, or
  29.  *  (at your option) any later version.
  30.  *
  31.  *  b2evolution is distributed in the hope that it will be useful,
  32.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  33.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  34.  *  GNU General Public License for more details.
  35.  *
  36.  *  You should have received a copy of the GNU General Public License
  37.  *  along with b2evolution; if not, write to the Free Software
  38.  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  39.  *
  40.  *  In addition, as a special exception, the copyright holders give permission to link
  41.  *  the code of this program with the PHP/SWF Charts library by maani.us (or with
  42.  *  modified versions of this library that use the same license as PHP/SWF Charts library
  43.  *  by maani.us), and distribute linked combinations including the two. You must obey the
  44.  *  GNU General Public License in all respects for all of the code used other than the
  45.  *  PHP/SWF Charts library by maani.us. If you modify this file, you may extend this
  46.  *  exception to your version of the file, but you are not obligated to do so. If you do
  47.  *  not wish to do so, delete this exception statement from your version.
  48.  *  }}}
  49.  *
  50.  *  {@internal 
  51.  *  Daniel HAHLER grants François PLANQUE the right to license
  52.  *  Daniel HAHLER's contributions to this file and the b2evolution project
  53.  *  under any OSI approved OSS license (http://www.opensource.org/licenses/).
  54.  *  }}}
  55.  *
  56.  * @package admin
  57.  *
  58.  *  {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  59.  * @author fplanque: François PLANQUE
  60.  * @author blueyed: Daniel HAHLER
  61.  *
  62.  * @version $Id: import-mt.php,v 1.1.2.25 2005/10/03 23:33:02 blueyed Exp $
  63.  */
  64.  
  65. /**
  66.  * Enter the relative path of the import.txt file containing the MT entries.
  67.  * If the file is called import.txt and it is in /admin, then this line should be:
  68.  * <code>
  69.  * define('MTEXPORT', 'import.txt');
  70.  * </code>
  71.  *
  72.  * You only need this to force a specific file instead of using a dropdown list
  73.  * (UI selection)
  74.  */
  75. define('MTEXPORT''');
  76.  
  77. /**
  78.  * Set to true to get a lot of var_dumps, wrapped in pre tags
  79.  */
  80. $output_debug_dump 0;
  81.  
  82.  
  83. // ----------- don't change below if you don't know what you do ------------------------
  84.  
  85. set_magic_quotes_runtime);  // be clear on this
  86.  
  87. $head = <<<EOB
  88. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  89. <html xmlns="http://www.w3.org/1999/xhtml">
  90. <head>
  91.     <title>b2evolution &rsaquo; Import from Movable Type</title>
  92.     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  93.     <link href="variation.css" rel="stylesheet" type="text/css" title="Variation" />
  94.     <link href="desert.css" rel="alternate stylesheet" type="text/css" title="Desert" />
  95.     <link href="legacy.css" rel="alternate stylesheet" type="text/css" title="Legacy" />
  96. EOB;
  97. ifis_filedirname(__FILE__).'/custom.css' ) )
  98. {
  99.     $head .= '<link href="custom.css" rel="alternate stylesheet" type="text/css" title="Custom" />';
  100. }
  101. $head .= <<<EOB
  102.     <script type="text/javascript" src="styleswitcher.js"></script>
  103. </head>
  104. <body>
  105. <div id="header">
  106.     <a href="http://b2evolution.net"><img id="evologo" src="../img/b2evolution_minilogo2.png" alt="b2evolution"  title="visit b2evolution's website" width="185" height="40" /></a>
  107.     <div id="headinfo">
  108.         <br /><span style="font-size:150%; font-weight:bold">Import Movable Type into b2evolution</span>
  109.     </div>
  110. </div>
  111. EOB;
  112.  
  113. if!file_exists('../conf/_config.php') )
  114. {
  115.     dieerror"There doesn't seem to be a conf/_config.php file. You must install b2evolution before you can import any entries."$head );
  116. }
  117. require'../conf/_config.php' );
  118. if( (!isset($config_is_done|| !$config_is_done) )
  119. {
  120.     iffile_exists(dirname(__FILE__)."/$admin_dirout/$core_subdir/_conf_error_page.php") )
  121.     {
  122.         $error_message '';
  123.         requiredirname(__FILE__)."/$admin_dirout/$core_subdir/_conf_error_page.php);
  124.     }
  125.     dieerror'b2evolution configuration is not done yet.'$head );
  126. }
  127.  
  128.  
  129. $use_obhandler 0;  // no output buffering!
  130. require'../b2evocore/_main.php' );
  131.  
  132. // Check if user is logged in and is in group #1 (admins)
  133. if!is_logged_in(|| $current_User->Group->ID != )
  134. {    // login failed
  135.     echo $head;
  136.     $error 'You must login with an administrator (group #1) account.';
  137.     $redirect_to $ReqURI;
  138.     requiredirname(__FILE__"/$admin_dirout/$htsrv_subdir/login.php);
  139. }
  140.  
  141. echo $head;
  142.  
  143. param'exportedfile''string''' );
  144. param'mode''string''normal' );
  145.  
  146. /*** mode-tabs ***/ ?>
  147. <ul class="tabs"><?php
  148.     foreacharray'easy''normal''expert' as $tab )
  149.     {
  150.         echo $tab == $mode '<li class="current">' '<li>';
  151.         echo '<a href="import-mt.php?mode='.$tab.!empty($exportedfile'&amp;exportedfile='.$exportedfile '' ).'">'.ucwords($tab).'</a></li>';
  152.     }
  153. ?></ul></div>
  154.  
  155. <div style="padding-top:1em;clear:both;">
  156. <?php
  157.     // check existence of export-file
  158.     ifempty($exportedfile) )
  159.     {
  160.         if'' != MTEXPORT && !file_exists(MTEXPORT) )
  161.         {
  162.             ?>
  163.             <div class="error"><p>
  164.             The MT export file you defined in MTEXPORT at top of the script does not seem to exist.
  165.             Please check the path you've given for MTEXPORT or choose a file below.
  166.             </p></div>
  167.             <?php
  168.         }
  169.         elseif'' != MTEXPORT )
  170.         {
  171.             $exportedfile MTEXPORT;
  172.         }
  173.         ifempty($exportedfile) )
  174.         // no valid MTEXPORT defined
  175.             chooseexportfile();
  176.             die'</div></div></body></html>' );
  177.         }
  178.     }
  179.     else
  180.     {
  181.         if!file_exists($exportedfile) )
  182.         {
  183.             chooseexportfile();
  184.             dieerror("The MT export file [$exportedfile] you've chosen does not seem to exist. Please check path/permission.");
  185.         }
  186.     }
  187.  
  188.     // get the params
  189.     param'simulate''integer');
  190.     param'default_password''string''changeme' );
  191.     param'default_password2''string''changeme' );
  192.     param'post_locale''string'$Settings->get'default_locale' ) );
  193.  
  194.     if$default_password != $default_password2 )
  195.     {
  196.         dieerror'The two passwords for new users are not identical.' );
  197.     }
  198.  
  199.     param'default_userlevel''integer');
  200.     if$default_userlevel 10 $default_userlevel 10;
  201.     param'default_usergroup''integer'$Settings->get('newusers_grp_ID') );
  202.     param'default_convert_breaks''integer');
  203.     param'convert_html_tags''integer');
  204.  
  205.     param'action''string''' );
  206.  
  207.  
  208.     // global arrays
  209.     $categories_countprim array();  // counts posts in primary categories
  210.  
  211.     // load caches
  212.     blog_load_cache();
  213.     cat_load_cachefalse );
  214.  
  215.     $i_user = -1;
  216.  
  217.     ifempty($action) )
  218.     {
  219.         param'mode''string''normal'true );
  220.  
  221.         ?>
  222.         <div class="panelinfo">
  223.         <p>We are about to import <?php
  224.             echo '['.$exportedfile.'].';
  225.             if'' == MTEXPORT )
  226.             {
  227.                 ?> [<a href="import-mt.php?mode=<?php echo $mode ?>">choose another export-file</a>]<?php
  228.             ?></p>
  229.  
  230.         <p>This file contains <?php echo count$posts ?> post(s) from <?php echo count$authors ?> author(s) in <?php echo count$categories ?> category(ies).</p>
  231.  
  232.         <p>We'll import into b2evolution's database &quot;<?php echo DB_NAME ?>&quot;.</p>
  233.         </div>
  234.         <div class="panelinfo">
  235.             <p>Before importing, you should check the URLs of any &lt;img&gt; tags you may have in <?php echo $exportedfile ?>. Will these URLs still be valid after the migration? If not, we advise you do a search and replace on <?php echo $exportedfile ?> before continuing.</p>
  236.  
  237.             <p>Preferred location for inline images is [<?php echo $fileupload_realpath ?>]<br />
  238.             If you decide to use this location, your IMG SRC urls should point to [<?php echo $fileupload_url ?>]</p>
  239.  
  240.             <p>You can also handle the images later, but it might be easier now :)</p>
  241.         </div>
  242.  
  243.         <div class="panelinfo">
  244.             <p>The importer is smart enough not to import duplicates, so you can run this procedure multiple times without worrying if &#8212; for whatever reason &#8212; it doesn't finish (script timeout for example).</p>
  245.         </div>
  246.  
  247.  
  248.         <div class="panelblock">
  249.         <form class="fform" action="import-mt.php" method="post">
  250.             <input type="hidden" name="action" value="import" />
  251.         <?php
  252.         if!empty($exportedfile) )
  253.         {
  254.             ?><input type="hidden" name="exportedfile" value="<?php echo format_to_output$exportedfile'formvalue' ?>" />
  255.             <?php
  256.         }
  257.  
  258.         ?>
  259.  
  260.         <?php
  261.         switch$mode )
  262.         {
  263.             case 'easy':
  264.                 ?>
  265.                 <h2>Easy Import:</h2>
  266.                 <ul>
  267.                 <li>MT users with no matching b2evolution user login will be automatically created.</li>
  268.                 <li>MT categories with no matching b2evolution category name will be automatically created (in the default blog selected below.)</li>
  269.                 <?php
  270.                 ifisset($categories_countprim['[no category assigned]']) )
  271.                 ?>
  272.                 <li>Entries without categories (<?php echo $categories_countprim['[no category assigned]'?>) will be imported to category '[no category assigned]' in the default blog.</li>
  273.                 <?php
  274.                 }
  275.                 echo '</ul>';
  276.                 break;
  277.             case 'normal':
  278.                 ?>
  279.                 <h2>Normal Import:</h2>
  280.                 <ul>
  281.                 <li>MT users can be mapped to existing b2evo users, mapped to new users (provide login) or ignored.</li>
  282.                 <li>Categories can be mapped to existing b2evo categories, mapped to new categories (provide location + name) or ignored.</li>
  283.                 </ul>
  284.                 <?php
  285.                 break;
  286.             case 'expert':
  287.                 ?>
  288.                 <h2>Expert Import:</h2>
  289.                 <p>This gives you as much power as we can provide. It's like normal mode, but lets you map categories to a whole set of b2evo categories (one main category and as many extra categories as you like). You can run the importer multiple times to use different sets of b2evo categories for different sets of MT categories.</p>
  290.                 <?php
  291.                 break;
  292.  
  293.         }
  294.  
  295.         ?>
  296.  
  297.         <?php if$mode != 'expert' ?>
  298.         <fieldset>
  299.             <legend>Default blog</legend>
  300.             <fieldset>
  301.                 <div class="label"><?php echo $mode == 'easy' 'Create categories in blog' 'Use as default blog for categories' ?>:</div>
  302.                 <div class="input">
  303.                     <select name="default_blog">
  304.                     <?php
  305.                     $BlogCache->option_list);  // use first non-all blog as default
  306.                     ?>
  307.                     </select>
  308.                 </div>
  309.             </fieldset>
  310.         </fieldset>
  311.         <?php ?>
  312.  
  313.         <?php if$mode != 'easy' )    ?>
  314.         <fieldset><legend>Author mapping</legend>
  315.             <?php
  316.                 $evousers $DB->get_results("SELECT * FROM $tableusers ORDER BY ID");
  317.                 foreach ($authors as $author)
  318.                 {
  319.                     ++$i_user;
  320.                     ?>
  321.                     <fieldset>
  322.                     <div class="label"><label><?php echo $author ?></label></div>
  323.                     <div class="input">
  324.                         <select name="user_select[]">
  325.                             <option value="#CREATENEW#" selected="selected"> Create new: </option>
  326.                             <option value="#IGNORE#"> Ignore! </option>
  327.                             <?php
  328.                             foreach$evousers as $user )
  329.                             {
  330.                                 ?><option value="<?php echo $user->ID ?>"<?php ifstrtolower($author== strtolower$user->user_login ) ) echo ' selected="selected"';
  331.                                 echo '>'.format_to_output(strtolower($user->user_login)'formvalue').'</option>';
  332.                             }
  333.                         ?></select>
  334.                         <input type="text" value="<?php echo format_to_output($author'formvalue'?>" name="user_name[]" maxlength="30" class="input" />
  335.                         <span class="notes">(login for new user)</span>
  336.                     </div>
  337.                     </fieldset>
  338.                     <?php
  339.                 }
  340.             ?>
  341.         </fieldset>
  342.         <?php ?>
  343.  
  344.  
  345.         <fieldset><legend>New user defaults</legend>
  346.             <?php
  347.             form_text'default_password'$default_password20'Password for new users''this will be the password for users created during migration (default is "changeme")'30 '''password' );
  348.             form_text'default_password2'$default_password20'Confirm password''please confirm the password'30 '''password' );
  349.             form_select_object'default_usergroup'$Settings->get('newusers_grp_ID')$GroupCacheT_('User group') );
  350.             $field_note '[0 - 10] '.sprintfT_('See <a %s>online manual</a> for details.')'href="http://b2evolution.net/man/user_levels.html"' );
  351.             form_text'default_userlevel'$Settings->get('newusers_level')2T_('Level')$field_note);
  352.             ?>
  353.         </fieldset>
  354.  
  355.  
  356.         <?php if$mode != 'easy' )?>
  357.         <fieldset><legend>Category mapping</legend>
  358.         <?php
  359.         $i_cat 0;
  360.         foreach$categories as $cat )
  361.         {
  362.             ?>
  363.             <fieldset>
  364.             <div class="label">
  365.                 <label><?php echo format_to_output($cat'htmlbody'?></label>
  366.                 <br /><span class="notes" style="font-weight:normal">used <?php echo @(int)$categories_countprim[$cat?> times as primary category</span>
  367.             </div>
  368.             <div class="input"><select name="catmap_select[]">
  369.                 <?php
  370.                 if$mode == 'expert' )
  371.                     echo '<option value="#DEFAULTSET#">Map to default categories set (see below)</option>';
  372.                     else echo '<option value="#DEFAULTBLOG#">Create in default blog:</option>'?>
  373.                 <?php cats_optionslist$cat ?>
  374.                 <option value="#IGNORE#">Ignore entries with this primary cat</option>
  375.             </select>
  376.             <input type="text" name="catmap_name[]" value="<?php echo format_to_output$cat'formvalue' ?>" size="30" />
  377.             </div>
  378.             </fieldset>
  379.         <?php
  380.             $i_cat++;
  381.         ?>
  382.         <?php if$mode == 'expert' fieldset_cats(?>
  383.         </fieldset>
  384.         <?php ?>
  385.  
  386.  
  387.         <fieldset><legend>Post/Entry defaults</legend>
  388.             <?php
  389.             form_checkbox'default_convert_breaks'$default_convert_breaks'Convert-Breaks default''will be used for posts with empty CONVERT BREAKS or "__default__"' );
  390.             form_select'post_locale'$Settings->get('default_locale')'locale_options'T_('Default locale')'Locale for posts.' );
  391.             form_checkbox'convert_html_tags'$convert_html_tags'Convert ugly HTML''this will lowercase all html tags and add a XHTML compliant closing tag to &lt;br&gt;, &lt;img&gt;, &lt;hr&gt; (you\'ll get notes)' );
  392.  
  393.             if$mode != 'easy' )
  394.             // we'll use 'default' when importing
  395.                 ?>
  396.                 <div class="label">Renderers:</div>
  397.                 <div class="input"><?php renderer_list(?></div>
  398.             <?php ?>
  399.         </fieldset>
  400.  
  401.         <?php /*<fieldset style="padding-left:1ex"><legend>&lt;img&gt;-URL mapping</legend>
  402.             <a name="imgurls"><p class="notes">This lets you map found image urls (their basename) to another basename.
  403.             You probably want to put the images that you had on your MT installation into b2evo's media (fileupload) folder.<br />
  404.             So you would use <strong><?php echo $fileupload_url ?></strong> for replacement.<br />
  405.             You can leave this empty, of course and nothing will be replaced, but then you'll have probably broken images.</p></a>
  406.             <?php
  407.             preg_match_all( '#<img .*?src="([^"]*)/.*?"#is', $importdata, $matches );
  408.  
  409.             foreach( $matches[1] as $imgurl )
  410.             {
  411.                 if( !isset($imgurlscount[ $imgurl ]) )
  412.                     $imgurlscount[ $imgurl ] = 1;
  413.                 else $imgurlscount[ $imgurl ]++;
  414.             }
  415.  
  416.             asort( $imgurlscount );
  417.             $imgurlscount = array_reverse( $imgurlscount );
  418.  
  419.             param( 'singleimgurls', 'integer', 0 );
  420.             $i = 0;
  421.             foreach( $imgurlscount as $imgurl => $counter ) if( $counter > 1 || $singleimgurls )
  422.             {
  423.                 ?><input type="hidden" name="url_search[<?php echo $i ?>]" value="<?php echo format_to_output( $imgurl, 'formvalue' ) ?>" />
  424.                 <strong><?php echo $imgurl ?></strong>:<br />
  425.                 <div class="input"><input style="clear:left" type="text" name="url_replace[]" size="50" /></div>
  426.                 <span class="notes" style="font-weight:normal"> (used <?php echo $counter ?> times)</span>
  427.                 <br />
  428.                 <?php
  429.                 $i++;
  430.             }
  431.  
  432.             echo '<p class="center"><a name="imgurls" href="import-mt.php?tab=import&amp;singleimgurls='.( $singleimgurls ? '0' : '1' );
  433.             if( !empty($exportedfile) ) echo '&amp;exportedfile='.$exportedfile;
  434.             echo '">'.( $singleimgurls ? 'hide img urls only used once' : 'show also img urls only used once').'</a></p>';
  435.  
  436.         ?>
  437.         </fieldset>
  438.         */ ?>
  439.  
  440.         <fieldset><legend>other settings</legend>
  441.             <?php
  442.             form_checkbox'simulate'$simulate'Simulate: do not import really''Use this to test importing, without really changing the target database.' );
  443.         ?>
  444.         </fieldset>
  445.         <p>Please note:</p>
  446.         <ul>
  447.             <li>b2evolution does not support excerpts yet.
  448.             So, we will import them in front of the body with "<?php echo htmlspecialchars('<!--more-->< !--noteaser-->'?>" tags,
  449.             but only if there is no extended body for the post. In that case we'll use the extended body appended with the &lt;!--more--&gt; tag to the body - excerpts are lost then (but you'll get a note about it).
  450.             </li>
  451.         </ul>
  452.  
  453.         <fieldset class="submit">
  454.             <div class="input">
  455.                 <input type="hidden" name="mode" value="<?php echo $mode ?>" />
  456.                 <input class="search" type="submit" value=" Import! " />
  457.                 <input class="search" type="reset" value="Reset form" />
  458.             </div>
  459.         </fieldset>
  460.  
  461.         </div>
  462.  
  463.         </form>
  464.  
  465.         <?php
  466.     }
  467.  
  468.  
  469.     /*************
  470.         IMPORT
  471.     *************/
  472.     elseif$action == 'import' )
  473.     {
  474.         ?>
  475.         <div class="panelinfo">
  476.         <h4>Importing from [<?php echo $exportedfile ?>]..<?php if$simulate echo ' (simulating)' ?></h4>
  477.  
  478.         <?php
  479.         iffunction_exists'set_time_limit' ) )
  480.         {
  481.             set_time_limit900 )// 15 minutes ought to be enough for everybody *g
  482.         }
  483.         @ini_set'max_execution_time''900' );
  484.  
  485.         // counters
  486.         $count_postscreated 0;
  487.         $count_userscreated 0;
  488.         $count_commentscreated 0;
  489.         $count_trackbackscreated 0;
  490.  
  491.         // get POSTed data
  492.         param'mode''string'true );
  493.  
  494.         if$mode != 'expert' )
  495.         {
  496.             param'default_blog''integer'true );
  497.         }
  498.  
  499.  
  500.         {{{ // map categories
  501.         /**
  502.          * associative array that maps MT cats to b2evo.
  503.          * key is the MT category name.
  504.          * values:
  505.          * holds type and value:
  506.          *  types:
  507.          *   - 'blogid': blog_id, new name
  508.          *   - 'catid': cat_id
  509.          *   - 'defaultset': -
  510.          *   - 'ignore': -
  511.          */
  512.         $catsmapped array();
  513.  
  514.         $i_cat = -1;
  515.         // category mapping
  516.         if!isset($_POST['catmap_select']) )
  517.         // no category mapping
  518.             foreach$categories as $cat )
  519.             {
  520.                 $catsmapped$cat array('blogid'$default_blog$cat );
  521.             }
  522.         }
  523.         else foreach$_POST['catmap_select'as $cat )
  524.         {
  525.             $i_cat++;
  526.             if$cat == '#IGNORE#' )
  527.             {
  528.                 $catsmapped$categories[$i_cat] ] array'ignore' );
  529.             }
  530.             elseif$cat == '#DEFAULTSET#' )
  531.             {
  532.                 if!isset$default_post_category ) )
  533.                 // get the default category set
  534.                     ifisset($_POST['post_category']) )
  535.                     {
  536.                         $default_post_category = (int)$_POST['post_category'];
  537.                     }
  538.                     else
  539.                     {
  540.                         dieerror'You have chosen to map at least one category to the default category set, but you have not selected a main category for this set!<br />Please go back and correct that..' );
  541.                     }
  542.                     $default_post_extracats array();
  543.                     ifisset$_POST['post_extracats') )
  544.                     // get extra cats
  545.                         foreach$_POST['post_extracats'as $tcat )
  546.                         {
  547.                             $default_post_extracats[= (int)$tcat;
  548.                         }
  549.                     }
  550.                 }
  551.                 $catsmapped$categories[$i_cat] ] array'defaultset' );
  552.             }
  553.             elseifpreg_match'/^\d+$/'$cat$match ) )
  554.             // we map to a b2evo cat
  555.                 $catsmapped$categories[$i_cat] ] array('catid'(int)$cat);
  556.             }
  557.             elseif$cat == '#DEFAULTBLOG#'
  558.                             || preg_match'/^#NEW#(\d+)$/'$cat$match ) )
  559.             // we want a new category
  560.                 $blog_id ($cat == '#DEFAULTBLOG#'$default_blog $match[1];
  561.                 // remember the name to create it when posts get inserted
  562.                 $catsmapped$categories[$i_cat] ] array'blogid'$blog_idremove_magic_quotes$_POST['catmap_name'][$i_cat]) );
  563.             }
  564.             else
  565.             {
  566.                 dieerror('This should never happen @catmapping. Please report it! (cat='.$cat.' / ');
  567.             }
  568.  
  569.         }
  570.  
  571.         foreach$catsmapped as $mtcat => $values if$values[0== 'blogid' )
  572.         {
  573.             global $tablecategories;
  574.  
  575.             echo 'Category <span style="color:#09c">'.$values[2].'</span> (for blog #'.$values[1].') ';
  576.             // check if it already exists
  577.             $cat_ID $DB->get_var("SELECT cat_ID FROM $tablecategories
  578.                                                             WHERE cat_blog_ID = {$values[1]}
  579.                                                             AND cat_name = ".$DB->quote$values[2));
  580.             if!$cat_ID )
  581.             {
  582.                 echo 'will be created with first post.<br />';
  583.             }
  584.             else
  585.             {
  586.                 echo 'already exists.<br />';
  587.                 $catsmapped$mtcat array('catid'(int)$cat_ID)// map to existing category
  588.             }
  589.  
  590.         }
  591.  
  592.         debug_dump$catsmapped'catsmapped' );
  593.         }}}
  594.  
  595.  
  596.  
  597.         // get renderers
  598.         if$mode != 'easy' )
  599.         {
  600.             $default_renderers array();
  601.             if!isset($_POST['renderers']) )
  602.             // all unchecked
  603.                 $default_renderers array();
  604.             }
  605.             else $default_renderers $_POST['renderers'];
  606.  
  607.             // the special Auto-P renderer
  608.             param'autop''string'true );
  609.             if$autop === '1' )
  610.             // use always
  611.                 $default_renderers['b2WPAutP';
  612.             }
  613.         }
  614.         else
  615.         {
  616.             $default_renderers $Renderer->validate_listarray('default') );
  617.             $autop 1;
  618.         }
  619.  
  620.  
  621.         /*
  622.         // get image s&r
  623.         $urlsearch = array();
  624.         $urlreplace = array();
  625.         $i = 0;
  626.         foreach( $_POST['url_replace'] as $replace )
  627.         {
  628.             if( !empty($replace) )
  629.             {
  630.                 $urlsearch[] = remove_magic_quotes($_POST['url_search'][$i]);
  631.                 $urlreplace[] = remove_magic_quotes( $replace );
  632.             }
  633.             $i++;
  634.         }
  635.         */
  636.  
  637.         // get users
  638.         $i_user 0;
  639.         if!isset($_POST['user_select']) )
  640.         {
  641.             foreach$authors as $author )
  642.             {
  643.                 $usersmapped$author array('createnew'$author );
  644.             }
  645.  
  646.         }
  647.         else foreach$_POST['user_select'as $select )
  648.         {
  649.             $mtauthor $authors$i_user ];
  650.  
  651.             if$select == '#IGNORE#' )
  652.             {
  653.                 $usersmapped$mtauthor array'ignore' );
  654.             }
  655.             elseif$select == '#CREATENEW#' )
  656.             {
  657.                 $usersmapped$mtauthor array'createnew'remove_magic_quotes$_POST['user_name'][$i_user) );
  658.             }
  659.             elseifpreg_match'#\d+#'$select$match ) )
  660.             {
  661.                 $usersmapped$mtauthor array'b2evo'$select );
  662.             }
  663.             else
  664.             {
  665.                 ?><p class="error">Unknown user mapping. This should never ever happen. Please report it.</p><?php
  666.             }
  667.             $i_user++;
  668.         }
  669.         debug_dump$usersmapped'usersmapped' );
  670.  
  671.  
  672.         if$simulate )
  673.         {
  674.             $simulate_cat_id $DB->get_var'SELECT MAX( cat_ID )+1 FROM T_categories' );
  675.         }
  676.  
  677.         $i = -1;
  678.         echo "\n<ol>";
  679.         foreach ($posts as $post)
  680.         {
  681.             ++$i;
  682.  
  683.             // Defaults:
  684.             $post_catids array();
  685.             $post_renderers $default_renderers;
  686.             $post_status 'published';
  687.  
  688.             // strip the post's last '-----'
  689.             $post preg_replace("|-----\n+$|s"''$post);
  690.  
  691.             // first line is author of post
  692.             $post_author trimsubstr$post0strpos$post"\n") ) );
  693.             $post preg_replace'/^.*\n/'''$post );
  694.             $message "\n<li>Post from ".format_to_output$post_author'entityencoded' ).' <ul>';
  695.  
  696.             // Take the pings out first
  697.             preg_match("|(-----\n\nPING:.*)|s"$post$pings);
  698.             $post preg_replace("|(-----\n\nPING:.*)|s"''$post);
  699.  
  700.             // Then take the comments out
  701.             preg_match("|(-----\nCOMMENT:.*)|s"$post$comments);
  702.             $post preg_replace("|(-----\nCOMMENT:.*)|s"''$post);
  703.  
  704.             // We ignore the keywords
  705.             $post preg_replace("|(-----\nKEYWORDS:.*)|s"''$post);
  706.  
  707.             // We want the excerpt - it's put with more and noteaser tag into main body, only if we have no extended body!
  708.             preg_match("|-----\nEXCERPT:(.*)|s"$post$excerpt);
  709.             $excerpt trim($excerpt[1]);
  710.             $post preg_replace("|(-----\nEXCERPT:.*)|s"''$post);
  711.  
  712.             // We're going to put extended body into main body with a more tag
  713.             preg_match("|-----\nEXTENDED BODY:(.*)|s"$post$extended);
  714.             $extended trim($extended[1]);
  715.             $post preg_replace("|(-----\nEXTENDED BODY:.*)|s"''$post);
  716.  
  717.             // Now for the main body
  718.             preg_match("|-----\nBODY:(.*)|s"$post$body);
  719.             $body trim($body[1]);
  720.             ifempty($extended) )
  721.             // no extended body, so we can use the excerpt
  722.                 ifempty($excerpt) )
  723.                     $post_content $body;
  724.                 else $post_content $excerpt."\n<!--more--><!--noteaser-->\n".$body;
  725.             }
  726.             else
  727.             // we'll use body and extended body
  728.                 if!empty($excerpt) )
  729.                 {
  730.                     $message .=    '<li><span style="color:red">Excerpt discarded because of existing extended body:</span>
  731.                     <blockquote>'.htmlspecialchars($excerpt).'</blockquote></li>';
  732.                 }
  733.                 $post_content $body."\n<!--more-->\n".$extended;
  734.             }
  735.  
  736.             $post preg_replace("|(-----\nBODY:.*)|s"''$post);
  737.  
  738.  
  739.             // Grab the metadata from what's left
  740.             $metadata explode("\n"$post);
  741.  
  742.             $post_categories array();
  743.             foreach ($metadata as $lineif!empty($line) )
  744.             {
  745.                 debug_dump($line);
  746.  
  747.                 if!preg_match("/^(.*?):(.*)/"$line$token) )
  748.                 {
  749.                     $message .= "<li class=\"notes\">Unknown meta-data: [$line] (ignoring)</li>";
  750.                     continue;
  751.                 }
  752.                 $key trim$token[1);
  753.                 $value trim$token[2);
  754.  
  755.                 // Now we decide what it is and what to do with it
  756.                 switch($key)
  757.                 {
  758.                     case 'TITLE':
  759.                         $message .= '<li>title: '.strip_tags($value).'</li>';
  760.                         $post_title $value;
  761.                         break;
  762.                     case 'STATUS':
  763.                         ifstrtolower($value== 'publish' )
  764.                             $post_status 'published';
  765.                         elseifstrtolower($value== 'draft' )
  766.                             $post_status 'draft';
  767.                         else
  768.                         {
  769.                             $message .= '<li>Unknown post status ['.$value.'], using "draft".</li>';
  770.                             $post_status 'draft';
  771.                         }
  772.                         break;
  773.                     case 'ALLOW COMMENTS':
  774.                         $post_allow_comments $value;
  775.                         switch$post_allow_comments {
  776.                             case 0$comment_status 'disabled'break;
  777.                             case 1$comment_status 'open'break;
  778.                             case 2$comment_status 'closed'break;
  779.                             default:
  780.                                 $message .= '<li>Unknown comment status ['.$value.'], using "closed".</li>';
  781.                                 $comment_status 'closed';
  782.                         }
  783.                         break;
  784.                     case 'CONVERT BREAKS':
  785.                         if$value == '__default__' || empty($value) )
  786.                         {
  787.                             $post_convert_breaks $default_convert_breaks;
  788.                         }
  789.                         elseif$value == 'textile_2'    && array_search'b2DATxtl'$post_renderers === false )
  790.                         // add the textile 2 renderer to the post's renderers
  791.                             $post_renderers['b2DATxtl';
  792.                             $post_convert_breaks 1;  // TODO: check if this makes sense!
  793.                         }
  794.                         elseifpreg_match('/\d+/'$value) )
  795.                         {
  796.                             $post_convert_breaks = (int)$value );
  797.                         }
  798.                         else
  799.                         {
  800.                             $message .= '<li>Unknown CONVERT BREAKS value, using default ('.$default_convert_breaks.')..</li>';
  801.                             $post_convert_breaks $default_convert_breaks;
  802.                         }
  803.  
  804.                         if$autop == 'depends' && $post_convert_breaks && array_search'b2WPAutP'$post_renderers === false  )
  805.                         // add the Auto-P renderer
  806.                             $post_renderers['b2WPAutP';
  807.                         }
  808.  
  809.                         break;
  810.                     case 'ALLOW PINGS':
  811.                         if$value == 1)
  812.                         {
  813.                             $post_allow_pings 'open';
  814.                         }
  815.                         else
  816.                         {
  817.                             $post_allow_pings 'closed';
  818.                         }
  819.                         break;
  820.                     case 'PRIMARY CATEGORY':
  821.                     case 'CATEGORY':
  822.                         if!empty($value&& !isset($post_categories[$value]) )
  823.                         {
  824.                             if$catsmapped$value ][0== 'defaultset' )
  825.                             // we add default set
  826.                                 $post_categories[$value$default_post_extracats;
  827.                                 array_unshift$post_categories[$value]'catid'$default_post_category );
  828.                             }
  829.                             else $post_categories[$value$catsmapped$value ];
  830.                         }
  831.                         break;
  832.                     case 'DATE':
  833.                         $post_date strtotime$value );
  834.                         $post_date date('Y-m-d H:i:s'$post_date);
  835.                         break;
  836.                     default:
  837.                         $message .= "\n<li>Unknown key [$key] in metadata:\nvalue: $value\n</li>";
  838.                         break;
  839.                 }
  840.             // End foreach (metadata)
  841.  
  842.             $dontimport 0;
  843.  
  844.  
  845.             ifempty($post_categories) )
  846.             // no category metadata found!
  847.  
  848.                 if$catsmapped'[no category assigned]' ][0== 'defaultset' )
  849.                 // we must convert default set
  850.                     $post_categories['[no category assigned]'$default_post_extracats;
  851.                     array_unshift$post_categories['[no category assigned]']'catid'$default_post_category );
  852.                 }
  853.                 else $post_categories'[no category assigned]' $catsmapped'[no category assigned]' ];
  854.  
  855.             }
  856.  
  857.             // Let's check to see if it's in already
  858.             if$post_ID $DB->get_var("SELECT ID FROM $tableposts WHERE post_title = ".$DB->quote($post_title)." AND post_issue_date = '$post_date'")) {
  859.                 $message .= '<li style="color:blue">Post already imported.</li>';
  860.             }
  861.             else
  862.             // insert post
  863.  
  864.                 // check&map author
  865.                 switch$usersmapped$post_author ][0)
  866.                 {
  867.                     case 'ignore':
  868.                         $message .= '<li style="color:blue">User ignored!</li>';
  869.                         echo $message.'</ul>';
  870.                         continue;  // next post
  871.  
  872.                     case 'b2evo':
  873.                         $post_author $usersmapped$post_author ][1];
  874.                         break;
  875.  
  876.                     case 'createnew':
  877.                         // check if the user already exists
  878.                         $user_data get_userdatabylogin$usersmapped$post_author ][1);
  879.                         if$user_data )
  880.                         {
  881.                             $post_author $user_data['ID'];
  882.                         }
  883.                         else
  884.                         {
  885.                             $new_user new User();
  886.                             $new_user->set('login'strtolower($usersmapped$post_author ][1]));
  887.                             $new_user->set('nickname'$usersmapped$post_author ][1]);
  888.                             $new_user->set('pass'md5$default_password ));
  889.                             $new_user->set('level'$default_userlevel);
  890.                             $new_user_Group $GroupCache->get_by_ID$default_usergroup );
  891.                             $new_user->setGroup$new_user_Group );
  892.                             $new_user->set_datecreatedtime(($Settings->get('time_difference'3600) );
  893.  
  894.                             if$simulate )
  895.                             {
  896.                                 $cache_userdata$post_author array'ID' => 'simulating' );
  897.                             }
  898.                             else
  899.                             {
  900.                                 $new_user->dbinsert();
  901.                             }
  902.  
  903.                             $message .= '<li style="color:orange">user '.$usersmapped$post_author ][1].' created</li>';
  904.                             $count_userscreated++;
  905.  
  906.                             $post_author $new_user->ID;
  907.                         }
  908.                         break;
  909.                     default:
  910.                         $message .= '<li style="color:red">unknown type in checkauthor ('.$usersmapped$author ][0].'). This should never ever happen. Post ignored. Please report it.</li>';
  911.                         echo $message.'</ul>';
  912.                         continue;  // next post
  913.                 }
  914.  
  915.  
  916.                 debug_dump$post_categories'cats to check' );
  917.  
  918.                 // Check categories
  919.                 $i_cat = -1;
  920.                 $message_ignored '';
  921.                 foreach$post_categories as $catname => $checkcat )
  922.                 {
  923.                     $i_cat++;
  924.                     switch$checkcat[0)
  925.                     {
  926.                         case 'catid'// existing b2evo catids
  927.                             array_shift($checkcat);
  928.                             while$cat_id array_shift($checkcat) )
  929.                                 $post_catids[$cat_id// get all catids
  930.                             continue;
  931.  
  932.                         case 'ignore'// category is ignored
  933.                             if$i_cat == )
  934.                             // main category ignored, don't import post
  935.                                 $dontimport 1;
  936.                                 $message_ignored .= '<li>Main Category &quot;'.$catname.'&quot; ignored! - no import</li>';
  937.                                 break;
  938.                             }
  939.                             else
  940.                             // ignored category in extracats, remove it there
  941.                                 $message_ignored .= '<li>Extra category '.$catname.' ignored.</li>';
  942.                                 unset$post_categories$catname );
  943.                             }
  944.                             break;
  945.  
  946.                         case 'blogid'// category has to be created
  947.                             // create it and remember ID
  948.                             if$simulate )
  949.                             {
  950.                                 $cat_id = ++$simulate_cat_id;
  951.                             }
  952.                             else
  953.                             {
  954.                                 $cat_id cat_create$checkcat[2]'NULL'$checkcat[1);
  955.                             }
  956.                             $catsmapped$catname array'catid'$cat_id )// use ID from now on.
  957.  
  958.                             if!isset($cache_categories$cat_id ) )
  959.                             // stupid workaround because of a bug where cache_categories does not get updated and we want to use get_catname later
  960.                                 $cache_categories$cat_id array(
  961.                                     'cat_name' => $checkcat[2],
  962.                                     'cat_blog_ID' => $checkcat[1],
  963.                                     'cat_parent_ID' => NULL,
  964.                                     'cat_postcount' => 0,
  965.                                     'cat_children' => 0
  966.                                 );
  967.                             }
  968.                             $post_catids[$cat_id;
  969.                             $message .= '<li style="color:orange">category '.$checkcat[2].' [ID '.$cat_id.'] created</li>';
  970.                             break;
  971.  
  972.                         default:
  973.                             $message .= '<li style="color:red">This should never ever happen @check_cats. Please report it! (checkcat[0]: '.$checkcat[0].')</li>';
  974.  
  975.                     }
  976.                 }
  977.                 if!empty($message_ignored) )
  978.                     $message .= '<li style="color:blue">Categories ignored: <ul>'.$message_ignored.'</ul></li>';
  979.  
  980.                 debug_dump$dontimport'dontimport' );
  981.                 if$dontimport )
  982.                 // see var name :)
  983.                     echo $message;
  984.                     continue;  // next post
  985.                 }
  986.  
  987.                 if$convert_html_tags )
  988.                 {
  989.                     $old_content $post_content;
  990.                     // convert tags to lowercase
  991.                     $post_content preg_replace"/(<\/?)(\w+)([^>]*>)/e""'\\1'.strtolower('\\2').'\\3'"$post_content);
  992.  
  993.                     // close br, hr and img tags
  994.                     $post_content preg_replacearray('/<(br)>/''/<(hr\s?.*?)>/''/<(img\s.*?)>/')'<\\1 />'remove_magic_quotes($post_content) );
  995.  
  996.                     // add quotes for href tags that don't have them
  997.                     $post_content preg_replace'|href=([^"\'][^\s>"\']+)["\']?|''href="$1"'$post_content );
  998.  
  999.                     $post_content preg_replacearray('/<(br)>/''/<(hr\s?.*?)>/''/<(img\s.*?)>/')'<\\1 />'remove_magic_quotes($post_content) );
  1000.  
  1001.                     if$post_content != $old_content )
  1002.                     {
  1003.                         $message .= '<li><p style="color:darkblue;border:1px dashed orange;">'.htmlspecialchars($old_content).'</p>
  1004.                         html-converted to: <p style="color:darkblue;border:1px dashed orange;">'.htmlspecialchars($post_content).'</p></li>';
  1005.                     }
  1006.                 }
  1007.  
  1008.                 /*if( count($urlreplace) )
  1009.                 {
  1010.                     $old_content = $post_content;
  1011.                     foreach( $urlreplace as $search => $replace )
  1012.                     {
  1013.                         $post_content = str_replace( $urlsearch, $urlreplace, $post_content );
  1014.                     }
  1015.                     if( $post_content != $old_content )
  1016.                     {
  1017.                         echo '<p style="color:darkblue;border:1px dashed orange;">'.htmlspecialchars($old_content).'</p>
  1018.                         converted img-links to: <p style="color:darkblue;border:1px dashed orange;">'.htmlspecialchars($post_content).'</p>';
  1019.                     }
  1020.                 }*/
  1021.  
  1022.                 debug_dump$post_catids'post_extracats' );
  1023.                 $post_category array_shift($post_catids);
  1024.                 debug_dump$post_category'post_category' );
  1025.                 debug_dump$post_categories'post_categories' );
  1026.                 debug_dump$post_author'post_author' );
  1027.  
  1028.                 if!$simulate )
  1029.                 {
  1030.                     $post_ID =
  1031.                         bpost_create$post_author$post_title$post_content,    $post_date$post_category$post_catids,
  1032.                                                     $post_status,    $post_locale,    '' /* $post_trackbacks */$post_convert_breakstrue /* $pingsdone */,
  1033.                                                     '' /* $post_urltitle */'' /* $post_url */$comment_status$post_renderers );
  1034.                 }
  1035.  
  1036.                 $message .= '<li><span style="color:green">Imported successfully</span><ul><li>main category: <span style="color:#09c">'.get_catname$post_category ).'</span></li>';
  1037.                 ifcount($post_catids) )
  1038.                     $message .= '<li>extra categories: <span style="color:#09c">'.preg_replace'/(\d+)/e'"get_catname('\\1')"implode', '$post_catids ) ).'</span></li>';
  1039.                 $message .= '</ul></li>';
  1040.                 $count_postscreated++;
  1041.  
  1042.             }
  1043.             echo $message.'</ul>';
  1044.  
  1045.  
  1046.             ifcount($comments) )
  1047.             // comments
  1048.                 $message '';
  1049.  
  1050.                 $comments explode("-----\nCOMMENT:"$comments[0]);
  1051.                 foreach ($comments as $comment)
  1052.                 {
  1053.                     $comment trim($comment);
  1054.                     ifempty($comment) ) continue;
  1055.  
  1056.                     $comment_author ripline'AUTHOR:'$comment );
  1057.                     $comment_email ripline'EMAIL:'$comment );
  1058.                     $comment_ip ripline'IP:'$comment );
  1059.                     $comment_url ripline'URL:'$comment );
  1060.                     $comment_date date('Y-m-d H:i:s'strtotimeripline'DATE:'$comment )));
  1061.  
  1062.                     $comment_content preg_replace("/\n*-----$/"''$comment);
  1063.  
  1064.                     // Check if it's already in there
  1065.                     if!$DB->get_row("SELECT * FROM $tablecomments WHERE comment_date = '$comment_date' AND comment_content = ".$DB->quote$comment_content )) )
  1066.                     {
  1067.                         if!$simulate )
  1068.                         {
  1069.                             $DB->query"INSERT INTO $tablecomments( comment_post_ID, comment_type, comment_author_ID, comment_author,
  1070.                                                                                                         comment_author_email, comment_author_url, comment_author_IP,
  1071.                                                                                                         comment_date, comment_content)
  1072.                                                 VALUES( $post_ID, 'comment', 'NULL', ".$DB->quote($comment_author).",
  1073.                                                                 ".$DB->quote($comment_email).",    ".$DB->quote($comment_url).",
  1074.                                                                 ".$DB->quote($comment_ip).", '$comment_date', ".$DB->quote($comment_content)." )" );
  1075.                         }
  1076.  
  1077.                         $message .= '<li>Comment from '.$comment_author.' added.</li>';
  1078.                         $count_commentscreated++;
  1079.                     }
  1080.                 }
  1081.                 if!empty($message) )
  1082.                 {
  1083.                     echo '<ul>'.$message.'</ul>';
  1084.                 }
  1085.  
  1086.             }
  1087.  
  1088.             // Finally the pings
  1089.             // fix the double newline on the first one
  1090.             ifcount($pings) )
  1091.             {
  1092.                 $message '';
  1093.                 $pings[0str_replace("-----\n\n""-----\n"$pings[0]);
  1094.                 $pings explode("-----\nPING:"$pings[0]);
  1095.                 foreach$pings as $ping )
  1096.                 {
  1097.                     $ping trim($ping);
  1098.                     ifempty($ping) ) continue;
  1099.  
  1100.                     $comment_author ripline'BLOG NAME:'$ping );
  1101.                     $comment_email '';
  1102.                     $comment_ip ripline'IP:'$ping );
  1103.                     $comment_url ripline'URL:'$ping );
  1104.                     $comment_date date('Y-m-d H:i:s'strtotimeripline'DATE:'$ping )));
  1105.                     $ping_title ripline'TITLE:'$ping );
  1106.  
  1107.                     $comment_content preg_replace("/\n*-----$/"''$ping);
  1108.  
  1109.                     $comment_content "<strong>$ping_title</strong><br />$comment_content";
  1110.  
  1111.                     // Check if it's already there
  1112.                     if (!$DB->get_row("SELECT * FROM $tablecomments WHERE comment_date = '$comment_date' AND comment_type = 'trackback' AND comment_content = ".$DB->quote($comment_content)))
  1113.                     {
  1114.                         if!$simulate )
  1115.                         {
  1116.                             $DB->query"INSERT INTO $tablecomments
  1117.                                 (comment_post_ID, comment_type, comment_author, comment_author_email, comment_author_url,
  1118.                                 comment_author_IP, comment_date, comment_content )
  1119.                                 VALUES
  1120.                                 ($post_ID, 'trackback', ".$DB->quote($comment_author).", ".$DB->quote($comment_email).", ".$DB->quote($comment_url).",
  1121.                                 ".$DB->quote($comment_ip).", ".$DB->quote($comment_date).", ".$DB->quote($comment_content)." )" );
  1122.                         }
  1123.                         $message .= '<li>Trackback from '.$comment_url.' added.</li>';
  1124.                         $count_trackbackscreated++;
  1125.                     }
  1126.                 }
  1127.                 echo $message;
  1128.             }
  1129.  
  1130.             echo "</li>\n";
  1131.             flush();
  1132.         }
  1133.         ?>
  1134.         </ol>
  1135.         <h4>All done.<?php if$simulate echo ' (simulated - no real import!)' ?></h4>
  1136.         <ul>
  1137.             <li><?php echo $count_postscreated ?> post(s) imported.</li>
  1138.             <li><?php echo $count_userscreated ?> user(s) created.</li>
  1139.             <li><?php echo $count_commentscreated ?> comment(s) imported.</li>
  1140.             <li><?php echo $count_trackbackscreated ?> trackback(s) imported.</li>
  1141.             <li>in <?php echo number_format(timer_stop()3?> seconds.</li>
  1142.         </ul>
  1143.         <?php
  1144.         if$simulate )
  1145.         {
  1146.             echo '
  1147.             <form action="import-mt.php" method="post">
  1148.             <p>
  1149.             <strong>This was only simulated..</strong>
  1150.             ';
  1151.             foreach$_POST as $key => $value )
  1152.             {
  1153.                 if$key != 'simulate' )
  1154.                 {
  1155.                     ifis_array$value ) )
  1156.                     {
  1157.                         foreach$value as $key2 => $value2 )
  1158.                         {
  1159.                             echo '<input type="hidden" name="'.$key.'['.$key2.']" value="'.format_to_output$value2'formvalue' ).'" />';
  1160.                         }
  1161.                     }
  1162.                     else
  1163.                     {
  1164.                         echo '<input type="hidden" name="'.$key.'" value="'.format_to_output$value'formvalue' ).'" />';
  1165.                     }
  1166.                 }
  1167.             }
  1168.             echo '<input type="submit" value="Do it for real now!" /></p></form>'."\n";
  1169.         }
  1170.         ?>
  1171.         <p>
  1172.             <a href="<?php echo $admin_dirout ?>">Have fun in your blogs</a> or <a href="<?php echo $admin_url ?>">go to admin</a> (it's fun there, too)
  1173.         </p>
  1174.         <?php
  1175.         if$count_userscreated )
  1176.         {
  1177.             echo '<p class="note">Please note that the new users being created are not member of any blog yet. You\'ll have to setup this in the <a href="'.$admin_url.'/b2blogs.php">blogs admin</a>.</p>';
  1178.         }
  1179.         ?>
  1180.         </div>
  1181.     <?php
  1182.     }
  1183.  
  1184. ?>
  1185. <div class="panelinfo">
  1186.     <p>
  1187.         Feel free to <a href="http://thequod.de/contact">contact me</a> in case of suggestions, bugs and lack of clarity.
  1188.         Of course, you're also welcome to <a href="https://sourceforge.net/donate/index.php?user_id=663176">donate to me</a> or <a href="http://sourceforge.net/donate/index.php?group_id=85535">the b2evolution project</a>.. :)
  1189.     </p>
  1190. </div>
  1191. <div class="clear">
  1192. <?php if$output_debug_dump $DB->dump_queries(?>
  1193. </div>
  1194. </div>
  1195. </body>
  1196. </html>
  1197. <?php
  1198.  
  1199. /* ------ FUNCTIONS ------ */
  1200.  
  1201. function fieldset_cats()
  1202. {
  1203.     global $cache_blogs$cache_categories;
  1204.  
  1205.     ?>
  1206.     <fieldset title="default categories set" style="background-color:#fafafa; border:1px solid #ccc; padding: 1em; display:inline; float:right; white-space:nowrap;">
  1207.         <legend>Default categories set (only needed if you want to map categories to this)</legend>
  1208.         <p class="extracatnote">
  1209.         <?php
  1210.             ifcount$cache_categories ) )
  1211.             {
  1212.                 echo T_('Select main category in target blog and optionally check additional categories').':';
  1213.             }
  1214.             else
  1215.             {
  1216.                 echo 'No categories in your blogs..';
  1217.             }
  1218.         ?>
  1219.         </p>
  1220.  
  1221.         <?php
  1222.         // ----------------------------  CATEGORIES ------------------------------
  1223.         $default_main_cat 0;
  1224.         $blog 1;
  1225.  
  1226.         // ----------------- START RECURSIVE CAT LIST ----------------
  1227.         cat_queryfalse );    // make sure the caches are loaded
  1228.         function cat_select_before_first$parent_cat_ID$level )
  1229.         {    // callback to start sublist
  1230.             echo "\n<ul>\n";
  1231.         }
  1232.  
  1233.         function cat_select_before_each$cat_ID$level )
  1234.         {    // callback to display sublist element
  1235.             global $current_blog_ID$blog$cat$postdata$default_main_cat$action$tabindex$allow_cross_posting;
  1236.             $this_cat get_the_category_by_ID$cat_ID );
  1237.             echo '<li>';
  1238.  
  1239.             if$allow_cross_posting )
  1240.             // We allow cross posting, display checkbox:
  1241.                 echo'<input type="checkbox" name="post_extracats[]" class="checkbox" title="'T_('Select as an additionnal category''" value="',$cat_ID,'"';
  1242.                 echo ' />';
  1243.             }
  1244.  
  1245.             // Radio for main cat:
  1246.             if$current_blog_ID == $blog )
  1247.             {
  1248.                 if( ($default_main_cat == 0&& ($action == 'post') )
  1249.                 {    // Assign default cat for new post
  1250.                     $default_main_cat $cat_ID;
  1251.                 }
  1252.                 echo ' <input type="radio" name="post_category" class="checkbox" title="'T_('Select as MAIN category')'" value="',$cat_ID,'"';
  1253.                 if( ($cat_ID == $postdata["Category"]|| ($cat_ID == $default_main_cat))
  1254.                     echo ' checked="checked"';
  1255.                 echo ' />';
  1256.             }
  1257.             echo ' '.$this_cat['cat_name'];
  1258.         }
  1259.         function cat_select_after_each$cat_ID$level )
  1260.         {    // callback after each sublist element
  1261.             echo "</li>\n";
  1262.         }
  1263.         function cat_select_after_last$parent_cat_ID$level )
  1264.         {    // callback to end sublist
  1265.             echo "</ul>\n";
  1266.         }
  1267.  
  1268.         // go through all blogs with cats:
  1269.         foreach$cache_blogs as $i_blog )
  1270.         // run recursively through the cats
  1271.             $current_blog_ID $i_blog->blog_ID;
  1272.             ifblog_has_cats$current_blog_ID ) ) continue;
  1273.             #if( ! $current_User->check_perm( 'blog_post_statuses', 'any', false, $current_blog_ID ) ) continue;
  1274.             echo "<h4>".$i_blog->blog_name."</h4>\n";
  1275.             cat_children$cache_categories$current_blog_IDNULL'cat_select_before_first',
  1276.                                         'cat_select_before_each''cat_select_after_each''cat_select_after_last');
  1277.         }
  1278.         // ----------------- END RECURSIVE CAT LIST ----------------
  1279.         ?>
  1280.     </fieldset>
  1281. <?php
  1282. }
  1283.  
  1284.  
  1285. /*
  1286.     -- Category options list --
  1287. */
  1288. function cats_optionslist$forcat )
  1289. {
  1290.     global $cache_categories$cache_blogs$cache_optionslist;
  1291.  
  1292.     if!isset($cache_optionslist) )
  1293.     {
  1294.         $cache_optionslist '';
  1295.         foreach$cache_blogs as $i_blog )
  1296.         {
  1297.             $cache_optionslist .= '<option value="#NEW#'.$i_blog->blog_ID.'">[-- create in blog '.$i_blog->blog_shortname.' --]:</option>';
  1298.             cat_children2$cache_categories$i_blog->blog_IDNULL);
  1299.         }
  1300.     }
  1301.  
  1302.     $cat_id false;
  1303.     foreach$cache_categories as $key => $value )
  1304.     {
  1305.         if$value['cat_name'== $forcat )
  1306.         {
  1307.             $cat_id $key;
  1308.             break;
  1309.         }
  1310.     }
  1311.  
  1312.     ifis_int($cat_id) )
  1313.     {
  1314.         echo str_replace'<option value="'.$cat_id.'">''<option value="'.$cat_id.'" selected="selected">'$cache_optionslist );
  1315.     }
  1316.     else
  1317.     {
  1318.         echo $cache_optionslist;
  1319.     }
  1320. }
  1321.  
  1322. function cat_children2(
  1323.     $ccats,     // PHP requires this stupid cloning of the cache_categories array in order to be able to perform foreach on it
  1324.     $blog_ID,
  1325.     $parent_ID,
  1326.     $level )    // Caller nesting level, just to keep track of how far we go :)
  1327. {
  1328.     global $cache_optionslist;
  1329.  
  1330.     // echo 'Number of cats=', count($ccats);
  1331.     ifempty$ccats ) ) // this can happen if there are no cats at all!
  1332.     {
  1333.         $child_count 0;
  1334.         foreach$ccats as $icat_ID => $i_cat )
  1335.         {
  1336.             if$icat_ID && (($blog_ID == 0|| ($i_cat['cat_blog_ID'== $blog_ID)) && ($i_cat['cat_parent_ID'== $parent_ID) )
  1337.             // this cat is in the blog and is a child of the parent
  1338.                 $child_count++;
  1339.  
  1340.                 $cache_optionslist .= '<option value="'.$icat_ID.'">';
  1341.  
  1342.                 for$i 0$i $level$i++ )
  1343.                 {
  1344.                     $cache_optionslist .= '-';
  1345.                 }
  1346.  
  1347.                 $cache_optionslist .= '&gt; '.format_to_output$ccats$icat_ID ]['cat_name']'entityencoded' ).'</option>';
  1348.  
  1349.                 cat_children2$ccats$blog_ID$icat_ID$level+);
  1350.             }
  1351.         }
  1352.     }
  1353. }
  1354.  
  1355.  
  1356. /**
  1357.  * extracts unique authors and cats from posts array
  1358.  */
  1359. {
  1360.     global $authors$categories$posts;
  1361.     global $exportedfile;
  1362.     global $categories_countprim;
  1363.     global $importdata;
  1364.     global $mode;
  1365.  
  1366.     $fp fopen$exportedfile'rb');
  1367.     $buffer fread($fpfilesize$exportedfile ));
  1368.     fclose($fp);
  1369.     if!preg_match'/^AUTHOR: /'$buffer ) )
  1370.     {
  1371.         dieerror("The file [$exportedfile] does not seem to be a MT exported file.. ".'[<a href="import-mt.php?mode='.$mode.'">choose another export-file</a>]');
  1372.     }
  1373.  
  1374.     $importdata preg_replace"/\r?\n|\r/""\n"$buffer );
  1375.     $posts preg_split'/(^|--------\n)(AUTHOR: |$)/'$importdata );
  1376.  
  1377.     $authors array()$tempauthors array();
  1378.     $categories array()$tempcategories array();
  1379.  
  1380.     foreach ($posts as $nr => $post)
  1381.     {
  1382.         if ('' != trim($post))
  1383.         {
  1384.             // first line is author of post
  1385.             $tempauthors[trimsubstr$post0strpos$post"\n") ) );
  1386.  
  1387.             $oldcatcount count$tempcategories );
  1388.  
  1389.             ifpreg_match_all"/^(PRIMARY )?CATEGORY: (.*)/m"$post$matches ) )
  1390.             {
  1391.                 for$i 1$i count$matches[2)$i++ )
  1392.                 {
  1393.                     $cat trim$matches[2][$i);
  1394.                     if!empty$cat ) ) $tempcategories[$cat;
  1395.                 }
  1396.  
  1397.                 // main category last (-> counter)
  1398.                 if!empty($matches[2][0]) ) $tempcategories[$matches[2][0];
  1399.             }
  1400.  
  1401.             if$oldcatcount == count$tempcategories ) )
  1402.             {
  1403.                 $tempcategories['[no category assigned]';
  1404.             }
  1405.  
  1406.             // remember how many times used as primary category
  1407.             @$categories_countprim$tempcategoriescount$tempcategories )-] ]++;
  1408.         }
  1409.         else
  1410.         {
  1411.             unset$posts$nr );
  1412.         }
  1413.     }
  1414.  
  1415.     // we need to find unique values of author names, while preserving the order, so this function emulates the unique_value(); php function, without the sorting.
  1416.     $authors[0array_shift($tempauthors);
  1417.     $y count($tempauthors1;
  1418.     for ($x 1$x $y$x++)
  1419.     {
  1420.         $next array_shift($tempauthors);
  1421.         if!(in_array($next,$authors)) ) $authors[$next;
  1422.     }
  1423.     $categories[0array_shift$tempcategories );
  1424.     $y count($tempcategories1;
  1425.     for ($x 1$x $y$x++)
  1426.     {
  1427.         $next array_shift($tempcategories);
  1428.         if!(in_array($next$categories)) ) $categories[$next;
  1429.     }
  1430. }
  1431.  
  1432.  
  1433. /**
  1434.  * Outputs a list of available renderers (not necessarily installed).
  1435.  */
  1436. function renderer_list()
  1437. {
  1438.     global $Renderer$renderers;
  1439.  
  1440.     $renderers array('default');
  1441.     $Renderer->restart();     // make sure iterator is at start position
  1442.     while$loop_RendererPlugin $Renderer->get_next() )
  1443.     // Go through whole list of renders
  1444.         // echo ' ',$loop_RendererPlugin->code;
  1445.         if$loop_RendererPlugin->apply_when == 'stealth'
  1446.             || $loop_RendererPlugin->apply_when == 'never' )
  1447.         {    // This is not an option.
  1448.             continue;
  1449.         }
  1450.         elseif$loop_RendererPlugin->code == 'b2WPAutP' )
  1451.         // special Auto-P plugin
  1452.             ?>
  1453.             <div class="input">
  1454.                 <label for="textile" title="<?php    $loop_RendererPlugin->short_desc()?>"><strong><?php echo $loop_RendererPlugin->name(?>:</strong></label>
  1455.                 <div style="margin-left:2ex" />
  1456.                 <input type="radio" name="autop" value="1" class="checkbox" checked="checked" /> yes (always)<br>
  1457.                 <input type="radio" name="autop" value="0" class="checkbox" /> no (never)<br>
  1458.                 <input type="radio" name="autop" value="depends" class="checkbox" /> depends on CONVERT BREAKS
  1459.                 <span class="notes"> ..that means it will apply if convert breaks results to true (set to either 1, textile_2 or __DEFAULT__ (and &quot;Convert-breaks default&quot; checked above)</span>
  1460.  
  1461.                 </div>
  1462.             </div>
  1463.             <?php
  1464.             continue;
  1465.         }
  1466.         ?>
  1467.         <div>
  1468.             <input type="checkbox" class="checkbox" name="renderers[]"
  1469.                 value="<?php $loop_RendererPlugin->code(?>" id="<?php $loop_RendererPlugin->code(?>"
  1470.                 <?php
  1471.                 switch$loop_RendererPlugin->apply_when )
  1472.                 {
  1473.                     case 'always':
  1474.                         // echo 'FORCED';
  1475.                         echo ' checked="checked"';
  1476.                         echo ' disabled="disabled"';
  1477.                         break;
  1478.  
  1479.                     case 'opt-out':
  1480.                         ifin_array$loop_RendererPlugin->code$renderers // Option is activated
  1481.                             || in_array'default'$renderers ) ) // OR we're asking for default renderer set
  1482.                         {
  1483.                             // echo 'OPT';
  1484.                             echo ' checked="checked"';
  1485.                         }
  1486.                         // else echo 'NO';
  1487.                         break;
  1488.  
  1489.                     case 'opt-in':
  1490.                         ifin_array$loop_RendererPlugin->code$renderers ) ) // Option is activated
  1491.                         {
  1492.                             // echo 'OPT';
  1493.                             echo ' checked="checked"';
  1494.                         }
  1495.                         // else echo 'NO';
  1496.                         break;
  1497.  
  1498.                     case 'lazy':
  1499.                         // cannot select
  1500.                         ifin_array$loop_RendererPlugin->code$renderers ) ) // Option is activated
  1501.                         {
  1502.                             // echo 'OPT';
  1503.                             echo ' checked="checked"';
  1504.                         }
  1505.                         echo ' disabled="disabled"';
  1506.                         break;
  1507.                 }
  1508.             ?>
  1509.             title="<?php    $loop_RendererPlugin->short_desc()?>" />
  1510.         <label for="<?php $loop_RendererPlugin->code(?>" title="<?php    $loop_RendererPlugin->short_desc()?>"><strong><?php echo $loop_RendererPlugin->name()?></strong></label>
  1511.     </div>
  1512.     <?php
  1513.     }
  1514. }
  1515.  
  1516.  
  1517. /**
  1518.  * Die with a message.
  1519.  *
  1520.  * @param string the message (wrapped in div and p tag of class error)
  1521.  * @param string optional head
  1522.  */
  1523. function dieerror$message$before '' )
  1524. {
  1525.     if!empty($before) )
  1526.         echo $before;
  1527.  
  1528.     die'<div class="error"><p class="error">'.$message.'</p></div>
  1529.     </div></body></html>' );
  1530. }
  1531.  
  1532.  
  1533. function debug_dump$var$title '' )
  1534. {
  1535.     global $output_debug_dump;
  1536.  
  1537.     if$output_debug_dump )
  1538.     {
  1539.         pre_dump$var$title );
  1540.     }
  1541. }
  1542.  
  1543.  
  1544. function chooseexportfile()
  1545. {
  1546.     global $exportedfile$mode;
  1547.     // Go through directory:
  1548.     $this_dir dirdirname(__FILE__) );
  1549.     $r '';
  1550.     while$this_file $this_dir->read() )
  1551.     {
  1552.         ifpreg_match'/^.+\.txt$/'$this_file ) )
  1553.         {
  1554.             $r .= '<option value="'.format_to_output$this_file'formvalue' ).'"';
  1555.             if$exportedfile == $this_file $r .= ' selected="selected"';
  1556.             $r .= '>'.format_to_output$this_file'entityencoded' ).'</option>';
  1557.         }
  1558.     }
  1559.  
  1560.     if$r )
  1561.     {
  1562.         ?>
  1563.         <form action="import-mt.php" class="center">
  1564.             <p>First, choose a file to import (.TXT files from /admin dir):</p>
  1565.             <select name="exportedfile" onChange="submit()">
  1566.                 <?php echo $r ?>
  1567.             </select>
  1568.             <input type="hidden" name="mode" value="<?php echo $mode ?>" />
  1569.             <input type="submit" value="Next step..." class="search" />
  1570.         </form>
  1571.         <?php
  1572.     }
  1573.     else
  1574.     // no file found
  1575.         ?>
  1576.         <div class="error">
  1577.         <p class="center">No .TXT file found in /admin. Nothing to import...</p>
  1578.         <p class="center">Please copy your Movable Type .TXT export file to the /admin directory.</p>
  1579.         </div>
  1580.         <?php
  1581.     }
  1582. }
  1583.  
  1584.  
  1585. function ripline$prefix&$haystack )
  1586. {
  1587.     ifpreg_match'|^'.$prefix.'(.*)|m'$haystack$match ) )
  1588.     {
  1589.         $haystack preg_replace('|^'.$prefix.".*\n?|m"''$haystack );
  1590.         return trim$match[1);
  1591.     }
  1592.     else return false;
  1593. }
  1594.  
  1595.  
  1596. function tidypostdata$string )
  1597. {
  1598.     return str_replacearray('&quot;''&#039;''&lt;''&gt;')array('"'"'"'<''>')remove_magic_quotes$string ) );
  1599. }
  1600. ?>

Documentation generated on Tue, 20 May 2008 01:51:44 +0200 by phpDocumentor 1.4.2