Exemple #1
0
    function extractISBNNumber( $isbnNr = false, &$error )
    {
        $ini = eZINI::instance( 'content.ini' );
        $ean = preg_replace( "/[\s|\-]+/", "", $isbnNr );
        if ( is_numeric( $ean ) and strlen( $ean ) == self::LENGTH )
        {
            $prefix = substr( $ean, 0, self::PREFIX_LENGTH );
            $this->Prefix = $prefix;

            $checkDigit = substr( $ean, 12, self::CHECK_LENGTH );
            $this->CheckDigit = $checkDigit;
            if ( $prefix == self::PREFIX_978 )
            {
                $registrantValue = false;
                $groupValue = false;
                $publicationValue = false;
                $checkDigit = false;

                $groupRange = eZISBNGroupRange::extractGroup( $ean );
                $groupLength = false;
                if ( $groupRange )
                {
                    $groupLength = $groupRange->attribute( 'group_length' );
                }

                if ( $groupLength )
                {
                    $groupValue = substr( $ean, self::PREFIX_LENGTH, $groupLength );
                    $this->RegistrationGroup = $groupValue;

                    $group = eZISBNGroup::fetchByGroup( $groupValue );
                    if ( $group instanceof eZISBNGroup )
                    {
                        $registrant = eZISBNRegistrantRange::extractRegistrant( $ean, $group, $groupRange, $registrantLength );
                        if ( $registrant instanceof eZISBNRegistrantRange and
                             $registrantLength > 0 )
                        {
                            $registrantOffset = self::PREFIX_LENGTH + $groupLength;
                            $registrantValue = substr( $ean, $registrantOffset, $registrantLength );

                            $this->RegistrantElement = $registrantValue;

                            $publicationOffset = $registrantOffset + $registrantLength;
                            $publicationLength = 12 - $publicationOffset;
                            $publicationValue = substr( $ean, $publicationOffset, $publicationLength );
                            $this->PublicationElement = $publicationValue;
                        }
                        else
                        {
                            $strictValidation = $ini->variable( 'ISBNSettings', 'StrictValidation' );
                            if ( $strictValidation == 'true' )
                            {
                                $error = ezpI18n::tr( 'kernel/classes/datatypes', 'The registrant element of the ISBN number does not exist.' );
                                return false;
                            }
                        }
                    }
                    else
                    {
                        $strictValidation = $ini->variable( 'ISBNSettings', 'StrictValidation' );
                        if ( $strictValidation == 'true' )
                        {
                            $error = ezpI18n::tr( 'kernel/classes/datatypes', 'The ISBN number has a incorrect registration group number.' );
                            return false;
                        }
                    }
                }
                else
                {
                    $strictValidation = $ini->variable( 'ISBNSettings', 'StrictValidation' );
                    if ( $strictValidation == 'true' )
                    {
                        $error = ezpI18n::tr( 'kernel/classes/datatypes', 'The group element of the ISBN number does not exist.' );
                        return false;
                    }
                }
            }
            else
            {
                $strictValidation = $ini->variable( 'ISBNSettings', 'StrictValidation' );
                if ( $strictValidation == 'true' )
                {
                    $error = ezpI18n::tr( 'kernel/classes/datatypes', '%1 is not a valid prefix of the ISBN number.', null, array( $prefix ) );
                    return false;
                }
            }
        }
        else
        {
            $error = ezpI18n::tr( 'kernel/classes/datatypes', 'All ISBN 13 characters need to be numeric' );
            return false;
        }
        return true;
    }