[ Index ] |
PHP Cross Reference of Textpattern 4.0.8 |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 $HeadURL: https://textpattern.googlecode.com/svn/releases/4.0.8/source/textpattern/include/txp_import.php $ 5 $LastChangedRevision: 2812 $ 6 */ 7 8 if (!defined('txpinterface')) die('txpinterface is undefined.'); 9 10 // TO-DO: 11 // * Improve performance of file imports 12 // * Test a php_ini format for blogger exports 13 // * Provide an Export option 14 // * Write best help 15 16 //Keep error display until we add an error handler for this 17 error_reporting(E_ALL); 18 @ini_set("display_errors","1"); 19 20 require_privs('import'); 21 22 $vars = array('import_tool', 'Section','type','comments_invite','blog_id','importdb','importdblogin','importdbpass','importdbhost','wpdbprefix'); 23 24 // Add new tools here. 25 // First: Array key must be the end of the import tool file name; 26 // that is import_[key].php. 27 // Then: Add the specific tool call on start_import switch statement 28 29 $tools = array( 30 ''=>'', 31 'mt'=>'Movable Type (File)', 32 'mtdb'=>'Movable Type (MySQL DB)', 33 'blogger'=>'Blogger', 34 'b2' => 'b2', 35 'wp'=>'WordPress' 36 ); 37 38 39 if(!$step or !in_array($step, array('switch_tool','start_import'))){ 40 switch_tool(); 41 } else $step(); 42 43 // ------------------------------------------------------------- 44 // Select the tool we want to import from and provide required data 45 function switch_tool(){ 46 47 global $vars,$step,$tools; 48 extract(gpsa($vars)); 49 pagetop(gTxt('txp_import'), ''); 50 51 ?> 52 53 <script type="text/javascript"> 54 <!--// 55 function showHideFields($sel) 56 { 57 if(document.getElementById){ 58 document.getElementById('mtblogid').style.display = ($sel=='mtdb') ? 'block': 'none'; 59 document.getElementById('wponly').style.display = ($sel=='wp') ? 'block': 'none'; 60 document.getElementById('databased').style.display = ($sel=='wp' || $sel=='mtdb' || $sel=='b2')? 'block':'none'; 61 } 62 } 63 //--> 64 </script> 65 66 <?php 67 $content= startTable('edit'); 68 $content.= tr(tdcs(hed(gTxt('txp_import'),3),2)); 69 //Select tool 70 $content.= tr( 71 fLabelCell ('select_tool','import'). 72 td( 73 tag(type_options($tools), 74 'select', 75 " name=\"import_tool\" onchange=\"showHideFields(this.value);\"") 76 ) 77 ); 78 79 80 //Some data we collect 81 $content.= tr( 82 fLabelCell ('import_section','import_section'). 83 td(import_section_popup('')) 84 ); 85 86 $status_options = array( 87 4 => gTxt('live'), 88 1 => gTxt('draft'), 89 2 => gTxt('hidden'), 90 3 => gTxt('pending') 91 ); 92 93 $content.= tr( 94 fLabelCell ('import_status','import_status'). 95 td(type_select($status_options)) 96 ); 97 98 $content.= tr( 99 fLabelCell ('import_invite','import_invite'). 100 td(fInput('text','comments_invite', gTxt('comments'),'edit')) 101 ); 102 103 //DataBase imports only 104 105 $databased = 106 tr(tdcs(hed(gTxt('database_stuff'),3),2)). 107 tr( 108 fLabelCell ('import_database','import_database'). 109 td(fInput('text','importdb', '','edit')) 110 ). 111 tr( 112 fLabelCell ('import_login','import_login'). 113 td(fInput('text','importdblogin', '','edit')) 114 ). 115 tr( 116 fLabelCell ('import_password','import_password'). 117 td(fInput('text','importdbpass', '','edit')) 118 ). 119 tr( 120 fLabelCell ('import_host','import_host'). 121 td(fInput('text','importdbhost', '','edit')) 122 ); 123 124 //Ugly, but a way to present a clean screen with only required fields 125 //while we keep JavaScript code at minimum 126 $content.= tr(tda(tag($databased, 'table', ' id="databased" style="display: none; border: none;"'),' colspan="2"')); 127 //MT-DB Specific 128 $mtblogid = tr( 129 fLabelCell ('import_blogid','import_blogid'). 130 td(fInput('text','blog_id','','edit')) 131 ); 132 $content.= tr(tda(tag($mtblogid, 'table', ' id="mtblogid" style="display: none; border: none;"'),' colspan="2"')); 133 //WordPress specific option 134 $wponly = tr( 135 fLabelCell ('import_wpprefix','import_wpprefix'). 136 td(fInput('text','wpdbprefix', 'wp_','edit')) 137 ); 138 $content.= tr(tda(tag($wponly, 'table', ' id="wponly" style="display: none; border: none;"'),' colspan="2"')); 139 140 $content.= endTable(); 141 $content.= tag(fInput('submit','choose',gTxt('continue'),'publish'),'p',' style="text-align:center"'); 142 $content.= sInput('start_import').eInput('import'); 143 echo tag($content, 'form', ' id="import" action="index.php" method="post"'); 144 } 145 146 147 // ------------------------------------------------------------ 148 //Pre import tasks, then call the import funtion 149 function start_import() 150 { 151 global $vars; 152 extract(psa($vars)); 153 154 $insert_into_section = $Section; 155 $insert_with_status = $type; 156 $default_comment_invite = $comments_invite; 157 include_once txpath.'/include/import/import_'.$import_tool.'.php'; 158 159 $ini_time = ini_get('max_execution_time'); 160 161 @ini_set('max_execution_time', 300 + intval($ini_time) ); 162 163 switch ($import_tool) 164 { 165 case 'mtdb': 166 $out = doImportMTDB($importdblogin, $importdb, $importdbpass, $importdbhost, $blog_id, $insert_into_section, $insert_with_status, $default_comment_invite); 167 rebuild_tree('root',1,'article'); 168 break; 169 case 'mt': 170 $file = check_import_file(); 171 if (!empty($file)){ 172 $out = doImportMT($file, $insert_into_section, $insert_with_status, $comments_invite); 173 //Rebuilding category tree 174 rebuild_tree('root',1,'article'); 175 }else{ 176 $out = 'Import file not found'; 177 } 178 break; 179 case 'b2': 180 $out = doImportB2($importdblogin, $importdb, $importdbpass, $importdbhost, $insert_into_section, $insert_with_status, $default_comment_invite); 181 break; 182 case 'wp': 183 $out = doImportWP($importdblogin, $importdb, $importdbpass, $importdbhost, $wpdbprefix, $insert_into_section, $insert_with_status, $default_comment_invite); 184 rebuild_tree('root',1,'article'); 185 break; 186 case 'blogger': 187 $file = check_import_file(); 188 if (!empty($file)){ 189 $out = doImportBLOGGER($file, $insert_into_section, $insert_with_status, $comments_invite); 190 }else{ 191 $out = gTxt('import_file_not_found'); 192 } 193 break; 194 } 195 196 $out = tag('max_execution_time = '.ini_get('max_execution_time'),'p', ' style="color:red;"').$out; 197 pagetop(gTxt('txp_import')); 198 $content= startTable('list'); 199 $content.= tr(tdcs(hed(gTxt('txp_import'),3),2)); 200 $content.= tr(td($out)); 201 $content.= endTable(); 202 echo $content; 203 204 $rs = safe_rows_start('parentid, count(*) as thecount','txp_discuss','visible=1 group by parentid'); 205 if (mysql_num_rows($rs) > 0) 206 while ($a = nextRow($rs)) 207 safe_update('textpattern',"comments_count=".$a['thecount'],"ID=".$a['parentid']); 208 } 209 210 211 // ------------------------------------------------------------- 212 //checks the existence of a file called import.txt on the import dir. 213 // Used when importing from a file 214 function check_import_file() 215 { 216 //Check here file size too. And explain how to split the file if 217 //size is too long and time_limit can not be altered 218 219 $import_file = txpath.'/include/import/import.txt'; 220 if (!is_file($import_file)) { 221 // trigger_error('Import file not found', E_USER_WARNING); 222 return ''; 223 } 224 return $import_file; 225 } 226 227 // ------------------------------------------------------------- 228 // from Dean import 229 // add slashes to $in, no matter if is a single 230 231 function array_slash($in) 232 { 233 return is_array($in) ? array_map('addslashes',$in) : addslashes($in); 234 } 235 236 237 // ----------------------------------------------------------------- 238 // Some cut and paste here 239 //-------------------------------------------------------------- 240 // Display a popup of textpattern avaliable sections 241 242 function import_section_popup($Section) 243 { 244 $rs = safe_column("name", "txp_section", "name!='default'"); 245 if ($rs) { 246 return selectInput("Section", $rs, $Section, 1); 247 } 248 return false; 249 } 250 251 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu May 21 23:03:01 2009 | Cross-referenced by PHPXref 0.7 |