Blame view

addons/exam/library/FrontService.php 8.35 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
  <?php

  /**

   * Created by PhpStorm.

   * User         : zgcLives

   * CreateTime   : 2023/5/3 10:54

   */

  

  namespace addons\exam\library;

  

  class FrontService

  {

      /** 小程序页面列表 */

      const PAGES

          = [

              [

                  'path'   => '/pages/index/index',

                  'name'   => '首页',

                  'params' => [],

                  'module' => '',

              ],

              [

                  'path'   => '/pages/search/index',

                  'name'   => '题目搜索',

                  'params' => [

                      [

                          'field'   => 'keyword',

                          'name'    => '搜索关键词',

                          'type'    => 'string',

                          'require' => false,

                          'value'   => '',

                      ],

                  ],

                  'module' => '',

              ],

              [

                  'path'   => '/pages/paper/index',

                  'name'   => '试卷列表',

                  'params' => [],

                  'module' => '',

              ],

              [

                  'path'   => '/pages/paper/paper',

                  'name'   => '考试试卷',

                  'params' => [

                      [

                          'field'      => 'id',

                          'name'       => '试卷ID',

                          'type'       => 'selectpage',

                          'require'    => true,

                          'value'      => '',

                          'selectpage' => [

                              'source' => 'exam/paper/index',

                              'field'  => 'title',

                              'params' => [],

                          ],

                      ],

                      [

                          'field'      => 'room_id',

                          'name'       => '考场ID',

                          'type'       => 'selectpage',

                          'require'    => false,

                          'value'      => '',

                          'selectpage' => [

                              'source' => 'exam/room/index',

                              'field'  => 'name',

                              'params' => [],

                          ],

                      ],

                  ],

                  'module' => '',

              ],

              [

                  'path'   => '/pages/paper/grade',

                  'name'   => '考试记录',

                  'params' => [],

                  'module' => '',

              ],

              [

                  'path'   => '/pages/paper/rank',

                  'name'   => '考试排行榜',

                  'params' => [

                      [

                          'field'      => 'paper_id',

                          'name'       => '试卷ID',

                          'type'       => 'selectpage',

                          'require'    => true,

                          'value'      => '',

                          'selectpage' => [

                              'source' => 'exam/paper/index',

                              'field'  => 'title',

                              'params' => [],

                          ],

                      ],

                  ],

                  'module' => '',

              ],

              [

                  'path'   => '/pages/room/index',

                  'name'   => '考场列表',

                  'params' => [],

                  'module' => '',

              ],

              [

                  'path'   => '/pages/room/detail',

                  'name'   => '考场详情',

                  'params' => [

                      [

                          'field'      => 'id',

                          'name'       => '考场ID',

                          'type'       => 'selectpage',

                          'require'    => true,

                          'value'      => '',

                          'selectpage' => [

                              'source' => 'exam/room/index',

                              'field'  => 'name',

                              'params' => [],

                          ],

                      ],

                  ],

                  'module' => '',

              ],

              [

                  'path'   => '/pages/room/grade',

                  'name'   => '考场成绩',

                  'params' => [],

                  'module' => '',

              ],

              [

                  'path'   => '/pages/room/rank',

                  'name'   => '考场排行榜',

                  'params' => [

                      [

                          'field'      => 'paper_id',

                          'name'       => '试卷ID',

                          'type'       => 'selectpage',

                          'require'    => true,

                          'value'      => '',

                          'selectpage' => [

                              'source' => 'exam/paper/index',

                              'field'  => 'title',

                              'params' => [],

                          ],

                      ],

                      [

                          'field'      => 'room_id',

                          'name'       => '考场ID',

                          'type'       => 'selectpage',

                          'require'    => true,

                          'value'      => '',

                          'selectpage' => [

                              'source' => 'exam/room/index',

                              'field'  => 'name',

                              'params' => [],

                          ],

                      ],

                  ],

                  'module' => '',

              ],

              [

                  'path'   => '/pages/room/signup-index',

                  'name'   => '考场报名记录',

                  'params' => [],

                  'module' => '',

              ],

              [

                  'path'   => '/pages/user/user',

                  'name'   => '用户中心',

                  'params' => [],

                  'module' => '',

              ],

              [

                  'path'   => '/pages/user/set',

                  'name'   => '个人设置',

                  'params' => [],

                  'module' => '',

              ],

              [

                  'path'   => '/pages/user/my-cate',

                  'name'   => '常用题库设置',

                  'params' => [],

                  'module' => '',

              ],

              [

                  'path'   => '/pages/user/login-reg',

                  'name'   => '登录注册',

                  'params' => [],

                  'module' => '',

              ],

              [

                  'path'   => '/pages/collect/index',

                  'name'   => '我的收藏',

                  'params' => [],

                  'module' => '',

              ],

              [

                  'path'   => '/pages/wrong/index',

                  'name'   => '错题记录',

                  'params' => [],

                  'module' => '',

              ],

              [

                  'path'   => '/pages/webview/webview',

                  'name'   => '跳转网页',

                  'params' => [

                      [

                          'field'   => 'url',

                          'name'    => '网页地址',

                          'type'    => 'string',

                          'require' => true,

                          'value'   => '',

                      ],

                  ],

                  'module' => '',

              ],

          ];

  

      /**

       * 获取小程序跳转路径及参数

       * @return string

       */

      public static function buildUrl($path, $params = [])

      {

          return $path . '?' . http_build_query($params);

      }

  

      /**

       * 替换内容里的图片CDN链接

       * @param $title

       * @return string

       */

      public static function replaceImgUrl($title)

      {

          $pattern = '/<img.*?src="(.*?)".*?>/i';

          $title   = preg_replace_callback($pattern, function ($matches) {

              $url      = $matches[1];

              $host     = parse_url($url, PHP_URL_HOST);

              $cdn_host = parse_url(cdnurl('', true), PHP_URL_HOST);

              if ($host) {

                  if ($host != $cdn_host) {

                      $url = str_replace($host, $cdn_host, $url);

                  }

              } else {

                  $url = cdnurl($url, true);

              }

              return '<img src="' . $url . '">';

          }, $title);

          return $title;

      }

  }