<?

protected function _getIcon()
    {
        // #1479/1179M - Article icon automatic generation
        //if set to do not generate.
        $myConfig = $this->getConfig();

        if (!$myConfig->getConfigParam( 'blAutoIcons' ) ) {
            if ($this->oxarticles__oxicon->value) {
                return basename($this->oxarticles__oxicon->value);
            } else {
                $sQ = "UPDATE oxarticles SET oxicon = 'nopic_ico.jpg' WHERE oxid = '".$this->getId()."'";
                oxDb::getDb()->execute($sQ);
                return 'nopic_ico.jpg';
            }
        }

        // if set to generate and icon already exist
        if ( $this->oxarticles__oxicon->value && strpos( $this->oxarticles__oxicon->value, 'nopic_ico.jpg') === false ) {
            return basename($this->oxarticles__oxicon->value);
        }

        //we don't have an icon yet so lets make one
        if ($this->oxarticles__oxthumb->value && strpos( $this->oxarticles__oxthumb->value, 'nopic.jpg') === false &&  function_exists('gd_info')) {

            $sSourceFile = $this->oxarticles__oxthumb->value;
            $sTargetFile = str_replace('_th', '_ico', $sSourceFile);

            if ($sSourceFile == $sTargetFile) {
                $sPattern = '/(\.[a-z0-9]*$)/i';
                $sTargetFile = preg_replace($sPattern, '_ico\\1', $sTargetFile);
            }

            $sTarget = $myConfig->getAbsDynImageDir().'/icon/'. basename($sTargetFile);
            $sSource = $myConfig->getAbsDynImageDir().'/0/'. basename($sSourceFile);

            if (!$myConfig->getConfigParam( 'sIconsize' ) ) {
                $myConfig->setConfigParam( 'sIconsize', '56*42' );
            }

            $aSize = explode('*', $myConfig->getConfigParam( 'sIconsize' ) );
            $iX = $aSize[0];
            $iY = $aSize[1];

            oxUtilspic::getInstance()->resizeImage( $sSource, $sTarget, $iX, $iY );

            $sResult = $sTargetFile;
            
            //saving new icon
            $sIconFile = basename($sResult);
            $oDb = oxDb::getDb();
            $sQ = "UPDATE oxarticles SET oxicon = ".$oDb->quote($sIconFile)." WHERE oxid = '".$this->getId()."'";
            $oDb->execute($sQ);

        } else {
            $sResult = 'nopic_ico.jpg';
            $sIconFile = basename($sResult);
        }
        /*
        //saving new icon
        $sIconFile = basename($sResult);

        $sQ = "UPDATE oxarticles SET oxicon = '$sIconFile' WHERE oxid = '".$this->getId()."'";

        oxDb::getDb()->execute($sQ);
        */

        return $sIconFile;
    }
?>