Joomla / JomSocial的随机头像插件 - 如何诊断和修复?

时间:2013-07-01 08:35:45

标签: php joomla2.5 joomla-extensions jomsocial

我是新手,但我想学习......

我有一个GPL插件(适用于Joomla 1.6 / JomSocial 2.6)我想使用(带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' )))
        {
    
  3. 脚本只有大约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);
    //}
    }
    

0 个答案:

没有答案