[ Index ] |
|
Code source de Serendipity 1.2 |
1 <?php # $Id$ 2 # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team) 3 # All rights reserved. See LICENSE file for licensing details 4 5 class Serendipity_Import_Blogger extends Serendipity_Import { 6 var $info = array('software' => 'Blogger.com'); 7 var $data = array(); 8 var $inputFields = array(); 9 10 function Serendipity_Import_Blogger($data) { 11 global $serendipity; 12 13 $this->data = $data; 14 $this->inputFields = array(array('text' => 'Path to your Blogger export file', 15 'type' => 'input', 16 'name' => 'bloggerfile', 17 'value' => $serendipity['serendipityPath']), 18 19 array('text' => 'New author default password (used for non-existing authors on the serendipity backend, as author passwords from Blogger are not migrated)', 20 'type' => 'input', 21 'name' => 'defaultpass', 22 'value' => ''), 23 24 array('text' => CHARSET, 25 'type' => 'list', 26 'name' => 'charset', 27 'value' => 'UTF-8', 28 'default' => $this->getCharsets()), 29 30 array('text' => RSS_IMPORT_BODYONLY, 31 'type' => 'bool', 32 'name' => 'bodyonly', 33 'value' => 'false')); 34 } 35 36 function validateData() { 37 return sizeof($this->data); 38 } 39 40 function getInputFields() { 41 return $this->inputFields; 42 } 43 44 function getImportNotes() { 45 $out = ' 46 <style type="text/css"> 47 <!-- 48 .style1 { 49 font-size: large; 50 font-weight: bold; 51 font-family: Arial, Helvetica, sans-serif; 52 } 53 .style2 { 54 font-family: Arial, Helvetica, sans-serif; 55 font-size: x-small; 56 } 57 --> 58 </style> 59 60 <p class="style1">BLOGGER.COM to SERENDIPITY IMPORT</p> 61 <p class="style2">Version 0.1,( 29/10/2005 )</p> 62 <p class="style2"> <br /> 63 1. First go to Blogger.com, login.</p> 64 <p class="style2">2. Go to the templates section. Set the following as your template. You should backup the current template if you want to reset it back after this operation. Click "Save template changes" button to save this new template.</p> 65 <p class="style2"> 66 <label> 67 <textarea name="textarea" cols="60" rows="20"><Blogger> 68 STARTPOST 69 70 TITLE: <PostSubject><$BlogItemSubject$></PostSubject> 71 AUTHOR: <$BlogItemAuthor$> 72 DATE: <$BlogItemDateTime$> 73 ----- 74 BODY: 75 <$BlogItemBody$> 76 ----- 77 <BlogItemCommentsEnabled> 78 <BlogItemComments> 79 COMMENT: 80 AUTHOR: <$BlogCommentAuthor$> 81 DATE: <$BlogCommentDateTime$> 82 BODY: <$BlogCommentBody$> 83 ----- 84 </BlogItemComments> 85 </BlogItemCommentsEnabled> 86 ENDPOST 87 </Blogger> 88 </textarea> 89 </label> 90 </p> 91 <p class="style2">3. Go to the "Settings" section of blogger. </p> 92 <p class="style2">4. Click the "Formatting" link. From the formatting options, find the "Timestamp Format" option and set it to the top most option. i.e the one with the date and time showing. Find the "Show" option, and set it to 999. Save changes</p> 93 <p class="style2">5. Now click the "Comments" link. Find the "Comments Timestamp Format" option and set it to the 2nd option from the list. i.e the one with the date and time showing. Save changes. </p> 94 <p class="style2">6. On the server with your Serendipity installation, create a directory called "blogger". </p> 95 <p class="style2">7. Next, back on Blogger.com, go to the "Publishing" section. Set it to publish to an FTP server. Enter the details of the server with your Serendipity installation. Set the FTP path as the path to the "blogger" directory you created in the previous step. </p> 96 <p class="style2">8. Go back to Blogger.com and find "Publish Entire Blog" under "Posting" -> "Status". Click the Publish entire blog button to let blogger publish the blog to your ftp server.</p> 97 <p class="style2">9. Now in the box below type in the path to the "index.html" file blogger created under your "blogger" directory. File path should then look something like "/httpdocs/blogger/index.html".</p> 98 <p class="style2">10. This script will create the users as from the blogger blog being imported. However if a user already exists, then that user will be used instead of creating a new user with similar name. For the new users that this script will create, you need to provide a default password. Type it in the box below.</p> 99 <p class="style2">11. Click "Submit". Your posts and comments should be imported to serendipity!</p> 100 <p class="style2"> If you have questions or problems, feel free to drop me a mail at jaa at technova dot com dot mv.<br /> 101 <br /> 102 Jaa<br /> 103 http://jaa.technova.com.mv</p>'; 104 return $out; 105 } 106 107 function import() { 108 global $serendipity; 109 110 if (empty($this->data['bloggerfile']) || !file_exists($this->data['bloggerfile'])) { 111 echo "Path to blogger file empty or path to file wrong! Go back and correct."; 112 return false; 113 } 114 115 # get default pass from request 116 $defaultpass = $this->data['defaultpass']; 117 118 # get blogger uploaded file path from request and load file 119 $html = file_get_contents($this->data['bloggerfile']); 120 121 # find posts using pattern matching 122 preg_match_all("/STARTPOST(.*)ENDPOST/sU", $html, $posts); 123 124 # iterate through all posts 125 foreach($posts[1] as $post) { 126 127 # locate the post title 128 if (preg_match("/TITLE:(.*)/", $post, $title)) { 129 $title = trim($title[1]); 130 echo "<b>" . htmlspecialchars($title) . "</b><br />"; 131 } else { 132 $title = ""; 133 echo "<b>Empty title</b><br />"; 134 } 135 136 # locate the post author 137 if (preg_match("/AUTHOR:(.*)/", $post, $author)) { 138 $author = trim($author[1]); 139 echo "<em>" . htmlspecialchars($author[1]) . "</em><br />"; 140 } else { 141 $author = ""; 142 echo "<em>Unknown author</em><br />"; 143 } 144 145 # locate the post date 146 if (preg_match("/DATE:(.*)/", $post, $date)) { 147 $date = strtotime(trim($date[1])); 148 echo "Posted on " . htmlspecialchars($date[1]) . ".<br />"; 149 } else { 150 $date = time(); 151 echo "Unknown posting time.<br />"; 152 } 153 154 # locate the post body 155 if (preg_match("/BODY:(.*)-----/sU", $post, $body)) { 156 $body = trim($body[1]); 157 echo strlen($body) . " Bytes of text.<br />"; 158 } else { 159 $body = ""; 160 echo "<strong>Empty Body!</strong><br />"; 161 } 162 163 # find all comments for the post using pattern matching 164 if (preg_match_all( "/COMMENT:(.*)----/sU", $post, $commentlist)) { 165 echo count($commentlist[1]) . " comments found.<br />"; 166 } else { 167 $commentlist = array(); 168 echo "No comments found.<br />"; 169 } 170 171 $result = serendipity_db_query("SELECT authorid FROM ". $serendipity['dbPrefix'] ."authors WHERE username = '". serendipity_db_escape_string($author) ."' LIMIT 1", true, 'assoc'); 172 if (!is_array($result)) { 173 $data = array('right_publish' => 1, 174 'realname' => $author, 175 'username' => $author, 176 'userlevel' => 0, 177 'password' => md5($defaultpass)); // MD5 compatible 178 serendipity_db_insert('authors', $data); 179 $authorid = serendipity_db_insert_id('authors', 'authorid'); 180 } else { 181 $authorid = $result['authorid']; 182 } 183 184 185 $entry = array('title' => $title, 186 'isdraft' => 'false', 187 'allow_comments' => 'true', 188 'timestamp' => $date, 189 'body' => $body, 190 'extended' => '', 191 'author' => $author, 192 'authorid' => $authorid 193 ); 194 195 echo "Entry insert...<br />"; 196 if (!is_int($id = serendipity_updertEntry($entry))) { 197 echo "Inserting entry failed.<br />"; 198 return $id; 199 } else { 200 echo "Entry $id inserted.<br />"; 201 } 202 203 # iterate through all comments 204 $c = 0; 205 foreach($commentlist[1] as $comment) { 206 $c++; 207 208 # locate the author and author url 209 $curl = ''; 210 $cauthor = ''; 211 $cdate = time(); 212 $cbody = ''; 213 214 if (preg_match("/AUTHOR:(.*)/", $comment, $cauthor) && preg_match("/href=\"(.*)\"/", $cauthor[1], $curl)) { 215 $curl = (isset($curl[1]) ? trim($curl[1]) : ''); 216 $cauthor = trim(strip_tags($cauthor[1])); 217 } 218 219 # locate the date 220 if (preg_match("/DATE:(.*)/", $comment, $cdate)) { 221 $cdate = strtotime($cdate[1]); 222 } 223 224 # locate the comment body 225 if (preg_match("/BODY:(.*)/s", $comment, $cbody)) { 226 $cbody = trim($cbody[1]); 227 } 228 229 $icomment = array('entry_id ' => $id, 230 'parent_id' => 0, 231 'timestamp' => $cdate, 232 'author' => $cauthor, 233 'email' => '', 234 'url' => $curl, 235 'ip' => '', 236 'status' => 'approved', 237 'body' => $cbody, 238 'subscribed'=> 'false', 239 'type' => 'NORMAL'); 240 241 serendipity_db_insert('comments', $icomment); 242 } 243 244 serendipity_db_query("UPDATE ". $serendipity['dbPrefix'] ."entries SET comments = ". $c ." WHERE id = ". $id); 245 echo "Comment count set to: ". $c ."<br />"; 246 } 247 248 echo "Import finished.<br />"; 249 250 return true; 251 } 252 } 253 254 return 'Serendipity_Import_Blogger'; 255 256 /* vim: set sts=4 ts=4 expandtab : */ 257 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Nov 24 09:00:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |