Advertisement
Guest User

processor.php

a guest
Aug 29th, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.80 KB | None | 0 0
  1. <?php
  2.  
  3. if (!class_exists('bg3giProcessor')){
  4.     class bg3giProcessor{
  5.    
  6.         private $csv ;
  7.  
  8.         function __construct()
  9.         {
  10.             $this->csv = new CSV("recordlist.csv");
  11.         }
  12.    
  13.         function ProcessOneLine()
  14.         {
  15.             global $nggdb ;
  16.        
  17.             if($record = $this->GetRecord())
  18.             {
  19.                 echo ("<br/>Processing line: ".$record."<br/>");
  20.                
  21.                 $record = explode ( ";" , $record) ;
  22.                 $path = 'wp-content/gallery/foto/' . $record[1] ; // "wp-content/gallery/prova123" ;
  23.                 $title = $record[0]; // "Galleria di Prova" ;
  24.                 $album = (int)(trim($record[2])) ;// 15
  25.                
  26.                
  27.                 if ($alb = $nggdb->find_album($album))
  28.                 {
  29.                     $galId = nggAdmin::import_gallery($path, true);
  30.                     echo ("Added gallery #".$galId."<br/>");
  31.                    
  32.                     if($gal = $nggdb->find_gallery($galId))
  33.                     {
  34.                         $nggdb->update_gallery($galId, false, false, $title, false, false, false, false) ;
  35.                         echo ("Set name ".$title."<br/>");
  36.                        
  37.                         if ($alb)
  38.                         {
  39.                             //add to album and committ
  40.  
  41.                             if(!is_array($alb->gallery_ids))
  42.                                 $alb->gallery_ids = array( $galId ) ;
  43.        
  44.                             if (!in_array($galId, $alb->gallery_ids))
  45.                                 array_push($alb->gallery_ids, $galId) ;
  46.                                
  47.                             $nggdb->update_album($album, false, false, false, serialize($alb->gallery_ids), false );
  48.                             echo "Updated album ".$alb->name."!<br/>";         
  49.                             echo "".$this->csv->Count()." album left!<br/>";       
  50.                         }
  51.                     }
  52.                     else
  53.                         echo "<br/>Error creating gallery #$galId!<br/>";
  54.                 }
  55.                 else
  56.                     echo "<br/>No album found for #$album!<br/>";
  57.             }
  58.             else
  59.                 echo "<br/>Nothing to do!<br/>";
  60.  
  61.             $this->DeleteRecord();
  62.         }
  63.  
  64.         function GetRecord()
  65.         {
  66.             //open CSV and
  67.             return $this->csv->GetLast();
  68.         }
  69.        
  70.         function DeleteRecord()
  71.         {
  72.             $this->csv->DeleteLast();
  73.             $this->csv->Save();
  74.         }
  75.  
  76.     }
  77. }
  78.  
  79. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement