commit 942fdcae70303edfd27179e06ad27d3156768d72
parent 2d211dab63779543fba2bb8d2cfad6efb773935d
Author: dankert <devnull@localhost>
Date: Sun, 15 Mar 2015 17:16:57 +0100
Kleine Fehlerkorrektur.
Diffstat:
6 files changed, 188 insertions(+), 63 deletions(-)
diff --git a/blog.php b/blog.php
@@ -1,36 +1,51 @@
<?php
+header('Content-Type: text/html; charset=utf-8');
-if ($dh = opendir('./profiles'))
+?>
+
+<form method="post" action="">
+ <input type="submit" value="Neue Blogeinträge abrufen">
+</form>
+
+<?php
+
+if ( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
- while (($file = readdir($dh)) !== false)
+
+ if ($dh = opendir('./profiles'))
{
- if ( substr($file,-4) == '.ini' )
+ while (($file = readdir($dh)) !== false)
{
- $config = parse_ini_file('./profiles/'.$file,true);
-
- if ( !$config['enabled'] )
- continue;
-
- $blogger = new Blogger();
- if ( $config['debug'] ) echo "<h1>Profile: $file</h1>";
-
- $blogger->config = $config;
- $blogger->debug = $config['debug'];
-
- echo "<h2>Step 1: Pulling</h2>";
- $blogger->pull();
- echo "<h2>Step 2: CMS</h2>";
- $blogger->pushToCMS();
- echo "<h2>Step 3: Networks</h2>";
- $blogger->pushToNetwork();
+ if ( substr($file,-4) == '.ini' )
+ {
+ $config = parse_ini_file('./profiles/'.$file,true);
+
+ if ( !$config['enabled'] )
+ continue;
+
+ $blogger = new Blogger();
+ if ( $config['debug'] ) echo "<h1>Profile: $file</h1>";
+
+ $blogger->config = $config;
+ $blogger->debug = $config['debug'];
+
+ echo "<h2>Step 1: Pulling</h2>";
+ $blogger->pull();
+ flush();
+ echo "<h2>Step 2: CMS</h2>";
+ $blogger->pushToCMS();
+ flush();
+ echo "<h2>Step 3: Networks</h2>";
+ $blogger->pushToNetwork();
+ flush();
+ }
}
+ closedir($dh);
}
- closedir($dh);
}
-
class Blogger {
public $debug = true;
@@ -132,6 +147,7 @@ class Blogger {
$cms->filename = $blog['filename'];
$cms->path = $blog['path'];
$cms->keywords = $blog['keywords'];
+ $cms->timestamp = $blog['timestamp'];
$cms->debug = $this->debug;
$cms->push();
}
diff --git a/cms/OpenRat.class.php b/cms/OpenRat.class.php
@@ -11,6 +11,7 @@ class OpenRat {
public $shortUrl;
public $path;
public $debug = true;
+ public $timestamp;
public $config;
private $client;
@@ -25,12 +26,8 @@ class OpenRat {
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
+ ?><pre><?php print_r(""); ?></pre><pre><?php print_r($this->client->response); ?></pre><?php
}
$response = json_decode($this->client->response,true);
@@ -47,22 +44,11 @@ class OpenRat {
public function push()
{
+ $filesToPublish = array();
+ $objectsToPublish = explode(',',$this->config['publish']);
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'];
@@ -82,14 +68,14 @@ class OpenRat {
'subaction' => 'login',
'token' => $token,
'dbid' => $this->config['database'],
- 'login_name' => $username,
- 'login_password'=> $password ) );
+ 'login_name' => $this->config['user' ],
+ 'login_password'=> $this->config['password'] ) );
$this->client->cookie =$response['session']['name'].'='.$response['session']['id'];
$token = $response['session']['token'];
- // PRojekt auswählen
+ // Projekt auswählen
$response = $this->request( 'POST', array(
'action' => 'start',
'subaction' => 'projectmenu',
@@ -100,9 +86,11 @@ class OpenRat {
// Ordner laden.
$rootfolderid = $this->config['rootfolderid'];
$folderid = $rootfolderid;
-
+
+ $depth = 0;
foreach( $this->path as $foldername )
{
+ $depth++;
$response = $this->request( 'GET', array
(
'action' => 'folder',
@@ -132,22 +120,40 @@ class OpenRat {
'name' => $foldername
) );
$nextfolderid = $responseCreate['output']['objectid'];
+
+ // Seite anlegen.
+ if ( $depth < count($this->path) )
+ {
+ $response = $this->request( 'POST', array
+ (
+ 'action' => 'folder',
+ 'subaction' => 'createpage',
+ 'id' => $nextfolderid,
+ 'templateid' => $this->config['templateid'],
+ 'token' => $token,
+ 'name' => $foldername,
+ 'filename' => 'index'
+ ) );
+ $pageobjectid = $response['output']['objectid'];
+
+ $objectsToPublish[] = $pageobjectid;
+ }
}
$folderid = $nextfolderid;
}
- // Ein Unterordner pro Blogeintrag.
+ // Ein Unterordner für die Anlagen
$responseCreate = $this->request( 'POST', array
(
'action' => 'folder',
'subaction' => 'createfolder',
'id' => $folderid,
'token' => $token,
- 'name' => $this->filename
+ 'name' => 'attachments-'.$this->filename
) );
- $folderid = $responseCreate['output']['objectid'];
+ $attachment_folderid = $responseCreate['output']['objectid'];
- // Seite anlegen.
+ // Seite für den Blogeintrag anlegen.
$response = $this->request( 'POST', array
(
'action' => 'folder',
@@ -156,9 +162,23 @@ class OpenRat {
'templateid' => $this->config['templateid'],
'token' => $token,
'name' => $this->subject,
- 'filename' => 'index'
+ 'filename' => $this->filename
) );
$pageobjectid = $response['output']['objectid'];
+
+ $objectsToPublish[] = $pageobjectid;
+ // Timestamp nicht setzen (fraglich, ob die Funktion in der API bleibt)
+// $response = $this->request( 'POST', array
+// (
+// 'action' => 'page',
+// 'subaction' => 'prop',
+// 'id' => $pageobjectid,
+// 'name' => $this->subject,
+// 'filename' => 'index',
+// 'token' => $token,
+// 'creationTimestamp' => $this->timestamp
+// ) );
+
/*
*
@@ -186,6 +206,30 @@ class OpenRat {
'text' => $this->text
) );
+ // Ordner für die Bilder speichern
+ $response = $this->request( 'POST', array
+ (
+ 'action' => 'pageelement',
+ 'subaction' => 'edit',
+ 'id' => $pageobjectid,
+ 'elementid' => $this->config['elementid_attachment_folder'],
+ 'token' => $token,
+ 'release' => '1',
+ 'linkobjectid' => $attachment_folderid
+ ) );
+
+ // Datum speichern.
+ $response = $this->request( 'POST', array
+ (
+ 'action' => 'pageelement',
+ 'subaction' => 'edit',
+ 'id' => $pageobjectid,
+ 'elementid' => $this->config['elementid_date'],
+ 'token' => $token,
+ 'release' => '1',
+ 'date' => $this->timestamp
+ ) );
+
foreach( $this->filenames as $file )
{
// Datei anlegen.
@@ -193,13 +237,15 @@ class OpenRat {
(
'action' => 'folder',
'subaction' => 'createfile',
- 'id' => $folderid,
+ 'id' => $attachment_folderid,
'token' => $token,
'name' => $file['name'],
- 'filename' => basename($file['filename'])
+ 'filename' => basename($file['name'])
) );
$fileobjectid = $response['output']['objectid'];
+ $filesToPublish[] = $fileobjectid;
+
// Datei-Inhalt hochladen.
$response = $this->request( 'POST', array
(
@@ -244,6 +290,21 @@ class OpenRat {
'name' => $keyword
) );
$keyword_folderid = $responseCreate['output']['objectid'];
+
+ // Seite im neuen Keyword-Ordner anlegen
+ $response = $this->request( 'POST', array
+ (
+ 'action' => 'folder',
+ 'subaction' => 'createpage',
+ 'id' => $folderid,
+ 'templateid' => $this->config['templateid'],
+ 'token' => $token,
+ 'name' => $keyword,
+ 'filename' => 'index'
+ ) );
+ $pageobjectid = $response['output']['objectid'];
+
+ $objectsToPublish[] = $pageobjectid;
}
$responseCreate = $this->request( 'POST', array
@@ -258,6 +319,29 @@ class OpenRat {
) );
}
+
+ // Veröffentlichen der neuen und geänderten Seiten
+ foreach( $objectsToPublish as $objectToPublish )
+ {
+ $response = $this->request( 'POST', array
+ (
+ 'action' => 'page',
+ 'subaction' => 'pub',
+ 'id' => $objectToPublish,
+ 'token' => $token
+ ) );
+ }
+ // Veröffentlichen der neuen und geänderten Dateien
+ foreach( $filesToPublish as $fileToPublish )
+ {
+ $response = $this->request( 'POST', array
+ (
+ 'action' => 'file',
+ 'subaction' => 'pub',
+ 'id' => $fileToPublish,
+ 'token' => $token
+ ) );
+ }
}
diff --git a/network/Xing.class.php b/network/Xing.class.php
@@ -6,7 +6,30 @@ class Xing
public function push()
{
-
+ require_once('network/xing/xingoauth.php');
+
+ $connection = new XingOAuth($this->config['consumer_key'],$this->config['consumer_secret'],$this->config['oauth_token'],$this->config['oauth_token_secret']);
+
+ /* If method is set change API call made. Test is called by default. */
+
+ //$content = $connection->get(‘account/verify_credentials’);
+
+ /* Some example calls */
+
+ $praefix = $this->config['praefix_text'].' ';
+ $suffix = ' '.$this->shortUrl.' '.$this->config['suffix_text'];
+ $text = $praefix.substr($this->subject,0,140-strlen($praefix)-strlen($suffix)).$suffix;
+
+ $result = $connection->post('statuses/update', array('status' => $text));
+
+ if ( $this->debug )
+ {
+ echo '<pre>';
+ print_r( $result );
+ echo '</pre>';
+ }
+
+
}
}
?>
\ No newline at end of file
diff --git a/profiles/config-myproject.ini b/profiles/config-myproject.ini
@@ -4,7 +4,7 @@ debug=false
hostname = www.example.de
urlschema=daily ; daily|monthly|yearly|flat
-
+subdir_per_entry=false
[mailbox]
@@ -39,7 +39,7 @@ templateid=1111
elementid_text=1111
keywords_folderid=1111
-
+publish=1
[facebook]
diff --git a/source/Mailbox.class.php b/source/Mailbox.class.php
@@ -50,7 +50,7 @@ class Mailbox
$this->filenames = array();
$this->text = '';
$this->html = '';
- $subject = $headers->subject;
+ $subject = iconv_mime_decode($headers->subject,0,'UTF-8');
$s = imap_fetchstructure($inbox,$email_number);
@@ -130,17 +130,17 @@ class Mailbox
// PARAMETERS
// get all parameters, like charset, filenames of attachments, etc.
$params = array();
- if ($p->parameters)
+ if (@$p->parameters)
foreach ($p->parameters as $x)
$params[strtolower($x->attribute)] = $x->value;
- if ($p->dparameters)
+ 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']) {
+ 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()
@@ -155,13 +155,15 @@ class Mailbox
// TEXT
if ($p->type==0 && $data) {
+ $charset = $params['charset']; // assume all parts are same charset
+ $data = iconv($charset,'UTF-8//TRANSLIT',$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
@@ -174,7 +176,7 @@ class Mailbox
}
// SUBPART RECURSION
- if ($p->parts) {
+ if (@$p->parts) {
foreach ($p->parts as $partno0=>$p2)
$this->getpart($mbox,$mid,$p2,$partno.'.'.($partno0+1)); // 1.2, 1.2.1, etc.
}
diff --git a/source/Mock.class.php b/source/Mock.class.php
@@ -8,9 +8,9 @@ class Mock
public function pull()
{
$entrys[] = array(
- 'filenames'=> array( array('name'=>'Motorrad','filename'=>'/tmp/DSC00281.JPG') ),
- 'keywords' => array('Kazakhstan','Motorrad'),
- 'timestamp' => time(),
+ 'filenames'=> array( array('name'=>'Transalp','filename'=>'/home/dankert/Transalp1_2004_250.jpg') ),
+ 'keywords' => array('Alpen','Motorrad'),
+ 'timestamp' => mktime(14,30,25,6,9,1973), // 9.6.73 um 14:30:25
'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."
);