Show
Ignore:
Timestamp:
09/18/08 16:40:14 (4 months ago)
Author:
llaumgui
Message:

Métrosexualisation du code...

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • ez_publish/myutils/trunk/cronjobs/planet.php

    r222 r272  
    11<?php 
    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 */ 
    3035$beginScript = microtime(true); 
    3136 
     
    4348global $logInfo; 
    4449 
    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 
     67eZLog::write( "========== BEGIN | " . $logInfo['countTotalBlogs'] . " blogs ==========", $logInfo['logName'],    $logInfo['logDir'] ); 
    6368 
    6469 
     
    6671foreach ( $rssImportArray as $rssImport ) 
    6772{ 
    68         // Get RSSImport object 
    69         $rssImport                              = $rssImport->ContentObject; 
    70         $rssImportDataMap               = $rssImport->dataMap(); 
    71     $rssSource                          = $rssImportDataMap['location_rss']->content(); 
    72      
     73    // Get RSSImport object 
     74    $rssImport = $rssImport->ContentObject; 
     75    $rssImportDataMap = $rssImport->dataMap(); 
     76    $rssSource = $rssImportDataMap['location_rss']->content(); 
     77 
    7378    if( empty($rssSource)) 
    7479    { 
    75         if ( !$isQuiet ) 
    76                 { 
    77                 $cli->output( 'RSSImport '. $rssImport->attribute( 'name' ) .': Escape.' ); 
    78             } 
    79         eZLog::write( "====> " . $rssImport->attribute( 'name' ) . " : no RSS feeds", $logInfo['logName'], $logInfo['logDir'] ); 
    80         $logInfo['blogKO']++; 
     80        if ( !$isQuiet ) 
     81        { 
     82            $cli->output( 'RSSImport '. $rssImport->attribute( 'name' ) .': Escape.' ); 
     83        } 
     84        eZLog::write( "====> " . $rssImport->attribute( 'name' ) . " : no RSS feeds", $logInfo['logName'], $logInfo['logDir'] ); 
     85        $logInfo['blogKO']++; 
    8186    } 
    8287    else 
    8388    { 
    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        } 
    161166    } 
    162167} 
     
    165170eZStaticCache::executeActions(); 
    166171 
    167 $endScript              = microtime(true); 
    168 $executionTime  = round($endScript - $beginScript, 4); 
    169  
    170 eZLog::write(   "========== END | " . $executionTime . "s | " . $logInfo['countTotalBlogs'] . " blogs : " . $logInfo['blogOK'] . " OK, " . $logInfo['blogKO'] . " KO | " . $logInfo['countTotalBillets'] . " billets ==========\n", 
    171                                 $logInfo['logName'], 
    172                                 $logInfo['logDir'] ); 
     172$endScript = microtime(true); 
     173$executionTime = round($endScript - $beginScript, 4); 
     174 
     175eZLog::write( "========== END | " . $executionTime . "s | " . $logInfo['countTotalBlogs'] . " blogs : " . $logInfo['blogOK'] . " OK, " . $logInfo['blogKO'] . " KO | " . $logInfo['countTotalBillets'] . " billets ==========\n", 
     176              $logInfo['logName'], 
     177              $logInfo['logDir'] ); 
    173178 
    174179 
     
    178183/************************************************************************** Fonction */ 
    179184 
    180 /** 
    181  * Parse RSS 1.0 feed 
    182  * @param DOM root node 
    183  * @param RSS Import item 
    184  * @param cli 
     185/*§ 
     186 Parse RSS 1.0 feed 
     187 
     188 \param $root  DOM node 
     189 \param $rssImport RSS Import item 
     190 \param $cli eZCLI 
    185191 */ 
    186192function rssImport1( $root, $rssImport, $cli ) 
     
    204210        $cli->output( 'RSSImport '.$rssImport->attribute( 'name' ).': End. '.$addCount.' objects added' ); 
    205211    } 
    206     eZLog::write(       $rssImport->attribute( 'name' ) . " (RSS1) : $addCount objects added", $logInfo['logName'], $logInfo['logDir'] ); 
    207     $logInfo['countTotalBillets']       += $addCount; 
     212    eZLog::write( $rssImport->attribute( 'name' ) . " (RSS1) : $addCount objects added", $logInfo['logName'], $logInfo['logDir'] ); 
     213    $logInfo['countTotalBillets'] += $addCount; 
    208214    $logInfo['blogOK']++; 
    209215} 
     
    211217 
    212218 
    213 /** 
    214  * Parse RSS 2.0 feed 
    215  *  
    216  * @param DOM root node 
    217  * @param RSS Import item 
    218  * @param cli 
     219/*! 
     220 Parse RSS 2.0 feed 
     221 
     222 \param $root  DOM node 
     223 \param $rssImport RSS Import item 
     224 \param $cli eZCLI 
    219225 */ 
    220226function rssImport2( $root, $rssImport, $cli ) 
     
    237243        $cli->output( 'RSSImport '.$rssImport->attribute( 'name' ).': End. '.$addCount.' objects added' ); 
    238244    } 
    239         eZLog::write(   $rssImport->attribute( 'name' ) . " (RSS2) : $addCount objects added", $logInfo['logName'], $logInfo['logDir'] ); 
    240     $logInfo['countTotalBillets']       += $addCount; 
     245    eZLog::write(    $rssImport->attribute( 'name' ) . " (RSS2) : $addCount objects added", $logInfo['logName'], $logInfo['logDir'] ); 
     246    $logInfo['countTotalBillets'] += $addCount; 
    241247    $logInfo['blogOK']++; 
    242248} 
     
    244250 
    245251 
    246 /** 
    247  * Import specifiec rss item into content tree 
    248  *  
    249  * @param RSS item xml element 
    250  * @param $rssImport Object 
    251  * @param cli 
    252  * @param channel 
    253  * @return 1 if object added, 0 if not 
     252/*! 
     253 Import specifiec rss item into content tree 
     254 
     255 \param $item RSS item xml element 
     256 \param $rssImport RSS Import item 
     257 \param $cli eZCLI 
     258 \param $channel RSS channel xml element 
     259 \return 1 if object added, 0 if not 
    254260 */ 
    255261function importRSSItem( $item, $rssImport, $cli, $channel ) 
    256262{ 
    257263    global $isQuiet; 
    258      
    259     $iniPlanet          = eZINI::instance( "planet.ini" ); 
    260      
     264 
     265    $iniPlanet = eZINI::instance( "planet.ini" ); 
     266 
    261267    $rssImportID = $rssImport->attribute( 'id' ); 
    262268    $rssOwnerID = $rssImport->attribute( 'object_owner_id' ); // Get owner user id 
     
    341347    foreach( $classAttributeList as $classAttribute ) 
    342348    { 
    343         $classAttributeID               = $classAttribute->attribute( 'id' ); 
    344         $importClassAttributes  = $iniPlanet->variable( "BilletClass", "ClassAttributes" ); 
    345          
     349        $classAttributeID = $classAttribute->attribute( 'id' ); 
     350        $importClassAttributes = $iniPlanet->variable( "BilletClass", "ClassAttributes" ); 
     351 
    346352        if ( isset( $importClassAttributes[$classAttributeID] ) ) 
    347353        { 
     
    470476 
    471477 
    472 /** 
    473  * Enter description here... 
    474  * 
    475  * @param array $importDescriptionArray 
    476  * @param DOM $xmlDomNode 
    477  * @return unknown 
     478/*! 
     479 
     480 \param $importDescriptionArray array 
     481 \param $xmlDomNode DOM 
    478482 */ 
    479483function recursiveFindRSSElementValue( $importDescriptionArray, $xmlDomNode ) 
     
    514518 
    515519 
    516 /** 
    517  * Enter description here... 
    518  * 
    519  * @param unknown_type $objectAttribute 
    520  * @param unknown_type $value 
     520/*! 
     521 
     522 \param $objectAttribute 
     523 \param $value 
    521524 */ 
    522525function setObjectAttributeValue( $objectAttribute, $value ) 
     
    547550            $objectAttribute->setContent( $keyword ); 
    548551        } break; 
    549          
     552 
    550553        case 'eztext': 
    551554        { 
    552                 setEZTXTAttribute( $objectAttribute, $value ); 
     555            setEZTXTAttribute( $objectAttribute, $value ); 
    553556        } break; 
    554557 
     
    564567 
    565568 
    566 /** 
    567  * Enter description here... 
    568  * 
    569  * @param unknown_type $attribute 
    570  * @param unknown_type $attributeValue 
    571  * @param unknown_type $link 
     569/*! 
     570 
     571 \param $attribute 
     572 \param $attributeValue 
     573 \param $link 
    572574 */ 
    573575function setEZXMLAttribute( $attribute, $attributeValue, $link = false ) 
     
    596598 
    597599 
    598 /** 
    599  * Enter description here... 
    600  * 
    601  * @param unknown_type $attribute 
    602  * @param unknown_type $attributeValue 
    603  * @param unknown_type $link 
     600/*! 
     601 
     602 \param $attribute 
     603 \param $attributeValue 
     604 \param $link 
    604605 */ 
    605606function setEZTXTAttribute( $attribute, $attributeValue, $link = false ) 
    606607{ 
    607         myUtilsFunctions::cleanRSSDescription( $attributeValue ); 
    608         myUtilsFunctions::cleanTidy( $attributeValue ); 
    609          
    610         /* Et hop ! Dans eZ */ 
     608    myUtilsFunctions::cleanRSSDescription( $attributeValue ); 
     609    myUtilsFunctions::cleanTidy( $attributeValue ); 
     610 
     611    /* Et hop ! Dans eZ */ 
    611612    $attribute->setAttribute( 'data_text', $attributeValue ); 
    612613    $attribute->store();