| 2 | | /* |
| 3 | | * #################### BEGIN LICENSE BLOCK #################### |
| 4 | | * This file is part of myUtils. |
| 5 | | * Copyright (c) 2007 Guillaume Kulakowski and contributors. |
| 6 | | * |
| 7 | | * MyUtils is free software; you can redistribute it and/or modify |
| 8 | | * it under the terms of the GNU General Public License as |
| 9 | | * published by the Free Software Foundation; either version 2 |
| 10 | | * of the License, or (at your option) any later version. |
| 11 | | * |
| 12 | | * MyUtils is distributed in the hope that it will be useful, |
| 13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty |
| 14 | | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 15 | | * the GNU General Public License for more details. |
| 16 | | * |
| 17 | | * You should have received a copy of the GNU General Public |
| 18 | | * License along with ezipb; if not, write to the Free Software |
| 19 | | * Foundation, Inc., 59 Temple Place, Suite 330, |
| 20 | | * Boston, MA 02111-1307 USA |
| 21 | | * or visit http://www.gnu.org/licenses/gpl.html |
| 22 | | * ###################### END LICENSE BLOCK #################### |
| 23 | | * |
| 24 | | * planet cronjob. |
| 25 | | * |
| 26 | | * @author Guillaume Kulakowski <guillaume_AT_llaumgui_DOT_com> |
| 27 | | * @version 1.0 |
| 28 | | */ |
| 29 | | |
| | 2 | // |
| | 3 | // Created on: <01-Sep-2008 19:00:00 bf> |
| | 4 | // |
| | 5 | // SOFTWARE NAME: MyUtils |
| | 6 | // SOFTWARE RELEASE: 1.0 |
| | 7 | // BUILD VERSION: |
| | 8 | // COPYRIGHT NOTICE: Copyright (c) 2008 Guillaume Kulakowski and contributors |
| | 9 | // SOFTWARE LICENSE: GNU General Public License v2.0 |
| | 10 | // NOTICE: > |
| | 11 | // This program is free software; you can redistribute it and/or |
| | 12 | // modify it under the terms of version 2.0 of the GNU General |
| | 13 | // Public License as published by the Free Software Foundation. |
| | 14 | // |
| | 15 | // This program is distributed in the hope that it will be useful, |
| | 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| | 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| | 18 | // GNU General Public License for more details. |
| | 19 | // |
| | 20 | // You should have received a copy of version 2.0 of the GNU General |
| | 21 | // Public License along with this program; if not, write to the Free |
| | 22 | // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| | 23 | // MA 02110-1301, USA. |
| | 24 | // |
| | 25 | // |
| | 26 | |
| | 27 | |
| | 28 | /*! \file planet.php |
| | 29 | */ |
| | 30 | |
| | 31 | |
| | 32 | /*! |
| | 33 | \brief Planet cronjob. |
| | 34 | */ |
| 45 | | $iniSite = eZINI::instance( "site.ini" ); |
| 46 | | $iniPlanet = eZINI::instance( "planet.ini" ); |
| 47 | | $bloggeurGID = $iniPlanet->variable( "PlanetInfo", "UserGroupNodeID" ); |
| 48 | | |
| 49 | | $logInfo = array( |
| 50 | | 'countTotalBillets' => 0, |
| 51 | | 'countTotalBlogs' => 0, |
| 52 | | 'blogOK' => 0, |
| 53 | | 'blogKO' => 0, |
| 54 | | 'logName' => $iniPlanet->variable( "PlanetLog", "LogName" ), |
| 55 | | 'logDir' => $iniSite->variable( "FileSettings", "VarDir" ) . "/log" |
| 56 | | ); |
| 57 | | |
| 58 | | $rssImportArray = eZContentObjectTreeNode::fetch( $bloggeurGID ); |
| 59 | | $rssImportArray = $rssImportArray->children (); |
| 60 | | $logInfo['countTotalBlogs'] = count( $rssImportArray ); |
| 61 | | |
| 62 | | eZLog::write( "========== BEGIN | " . $logInfo['countTotalBlogs'] . " blogs ==========", $logInfo['logName'], $logInfo['logDir'] ); |
| | 50 | $iniSite = eZINI::instance( "site.ini" ); |
| | 51 | $iniPlanet = eZINI::instance( "planet.ini" ); |
| | 52 | $bloggeurGID = $iniPlanet->variable( "PlanetInfo", "UserGroupNodeID" ); |
| | 53 | |
| | 54 | $logInfo = array( |
| | 55 | 'countTotalBillets' => 0, |
| | 56 | 'countTotalBlogs' => 0, |
| | 57 | 'blogOK' => 0, |
| | 58 | 'blogKO' => 0, |
| | 59 | 'logName' => $iniPlanet->variable( "PlanetLog", "LogName" ), |
| | 60 | 'logDir' => $iniSite->variable( "FileSettings", "VarDir" ) . "/log" |
| | 61 | ); |
| | 62 | |
| | 63 | $rssImportArray = eZContentObjectTreeNode::fetch( $bloggeurGID ); |
| | 64 | $rssImportArray = $rssImportArray->children (); |
| | 65 | $logInfo['countTotalBlogs'] = count( $rssImportArray ); |
| | 66 | |
| | 67 | eZLog::write( "========== BEGIN | " . $logInfo['countTotalBlogs'] . " blogs ==========", $logInfo['logName'], $logInfo['logDir'] ); |
| 84 | | $addCount = 0; |
| 85 | | |
| 86 | | if ( !$isQuiet ) |
| 87 | | { |
| 88 | | $cli->output( 'RSSImport '.$rssImport->attribute( 'name' ).': Starting.' ); |
| 89 | | } |
| 90 | | |
| 91 | | $xmlData = myUtilsFunctions::getDataByURL( $rssSource ); |
| 92 | | if ( $xmlData === false ) |
| 93 | | { |
| 94 | | if ( !$isQuiet ) |
| 95 | | { |
| 96 | | $cli->output( 'RSSImport '.$rssImport->attribute( 'name' ).': Failed to open RSS feed file: '.$rssSource ); |
| 97 | | } |
| 98 | | eZLog::write( "====> " . $rssImport->attribute( 'name' ) . " : Failed to open RSS feed file", $logInfo['logName'], $logInfo['logDir'] ); |
| 99 | | $logInfo['blogKO']++; |
| 100 | | continue; |
| 101 | | } |
| 102 | | |
| 103 | | // Create DomDocument from http data |
| 104 | | $domDocument = new DOMDocument( '1.0', 'utf-8' ); |
| 105 | | $success = $domDocument->loadXML( $xmlData ); |
| 106 | | |
| 107 | | if ( !$success ) |
| 108 | | { |
| 109 | | if ( !$isQuiet ) |
| 110 | | { |
| 111 | | $cli->output( 'RSSImport '.$rssImport->attribute( 'name' ).': Invalid RSS document.' ); |
| 112 | | } |
| 113 | | eZLog::write( "====> " . $rssImport->attribute( 'name' ) . " : Invalid RSS document", $logInfo['logName'], $logInfo['logDir'] ); |
| 114 | | $logInfo['blogKO']++; |
| 115 | | continue; |
| 116 | | } |
| 117 | | |
| 118 | | $root = $domDocument->documentElement; |
| 119 | | |
| 120 | | switch( $root->getAttribute( 'version' ) ) |
| 121 | | { |
| 122 | | default: |
| 123 | | case '1.0': |
| 124 | | { |
| 125 | | $version = '1.0'; |
| 126 | | } break; |
| 127 | | |
| 128 | | case '0.91': |
| 129 | | case '0.92': |
| 130 | | case '2.0': |
| 131 | | { |
| 132 | | $version = $root->getAttribute( 'version' ); |
| 133 | | } break; |
| 134 | | } |
| 135 | | |
| 136 | | if ( $version != $rssImportDataMap['rss_version']->toString() ) |
| 137 | | { |
| 138 | | if ( !$isQuiet ) |
| 139 | | { |
| 140 | | $cli->output( 'RSSImport '.$rssImport->attribute( 'name' ).': Invalid RSS version missmatch. Please reconfigure import.' ); |
| 141 | | } |
| 142 | | eZLog::write( $rssImport->attribute( 'name' ) . " : Invalid RSS version missmatch. Please reconfigure import", $logInfo['logName'], $logInfo['logDir'] ); |
| 143 | | $logInfo['blogKO']++; |
| 144 | | continue; |
| 145 | | } |
| 146 | | switch( $root->getAttribute( 'version' ) ) |
| 147 | | { |
| 148 | | default: |
| 149 | | case '1.0': |
| 150 | | { |
| 151 | | rssImport1( $root, $rssImport, $cli ); |
| 152 | | } break; |
| 153 | | |
| 154 | | case '0.91': |
| 155 | | case '0.92': |
| 156 | | case '2.0': |
| 157 | | { |
| 158 | | rssImport2( $root, $rssImport, $cli ); |
| 159 | | } break; |
| 160 | | } |
| | 89 | $addCount = 0; |
| | 90 | |
| | 91 | if ( !$isQuiet ) |
| | 92 | { |
| | 93 | $cli->output( 'RSSImport '.$rssImport->attribute( 'name' ).': Starting.' ); |
| | 94 | } |
| | 95 | |
| | 96 | $xmlData = myUtilsFunctions::getDataByURL( $rssSource ); |
| | 97 | if ( $xmlData === false ) |
| | 98 | { |
| | 99 | if ( !$isQuiet ) |
| | 100 | { |
| | 101 | $cli->output( 'RSSImport '.$rssImport->attribute( 'name' ).': Failed to open RSS feed file: '.$rssSource ); |
| | 102 | } |
| | 103 | eZLog::write( "====> " . $rssImport->attribute( 'name' ) . " : Failed to open RSS feed file", $logInfo['logName'], $logInfo['logDir'] ); |
| | 104 | $logInfo['blogKO']++; |
| | 105 | continue; |
| | 106 | } |
| | 107 | |
| | 108 | // Create DomDocument from http data |
| | 109 | $domDocument = new DOMDocument( '1.0', 'utf-8' ); |
| | 110 | $success = $domDocument->loadXML( $xmlData ); |
| | 111 | |
| | 112 | if ( !$success ) |
| | 113 | { |
| | 114 | if ( !$isQuiet ) |
| | 115 | { |
| | 116 | $cli->output( 'RSSImport '.$rssImport->attribute( 'name' ).': Invalid RSS document.' ); |
| | 117 | } |
| | 118 | eZLog::write( "====> " . $rssImport->attribute( 'name' ) . " : Invalid RSS document", $logInfo['logName'], $logInfo['logDir'] ); |
| | 119 | $logInfo['blogKO']++; |
| | 120 | continue; |
| | 121 | } |
| | 122 | |
| | 123 | $root = $domDocument->documentElement; |
| | 124 | |
| | 125 | switch( $root->getAttribute( 'version' ) ) |
| | 126 | { |
| | 127 | default: |
| | 128 | break; |
| | 129 | case '1.0': |
| | 130 | $version = '1.0'; |
| | 131 | break; |
| | 132 | case '0.91': |
| | 133 | break; |
| | 134 | case '0.92': |
| | 135 | break; |
| | 136 | case '2.0': |
| | 137 | $version = $root->getAttribute( 'version' ); |
| | 138 | break; |
| | 139 | } |
| | 140 | |
| | 141 | if ( $version != $rssImportDataMap['rss_version']->toString() ) |
| | 142 | { |
| | 143 | if ( !$isQuiet ) |
| | 144 | { |
| | 145 | $cli->output( 'RSSImport '.$rssImport->attribute( 'name' ).': Invalid RSS version missmatch. Please reconfigure import.' ); |
| | 146 | } |
| | 147 | eZLog::write( $rssImport->attribute( 'name' ) . " : Invalid RSS version missmatch. Please reconfigure import", $logInfo['logName'], $logInfo['logDir'] ); |
| | 148 | $logInfo['blogKO']++; |
| | 149 | continue; |
| | 150 | } |
| | 151 | switch( $root->getAttribute( 'version' ) ) |
| | 152 | { |
| | 153 | default: |
| | 154 | break; |
| | 155 | case '1.0': |
| | 156 | rssImport1( $root, $rssImport, $cli ); |
| | 157 | break; |
| | 158 | case '0.91': |
| | 159 | break; |
| | 160 | case '0.92': |
| | 161 | break; |
| | 162 | case '2.0': |
| | 163 | break; |
| | 164 | rssImport2( $root, $rssImport, $cli ); |
| | 165 | } |