1

我对此很陌生,但我想学习...

我有一个我想使用的 GPL 插件(用于 Joomla 1.6 / JomSocial 2.6)(w/Joomla 2.5 和 JomSocial 2.8),但它需要一些修复或更新。它应该检查默认头像并将其替换为随机头像。它安装但不起作用。

  1. 我如何验证它是否获得了所需的数据?

  2. 我认为一个问题可能是数据库中没有列出默认文件。看起来这个插件希望有一个。

    function onUserLogin($user, $options)
    {
        $juser = CFactory::getUser($user);
        $curavatar = $juser->getThumbAvatar();
    
        $gender = $juser->getInfo($this->params->get( 'genderfield' , 'FIELD_GENDER' ));
    
        if($this->compareEnd("default.jpg", $curavatar) || $this->compareEnd("user.png", $curavatar) || ($this->contains('minisocialgender_images',$curavatar) && $this->params->get( 'reassign' , '0' )))
        {
    

该脚本只有大约 100 行,所以我希望有人能指出一些明显的问题。

感谢您的关注以及您可以提供的任何帮助。这是脚本的其余部分...

// no direct access

defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.plugin.plugin' );

require_once( JPATH_BASE . DS . 'components' . DS . 'com_community' . DS . 'libraries' . DS . 'core.php');

class plgUserMiniSocialGender extends JPlugin
{

function plgUserMiniSocialGender(& $subject, $config)
{
    parent::__construct($subject, $config);
}

//function onLoginUser($user, $options)
function onUserLogin($user, $options)
{
    //$juser = $this->getJomSocialUser($user);
    $juser = CFactory::getUser($userid);

    //$curavatar = $juser->getAvatar();
    $curavatar = $juser->getThumbAvatar();

    $gender = $juser->getInfo($this->params->get( 'genderfield' , 'FIELD_GENDER' ));
    //$gender = $user->getInfo('FIELD_GENDER');

    if($this->compareEnd("default.jpg", $curavatar) || $this->compareEnd("user.png", $curavatar) || ($this->contains('minisocialgender_images',$curavatar) && $this->params->get( 'reassign' , '0' )))
    {
        if($gender)
        {
            $maleurl = JPATH_SITE . DS . 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . 'male' . DS;
            $femaleurl = JPATH_SITE . DS . 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . 'female' . DS;

            $usermodel =& CFactory::getModel('user');

            if($this->params->get( 'maletype' , 'Male' ) == $gender)
            {
                if($this->contains("male", $curavatar))
                    return;
            }

            if($this->params->get( 'femaletype' , 'Female' ) == $gender)
            {
                if($this->contains("female", $curavatar))
                    return;
            }

            if($gender == $this->params->get( 'maletype' , 'Male' ))
            {
                $files = $this->getDirItems($maleurl);
                $random =   rand ( 0 , (count( $files) - 1));

                JFile::copy($maleurl . $files[$random], JPATH_SITE . DS . 'plugins' . DS . 'user' . DS .'minisocialgender' .DS . 'minisocialgender_images' . DS . $juser->id . 'male' . '.png');
                JFile::copy($maleurl . 'thumb' . DS .$files[$random], JPATH_SITE . DS . 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . 'thumb' . $juser->id . 'male' . '.png');

                $usermodel->setImage($juser->id, 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . $juser->id . 'male' . '.png', 'avatar');
                $usermodel->setImage($juser->id, 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . 'thumb'  . $juser->id . 'male' . '.png', 'thumb');
            }
            elseif($gender == $this->params->get( 'femaletype' , 'Female' ))
            {
                $files = $this->getDirItems($femaleurl);
                $random= rand ( 0 , (count( $files) - 1) );

                JFile::copy($femaleurl . $files[$random], JPATH_SITE . DS . 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . $juser->id . 'female' . '.png');
                JFile::copy($femaleurl . 'thumb' . DS . $files[$random], JPATH_SITE . DS . 'plugins' . DS . 'minisocialgender' .DS . 'user' . DS . 'minisocialgender_images' . DS . 'thumb' . $juser->id . 'female' . '.png');

                $usermodel->setImage($juser->id,  'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . $juser->id . 'female' . '.png', 'avatar');
                $usermodel->setImage($juser->id,  'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . 'thumb' . $juser->id . 'female' . '.png', 'thumb');
            }

            if($this->params->get( 'warnuser' , 1 ))
            {
                JFactory::getApplication()->enqueueMessage( $this->params->get( 'warnmessage' ));
            }
        }
    }
}

function getDirItems($dir)
{
    $files = array();
    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {
            while (($file = readdir($dh)) !== false) {
                if(filetype($dir . $file) == "file")
                {
                    $files[] = $file;
                }
            }
            closedir($dh);
        }
    }
    return $files;
}

function compareEnd($end, $fullstring)
{
    $StrLen = strlen($end);
    $FullStrEnd = substr($fullstring, strlen($fullstring) - $StrLen);
    return ($end == $FullStrEnd);
}

function contains($needle, $haystack)
{
    $pos = strpos($haystack,$needle);
    if($pos)
    return true;
    else
    return false;
}

//function getJomSocialUser($user)
//{
//  $user2 =& JFactory::getUser();
//  $userid = $user2->id;
//  return CFactory::getUser($userid);
//}
}
4

0 回答 0