fixing SAP blogs

This commit is contained in:
francois.lutran
2016-12-16 17:19:15 +13:00
parent 7fecaa602f
commit 1bca2ec8ad
3 changed files with 166 additions and 71 deletions

View File

@@ -262,7 +262,7 @@ class Databap extends PhpObject
'email' => "varchar(100) NOT NULL", 'email' => "varchar(100) NOT NULL",
'hash' => "varchar(32) NOT NULL", 'hash' => "varchar(32) NOT NULL",
'pass' => "varchar(255) NOT NULL", 'pass' => "varchar(255) NOT NULL",
'auth_cookie' => "varchar(255) NOT NULL", 'auth_cookie' => "varchar(255)",
'active' => "tinyint(1) DEFAULT ".self::MEMBER_ACTIVE, 'active' => "tinyint(1) DEFAULT ".self::MEMBER_ACTIVE,
'clearance' => "int(1) DEFAULT ".self::CLEARANCE_MEMBER, 'clearance' => "int(1) DEFAULT ".self::CLEARANCE_MEMBER,
MySqlManager::getText(self::CODE_TABLE) => "longtext NOT NULL", MySqlManager::getText(self::CODE_TABLE) => "longtext NOT NULL",
@@ -370,7 +370,7 @@ class Databap extends PhpObject
$this->oMySql->insertRow(self::OPTNAME_TABLE, array($sOptionNameIdCol=>self::OPT_CHAT_IMAGES, $sOptionNameCol=>'afficher les images du chat', 'type'=>self::OPT_CHECKBOX, 'language'=>self::LANG_FR)); $this->oMySql->insertRow(self::OPTNAME_TABLE, array($sOptionNameIdCol=>self::OPT_CHAT_IMAGES, $sOptionNameCol=>'afficher les images du chat', 'type'=>self::OPT_CHECKBOX, 'language'=>self::LANG_FR));
//Select/checkbox and Default Option values: option_name => array(option_value => is_default, ...) //Select/checkbox and Default Option values: option_name => array(option_value => is_default, ...)
$asDefaultValues = array( self::OPT_CONSOLE=>array(true=>false, false=>true), $asDefaultValues = array( self::OPT_CONSOLE=>array(true=>0, false=>1),
self::OPT_NICKNAME=>array('Utilisateur inconnu'=>true), self::OPT_NICKNAME=>array('Utilisateur inconnu'=>true),
self::OPT_BG=>array('#04357B'=>true), self::OPT_BG=>array('#04357B'=>true),
self::OPT_BG_2=>array('#88B2F0'=>true), self::OPT_BG_2=>array('#88B2F0'=>true),
@@ -380,7 +380,7 @@ class Databap extends PhpObject
self::OPT_STATUS=>array('aucune mission en cours'=>true), self::OPT_STATUS=>array('aucune mission en cours'=>true),
self::OPT_EMAIL=>array('email inconnu'=>true), self::OPT_EMAIL=>array('email inconnu'=>true),
self::OPT_CHAT_HISTO=>array('0'=>true), self::OPT_CHAT_HISTO=>array('0'=>true),
self::OPT_CHAT_IMAGES=>array(true=>true, false=>false) self::OPT_CHAT_IMAGES=>array(true=>1, false=>0)
); );
foreach($asDefaultValues as $sOptionNameId=>$asOptionValues) foreach($asDefaultValues as $sOptionNameId=>$asOptionValues)
{ {
@@ -510,7 +510,7 @@ class Databap extends PhpObject
'copyright'=>'Powered by Francois Lutran. RSS Feed Generator under GPLv3 License', 'copyright'=>'Powered by Francois Lutran. RSS Feed Generator under GPLv3 License',
'description'=>'Flux RSS du chat'.($sCat==''?'':', section '.$sCat), 'description'=>'Flux RSS du chat'.($sCat==''?'':', section '.$sCat),
'language'=>'fr', 'language'=>'fr',
'webmaster_mail'=>'francois@lutran.fr' 'webMaster'=>'francois@lutran.fr'
); );
$oFeed = new Feed($asDesc); $oFeed = new Feed($asDesc);
@@ -530,7 +530,7 @@ class Databap extends PhpObject
'description'=>$asRow['message'], 'description'=>$asRow['message'],
'author'=>$asRow['nickname'], 'author'=>$asRow['nickname'],
'link'=>$sChatlink, 'link'=>$sChatlink,
'pub_date'=>$asRow['time'], 'pubDate'=>$asRow['time'],
'guid'=>$sChatlink 'guid'=>$sChatlink
); );
$oFeed->addItem($asItem); $oFeed->addItem($asItem);
@@ -581,7 +581,7 @@ class Databap extends PhpObject
'description'=>'Lien post&eacute; par '.self::getNickNameFormat($asRow['nickname']).' &agrave; '.self::getDateFormat($asRow['led']).' : <a href="'.$asRow['link'].'" target="_blank">'.$asRow['message'].'</a>', 'description'=>'Lien post&eacute; par '.self::getNickNameFormat($asRow['nickname']).' &agrave; '.self::getDateFormat($asRow['led']).' : <a href="'.$asRow['link'].'" target="_blank">'.$asRow['message'].'</a>',
'author'=>$asRow['nickname'], 'author'=>$asRow['nickname'],
'link'=>$sChatlink, 'link'=>$sChatlink,
'pub_date'=>$asRow['led'], 'pubDate'=>$asRow['led'],
'guid'=>$sChatlink 'guid'=>$sChatlink
); );
$oFeed->addItem($asItem); $oFeed->addItem($asItem);
@@ -624,48 +624,38 @@ class Databap extends PhpObject
{ {
$asArticles = array(); $asArticles = array();
//SCN SAP //SAP Blogs
$sSAPDomain = 'http://scn.sap.com'; $sSAPDomain = 'https://blogs.sap.com/';
$asBlogPaths = array( '/community/data-warehousing/bw/blog', $asBlogTags = array('73554900100700001049', //Lumira
'/community/data-warehousing/blog', '73554900100700000818', //Design Studio
'/community/bw-hana/blog', '242586194391178517100436979900901', //BW
'/community/businessobjects-design-studio/blog', '01200245450800000012', //Another BW
'/community/businessobjects-analysis-ms-office/blog'); '242586194391178517100436979900901', //Another BW
foreach($asBlogPaths as $sSAPBlogPath) '73554900100700001661', // BW/4HANA
'73554900100700000814', //BO Platform
'907900296036854683333078008146613', //Webi
'73554900100700000813', //Analysis
);
$this->oClassManagement->incClass('rss');
foreach($asBlogTags as $asBlogTag)
{ {
$sSAPBlogUrl = $sSAPDomain.$sSAPBlogPath; $oRss = new Feed();
$oDom = $this->getRemotePageDom($sSAPBlogUrl); $oRss->loadRss($sSAPDomain.'tags/'.$asBlogTag.'/feed/');
$aoArticles = $oDom->getElementsByTagName('header'); $asBlogItems = $oRss->getItems();
foreach($aoArticles as $oArticle) foreach($asBlogItems as $asBlogItem)
{ {
if($oArticle->getAttribute('class')=='jive-blog-post-subject') $asArticleInfo['title'] = $asBlogItem['title'];
{
$asArticleInfo = array();
$aoLinks = $oArticle->getElementsByTagName('a');
foreach($aoLinks as $oLink)
{
switch($oLink->getAttribute('class'))
{
//Title & link
case 'font-color-normal':
$asArticleInfo['title'] = trim($oLink->nodeValue);
$asArticleInfo['title'] = mb_substr($asArticleInfo['title'], -1)=='.'?mb_substr($asArticleInfo['title'], 0, -1):$asArticleInfo['title']; $asArticleInfo['title'] = mb_substr($asArticleInfo['title'], -1)=='.'?mb_substr($asArticleInfo['title'], 0, -1):$asArticleInfo['title'];
$asArticleInfo['link'] = $oLink->getAttribute('href');
$asArticleInfo['date'] = mb_substr(str_replace(array($sSAPBlogUrl.'/', '/'), array('', '-'), $asArticleInfo['link']), 0, 10); $asArticleInfo['link'] = $asBlogItem['link'];
break; $asArticleInfo['date'] = date(self::DATE_SQL_FORMAT, strtotime($asBlogItem['pubDate']));
//Author $asNames = array_filter(explode(' ', ToolBox::mb_ucwords(trim($asBlogItem['author']))));
case 'jiveTT-hover-user jive-username-link':
$asNames = array_filter(explode(' ', ToolBox::mb_ucwords(trim($oLink->nodeValue))));
$asArticleInfo['first_name'] = array_shift($asNames); $asArticleInfo['first_name'] = array_shift($asNames);
$asArticleInfo['last_name'] = implode('-', $asNames); $asArticleInfo['last_name'] = implode('-', $asNames);
$asArticleInfo['email'] = $sSAPDomain.$oLink->getAttribute('href'); $asArticleInfo['email'] = '';
break;
}
}
$asArticles[] = $asArticleInfo; $asArticles[] = $asArticleInfo;
} }
} }
}
//BI Portal //BI Portal
$oDom = $this->getRemotePageDom('http://www.biportal.org/sap_bi_blog'); $oDom = $this->getRemotePageDom('http://www.biportal.org/sap_bi_blog');
@@ -818,7 +808,7 @@ class Databap extends PhpObject
MySqlManager::getId(self::COMP_TABLE)=>$iCompanyId, MySqlManager::getId(self::COMP_TABLE)=>$iCompanyId,
'pass'=>$this->oAuth->HashPassword(self::getLoginToken($sCompany)), 'pass'=>$this->oAuth->HashPassword(self::getLoginToken($sCompany)),
'clearance'=>$iClearance, 'clearance'=>$iClearance,
'led'=>'0000-00-00 00:00:00'); 'led'=>'2000-01-01 00:00:01');
if($iUserId>0) $asInfo[MySqlManager::getId(self::USER_TABLE)] = $iUserId; if($iUserId>0) $asInfo[MySqlManager::getId(self::USER_TABLE)] = $iUserId;
$iUserId = $this->oMySql->insertRow(self::USER_TABLE, $asInfo); $iUserId = $this->oMySql->insertRow(self::USER_TABLE, $asInfo);
$bSuccess = ($iUserId>0); $bSuccess = ($iUserId>0);

View File

@@ -3,28 +3,95 @@
/** /**
* RSS Feed Class * RSS Feed Class
* @author franzz * @author franzz
* @version 1.1 * @version 2.0
*
* Input:
* - $asDesc: Array. Description of the feed: fields 'title', 'link' (optional), 'copyright', 'description', 'language', 'webmaster_mail'
* - $asItems: Array. Feed item data: fields 'title', 'description', 'author', 'link', 'pub_date', 'guid'
*/ */
class Feed extends PhpObject { class Feed extends PhpObject
{
const CHANNEL_TAGS = array('title', 'link', 'copyright', 'description', 'language', 'lastBuildDate', 'generator', 'webMaster');
const ITEM_TAGS = array('title', 'author', 'link', 'category', 'description', 'pubDate', 'guid');
private $asDesc; private $asChannel;
private $asItems; private $asItems;
public function __construct($asDesc, $asItems=array()) /**
* Constructor
* @param array $asChannel Description of the feed: fields 'title', 'link' (optional), 'copyright', 'description', 'language', 'webMaster'
* @param array $asItems Feed item data: fields 'title', 'author', 'link', 'category', 'description', 'pubDate', 'guid'
*/
public function __construct($asChannel=array(), $asItems=array())
{ {
parent::__construct(__CLASS__, Settings::DEBUG); parent::__construct(__CLASS__, Settings::DEBUG);
if(!array_key_exists('link', $asDesc)) if(!empty($asChannel) && !array_key_exists('link', $asChannel))
{ {
$asDesc['link'] = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'].'/rss'; $asChannel['link'] = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'].'/rss';
} }
$this->asDesc = $asDesc; $this->asChannel = $asChannel;
//Items
$this->asItems = array();
array_walk($asItems, array($this, 'addItem')); array_walk($asItems, array($this, 'addItem'));
} }
public function loadRss($sUrl)
{
$sRssContent = file_get_contents($sUrl);
//Parse document encoding (useless)
$sEncoding = $this->getPregMatch("'encoding=[\'\"](.*?)[\'\"]'si", $sRssContent);
//Parse Channel info
preg_match("'<channel.*?>(.*?)</channel>'si", $sRssContent, $sChannelContent);
foreach(self::CHANNEL_TAGS as $sChannelTag)
{
$sTagContent = $this->getPregMatch("'<$sChannelTag.*?>(.*?)</$sChannelTag>'si", $sChannelContent[1]);
if($sTagContent != '') $this->asChannel[$sChannelTag] = $sTagContent;
}
//Parse Text Input info
/*preg_match("'<textinput(|[^>]*[^/])>(.*?)</textinput>'si", $sRssContent, $out_textinfo);
if (isset($out_textinfo[2])) {
foreach($this->textinputtags as $textinputtag) {
$temp = $this->getPregMatch("'<$textinputtag.*?>(.*?)</$textinputtag>'si", $out_textinfo[2]);
if ($temp != '') $result['textinput_'.$textinputtag] = $temp; // Set only if not empty
}
}*/
//Parse Image info
/*preg_match("'<image.*?>(.*?)</image>'si", $sRssContent, $out_imageinfo);
if (isset($out_imageinfo[1])) {
foreach($this->imagetags as $imagetag) {
$temp = $this->getPregMatch("'<$imagetag.*?>(.*?)</$imagetag>'si", $out_imageinfo[1]);
if ($temp != '') $result['image_'.$imagetag] = $temp; // Set only if not empty
}
}*/
//Parse Items
preg_match_all("'<item(| .*?)>(.*?)</item>'si", $sRssContent, $asItems);
$i = 0;
foreach($asItems[2] as $asItem)
{
$asItemTags = array();
foreach(self::ITEM_TAGS as $sItemTag)
{
$sTagContent = $this->getPregMatch("'<$sItemTag.*?>(.*?)</$sItemTag>'si", $asItem);
if($sTagContent != '') $asItemTags[$sItemTag] = $sTagContent;
}
//Strip HTML tags and other bullshit from DESCRIPTION
//if($this->stripHTML && $this->asItems[$i]['description']) $this->asItems[$i]['description'] = strip_tags($this->unhtmlentities(strip_tags($this->asItems[$i]['description'])));
//Strip HTML tags and other bullshit from TITLE
//if($this->stripHTML && $this->asItems[$i]['title']) $this->asItems[$i]['title'] = strip_tags($this->unhtmlentities(strip_tags($this->asItems[$i]['title'])));
//Fix for author
if(!array_key_exists('author', $asItemTags))
{
$sTagContent = $this->getPregMatch("'<dc\:creator.*?>(.*?)</dc\:creator>'si", $asItem);
if($sTagContent != '') $asItemTags['author'] = $sTagContent;
}
$this->asItems[] = $asItemTags;
}
}
public function addItem($asItem) public function addItem($asItem)
{ {
$this->asItems[] = $asItem; $this->asItems[] = $asItem;
@@ -38,12 +105,17 @@ class Feed extends PhpObject {
return $bExist; return $bExist;
} }
public function getItems()
{
return $this->asItems;
}
private function getGlobalPubDate() private function getGlobalPubDate()
{ {
$iGlobalPubDate = 0; $iGlobalPubDate = 0;
foreach($this->asItems as $asItem) foreach($this->asItems as $asItem)
{ {
$iItemPubDate = strtotime($asItem['pub_date']); $iItemPubDate = strtotime($asItem['pubDate']);
if($iItemPubDate>$iGlobalPubDate) if($iItemPubDate>$iGlobalPubDate)
{ {
$iGlobalPubDate = $iItemPubDate; $iGlobalPubDate = $iItemPubDate;
@@ -55,24 +127,24 @@ class Feed extends PhpObject {
public function getFeed() public function getFeed()
{ {
//feed header //Feed Channel
$sRssFeedHeader = self::getHtml($this->asDesc['title'], 'title'); $sRssChannel = self::getHtml($this->asChannel['title'], 'title');
$sRssFeedHeader .= self::getHtml($this->asDesc['link'], 'link'); $sRssChannel .= self::getHtml($this->asChannel['link'], 'link');
$sRssFeedHeader .= self::getHtml($this->asDesc['copyright'], 'copyright'); $sRssChannel .= self::getHtml($this->asChannel['copyright'], 'copyright');
$sRssFeedHeader .= self::getHtml($this->asDesc['description'], 'description'); $sRssChannel .= self::getHtml($this->asChannel['description'], 'description');
$sRssFeedHeader .= self::getHtml('', 'atom:link', '', '', array('href'=>$this->asDesc['link'], 'rel'=>'self', 'type'=>'application/atom+xml'), true); $sRssChannel .= self::getHtml('', 'atom:link', '', '', array('href'=>$this->asChannel['link'], 'rel'=>'self', 'type'=>'application/atom+xml'), true);
$sRssFeedHeader .= self::getHtml($this->asDesc['language'], 'language'); $sRssChannel .= self::getHtml($this->asChannel['language'], 'language');
$sRssFeedHeader .= self::getHtml($this->getGlobalPubDate(), 'pubDate'); $sRssChannel .= self::getHtml($this->getGlobalPubDate(), 'lastBuildDate');
$sRssFeedHeader .= self::getHtml('Lutran.fr RSS Feed Generator', 'generator'); $sRssChannel .= self::getHtml('Lutran.fr RSS Feed Generator', 'generator');
$sRssFeedHeader .= self::getHtml($this->asDesc['webmaster_mail'].' (Webmaster)', 'webMaster'); $sRssChannel .= self::getHtml($this->asChannel['webMaster'].' (Webmaster)', 'webMaster');
//feed items //Feed Items
$asSortedItems = $this->rSortTimeMatrix($this->asItems, 'pub_date'); $asSortedItems = $this->rSortTimeMatrix($this->asItems, 'pubDate');
$sItems = implode("\n", array_map(array($this, 'buildItem'), $asSortedItems)); $sItems = implode("\n", array_map(array($this, 'buildItem'), $asSortedItems));
//Global Feed //Global Feed
$sFeed = '<?xml version="1.0" encoding="'.Settings::TEXT_ENC.'" ?>'; $sFeed = '<?xml version="1.0" encoding="'.Settings::TEXT_ENC.'" ?>';
$sFeed .= self::getHtml(self::getHtml($sRssFeedHeader.$sItems, 'channel'), 'rss', '', '', array('version'=>'2.0', 'xmlns:atom'=>'http://www.w3.org/2005/Atom')); $sFeed .= self::getHtml(self::getHtml($sRssChannel.$sItems, 'channel'), 'rss', '', '', array('version'=>'2.0', 'xmlns:atom'=>'http://www.w3.org/2005/Atom'));
return $sFeed; return $sFeed;
} }
@@ -93,11 +165,26 @@ class Feed extends PhpObject {
$sRssItem .= self::getHtml($asItem['link'], 'link'); $sRssItem .= self::getHtml($asItem['link'], 'link');
$sRssItem .= self::getHtml($asItem['category'], 'category'); $sRssItem .= self::getHtml($asItem['category'], 'category');
$sRssItem .= self::getHtml(self::cleanRss($asItem['description']), 'description'); $sRssItem .= self::getHtml(self::cleanRss($asItem['description']), 'description');
$sRssItem .= self::getHtml(self::getDate($asItem['pub_date']), 'pubDate'); $sRssItem .= self::getHtml(self::getDate($asItem['pubDate']), 'pubDate');
$sRssItem .= self::getHtml($asItem['guid'], 'guid', '', '', array('isPermaLink'=>'true')); $sRssItem .= self::getHtml($asItem['guid'], 'guid', '', '', array('isPermaLink'=>'true'));
return self::getHtml($sRssItem, 'item'); return self::getHtml($sRssItem, 'item');
} }
private function getPregMatch($pattern, $subject)
{
preg_match($pattern, $subject, $out);
//if there is some result... process it and return it
if(isset($out[1]))
{
//If code page is set convert character encoding to required
//if ($this->cp != '') $out[1] = iconv($this->rsscp, $this->cp.'//TRANSLIT', $out[1]);
return str_replace(array('<![CDATA[', ']]>'), '', trim($out[1]));
}
else return '';
}
private static function getHtml($oText, $sTag, $sClass='', $sStyle='', $asExtraAttr=array(), $bAutoClose=false, $sInter='') private static function getHtml($oText, $sTag, $sClass='', $sStyle='', $asExtraAttr=array(), $bAutoClose=false, $sInter='')
{ {
$sHtmlAttr = ''; $sHtmlAttr = '';

18
settings-sample.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
class Settings
{
const DB_SERVER = 'localhost';
const DB_LOGIN = '';
const DB_PASS = '';
const DB_NAME = 'databap';
const DB_ENC = 'utf8mb4';
const TEXT_ENC = 'UTF-8';
const TIMEZONE = 'Europe/Paris';
const DEBUG = true;
const MAIL_SCRIPT = '';
const MAIL_API_KEY = '';
public static $OSS_ACCOUNTS = array('S User'=>'pass');
}
?>