diff --git a/inc/databap.php b/inc/databap.php index 77d06ec..f0937f1 100755 --- a/inc/databap.php +++ b/inc/databap.php @@ -262,7 +262,7 @@ class Databap extends PhpObject 'email' => "varchar(100) NOT NULL", 'hash' => "varchar(32) NOT NULL", 'pass' => "varchar(255) NOT NULL", - 'auth_cookie' => "varchar(255) NOT NULL", + 'auth_cookie' => "varchar(255)", 'active' => "tinyint(1) DEFAULT ".self::MEMBER_ACTIVE, 'clearance' => "int(1) DEFAULT ".self::CLEARANCE_MEMBER, 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)); //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_BG=>array('#04357B'=>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_EMAIL=>array('email inconnu'=>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) { @@ -510,7 +510,7 @@ class Databap extends PhpObject 'copyright'=>'Powered by Francois Lutran. RSS Feed Generator under GPLv3 License', 'description'=>'Flux RSS du chat'.($sCat==''?'':', section '.$sCat), 'language'=>'fr', - 'webmaster_mail'=>'francois@lutran.fr' + 'webMaster'=>'francois@lutran.fr' ); $oFeed = new Feed($asDesc); @@ -530,7 +530,7 @@ class Databap extends PhpObject 'description'=>$asRow['message'], 'author'=>$asRow['nickname'], 'link'=>$sChatlink, - 'pub_date'=>$asRow['time'], + 'pubDate'=>$asRow['time'], 'guid'=>$sChatlink ); $oFeed->addItem($asItem); @@ -581,7 +581,7 @@ class Databap extends PhpObject 'description'=>'Lien posté par '.self::getNickNameFormat($asRow['nickname']).' à '.self::getDateFormat($asRow['led']).' : '.$asRow['message'].'', 'author'=>$asRow['nickname'], 'link'=>$sChatlink, - 'pub_date'=>$asRow['led'], + 'pubDate'=>$asRow['led'], 'guid'=>$sChatlink ); $oFeed->addItem($asItem); @@ -624,46 +624,36 @@ class Databap extends PhpObject { $asArticles = array(); - //SCN SAP - $sSAPDomain = 'http://scn.sap.com'; - $asBlogPaths = array( '/community/data-warehousing/bw/blog', - '/community/data-warehousing/blog', - '/community/bw-hana/blog', - '/community/businessobjects-design-studio/blog', - '/community/businessobjects-analysis-ms-office/blog'); - foreach($asBlogPaths as $sSAPBlogPath) + //SAP Blogs + $sSAPDomain = 'https://blogs.sap.com/'; + $asBlogTags = array('73554900100700001049', //Lumira + '73554900100700000818', //Design Studio + '242586194391178517100436979900901', //BW + '01200245450800000012', //Another BW + '242586194391178517100436979900901', //Another BW + '73554900100700001661', // BW/4HANA + '73554900100700000814', //BO Platform + '907900296036854683333078008146613', //Webi + '73554900100700000813', //Analysis + ); + $this->oClassManagement->incClass('rss'); + foreach($asBlogTags as $asBlogTag) { - $sSAPBlogUrl = $sSAPDomain.$sSAPBlogPath; - $oDom = $this->getRemotePageDom($sSAPBlogUrl); - $aoArticles = $oDom->getElementsByTagName('header'); - foreach($aoArticles as $oArticle) + $oRss = new Feed(); + $oRss->loadRss($sSAPDomain.'tags/'.$asBlogTag.'/feed/'); + $asBlogItems = $oRss->getItems(); + foreach($asBlogItems as $asBlogItem) { - if($oArticle->getAttribute('class')=='jive-blog-post-subject') - { - $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['link'] = $oLink->getAttribute('href'); - $asArticleInfo['date'] = mb_substr(str_replace(array($sSAPBlogUrl.'/', '/'), array('', '-'), $asArticleInfo['link']), 0, 10); - break; - //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['last_name'] = implode('-', $asNames); - $asArticleInfo['email'] = $sSAPDomain.$oLink->getAttribute('href'); - break; - } - } - $asArticles[] = $asArticleInfo; - } + $asArticleInfo['title'] = $asBlogItem['title']; + $asArticleInfo['title'] = mb_substr($asArticleInfo['title'], -1)=='.'?mb_substr($asArticleInfo['title'], 0, -1):$asArticleInfo['title']; + + $asArticleInfo['link'] = $asBlogItem['link']; + $asArticleInfo['date'] = date(self::DATE_SQL_FORMAT, strtotime($asBlogItem['pubDate'])); + $asNames = array_filter(explode(' ', ToolBox::mb_ucwords(trim($asBlogItem['author'])))); + $asArticleInfo['first_name'] = array_shift($asNames); + $asArticleInfo['last_name'] = implode('-', $asNames); + $asArticleInfo['email'] = ''; + $asArticles[] = $asArticleInfo; } } @@ -818,7 +808,7 @@ class Databap extends PhpObject MySqlManager::getId(self::COMP_TABLE)=>$iCompanyId, 'pass'=>$this->oAuth->HashPassword(self::getLoginToken($sCompany)), '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; $iUserId = $this->oMySql->insertRow(self::USER_TABLE, $asInfo); $bSuccess = ($iUserId>0); diff --git a/inc/rss.php b/inc/rss.php index 51896bc..2921aa0 100644 --- a/inc/rss.php +++ b/inc/rss.php @@ -3,28 +3,95 @@ /** * RSS Feed Class * @author franzz - * @version 1.1 - * - * 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' + * @version 2.0 */ -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; - 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); - 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')); } + public function loadRss($sUrl) + { + $sRssContent = file_get_contents($sUrl); + + //Parse document encoding (useless) + $sEncoding = $this->getPregMatch("'encoding=[\'\"](.*?)[\'\"]'si", $sRssContent); + + //Parse Channel info + preg_match("'(.*?)'si", $sRssContent, $sChannelContent); + foreach(self::CHANNEL_TAGS as $sChannelTag) + { + $sTagContent = $this->getPregMatch("'<$sChannelTag.*?>(.*?)'si", $sChannelContent[1]); + if($sTagContent != '') $this->asChannel[$sChannelTag] = $sTagContent; + } + + //Parse Text Input info + /*preg_match("']*[^/])>(.*?)'si", $sRssContent, $out_textinfo); + if (isset($out_textinfo[2])) { + foreach($this->textinputtags as $textinputtag) { + $temp = $this->getPregMatch("'<$textinputtag.*?>(.*?)'si", $out_textinfo[2]); + if ($temp != '') $result['textinput_'.$textinputtag] = $temp; // Set only if not empty + } + }*/ + + //Parse Image info + /*preg_match("'(.*?)'si", $sRssContent, $out_imageinfo); + if (isset($out_imageinfo[1])) { + foreach($this->imagetags as $imagetag) { + $temp = $this->getPregMatch("'<$imagetag.*?>(.*?)'si", $out_imageinfo[1]); + if ($temp != '') $result['image_'.$imagetag] = $temp; // Set only if not empty + } + }*/ + + //Parse Items + preg_match_all("'(.*?)'si", $sRssContent, $asItems); + $i = 0; + foreach($asItems[2] as $asItem) + { + $asItemTags = array(); + foreach(self::ITEM_TAGS as $sItemTag) + { + $sTagContent = $this->getPregMatch("'<$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("'(.*?)'si", $asItem); + if($sTagContent != '') $asItemTags['author'] = $sTagContent; + } + + $this->asItems[] = $asItemTags; + } + } + public function addItem($asItem) { $this->asItems[] = $asItem; @@ -38,12 +105,17 @@ class Feed extends PhpObject { return $bExist; } + public function getItems() + { + return $this->asItems; + } + private function getGlobalPubDate() { $iGlobalPubDate = 0; foreach($this->asItems as $asItem) { - $iItemPubDate = strtotime($asItem['pub_date']); + $iItemPubDate = strtotime($asItem['pubDate']); if($iItemPubDate>$iGlobalPubDate) { $iGlobalPubDate = $iItemPubDate; @@ -55,24 +127,24 @@ class Feed extends PhpObject { public function getFeed() { - //feed header - $sRssFeedHeader = self::getHtml($this->asDesc['title'], 'title'); - $sRssFeedHeader .= self::getHtml($this->asDesc['link'], 'link'); - $sRssFeedHeader .= self::getHtml($this->asDesc['copyright'], 'copyright'); - $sRssFeedHeader .= self::getHtml($this->asDesc['description'], 'description'); - $sRssFeedHeader .= self::getHtml('', 'atom:link', '', '', array('href'=>$this->asDesc['link'], 'rel'=>'self', 'type'=>'application/atom+xml'), true); - $sRssFeedHeader .= self::getHtml($this->asDesc['language'], 'language'); - $sRssFeedHeader .= self::getHtml($this->getGlobalPubDate(), 'pubDate'); - $sRssFeedHeader .= self::getHtml('Lutran.fr RSS Feed Generator', 'generator'); - $sRssFeedHeader .= self::getHtml($this->asDesc['webmaster_mail'].' (Webmaster)', 'webMaster'); + //Feed Channel + $sRssChannel = self::getHtml($this->asChannel['title'], 'title'); + $sRssChannel .= self::getHtml($this->asChannel['link'], 'link'); + $sRssChannel .= self::getHtml($this->asChannel['copyright'], 'copyright'); + $sRssChannel .= self::getHtml($this->asChannel['description'], 'description'); + $sRssChannel .= self::getHtml('', 'atom:link', '', '', array('href'=>$this->asChannel['link'], 'rel'=>'self', 'type'=>'application/atom+xml'), true); + $sRssChannel .= self::getHtml($this->asChannel['language'], 'language'); + $sRssChannel .= self::getHtml($this->getGlobalPubDate(), 'lastBuildDate'); + $sRssChannel .= self::getHtml('Lutran.fr RSS Feed Generator', 'generator'); + $sRssChannel .= self::getHtml($this->asChannel['webMaster'].' (Webmaster)', 'webMaster'); - //feed items - $asSortedItems = $this->rSortTimeMatrix($this->asItems, 'pub_date'); + //Feed Items + $asSortedItems = $this->rSortTimeMatrix($this->asItems, 'pubDate'); $sItems = implode("\n", array_map(array($this, 'buildItem'), $asSortedItems)); //Global Feed $sFeed = ''; - $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; } @@ -93,11 +165,26 @@ class Feed extends PhpObject { $sRssItem .= self::getHtml($asItem['link'], 'link'); $sRssItem .= self::getHtml($asItem['category'], 'category'); $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')); 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(''), '', trim($out[1])); + } + else return ''; + } + private static function getHtml($oText, $sTag, $sClass='', $sStyle='', $asExtraAttr=array(), $bAutoClose=false, $sInter='') { $sHtmlAttr = ''; diff --git a/settings-sample.php b/settings-sample.php new file mode 100644 index 0000000..31d8eb3 --- /dev/null +++ b/settings-sample.php @@ -0,0 +1,18 @@ +'pass'); +} + +?> \ No newline at end of file