Changeset 624
- Timestamp:
- 07/16/06 15:38:43 (2 years ago)
- Location:
- sandbox/plugins/BlogAPI
- Files:
-
- 3 modified
-
blogger.php (modified) (1 diff)
-
index.php (modified) (9 diffs)
-
metaweblog.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sandbox/plugins/BlogAPI/blogger.php
r604 r624 139 139 } 140 140 141 function _get_post( $post, $type = "bl" )142 {143 DEBUG( "Enter: " . __FUNCTION__ . "\n" );144 $params = func_get_args();145 global $service, $hostURL, $blogURL;146 return array(147 "userid" => "",148 "dateCreated" => _dateiso8601( $post->created ),149 "datePosted" => _dateiso8601( $post->published ),150 "dateModified" => _dateiso8601( $post->modified ),151 "title" => _escape_content($post->title),152 "postid" => $post->id,153 "categories" => array( _getCategoryNameById($post->category) ),154 "link" => $hostURL . $blogURL . "/" . $post->id ,155 "permaLink" => $hostURL . $blogURL . "/" . $post->id ,156 "description" => ($type == "mt" ? $post->content : "" ),157 "content" => $post->content158 );159 }160 161 141 function blogger_getRecentPosts() 162 142 { -
sandbox/plugins/BlogAPI/index.php
r604 r624 41 41 if( TATTERTOOLS_VERSION < "1.0.6" && file_exists( $blogapi_dir . "/$name.php" ) ) 42 42 { 43 include_once ( $blogapi_dir . "/$name.php"); 43 DEBUG ( $blogapi_dir . "/$name.php\n"); 44 include_once( $blogapi_dir . "/$name.php"); 44 45 } 45 46 else 46 47 { 47 include_once ( $blogapi_dir . "/../../components/$name.php"); 48 $componet_file = $blogapi_dir . "/../../components/$name.php"; 49 if( file_exists( $componet_file ) ) 50 { 51 include_once( $componet_file ); 52 } 53 else 54 { 55 print( "File($componet_file) doesn't exist\n" ); 56 } 48 57 } 49 58 } … … 243 252 return $name; 244 253 254 } 255 256 function _make_post( $param, $ispublic, $postid = -1 ) 257 { 258 $post = new Post(); 259 if( $postid != -1 ) 260 { 261 if( !$post->open( $postid ) ) 262 { 263 return false; 264 } 265 } 266 267 $post->content = $param['description']; 268 $post->title = $param['title']; 269 $post->tags = array_merge( split(",", $param['mt_excerpt']) , $param['tagwords'] ); 270 271 $post->created = _timestamp( $param['dateCreated'] ); 272 $post->modified = _timestamp( $param['dateCreated'] ); 273 274 $post->category = _getCategoryIdByName( $param['categories'] ); 275 $post->acceptComment = $param['mt_allow_comments'] !== 0 ? true : false; 276 $post->acceptTrackback = $param['mt_allow_pings'] !== 0 ? true : false; 277 278 if( $ispublic ) 279 { 280 $post->visibility = "public"; 281 $post->published = _timestamp( $param['dateCreated'] ); 282 } 283 else 284 { 285 $post->visibility = "private"; 286 } 287 288 return $post; 289 } 290 291 function _get_post( $post, $type = "bl" ) 292 { 293 DEBUG( "Enter: " . __FUNCTION__ . "\n" ); 294 $post->loadTags(); 295 DEBUG( "Post " ); 296 DEBUG( $post, true ); 297 $params = func_get_args(); 298 global $service, $hostURL, $blogURL; 299 return array( 300 "userid" => "", 301 "dateCreated" => _dateiso8601( $post->created ), 302 "datePosted" => _dateiso8601( $post->published ), 303 "dateModified" => _dateiso8601( $post->modified ), 304 "title" => _escape_content($post->title), 305 "postid" => $post->id, 306 "categories" => array( _getCategoryNameById($post->category) ), 307 "link" => $hostURL . $blogURL . "/" . $post->id , 308 "permaLink" => $hostURL . $blogURL . "/" . $post->id , 309 "description" => ($type == "mt" ? $post->content : "" ), 310 "content" => $post->content, 311 "mt_allow_comments" => $post->acceptComment ? 1 : 0, 312 "mt_allow_pings" => $post->acceptTrackback ? 1 : 0, 313 "mt_excerpt" => join( ",", $post->tags ) 314 ); 245 315 } 246 316 … … 317 387 } 318 388 389 390 function _file_hash( $content ) 391 { 392 $md5sum = md5( $content ); 393 return sprintf( "ta%stt%ser%s", substr( $md5sum, 0, 7 ), substr( $md5sum, 7, 7 ), substr( $md5sum, 14, 7 ) ); 394 } 395 396 319 397 function addAttachment($owner,$parent,$file){ 320 398 global $database; … … 342 420 break; 343 421 } 422 423 /* Create directory for owner */ 344 424 $path="../../attach/$owner"; 345 425 if(!is_dir($path)){ … … 349 429 @chmod($path,0777); 350 430 } 351 do{ 352 $attachment['name']=rand(1000000000,9999999999).".$extension"; 353 $attachment['path']="$path/{$attachment['name']}"; 354 }while(file_exists($attachment['path'])); 355 356 /* Fixed by coolengineer */ 431 432 /* Select unique file name from md5sum of content */ 433 $attachment['name'] = _file_hash( $file['content'] ) . ".$extension"; 434 $attachment['path'] = "$path/{$attachment['name']}"; 435 436 DEBUG("\nCHECK " . __LINE__ ); 437 deleteAttachment($owner,-1,$attachment['name']); 438 DEBUG("\nCHECK " . __LINE__ ); 439 357 440 if( $file['content'] ) 358 441 { … … 362 445 return false; 363 446 } 364 DEBUG( "Length 1: " . $attachment['size'] . "\n");365 447 $attachment['size'] = fwrite( $f, $file['content'] ); 366 DEBUG( "Length 2: " . $attachment['size'] . "\n");367 448 fclose( $f ); 368 449 $file['tmp_name'] = $attachment['path']; … … 382 463 return false; 383 464 */ 465 DEBUG("\nCHECK " . __LINE__ ); 384 466 @chmod($attachment['path'],0666); 467 DEBUG( "\ninsert into {$database['prefix']}Attachments values ($owner, {$attachment['parent']}, '{$attachment['name']}', '$label', '{$attachment['mime']}', {$attachment['size']}, {$attachment['width']}, {$attachment['height']}, UNIX_TIMESTAMP(), 0,0)"); 385 468 $result=mysql_query("insert into {$database['prefix']}Attachments values ($owner, {$attachment['parent']}, '{$attachment['name']}', '$label', '{$attachment['mime']}', {$attachment['size']}, {$attachment['width']}, {$attachment['height']}, UNIX_TIMESTAMP(), 0,0)"); 386 469 if(!$result){ 470 DEBUG("\nCHECK " . __LINE__ ); 387 471 @unlink($attachment['path']); 388 472 return false; 389 473 } 474 DEBUG("\nCHECK " . __LINE__ ); 390 475 return $attachment; 391 476 } 477 392 478 393 479 /* Up to here, copied from blog/owner/entry/attach/index.php */ … … 406 492 global $database, $blogapi_dir; 407 493 @unlink("$blogapi_dir/../../attach/$owner/$name"); 408 if($parent===false){ 494 $name=mysql_escape_string($name); 495 $parent_clause = ""; 496 if( $parent >= 0 ) 497 { 498 $parent_clause = "parent = $parent and "; 499 } 500 DEBUG("\ndelete from {$database['prefix']}Attachments where owner = $owner and $parent_clause name = '$name'"); 501 if(mysql_query("delete from {$database['prefix']}Attachments where owner = $owner and $parent_clause name = '$name'")&&(mysql_affected_rows()==1)){ 409 502 return true; 410 503 } 411 $name=mysql_escape_string($name); 412 if(mysql_query("delete from {$database['prefix']}Attachments where owner = $owner and parent = $parent and name = '$name'")&&(mysql_affected_rows()==1)){ 413 return true; 414 } 504 DEBUG("\nDelete failure: " . mysql_error() ); 415 505 return false; 416 506 } … … 429 519 /* Work around end */ 430 520 431 function preview_encode( $owner, $name ) 432 { 433 return "?__preview__{" . $owner . "," . $name . "}"; 434 } 435 436 function preview_decode_core( $content ) 437 { 438 if( preg_match( "/\?__preview__{([^,]+),([^}]+)}/", $content, $matches ) ) 439 { 440 return array( $matches[1], $matches[2] ); 441 } 442 return false; 443 } 444 445 function preview_decode( $content, $parent ) 521 function _get_attaches( $content, $parent ) 446 522 { 447 523 global $owner; 448 $attaches = array(); 449 while( list($o,$n) = preview_decode_core($content) ) 450 { 451 DEBUG("Owner: $o, Name $n\n" ); 452 array_push( $attaches, array( $o, $n ) ); 453 $content = preg_replace( "/\?__preview__[^}]+}/", "", $content, 1 ); 454 } 455 DEBUG( $attaches, true ); 456 return array( $content, $attaches ); 457 } 458 459 function fixAttachments( $attaches, $parent ) 524 preg_match_all( "/attach\/$owner\/(ta.{7}tt.{7}er.{7}\.[a-z]{2,5})/", $content, $matches ); 525 DEBUG( $matches[1], true ); 526 return $matches[1]; 527 } 528 529 function _update_attaches( $attaches, $parent ) 460 530 { 461 531 global $database, $owner; 462 deleteAttachments( $owner, $parent );463 532 foreach( $attaches as $att ) 464 533 { 465 if( $att[0] == $owner ) 466 { 467 DEBUG( "update {$database['prefix']}Attachments set parent=$parent where owner=$owner and parent=0 and name='" . $att[1] . "'\n"); 468 mysql_query( "update {$database['prefix']}Attachments set parent=$parent where owner=$owner and parent=0 and name='" . $att[1] . "'"); 469 } 534 DEBUG( "update {$database['prefix']}Attachments set parent=$parent where owner=$owner and parent=0 and name='" . $att . "'\n"); 535 mysql_query( "update {$database['prefix']}Attachments set parent=$parent where owner=$owner and parent=0 and name='" . $att . "'"); 470 536 } 471 537 } -
sandbox/plugins/BlogAPI/metaweblog.php
r604 r624 19 19 20 20 $cat = array(); 21 while( 1)21 while($category->id) 22 22 { 23 23 DEBUG( " Category: " . $category->name . "\n" ); … … 139 139 } 140 140 141 $post = new Post(); 142 $post->content = $params[3]['description']; 143 $post->title = $params[3]['title']; 144 $post->tags = join( ',', $params[3]['mt_keywords'] ); 145 $post->created = _timestamp( $params[3]['dateCreated'] ); 146 $post->modified = _timestamp( $params[3]['dateCreated'] ); 147 $post->published = _timestamp( $params[3]['dateCreated'] ); 148 $post->category = _getCategoryIdByName( $params[3]['categories'] ); 149 150 if( $params[4] ) 151 { 152 $post->visibility = "public"; 153 } 154 else 155 { 156 $post->visibility = "private"; 157 } 158 159 list( $post->content, $attaches ) = preview_decode( $post->content ); 141 $post = _make_post( $params[3], $params[4] ); 142 143 $attaches = _get_attaches( $post->content ); 160 144 161 145 if( !$post->add() ) … … 163 147 $post->close(); 164 148 DEBUG( "Adding failure." ); 165 return XMLRPCFault( 1, " Posting error" );166 } 167 168 fixAttachments( $attaches, $post->id );149 return XMLRPCFault( 1, "Tattertools posting error" ); 150 } 151 152 _update_attaches( $attaches, $post->id ); 169 153 RSS::refresh(); 170 154 … … 249 233 } 250 234 251 $post = new Post(); 252 if( !$post->open( $params[0] ) ) 253 { 254 return XMLRPCFault( 1, "Posting error" ); 255 } 256 257 $post->content = $params[3]['description']; 258 $post->title = $params[3]['title']; 259 $post->tags = join( ',', $params[3]['categories'] ); 260 $post->modified = _timestamp( $params[3]['dateCreated'] ); 261 262 list( $post->content, $attaches ) = preview_decode( $post->content ); 263 264 if( $params[4] ) 265 { 266 $post->visibility = "public"; 267 $post->published = _timestamp( $params[3]['dateCreated'] ); 268 } 269 else 270 { 271 $post->visibility = "private"; 272 } 235 $post = _make_post( $params[3], $params[4], $params[0] ); 236 if( !$post ) 237 { 238 return XMLRPCFault( 1, "Tattertools editing error" ); 239 } 240 241 $attaches = _get_attaches( $post->content ); 273 242 274 243 $ret = $post->update(); 275 244 276 fixAttachments( $attaches, $post->id );245 _update_attaches( $attaches, $post->id ); 277 246 RSS::refresh(); 278 247 … … 319 288 return new XMLRPCFault( 1, "Can't create file" ); 320 289 } 321 return array ( 'url' => getBlogURL() . "/attach/$owner/" . $attachment['name'] . preview_encode( $owner, $attachment['name'] ) ); 290 $attachurl = array ( 'url' => getBlogURL() . "/attach/$owner/" . $attachment['name'] ); 291 DEBUG( "\nAttached url : " ); 292 DEBUG( $attachurl, true ); 293 return $attachurl; 322 294 } 323 295 ?>
