求大佬帮忙完成修改

插件开发及发布

版主: woniou

回复
deerda
帖子: 2
注册时间: 2021年 4月 5日 03:35

求大佬帮忙完成修改

帖子 deerda »

最近我在“改造”teStore这个插件,想把它改成主题商店,于是我把这个版本命名为'teStoreTheme'
现在已经改得差不多了,因为teStore的github中我发现还有一个主题仓库,于是直接用了。
现在已经可以加载主题列表了
但在我尝试制作安装部分的时候我发现它一直显示安装错误
无法下载压缩包
我也是个萌新,看不懂。

代码: 全选

//下载至临时目录
            $zipFile = $this->useCurl ? $this->curlGet($zip) : @file_get_contents($zip,0,
               stream_context_create(array('http'=>array('timeout'=>20)))); //设20秒超时
            if (!$zipFile) {
               $result['error'] = _t('下载压缩包出错');
            } else {
               if (strpos($zipFile,'404')===0 || strpos($zipFile,'Couldn\'t find')===0) {
                  $result['error'] = _t('未找到下载文件');
                  @unlink($tempFile);
               } else {
                  file_put_contents($tempFile,$zipFile);
                  $phpZip = new ZipArchive();
                  $open = $phpZip->open($tempFile,ZipArchive::CHECKCONS);
                  if ($open!==true) {
                     $result['error'] = _t('压缩包校验错误');
                     @unlink($tempFile);
                  } else {
                     //解压至临时目录
                     if (!$phpZip->extractTo($tempDir)) {
                        $error = error_get_last();
                        $result['error'] = $error['message'];
                     } else {
                        $phpZip->close();
                        @unlink($tempFile); //删除已解压包

                        //遍历各文件层级
                        foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tempDir)) as $fileName) {
                           if (!is_dir($fileName)) {
                              $tmpRoutes[] = $fileName;
                           }
                        }

                        //定位Plugin.php
                        $trueDir = '';
                        $parentDir = '';
                        foreach ($tmpRoutes as $tmpRoute) {
                           if (!strcasecmp(basename($tmpRoute),'index.php')) {
                              $trueDir = dirname($tmpRoute);
                              $parentDir = dirname($trueDir);
                           }
                        }

                        //处理目录型插件
                        if ($trueDir) {
                           $pluginDir = $this->pluginRoot.'/'.$plugin;
                           if (is_dir($pluginDir)) {
                              @$this->delTree($pluginDir,true); //清理旧版残留
                           }
                           foreach ($tmpRoutes as $tmpRoute) {
                              //按文件路径创建目录
                              $fileDir = $parentDir==$tempDir ? $tempDir : $parentDir;
                              $tarRoute = str_replace((strpos($tmpRoute,$trueDir)===0 ? $trueDir : $fileDir),
                                 $pluginDir,$tmpRoute);
                              $tarDir = dirname($tarRoute);
                              if (!is_dir($tarDir)) {
                                 $this->makedir($tarDir);
                              }
                              //移动文件到各层目录
                              if (!rename($tmpRoute,$tarRoute)) {
                                 $error = error_get_last();
                                 $result['error'] = $error['message'];
                              }
                           }
                           $result['status'] = true;

                        //处理单文件型插件
                        } elseif (count($tmpRoutes)<=2) {
                           foreach ($tmpRoutes as $tmpRoute) {
                              $name = basename($tmpRoute);
                              if ($name==$plugin.'.php') {
                                 //移动文件到根目录
                                 if (!rename($tmpRoute,$this->pluginRoot.'/'.$name)) {
                                    $result['error'] = _t('移动文件出错');
                                 } else {
                                    $result['status'] = true;
                                 }
                              }
                           }
                        }

                        //清空临时目录
                        @$this->delTree($tempDir,true);
                     }
                  }
               }
            }
 

我的进度http://lut.lu.mk/usr/uploads/file/forum/help/tetheme.zip
deerda
帖子: 2
注册时间: 2021年 4月 5日 03:35

Re: 求大佬帮忙完成修改

帖子 deerda »

没人吗
回复