commit 4a73e501f15c0eeee3500b7a2cf9f9c089601dc2
parent 8b3853172ebeb8cfe84420d837d4050cdb590ff5
Author: dankert <devnull@localhost>
Date: Sun, 6 Jul 2014 12:48:15 +0200
Umfangreicher Umbau auf Plugin-System.
Diffstat:
16 files changed, 1115 insertions(+), 359 deletions(-)
diff --git a/blog.php b/blog.php
@@ -0,0 +1,213 @@
+<?php
+
+
+if ($dh = opendir('./profiles'))
+{
+ while (($file = readdir($dh)) !== false)
+ {
+ if ( substr($file,-4) == '.ini' )
+ {
+ $config = parse_ini_file('./profiles/'.$file,true);
+
+ if ( !$config['enabled'] )
+ continue;
+
+ $blogger = new Blogger();
+ if ( $config['debug'] ) echo "<h2>Profile: $file</h2>";
+
+ $blogger->config = $config;
+ $blogger->debug = $config['debug'];
+
+ $blogger->pull();
+ $blogger->pushToCMS();
+ $blogger->pushToNetwork();
+ }
+ }
+ closedir($dh);
+}
+
+
+
+class Blogger {
+
+ public $debug = true;
+ public $config;
+
+ private $blogs = array();
+
+ public function pull()
+ {
+ if ($dh = opendir('./source'))
+ {
+ while (($file = readdir($dh)) !== false)
+ {
+ if ( substr($file,-4) == '.php' )
+ {
+ require_once('./source/'.$file);
+ $className = substr($file,0,strlen($file)-10);
+
+ if ( $this->debug )
+ echo "<h3>Source-Plugin: ".$className.'</h3>';
+
+ if ( isset($this->config[strtolower($className)] ))
+ {
+ $source = new $className;
+
+ $source->config = $this->config[strtolower($className)];
+ $source->debug = $this->debug;
+
+ foreach( $source->pull() as $blog )
+ {
+ $blog['filename'] = $this->createPageFilename($blog['subject']);
+ $d = isset($blog['timestamp'])?$blog['timestamp']:time();
+
+ switch( $this->config['urlschema' ])
+ {
+ case 'flat':
+ $blog['path'] = array();
+ break;
+ case 'yearly':
+ $blog['path'] = array( date('Y',$d) );
+ break;
+ case 'monthly':
+ $blog['path'] = array( date('Y',$d),date('m',$d) );
+ break;
+ case 'daily':
+ default:
+ $blog['path'] = array( date('Y',$d),date('m',$d),date('d',$d) );
+ break;
+ }
+ $blog['url' ] = 'http://'.$this->config['hostname'].'/'.implode('/',$blog['path']).'/'.$blog['filename'];
+ $blog['shortUrl'] = $this->createShortUrl($blog['url']);
+
+ $this->blogs[] = $blog;
+ }
+ }
+ }
+ }
+ closedir($dh);
+
+ if ( $this->debug )
+ {
+ echo "<h3>Blogs</h3>";
+ echo '<pre>';
+ print_r($this->blogs);
+ echo '</pre>';
+ }
+ }
+
+ }
+
+ public function pushToCMS()
+ {
+ if ($dh = opendir('./cms'))
+ {
+ while (($file = readdir($dh)) !== false)
+ {
+ if ( substr($file,-4) == '.php' )
+ {
+ require_once('./cms/'.$file);
+ $className = substr($file,0,strlen($file)-10);
+
+ if ( $this->debug )
+ echo "<h3>CMS-Plugin: ".$className.'</h3>';
+
+ $cms = new $className;
+
+ if ( isset($this->config[strtolower($className)] ))
+ {
+ $cms->config = $this->config[strtolower($className)];
+
+ foreach( $this->blogs as $blog )
+ {
+
+ $cms->url = $blog['url'];
+ $cms->shortUrl = $blog['shortUrl'];
+ $cms->text = $blog['text'];
+ $cms->subject = $blog['subject'];
+ $cms->filenames = $blog['filenames'];
+ $cms->filename = $blog['filename'];
+ $cms->path = $blog['path'];
+ $cms->keywords = $blog['keywords'];
+ $cms->debug = $this->debug;
+ $cms->push();
+ }
+ }
+ }
+ }
+ closedir($dh);
+ }
+
+ }
+
+
+ public function pushToNetwork()
+ {
+ if ($dh = opendir('./network'))
+ {
+ while (($file = readdir($dh)) !== false)
+ {
+ if ( substr($file,-4) == '.php' )
+ {
+ require_once('./network/'.$file);
+ $className = substr($file,0,strlen($file)-10);
+
+ if ( $this->debug )
+ echo "Network-Plugin: "+$className;
+
+ if ( isset($this->config[strtolower($className)] ))
+ {
+ $network = new $className;
+
+ $network->config = $this->config[strtolower($className)];
+
+ foreach( $this->blogs as $blog )
+ {
+ $network->url = $blog['url'];
+ $network->shortUrl = $blog['shortUrl'];
+ $network->text = $blog['text'];
+ $network->subject = $blog['subject'];
+ $network->debug = $this->debug;
+ $network->push();
+ }
+ }
+ }
+ }
+ closedir($dh);
+ }
+
+ }
+
+
+ private function createShortUrl( $url )
+ {
+ $su = file_get_contents('http://l.jdhh.de/?url='.$url);
+ $doc = json_decode($su,true);
+
+ return 'http://l.jdhh.de/'.$doc['short_url'];
+ }
+
+
+ private function createPageFilename( $title )
+ {
+ $title = strtolower(trim($title));
+ $title = strtr($title, array(
+ ' ' => '-',
+ 'ä' => 'ae',
+ 'Ä' => 'ae',
+ 'ö' => 'oe',
+ 'Ö' => 'oe',
+ 'ü' => 'ue',
+ 'Ü' => 'ue',
+ 'ß' => 'ss',
+ '_' => '-' ) );
+
+ $gueltig = 'abcdefghijklmnopqrstuvwxyz0123456789-';
+ $tmp = strtr($title, $gueltig, str_repeat('#', strlen($gueltig)));
+ $title = strtr($title, $tmp, str_repeat('-', strlen($tmp)));
+
+ return $title;
+ }
+}
+
+?>+
\ No newline at end of file
diff --git a/client/OpenratClient.php b/client/OpenratClient.php
@@ -1,122 +0,0 @@
-<?php
-
-class OpenratClient
-{
- public $error = '';
- public $status = '';
-
- public $host;
- public $port;
- public $path;
- public $method = 'GET';
- public $response;
- public $parameter = array();
- public $type = "text/json";
- public $cookie = "";
-
- public function request()
- {
- $errno = 0;
- $errstr = '';
-
- // Die Funktion fsockopen() erwartet eine Protokollangabe (bei TCP optional, bei SSL notwendig).
- if ( $this->port == '443' )
- $prx_proto = 'ssl://'; // SSL
- else
- $prx_proto = 'tcp://'; // Default
-
- $fp = fsockopen($prx_proto.$this->host,$this->port, $errno, $errstr, 30);
-
- if ( !$fp || !is_resource($fp) )
- {
- $this->error = "Connection refused: '".$prx_proto.$host.':'.$port." - $errstr ($errno)";
- }
- else
- {
- $lb = "\r\n";
- $http_get = $this->path;
-
- $parameterString = '';
-
- foreach( $this->parameter as $pkey=>$pvalue)
- {
- if ( strlen($parameterString) > 0)
- $parameterString .= '&';
-
- $parameterString .= urlencode($pkey) . '=' .urlencode($pvalue);
- }
- //print_r($parameterString);
-
- if ( $this->method == 'GET')
- if ( !empty($parameterString) )
- $http_get .= '?'.$parameterString;
-
- if ( $this->method == 'POST' )
- {
- $header[] = 'Content-Type: application/x-www-form-urlencoded';
- $header[] = 'Content-Length: '.strlen($parameterString);
- }
-
- $header[] = 'Host: '.$this->host;
- $header[] = 'Accept: '.$this->type;
- $header[] = 'Cookie: '.$this->cookie;
- $request_header = array_merge(array( $this->method.' '.$http_get.' HTTP/1.0'),$header);
- //print_r($request_header);
- $http_request = implode($lb,$request_header).$lb.$lb;
-
-
- if ( $this->method == 'POST' )
- $http_request .= $parameterString;
-
- //echo "<textarea>".htmlentities($http_request)."</textarea>";
-
- if (!is_resource($fp)) {
- $error = 'Connection lost after connect: '.$prx_proto.$host.':'.$port;
- return false;
- }
- fputs($fp, $http_request); // Die HTTP-Anfrage zum Server senden.
-
- // Jetzt erfolgt das Auslesen der HTTP-Antwort.
- $isHeader = true;
-
- // RFC 1945 (Section 6.1) schreibt als Statuszeile folgendes Format vor
- // "HTTP/" 1*DIGIT "." 1*DIGIT SP 3DIGIT SP
- if (!is_resource($fp)) {
- echo 'Connection lost during transfer: '.$host.':'.$port;
- }
- elseif (!feof($fp)) {
- $line = fgets($fp,1028);
- $this->status = substr($line,9,3);
- }
- else
- {
- echo 'Unexpected EOF while reading HTTP-Response';
- }
-
- $body = '';
-
- while (!feof($fp)) {
- $line = fgets($fp,1028);
- if ( $isHeader && trim($line)=='' ) // Leerzeile nach Header.
- {
- $isHeader = false;
- }
- elseif( $isHeader )
- {
- list($headerName,$headerValue) = explode(': ',$line) + array(1=>'');
- //if ( $headerName == 'Set-Cookie' )
- // $this->cookie = $headerValue;
- $responseHeader[$headerName] = trim($headerValue);
- }
- else
- {
- $body .= $line;
- }
- }
- fclose($fp); // Verbindung brav schliessen.
- $this->response = $body;
- }
- }
-}
-
-?>-
\ No newline at end of file
diff --git a/cms/OpenRat.class.php b/cms/OpenRat.class.php
@@ -0,0 +1,266 @@
+<?php
+
+
+class OpenRat {
+
+ public $text = '';
+ public $filenames = array();
+ public $filename;
+ public $subject;
+ public $keywords = array();
+ public $shortUrl;
+ public $path;
+ public $debug = true;
+ public $config;
+
+ private $client;
+
+ private function request( $method,$parameter )
+ {
+
+ $this->client->parameter = $parameter;
+ $this->client->method = $method;
+ $this->client->request();
+
+ if ( $this->client->status != '200' || $this->debug)
+ {
+ echo '<span style="background-color:'.($this->client->status=='200'?'green':'red').'">HTTP-Status '.$this->client->status.'</span>';
+ }
+
+ if ( $this->debug )
+ {
+ echo "<h4>".$parameter['action'].'/'.$parameter['subaction'].'</h4>';
+ ?><pre><?php print_r($this->client); ?></pre><?php
+ }
+
+ $response = json_decode($this->client->response,true);
+
+ if ( $response == null )
+ {
+ echo '<span style="background-color:red">Kein JSON: <pre>'.htmlentities($this->client->response).'</pre></span>';
+ exit;
+ }
+
+ return $response;
+ }
+
+
+ public function push()
+ {
+ require_once('./cms/openrat/OpenratClient.php');
+ $this->client = new OpenratClient();
+
+ /*
+ *
+ if (!isset($_SERVER['PHP_AUTH_USER'])) {
+ header('WWW-Authenticate: Basic realm="Blog Upload"');
+ header('HTTP/1.0 401 Unauthorized');
+ echo 'sorry, authentication required to blog something';
+ exit;
+ }
+ */
+
+ $username = $this->config['user'];
+ $password = $this->config['password'];
+
+ $this->client->host = $this->config['host'];
+ $this->client->port = $this->config['port'];
+ $this->client->path = $this->config['path'];
+ $this->client->type ="application/json";
+
+
+ $response = $this->request( 'GET',
+ array('action' =>'login',
+ 'subaction'=>'login') );
+
+ $token = $response['session']['token'];
+ $this->client->cookie =$response['session']['name'].'='.$response['session']['id'];
+
+
+ $response = $this->request( 'POST', array(
+ 'action' => 'login',
+ 'subaction' => 'login',
+ 'token' => $token,
+ 'dbid' => $this->config['database'],
+ 'login_name' => $username,
+ 'login_password'=> $password ) );
+
+ $this->client->cookie =$response['session']['name'].'='.$response['session']['id'];
+ $token = $response['session']['token'];
+
+
+ // PRojekt auswählen
+ $response = $this->request( 'POST', array(
+ 'action' => 'start',
+ 'subaction' => 'projectmenu',
+ 'token' => $token,
+ 'id' => $this->config['projectid']) );
+
+
+ // Ordner laden.
+ $rootfolderid = $this->config['rootfolderid'];
+ $folderid = $rootfolderid;
+
+ foreach( $this->path as $foldername )
+ {
+ $response = $this->request( 'GET', array
+ (
+ 'action' => 'folder',
+ 'subaction' => 'edit',
+ 'id' => $folderid
+ ) );
+
+ // Prüfen, ob der nächste Unterordner bereits existiert.
+ $nextfolderid = null;
+ foreach( $response['output']['object'] as $objectid=>$object )
+ {
+ if ( $object['name'] == $foldername )
+ {
+ $nextfolderid = $objectid;
+ break;
+ }
+ }
+ if ( empty($nextfolderid) )
+ {
+ // Der nächste Unterordner existiert noch nicht, also müssen wir diesen anlegen.
+ $responseCreate = $this->request( 'POST', array
+ (
+ 'action' => 'folder',
+ 'subaction' => 'createfolder',
+ 'id' => $folderid,
+ 'token' => $token,
+ 'name' => $foldername
+ ) );
+ $nextfolderid = $responseCreate['output']['objectid'];
+ }
+ $folderid = $nextfolderid;
+ }
+
+ // Ein Unterordner pro Blogeintrag.
+ $responseCreate = $this->request( 'POST', array
+ (
+ 'action' => 'folder',
+ 'subaction' => 'createfolder',
+ 'id' => $folderid,
+ 'token' => $token,
+ 'name' => $this->filename
+ ) );
+ $folderid = $responseCreate['output']['objectid'];
+
+ // Seite anlegen.
+ $response = $this->request( 'POST', array
+ (
+ 'action' => 'folder',
+ 'subaction' => 'createpage',
+ 'id' => $folderid,
+ 'templateid' => $this->config['templateid'],
+ 'token' => $token,
+ 'name' => $this->subject,
+ 'filename' => 'index'
+ ) );
+ $pageobjectid = $response['output']['objectid'];
+
+ /*
+ *
+ // Ggf. Datei anlegen.
+ $response = $this->request( 'POST', array
+ (
+ 'action' => 'folder',
+ 'subaction' => 'createfile',
+ 'token' => $token,
+ 'name' => $title,
+ 'filename' => $title
+ ) );
+ $pageobjectid = $response['objectid'];
+ */
+
+ // Text speichern anlegen.
+ $response = $this->request( 'POST', array
+ (
+ 'action' => 'pageelement',
+ 'subaction' => 'edit',
+ 'id' => $pageobjectid,
+ 'elementid' => $this->config['elementid_text'],
+ 'token' => $token,
+ 'release' => '1',
+ 'text' => $this->text
+ ) );
+
+ foreach( $this->filenames as $file )
+ {
+ // Datei anlegen.
+ $response = $this->request( 'POST', array
+ (
+ 'action' => 'folder',
+ 'subaction' => 'createfile',
+ 'id' => $folderid,
+ 'token' => $token,
+ 'name' => $file['name'],
+ 'filename' => basename($file['filename'])
+ ) );
+ $fileobjectid = $response['output']['objectid'];
+
+ // Datei-Inhalt hochladen.
+ $response = $this->request( 'POST', array
+ (
+ 'action' => 'file',
+ 'subaction' => 'value',
+ 'id' => $fileobjectid,
+ 'token' => $token,
+ 'value' => file_get_contents($file['filename'])
+ ) );
+
+ }
+
+ // Keywords
+ foreach( $this->keywords as $keyword )
+ {
+ $response = $this->request( 'GET', array
+ (
+ 'action' => 'folder',
+ 'subaction' => 'edit',
+ 'id' => $this->config['keywords_folderid']
+ ) );
+
+ // Prüfen, ob das Keyword schon existiert
+ $keyword_folderid = null;
+ foreach( $response['output']['object'] as $objectid=>$object )
+ {
+ if ( $object['name'] == $keyword )
+ {
+ $keyword_folderid = $objectid;
+ break;
+ }
+ }
+ if ( empty($keyword_folderid) )
+ {
+ // Der Keyword-Ordner existiert noch nicht, also müssen wir diesen anlegen.
+ $responseCreate = $this->request( 'POST', array
+ (
+ 'action' => 'folder',
+ 'subaction' => 'createfolder',
+ 'id' => $this->config['keywords_folderid'],
+ 'token' => $token,
+ 'name' => $keyword
+ ) );
+ $keyword_folderid = $responseCreate['output']['objectid'];
+ }
+
+ $responseCreate = $this->request( 'POST', array
+ (
+ 'action' => 'folder',
+ 'subaction' => 'createlink',
+ 'id' => $keyword_folderid,
+ 'token' => $token,
+ 'name' => $this->subject,
+ 'filename' => $this->filename,
+ 'targetobjectid'=> $pageobjectid
+ ) );
+
+ }
+ }
+
+
+}
+
+?>+
\ No newline at end of file
diff --git a/cms/openrat/OpenratClient.php b/cms/openrat/OpenratClient.php
@@ -0,0 +1,122 @@
+<?php
+
+class OpenratClient
+{
+ public $error = '';
+ public $status = '';
+
+ public $host;
+ public $port;
+ public $path;
+ public $method = 'GET';
+ public $response;
+ public $parameter = array();
+ public $type = "text/json";
+ public $cookie = "";
+
+ public function request()
+ {
+ $errno = 0;
+ $errstr = '';
+
+ // Die Funktion fsockopen() erwartet eine Protokollangabe (bei TCP optional, bei SSL notwendig).
+ if ( $this->port == '443' )
+ $prx_proto = 'ssl://'; // SSL
+ else
+ $prx_proto = 'tcp://'; // Default
+
+ $fp = fsockopen($prx_proto.$this->host,$this->port, $errno, $errstr, 30);
+
+ if ( !$fp || !is_resource($fp) )
+ {
+ $this->error = "Connection refused: '".$prx_proto.$host.':'.$port." - $errstr ($errno)";
+ }
+ else
+ {
+ $lb = "\r\n";
+ $http_get = $this->path;
+
+ $parameterString = '';
+
+ foreach( $this->parameter as $pkey=>$pvalue)
+ {
+ if ( strlen($parameterString) > 0)
+ $parameterString .= '&';
+
+ $parameterString .= urlencode($pkey) . '=' .urlencode($pvalue);
+ }
+ //print_r($parameterString);
+
+ if ( $this->method == 'GET')
+ if ( !empty($parameterString) )
+ $http_get .= '?'.$parameterString;
+
+ if ( $this->method == 'POST' )
+ {
+ $header[] = 'Content-Type: application/x-www-form-urlencoded';
+ $header[] = 'Content-Length: '.strlen($parameterString);
+ }
+
+ $header[] = 'Host: '.$this->host;
+ $header[] = 'Accept: '.$this->type;
+ $header[] = 'Cookie: '.$this->cookie;
+ $request_header = array_merge(array( $this->method.' '.$http_get.' HTTP/1.0'),$header);
+ //print_r($request_header);
+ $http_request = implode($lb,$request_header).$lb.$lb;
+
+
+ if ( $this->method == 'POST' )
+ $http_request .= $parameterString;
+
+ //echo "<textarea>".htmlentities($http_request)."</textarea>";
+
+ if (!is_resource($fp)) {
+ $error = 'Connection lost after connect: '.$prx_proto.$host.':'.$port;
+ return false;
+ }
+ fputs($fp, $http_request); // Die HTTP-Anfrage zum Server senden.
+
+ // Jetzt erfolgt das Auslesen der HTTP-Antwort.
+ $isHeader = true;
+
+ // RFC 1945 (Section 6.1) schreibt als Statuszeile folgendes Format vor
+ // "HTTP/" 1*DIGIT "." 1*DIGIT SP 3DIGIT SP
+ if (!is_resource($fp)) {
+ echo 'Connection lost during transfer: '.$host.':'.$port;
+ }
+ elseif (!feof($fp)) {
+ $line = fgets($fp,1028);
+ $this->status = substr($line,9,3);
+ }
+ else
+ {
+ echo 'Unexpected EOF while reading HTTP-Response';
+ }
+
+ $body = '';
+
+ while (!feof($fp)) {
+ $line = fgets($fp,1028);
+ if ( $isHeader && trim($line)=='' ) // Leerzeile nach Header.
+ {
+ $isHeader = false;
+ }
+ elseif( $isHeader )
+ {
+ list($headerName,$headerValue) = explode(': ',$line) + array(1=>'');
+ //if ( $headerName == 'Set-Cookie' )
+ // $this->cookie = $headerValue;
+ $responseHeader[$headerName] = trim($headerValue);
+ }
+ else
+ {
+ $body .= $line;
+ }
+ }
+ fclose($fp); // Verbindung brav schliessen.
+ $this->response = $body;
+ }
+ }
+}
+
+?>+
\ No newline at end of file
diff --git a/config.ini b/config.ini
@@ -1,21 +0,0 @@
-
-
-[server]
-
-host="duese"
-port="80"
-path="/~dankert/cms/cms09/dispatcher.php"
-database="pg_prod"
-
-
-[project]
-
-projectid=13
-languageid=19
-rootfolderid=5145
-; daily|monthly|yearly|flat
-urlschema=daily
-templateid=23
-
-elementid_text=69
-elementid_image=
diff --git a/index.php b/index.php
@@ -1,215 +0,0 @@
-<?php
-
-$config = parse_ini_file('./config.ini',true);
-
-require('./client/OpenratClient.php');
-$client = new OpenratClient();
-
-if (!isset($_SERVER['PHP_AUTH_USER'])) {
- header('WWW-Authenticate: Basic realm="Blog Upload"');
- header('HTTP/1.0 401 Unauthorized');
- echo 'sorry, authentication required to blog something';
- exit;
-}
-
-$username = $_SERVER['PHP_AUTH_USER'];
-$password = $_SERVER['PHP_AUTH_PW'];
-
-function request( $client,$method,$parameter )
-{
- echo "<hr />";
- $client->parameter = $parameter;
- $client->method = $method;
- $client->request();
- $response = json_decode($client->response,true);
- ?><pre><?php print_r($client); ?></pre><?php
- if ( $client->status != '200')
- {
- echo '<span style="background-color:'.($client->status=='200'?'green':'red').'">HTTP-Status '.$client->status.'</span>';
- }
- return $response;
-}
-
-
-?>
-
-<html>
-<head>
-<title>Blog Form</title>
-</head>
-<body>
-
-<?php if ( !empty($_POST['text']) ) {
-
- ?><h1>Result</h1><?php
-
- $client->host = $config['server']['host'];
- $client->port = $config['server']['port'];
- $client->path = $config['server']['path'];
- $client->type ="application/json";
-
-
- $response = request( $client,'GET',
- array('action' =>'login',
- 'subaction'=>'login') );
-
- $token = $response['session']['token'];
- $client->cookie =$response['session']['name'].'='.$response['session']['id'];
-
-
- $response = request( $client,'POST', array(
- 'action' => 'login',
- 'subaction' => 'login',
- 'token' => $token,
- 'dbid' => $config['server']['database'],
- 'login_name' => $username,
- 'login_password'=> $password ) );
-
- $client->cookie =$response['session']['name'].'='.$response['session']['id'];
- $token = $response['session']['token'];
-
-
- // PRojekt auswählen
- $response = request( $client,'POST', array(
- 'action' => 'start',
- 'subaction' => 'projectmenu',
- 'token' => $token,
- 'id' => $config['project']['projectid']) );
-
-
- // Ordner laden.
- $rootfolderid = $config['project']['rootfolderid'];
- $urlschema = $config['project']['urlschema' ];
-
- $folderid = $rootfolderid;
-
- switch( $urlschema )
- {
- case 'flat':
- $foldernames = array();
- break;
- case 'yearly':
- $foldernames = array( date('Y') );
- break;
- case 'monthly':
- $foldernames = array( date('Y'),date('m') );
- break;
- case 'daily':
- default:
- $foldernames = array( date('Y'),date('m'),date('d') );
- break;
- }
-
- foreach( $foldernames as $foldername )
- {
- $response = request( $client,'GET', array
- (
- 'action' => 'folder',
- 'subaction' => 'edit',
- 'id' => $folderid
- ) );
-
- // Prüfen, ob der nächste Unterordner bereits existiert.
- $nextfolderid = null;
- foreach( $response['output']['object'] as $objectid=>$object )
- {
- if ( $object['name'] == $foldername )
- {
- $nextfolderid = $objectid;
- break;
- }
- }
- if ( empty($nextfolderid) )
- {
- // Der nächste Unterordner existiert noch nicht, also müssen wir diesen anlegen.
- $responseCreate = request( $client,'POST', array
- (
- 'action' => 'folder',
- 'subaction' => 'createfolder',
- 'id' => $folderid,
- 'token' => $token,
- 'name' => $foldername
- ) );
- $nextfolderid = $responseCreate['output']['objectid'];
- }
- $folderid = $nextfolderid;
- }
-
- // Seite anlegen.
- $response = request( $client,'POST', array
- (
- 'action' => 'folder',
- 'subaction' => 'createpage',
- 'id' => $folderid,
- 'templateid' => $config['project']['templateid'],
- 'token' => $token,
- 'name' => $_POST['title'],
- 'filename' => $_POST['title']
- ) );
- $pageobjectid = $response['output']['objectid'];
-
- /*
- *
- // Ggf. Datei anlegen.
- $response = request( $client,'POST', array
- (
- 'action' => 'folder',
- 'subaction' => 'createfile',
- 'token' => $token,
- 'name' => $title,
- 'filename' => $title
- ) );
- $pageobjectid = $response['objectid'];
- */
-
- // Text speichern anlegen.
- $response = request( $client,'POST', array
- (
- 'action' => 'pageelement',
- 'subaction' => 'edit',
- 'id' => $pageobjectid,
- 'elementid' => $config['project']['elementid_text'],
- 'token' => $token,
- 'release' => '1',
- 'text' => $_POST['text']
- ) );
-
- ?>
-
-
- <?php } ?>
-
-<h1>Blog</h1>
-<form action="<?php echo $_SERVER['SCRIPT_NAME'] ?>" method="post">
-
-<div class="line">
-<div class="label">Benutzer</div>
-<div class="value"><input type="text" name="username" readonly="readonly"
- value="<?php echo $username ?>" /></div>
-</div>
-<div class="line">
-<div class="label">Titel</div>
-<div class="value"><input type="text" name="title" value="" /></div>
-</div>
-<div class="line">
-<div class="label">Text</div>
-<div class="value"><textarea name="text"></textarea></div>
-</div>
-</div>
-<div class="line">
-<div class="label">File</div>
-<div class="value"><input type="file" name="image"></textarea></div>
-</div>
-
-<div class="line">
-<div class="label">Options</div>
-<div class="value"><select name="option"><option name="public" >test</option></select></div>
-</div>
-
-<br>
-
-<input type="submit"></form>
-<hr>
-
-</body>
-</html>
diff --git a/network/Facebook.class.php b/network/Facebook.class.php
@@ -0,0 +1,12 @@
+<?php
+
+class Facebook
+{
+ public $config;
+
+ public function push()
+ {
+
+ }
+}
+?>+
\ No newline at end of file
diff --git a/network/GooglePlus.class.php b/network/GooglePlus.class.php
@@ -0,0 +1,12 @@
+<?php
+
+class GooglePlus
+{
+ public $config;
+
+ public function push()
+ {
+
+ }
+}
+?>+
\ No newline at end of file
diff --git a/network/Reddit.class.php b/network/Reddit.class.php
@@ -0,0 +1,13 @@
+<?php
+
+class Reddit
+{
+ public $config;
+
+ public function push()
+ {
+
+ }
+}
+
+?>+
\ No newline at end of file
diff --git a/network/Twitter.class.php b/network/Twitter.class.php
@@ -0,0 +1,12 @@
+<?php
+
+class Twitter
+{
+ public $config;
+
+ public function push()
+ {
+
+ }
+}
+?>+
\ No newline at end of file
diff --git a/network/Xing.class.php b/network/Xing.class.php
@@ -0,0 +1,12 @@
+<?php
+
+class Xing
+{
+ public $config;
+
+ public function push()
+ {
+
+ }
+}
+?>+
\ No newline at end of file
diff --git a/post.php b/post.php
@@ -0,0 +1,59 @@
+<html>
+<head>
+<title>Submit a new blog entry</title>
+</head>
+<body>
+
+<?php if ( !empty($_POST['text']) ) {
+
+ $dirname = './blogs/'.date('Ymd-His');
+ mkdir($dirname);
+
+ $textfile = fopen($dirname.'/text','w');
+ fwrite($textfile,$_POST['text']);
+
+ $titlefile = fopen($dirname.'/subject','w');
+ fwrite($titlefile,$_POST['title']);
+ fclose($titlefile);
+
+ if ( !empty($_FILES['image']) )
+ {
+ $imagenamefile = fopen($dirname.'/image','w');
+ fwrite($imagenamefile,'image-'.$_FILES['image']['name']);
+ fclose($imagenamefile);
+ move_uploaded_file($_FILES['image']['tmp_name'],$dirname.'/image-'.$_FILES['image']['name']);
+ }
+
+ $okfile = fopen($dirname.'/OK','w');
+ fwrite($okfile,'');
+ fclose($okfile);
+
+
+ ?>
+ <h3>Saved!</h3><a href="blog.php">Start push to server now...</a><?php }
+ ?>
+
+<h1>Blog</h1>
+<form enctype="multipart/form-data" action="<?php echo $_SERVER['SCRIPT_NAME'] ?>" method="post">
+
+<div class="line">
+<div class="label">Titel</div>
+<div class="value"><input type="text" name="title" value="" /></div>
+</div>
+<div class="line">
+<div class="label">Text</div>
+<div class="value"><textarea name="text"></textarea></div>
+</div>
+<div class="line">
+<div class="label">File</div>
+<div class="value"><input type="file" name="image"></input></div>
+</div>
+
+
+<br>
+
+<input type="submit"></form>
+<hr>
+
+</body>
+</html>
diff --git a/profiles/config-myproject.ini b/profiles/config-myproject.ini
@@ -0,0 +1,39 @@
+
+enabled=false
+debug=false
+
+hostname = www.example.de
+urlschema=daily ; daily|monthly|yearly|flat
+
+
+[mailbox]
+
+host = {mail.example.de:143/novalidate-cert}INBOX
+username = foo
+password = bar
+archive_folder = Archiv
+dry=false
+
+
+[mock-disabled]
+
+
+[openrat]
+
+user=foo
+password=bar
+
+host="cms.example.de"
+port="80"
+path="/~foo/cms/dispatcher.php"
+database="dbname"
+
+projectid=1111
+languageid=1111
+rootfolderid=1111
+
+templateid=1111
+
+elementid_text=1111
+
+keywords_folderid=1111
diff --git a/source/File.class.php b/source/File.class.php
@@ -0,0 +1,132 @@
+<?php
+
+class File
+{
+ public $debug = false;
+ public $config = array();
+
+ private $text;
+ private $html;
+ private $filenames;
+
+ public function pull()
+ {
+ $entrys = array();
+
+ $dh = opendir('./blogs');
+
+ while (($file = readdir($dh)) !== false)
+ {
+ $file = './blogs/'.$file;
+ if ( is_dir($file) && is_file($file.'/OK') && !is_file($file.'/PROCESSED'))
+ {
+ $filenames = array();
+
+ if ( file_exists($file.'/image') )
+ {
+ $imagename = file_get_contents($file.'/image');
+ $tmpfilename = tempnam('/tmp','blog-').$imagename;
+ copy( $file.'/'.$imagename,$tmpfilename);
+ $filenames[] = array('name'=>$imagename,'filename'=>$tmpfilename);
+ }
+
+ $entrys[] = array(
+ 'filenames'=> $filenames,
+ 'keywords' => array(),
+ 'timestamp' => filectime($file),
+ 'subject' => file_get_contents($file.'/subject'),
+ 'text' => file_get_contents($file.'/text' )
+ );
+
+ // als "verarbeitet" markieren...
+ $processed = fopen($file.'/PROCESSED','w');
+ fwrite($processed,'');
+ fclose($processed);
+
+ // und verschieben...
+ if ( !is_dir('./blogs/archive'))
+ {
+ mkdir('./blogs/archive');
+ }
+ rename($file,'blogs/archive/'.basename($file));
+
+ }
+ }
+
+
+ return $entrys;
+ }
+
+
+
+ private function getpart($mbox,$mid,$p,$partno)
+ {
+ // $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple
+
+ // DECODE DATA
+ $data = ($partno) ?
+ imap_fetchbody($mbox,$mid,$partno): // multipart
+ imap_body($mbox,$mid); // simple
+
+ // Any part may be encoded, even plain text messages, so check everything.
+ if ($p->encoding==4)
+ $data = quoted_printable_decode($data);
+ elseif ($p->encoding==3)
+ $data = base64_decode($data);
+
+ // PARAMETERS
+ // get all parameters, like charset, filenames of attachments, etc.
+ $params = array();
+ if ($p->parameters)
+ foreach ($p->parameters as $x)
+ $params[strtolower($x->attribute)] = $x->value;
+ if ($p->dparameters)
+ foreach ($p->dparameters as $x)
+ $params[strtolower($x->attribute)] = $x->value;
+
+ // ATTACHMENT
+ // Any part with a filename is an attachment,
+ // so an attached text file (type 0) is not mistaken as the message.
+ if ($params['filename'] || $params['name']) {
+ // filename may be given as 'Filename' or 'Name' or both
+ $filename = ($params['filename'])? $params['filename'] : $params['name'];
+ // filename may be encoded, so see imap_mime_header_decode()
+ $fname = tempnam(null,'blog-file-');
+ $file = fopen($fname,'w');
+ fwrite($file,$data);
+ fclose($file);
+ chmod($fname,0644);
+
+ $this->filenames[] = array('filename'=>$fname,'name'=>$filename);
+ }
+
+ // TEXT
+ if ($p->type==0 && $data) {
+ // Messages may be split in different parts because of inline attachments,
+ // so append parts together with blank row.
+ if (strtolower($p->subtype)=='plain')
+ $this->text.= trim($data) ."\n\n";
+ else
+ $this->html.= $data ."<br><br>";
+ $charset = $params['charset']; // assume all parts are same charset
+ }
+
+ // EMBEDDED MESSAGE
+ // Many bounce notifications embed the original message as type 2,
+ // but AOL uses type 1 (multipart), which is not handled here.
+ // There are no PHP functions to parse embedded messages,
+ // so this just appends the raw source to the main message.
+ elseif ($p->type==2 && $data) {
+ $this->text.= $data."\n\n";
+ }
+
+ // SUBPART RECURSION
+ if ($p->parts) {
+ foreach ($p->parts as $partno0=>$p2)
+ $this->getpart($mbox,$mid,$p2,$partno.'.'.($partno0+1)); // 1.2, 1.2.1, etc.
+ }
+ }
+
+}
+
+?>+
\ No newline at end of file
diff --git a/source/Mailbox.class.php b/source/Mailbox.class.php
@@ -0,0 +1,185 @@
+<?php
+
+class Mailbox
+{
+ public $debug = false;
+ public $config = array();
+
+ private $text;
+ private $html;
+ private $filenames;
+
+ public function pull()
+ {
+
+ $entrys = array();
+
+ /* connect to gmail */
+ $hostname = $this->config['host'];
+ $username = $this->config['username'];
+ $password = $this->config['password'];
+
+ /* try to connect */
+ $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to IMAP server: ' . imap_last_error());
+
+ /* grab emails */
+ $emails = imap_search($inbox,'ALL UNDELETED UNSEEN');
+
+ print_r($emails);
+
+ /* if emails are returned, cycle through each... */
+ if($emails) {
+
+ /* put the newest emails on top */
+ rsort($emails);
+
+ /* for every email... */
+ foreach($emails as $email_number) {
+
+ /* get information specific to this email */
+ // $overview = imap_fetch_overview($inbox,$email_number,0);
+ $headers = imap_headerinfo($inbox,$email_number);
+ $structure = imap_fetchstructure($inbox,$email_number);
+ // $message = imap_fetchbody($inbox,$email_number);
+
+ // echo "\nOverview:";
+ // print_r($overview);
+ if ( $this->debug ) { echo '<pre>'; print_r($headers); echo '</pre>'; }
+
+ // Initalize
+ $this->filenames = array();
+ $this->text = '';
+ $this->html = '';
+ $subject = $headers->subject;
+
+ $s = imap_fetchstructure($inbox,$email_number);
+
+ if (!$s->parts) // simple
+ $this->getpart($inbox,$email_number,$s,0); // pass 0 as part-number
+ else { // multipart: cycle through each part
+ foreach ($s->parts as $partno0=>$p)
+ $this->getpart($inbox,$email_number,$p,$partno0+1);
+ }
+
+ // print_r($message);
+ /* output the email header information */
+ // $output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
+ // $output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
+ // $output.= '<span class="from">'.$overview[0]->from.'</span>';
+ // $output.= '<span class="date">on '.$overview[0]->date.'</span>';
+ // $output.= '</div>';
+
+ /* output the email body */
+ // $output.= '<div class="body">'.$message.'</div>';
+
+ if ( $this->debug ) echo "\n\nBetreff: ".$subject;
+ if ( $this->debug ) echo "\n\nText: ";
+ if ( $this->debug ) print_r($this->text);
+ if ( $this->debug ) echo "\n\nAnlagen: ";
+ if ( $this->debug ) print_r($this->filenames);
+
+ $entrys[] = array(
+ 'filenames'=> $this->filenames,
+ 'keywords' => array(),
+ 'timestamp' => strtotime($headers->date),
+ 'subject' => $subject,
+ 'text' => $this->text
+ );
+
+ // Aufräumen:
+ // - Mail als gelesen markieren und in das Archiv verschieben.
+ if ( $this->config['dry'] )
+ ;
+ else
+ {
+ imap_setflag_full($inbox,$email_number,'\\SEEN',0);
+
+ if (isset($this->config['archive_folder']))
+ {
+ imap_mail_move($inbox,$email_number,$this->config['archive_folder']) or die("IMAP: Move did not suceed: "+imap_last_error() );
+
+ imap_expunge($inbox);
+ }
+ }
+ }
+ }
+
+ /* close the connection */
+ imap_close($inbox);
+
+ return $entrys;
+ }
+
+
+
+ private function getpart($mbox,$mid,$p,$partno)
+ {
+ // $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple
+
+ // DECODE DATA
+ $data = ($partno) ?
+ imap_fetchbody($mbox,$mid,$partno): // multipart
+ imap_body($mbox,$mid); // simple
+
+ // Any part may be encoded, even plain text messages, so check everything.
+ if ($p->encoding==4)
+ $data = quoted_printable_decode($data);
+ elseif ($p->encoding==3)
+ $data = base64_decode($data);
+
+ // PARAMETERS
+ // get all parameters, like charset, filenames of attachments, etc.
+ $params = array();
+ if ($p->parameters)
+ foreach ($p->parameters as $x)
+ $params[strtolower($x->attribute)] = $x->value;
+ if ($p->dparameters)
+ foreach ($p->dparameters as $x)
+ $params[strtolower($x->attribute)] = $x->value;
+
+ // ATTACHMENT
+ // Any part with a filename is an attachment,
+ // so an attached text file (type 0) is not mistaken as the message.
+ if ($params['filename'] || $params['name']) {
+ // filename may be given as 'Filename' or 'Name' or both
+ $filename = ($params['filename'])? $params['filename'] : $params['name'];
+ // filename may be encoded, so see imap_mime_header_decode()
+ $fname = tempnam(null,'blog-file-');
+ $file = fopen($fname,'w');
+ fwrite($file,$data);
+ fclose($file);
+ chmod($fname,0644);
+
+ $this->filenames[] = array('filename'=>$fname,'name'=>$filename);
+ }
+
+ // TEXT
+ if ($p->type==0 && $data) {
+ // Messages may be split in different parts because of inline attachments,
+ // so append parts together with blank row.
+ if (strtolower($p->subtype)=='plain')
+ $this->text.= trim($data) ."\n\n";
+ else
+ $this->html.= $data ."<br><br>";
+ $charset = $params['charset']; // assume all parts are same charset
+ }
+
+ // EMBEDDED MESSAGE
+ // Many bounce notifications embed the original message as type 2,
+ // but AOL uses type 1 (multipart), which is not handled here.
+ // There are no PHP functions to parse embedded messages,
+ // so this just appends the raw source to the main message.
+ elseif ($p->type==2 && $data) {
+ $this->text.= $data."\n\n";
+ }
+
+ // SUBPART RECURSION
+ if ($p->parts) {
+ foreach ($p->parts as $partno0=>$p2)
+ $this->getpart($mbox,$mid,$p2,$partno.'.'.($partno0+1)); // 1.2, 1.2.1, etc.
+ }
+ }
+
+}
+
+?>+
\ No newline at end of file
diff --git a/source/Mock.class.php b/source/Mock.class.php
@@ -0,0 +1,27 @@
+<?php
+
+class Mock
+{
+ public $debug = false;
+ public $config = array();
+
+ public function pull()
+ {
+ $entrys[] = array(
+ 'filenames'=> array( array('name'=>'Motorrad','filename'=>'/tmp/DSC00281.JPG') ),
+ 'keywords' => array('Kazakhstan','Motorrad'),
+ 'timestamp' => time(),
+ 'subject' => 'Glorious Nation of Kazakhstan',
+ 'text' => "In Kazakhstan, the favorite hobbies are disco dancing, archery, rape, and table tennis.\n\nWawaweewaa! Ooh lala! Oh well, king in the castle, king in the castle, I have a chair! Go do this, go do this, king in the castle."
+ );
+
+ if ( $this->debug )
+ echo '<h4>Mock!</h4>';
+
+ return $entrys;
+ }
+
+
+}
+
+?>+
\ No newline at end of file