-
Notifications
You must be signed in to change notification settings - Fork 1
/
hint.php
128 lines (102 loc) · 3.32 KB
/
hint.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
<?php
/**
* Copyright (c) 2012, Sergey Kambalin
* All rights reserved.
* ATTENTION: This commercial software is intended for use with Oxwall Free Community Software http://www.oxwall.org/
* and is licensed under Oxwall Store Commercial License.
* Full text of this license can be found at http://www.oxwall.org/store/oscl
*/
/**
*
* @author Sergey Kambalin <greyexpert@gmail.com>
* @package hint.controllers
*/
class HINT_CTRL_Hint extends OW_ActionController
{
public function rsp()
{
if ( !OW::getRequest()->isAjax() )
{
throw new Redirect404Exception();
}
if ( empty($_GET['url']) )
{
exit;
}
$url = trim($_GET['url']);
$parser = HINT_CLASS_ParseManager::getInstance()->getParser($url);
if ( $parser === null )
{
exit;
}
$params = $parser->parse($url);
$hint = $parser->renderHint($params);
$topCorner = empty($hint['topCorner']) ? null : $hint['topCorner'];
$bottomCorner = empty($hint['bottomCorner']) ? null : $hint['bottomCorner'];
$rightCorner = empty($hint['rightCorner']) ? null : $hint['rightCorner'];
$out = array(
'markup' => $this->getMarkup($hint['body'], $topCorner, $bottomCorner, $rightCorner)
);
echo json_encode($out);
exit;
}
private function getMarkup( $html, $topCorner, $bottomCorner, $rightCorner )
{
/* @var $document OW_AjaxDocument */
$document = OW::getDocument();
$responce = array();
$responce['content'] = array(
'body' => $html,
'topCorner' => $topCorner,
'bottomCorner' => $bottomCorner,
'rightCorner' => $rightCorner
);
$beforeIncludesScript = $document->getScriptBeforeIncludes();
if ( !empty($beforeIncludesScript) )
{
$responce['beforeIncludes'] = $beforeIncludesScript;
}
foreach ( $document->getScripts() as $script )
{
$responce['scriptFiles'][] = $script;
}
$onloadScript = $document->getOnloadScript();
if ( !empty($onloadScript) )
{
$responce['onloadScript'] = $onloadScript;
}
$styleDeclarations = $document->getStyleDeclarations();
if ( !empty($styleDeclarations) )
{
$responce['styleDeclarations'] = $styleDeclarations;
}
$styleSheets = $document->getStyleSheets();
if ( !empty($styleSheets) )
{
$responce['styleSheets'] = $styleSheets;
}
return $responce;
}
public function test()
{
$hint = new HINT_CMP_UserHint(1);
$this->addComponent('hint', $hint);
}
public function query()
{
if ( !OW::getRequest()->isAjax() )
{
throw new Redirect404Exception();
}
$command = $_GET["command"];
$params = empty($_GET["params"]) ? array() : json_decode($_GET["params"], true);
$event = new OW_Event(HINT_BOL_Service::EVENT_QUERY, array(
"command" => $command,
"params" => $params
));
OW::getEventManager()->trigger($event);
$data = $event->getData();
echo json_encode(empty($data) ? array() : $data);
exit;
}
}