|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Receive callback option/display for admins to copy link. |
|
4
|
|
|
* |
|
5
|
|
|
* @package ThreemaGateway |
|
6
|
|
|
* @author rugk |
|
7
|
|
|
* @copyright Copyright (c) 2016 rugk |
|
8
|
|
|
* @license MIT |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
class ThreemaGateway_Option_ReceiveCallback |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var int The default length of an access token |
|
15
|
|
|
*/ |
|
16
|
|
|
const ACCESS_TOKEN_LENGTH = 46; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Renders the debug mode text input field with on/off buttons. |
|
20
|
|
|
* |
|
21
|
|
|
* @param XenForo_View $view View object |
|
22
|
|
|
* @param string $fieldPrefix Prefix for the HTML form field name |
|
23
|
|
|
* @param array $preparedOption Prepared option info |
|
24
|
|
|
* @param bool $canEdit True if an "edit" link should appear |
|
25
|
|
|
* |
|
26
|
|
|
* @return XenForo_Template_Abstract Template object |
|
27
|
|
|
*/ |
|
28
|
|
|
public static function renderOption(XenForo_View $view, $fieldPrefix, array $preparedOption, $canEdit) |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
/** @var XenForo_Options $options */ |
|
31
|
|
|
$options = XenForo_Application::getOptions(); |
|
32
|
|
|
|
|
33
|
|
|
// set default value |
|
34
|
|
|
if (empty($preparedOption['option_value'])) { |
|
35
|
|
|
$preparedOption['option_value'] = self::generateDefault(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
//modify array to use custom template |
|
39
|
|
|
$preparedOption['edit_format'] = 'template'; |
|
40
|
|
|
$preparedOption['formatParams'] = [ |
|
41
|
|
|
'template' => 'threemagw_option_list_receivecallback', |
|
42
|
|
|
'basetext' => $options->boardUrl . '/' . ThreemaGateway_Constants::CALLBACK_FILE . '?accesstoken=', |
|
43
|
|
|
'placeholder' => '' |
|
44
|
|
|
]; |
|
45
|
|
|
|
|
46
|
|
|
//pass this to the default handler |
|
47
|
|
|
return XenForo_ViewAdmin_Helper_Option::renderPreparedOptionHtml($view, $preparedOption, $canEdit); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Verifies whether the dir of the file is valid (can be created) and is writable. |
|
52
|
|
|
* |
|
53
|
|
|
* @param XenForo_DataWriter $dataWriter |
|
54
|
|
|
* @param string $fieldName Name of field/option |
|
55
|
|
|
* |
|
56
|
|
|
* @return bool |
|
57
|
|
|
*/ |
|
58
|
|
|
public static function verifyOption(&$input, XenForo_DataWriter $dataWriter, $fieldName) |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
|
|
// set default value |
|
61
|
|
|
if (empty($input)) { |
|
62
|
|
|
$input = self::generateDefault(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return true; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Generates the default, which should be used for this option. |
|
70
|
|
|
* |
|
71
|
|
|
* @return string |
|
72
|
|
|
*/ |
|
73
|
|
|
protected static function generateDefault() |
|
74
|
|
|
{ |
|
75
|
|
|
return ThreemaGateway_Helper_Random::getRandomAlphaNum(self::ACCESS_TOKEN_LENGTH); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.