comment2cms

Unnamed repository; edit this file 'description' to name the repository.
git clone http://git.code.weiherhei.de/comment2cms.git
Log | Files | Refs

comment.php (2592B)


      1 <?php
      2 
      3 header('Content-Type: text/html; charset=utf-8');
      4 
      5 ?>
      6 
      7 <form method="post" action="">
      8   <input type="submit" value="Neue Kommentare verarbeiten abrufen">
      9 </form>
     10 
     11 <?php
     12 
     13 if	( $_SERVER['REQUEST_METHOD'] == 'POST' )
     14 {
     15 
     16 	if ($dh = opendir('./profiles'))
     17 	{
     18 		while (($file = readdir($dh)) !== false)
     19 		{
     20 			if	( substr($file,-4) == '.ini' )
     21 			{
     22 				$config = parse_ini_file('./profiles/'.$file,true);
     23 				
     24 				if	( !$config['enabled'] )
     25 						continue;
     26 				
     27 				$blogger = new Blogger();
     28 				if	( $config['debug'] ) echo "<h1>Profile: $file</h1>";
     29 				
     30 				$blogger->config = $config;
     31 				$blogger->debug = $config['debug'];
     32 				
     33 				echo "<h2>Step 1: Pulling</h2>";
     34 				$blogger->pull();
     35 				flush();
     36 				echo "<h2>Step 2: CMS</h2>";
     37 				$blogger->pushToCMS();
     38 				flush();
     39 			}
     40 		}
     41 		closedir($dh);
     42 	}
     43 }
     44 
     45 
     46 class Blogger {
     47 
     48 	public $debug = true;
     49 	public $config;
     50 	
     51 	private $blogs = array(); 
     52 	
     53 	public function pull()
     54 	{
     55 		if ($dh = opendir('./source'))
     56 		{
     57 			while (($file = readdir($dh)) !== false)
     58 			{
     59 				if	( substr($file,-4) == '.php' )
     60 				{
     61 					require_once('./source/'.$file);
     62 					$className = substr($file,0,strlen($file)-10);
     63 
     64 					if	( $this->debug )
     65 						echo "<h3>Source-Plugin: ".$className.'</h3>';
     66 
     67 					if	( isset($this->config[strtolower($className)] ))
     68 					{
     69 						$source = new $className;
     70 		
     71 						$source->config = $this->config[strtolower($className)];
     72 						$source->debug    = $this->debug;
     73 
     74 						foreach( $source->pull() as $blog )
     75 						{
     76 							$this->blogs[] = $blog;
     77 						}
     78 					}
     79 				}
     80 			}
     81 			closedir($dh);
     82 			
     83 			if	( $this->debug )
     84 			{
     85 				echo "<h3>Blogs</h3>";
     86 				echo '<pre>';
     87 				print_r($this->blogs);
     88 				echo '</pre>';
     89 			}
     90 		}
     91 	
     92 	}
     93 	
     94 	public function pushToCMS()
     95 	{
     96 		if ($dh = opendir('./cms'))
     97 		{
     98 			while (($file = readdir($dh)) !== false)
     99 			{
    100 				if	( substr($file,-4) == '.php' )
    101 				{
    102 					require_once('./cms/'.$file);
    103 					$className = substr($file,0,strlen($file)-10);
    104 						
    105 					if	( $this->debug )
    106 						echo "<h3>CMS-Plugin: ".$className.'</h3>';
    107 						
    108 					$cms = new $className;
    109 		
    110 					if	( isset($this->config[strtolower($className)] ))
    111 					{
    112 						$cms->config = $this->config[strtolower($className)];
    113 						
    114 						foreach( $this->blogs as $blog )
    115 						{
    116 							
    117 							$cms->text      = $blog['text'     ];
    118 							$cms->subject   = $blog['subject'  ];
    119 							$cms->name      = $blog['name'     ];
    120 							$cms->pageId    = $blog['pageid'   ];
    121 							$cms->timestamp = $blog['timestamp'];
    122 							$cms->debug     = $this->debug;
    123 							$cms->push();
    124 						}
    125 					}
    126 				}
    127 			}
    128 			closedir($dh);
    129 		}
    130 		
    131 	}
    132 }
    133 
    134 ?>