移植MyBB到SAE平台(三)

修改一下头像,发现无法修改,又是写文件的问题。

 

首先下载api文件saestorage.class.php.

 

修改1:inc/functions_upload.php, 修改function remove_avatars($uid, $exclude="")为

function remove_avatars($uid, $exclude="")
{
	global $mybb, $plugins;
	
	if(defined('IN_ADMINCP'))
	{
		$avatarpath = $mybb->settings['avataruploadpath'];
	}
	else
	{
		$avatarpath = $mybb->settings['avataruploadpath'];
	}

	$file = "avatar_".$uid.".png";

	if ($file != $exclude)
	{
		@unlink($avatarpath."/".$file);
	}

	$file = "avatar_".$uid.".jpg";

	if ($file != $exclude)
	{
		@unlink($avatarpath."/".$file);
	}

	$file = "avatar_".$uid.".gif";

	if ($file != $exclude)
	{
		@unlink($avatarpath."/".$file);
	}	
}



修改2:把所有的

	if(defined('IN_ADMINCP'))
	{
		$avatarpath = '../'.$mybb->settings['avataruploadpath'];
		$lang->load("messages", true);
	}


替换成

	if(defined('IN_ADMINCP'))
	{
		$avatarpath = $mybb->settings['avataruploadpath'];
		$lang->load("messages", true);
	}


在function upload_avatar($avatar=array(), $uid=0)最后加上

 $ret['avatar'] = str_replace("saestor://uploads/", "", $ret['avatar']);

这是使得保存到数据库中时不包含saestor://uploads前缀,

 

修改3:inc/class_session.php,在function load_user($uid, $password='')中,添加如下代码

		//get the real avatar url
		if ($mybb->user['avatar'] != '')
		{
			if (stristr($mybb->user['avatar'], "://") == false)
			{
				require_once MYBB_ROOT."saelib/saestorage.class.php";
				$s = new SaeStorage();
		
				$mybb->user['avatar'] = $s->getUrl("uploads", $mybb->user['avatar']);
			}
		}


目的是获取头像在storage中的真正url位置

在inc/functions_user.php的function get_usertitle($uid="")中添加同样代码

		//get the real avatar url
		if ($user['avatar'] != '')
		{
			if (stristr($user['avatar'], "://") == false)
			{
				require_once MYBB_ROOT."saelib/saestorage.class.php";
				$s = new SaeStorage();
		
				$user['avatar'] = $s->getUrl("uploads", $user['avatar']);
			}
		}


在inc/functions_post.php的第304行后加上

			if (stristr($post['avatar'], "://") == false)
			{
				require_once MYBB_ROOT."saelib/saestorage.class.php";
				$s = new SaeStorage();
	
				$post['avatar'] = $s->getUrl("uploads", $post['avatar']);
			}


在memberlist.php的第331行后加上

			if (stristr($user['avatar'], "://") == false)
			{
				require_once MYBB_ROOT."saelib/saestorage.class.php";
				$s = new SaeStorage();
	
				$user['avatar'] = $s->getUrl("uploads", $user['avatar']);
			}


在admin\modules\user\users.php中,

替换"../".$mybb->settings['avatardir']为$mybb->settings['avatardir']。

在576行和3437行分别加上

	//get the real avatar url
	if ($user['avatar'] != '')
	{
		if (stristr($user['avatar'], "://") == false)
		{
			require_once MYBB_ROOT."saelib/saestorage.class.php";
			$s = new SaeStorage();

			$user['avatar'] = $s->getUrl("uploads", $user['avatar']);
		}
	}


修改@unlink("../".substr($user['avatar'], 2, -20));为@unlink("saestor://uploads/".$user{'avatar'});

完成。上传代码,再试一下更改头像,终于可以了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#include<stdio.h> #include<math.h> #include<stdlib.h> #define dx 100 struct bb { int m; int n; int hl[dx][dx]; int jk[dx][dx]; }; double det(struct bb *A, int n); double algebraic_cofactor(struct bb *A, struct bb *B, int row, int col); void adjoint(struct bb *A, struct bb *B); void inverse(struct bb *A,double inv[][dx],int N); int main() { struct bb A; int m,n; printf("输入几行几列:\n"); scanf("%d %d",&m,&n); A.m = m; A.n = n; printf("请输入矩阵:\n"); for(int i = 0; i < A.m; i++) { for(int j = 0; j < A.n; j++) { scanf("%d", &A.hl[i][j]); } } double inv[dx][dx]; int N = A.m; // Assuming square matrix // 计算逆矩阵 inverse(&A, inv, N); // 输出结果 printf("逆矩阵:\n"); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { printf("%.2f ", A.hl[i][j]); } printf("\n"); } return 0; } double det(struct bb *A, int n) { double sum=0; if(n==1) { return A->hl[0][0]; } else if(n==2) { return A->hl[0][0]*A->hl[1][1]-A->hl[0][1]*A->hl[1][0]; } int i,j,k; struct bb *mybb = (struct bb *)malloc(sizeof(struct bb)); for(k=0;k<n;k++) { double b[dx][dx]; for(i=1;i<n;i++) { for(j=0;j<n;j++) { if(j<k) { b[i-1][j]=A->hl[i][j]; } else if(j>k) { b[i-1][j-1]=A->hl[i][j]; } } } mybb->m = n - 1; mybb->n = n - 1; for(i=0;i<mybb->m;i++) { for(j=0;j<mybb->n;j++) { mybb->hl[i][j] = b[i][j]; } } double detb=det(mybb,n-1); sum+=A->hl[0][k]*pow(-1,k)*detb; } free(mybb); return sum; } double algebraic_cofactor(struct bb *A, struct bb B, int row, int col) { int i,j,m=0,n=0,M=A->m; double sign; if((row+col)%2==0) { sign=1; } else { sign=-1; } for(i=0;i<M;i++) { if(i!=row) { for(j=0;j<M;j++) { if(j!=col) { B->jk[m][n]=A->hl[i][j]; n++; } } m++; n=0; } } double detb=det(B,M-1); return signdetb; } void adjoint(struct bb *A, struct bb *B) { int i,j,M=A->m; for(i=0;i<M;i++) { for(j=0;j<M;j++) { B->hl[j][i]=algebraic_cofactor(A,B,i,j); //注意这里是 hl[j][i] 而不是 hl[i][j] } } } void inverse(struct bb *A,double inv[][dx],int N) { // 构造伴随矩阵 struct bb B; B.m = N; B.n = N; adjoint(A, &B); // 计算行列式的值 double dets=det(A,N); // 判断行列式是否为零 if(dets == 0) { printf("该矩阵不可逆!\n"); return; } // 计算逆矩阵 for(int i=0;i<N;i++) { for(int j=0;j<N;j++) { inv[i][j] = B.hl[i][j] / dets; } } }修改这个代码找出错误并改正
05-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值