[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/cronjobs/ -> linkcheck.php (source)

   1  <?php
   2  //
   3  // Definition of  class
   4  //
   5  // Created on: <07-Jul-2003 10:06:19 wy>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*! \file linkcheck.php
  30  */
  31  include_once ( "lib/ezutils/classes/ezmodule.php" );
  32  include_once ( 'kernel/classes/datatypes/ezurl/ezurl.php' );
  33  include_once ( "lib/ezutils/classes/ezini.php" );
  34  include_once ( "lib/ezutils/classes/ezhttptool.php" );
  35  
  36  ini_set( 'user_agent', 'eZ publish Link Validator' );
  37  
  38  eZModule::setGlobalPathList( array( "kernel" ) );
  39  if ( !$isQuiet )
  40      $cli->output( "Checking link ..." );
  41  
  42  $cronjobIni =& eZINI::instance( 'cronjob.ini' );
  43  $siteURLs = $cronjobIni->variable( 'linkCheckSettings', 'SiteURL' );
  44  $linkList = eZURL::fetchList( array( 'only_published' => true ) );
  45  foreach ( array_keys( $linkList ) as $key )
  46  {
  47      $link =& $linkList[$key];
  48      $linkID = $link->attribute( 'id' );
  49      $url = $link->attribute( 'url' );
  50      $isValid = $link->attribute( 'is_valid' );
  51  
  52      $cli->output( "check-" . $cli->stylize( 'emphasize', $url ) . " ", false );
  53      if ( preg_match("/^(http:)/i", $url ) or
  54           preg_match("/^(ftp:)/i", $url ) or
  55           preg_match("/^(https:)/i", $url ) or
  56           preg_match("/^(file:)/i", $url ) or
  57           preg_match("/^(mailto:)/i", $url ) )
  58      {
  59          if ( preg_match("/^(mailto:)/i", $url))
  60          {
  61              if ( eZSys::osType() != 'win32' )
  62              {
  63                  $url = trim( preg_replace("/^mailto:(.+)/i", "\\1", $url));
  64                  list($userName, $host) = split("@", $url);
  65                  list($host, $junk)= split("\?", $host);
  66                  $dnsCheck = checkdnsrr( $host,"MX" );
  67                  if ( !$dnsCheck )
  68                  {
  69                      if ( $isValid )
  70                          eZURL::setIsValid( $linkID, false );
  71                      $cli->output( $cli->stylize( 'warning', "invalid" ) );
  72                  }
  73                  else
  74                  {
  75                      if ( !$isValid )
  76                          eZURL::setIsValid( $linkID, true );
  77                      $cli->output( $cli->stylize( 'success', "valid" ) );
  78                  }
  79              }
  80          }
  81          else if ( preg_match("/^(http:)/i", $url ) or
  82                    preg_match("/^(file:)/i", $url ) or
  83                    preg_match("/^(ftp:)/i", $url ) )
  84          {
  85              if ( !eZHTTPTool::getDataByURL( $url, true ) )
  86              {
  87                  if ( $isValid )
  88                      eZURL::setIsValid( $linkID, false );
  89                  $cli->output( $cli->stylize( 'warning', "invalid" ) );
  90              }
  91              else
  92              {
  93                  if ( !$isValid )
  94                      eZURL::setIsValid( $linkID, true );
  95                  $cli->output( $cli->stylize( 'success', "valid" ) );
  96              }
  97          }
  98          else
  99          {
 100              $cli->output( "Couldn't check https protocol" );
 101          }
 102      }
 103      else
 104      {
 105          include_once ( 'kernel/classes/ezurlalias.php' );
 106          $translateResult = eZURLAlias::translate( $url );
 107          if ( !$translateResult )
 108              $translateResult =& eZURLAlias::translateByWildcard( $url );
 109  
 110          if ( !$translateResult )
 111          {
 112                $isInternal = false;
 113                // Check if it is a valid internal link.
 114                foreach ( $siteURLs as $siteURL )
 115                {
 116                    $siteURL = preg_replace("/\/$/e", "", $siteURL );
 117                    $fp = @fopen( $siteURL . "/". $url, "r" );
 118                    if ( !$fp )
 119                    {
 120                        // do nothing
 121                    }
 122                    else
 123                    {
 124                        $isInternal = true;
 125                        fclose($fp);
 126                    }
 127                }
 128                $translateResult = $isInternal;
 129          }
 130          if ( $translateResult )
 131          {
 132              if ( !$isValid )
 133                  eZURL::setIsValid( $linkID, true );
 134              $cli->output( $cli->stylize( 'success', "valid" ) );
 135          }
 136          else
 137          {
 138              if ( $isValid )
 139                  eZURL::setIsValid( $linkID, false );
 140              $cli->output( $cli->stylize( 'warning', "invalid" ) );
 141          }
 142      }
 143      eZURL::setLastChecked( $linkID );
 144  }
 145  
 146  if ( !$isQuiet )
 147      $cli->output( "All links have been checked!" );
 148  
 149  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7