@@ -15,80 +15,80 @@ |
||
15 | 15 | class DocumentTypeRouting implements CmsRouting |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * DocumentTypeRouting constructor. |
|
20 | - * |
|
21 | - * @param Request $request |
|
22 | - * @param String $relativeCmsUri |
|
23 | - * @param CmsComponent $cmsComponent |
|
24 | - */ |
|
25 | - public function __construct($request, $relativeCmsUri, $cmsComponent) |
|
26 | - { |
|
27 | - if ($relativeCmsUri == '/configuration/document-types') { |
|
28 | - $this->overviewRoute($cmsComponent); |
|
29 | - } elseif ($relativeCmsUri == '/configuration/document-types/new') { |
|
30 | - $this->newRoute($request, $cmsComponent); |
|
31 | - } elseif ($relativeCmsUri == '/configuration/document-types/edit' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
32 | - $this->editRoute($request, $cmsComponent); |
|
33 | - } elseif ($relativeCmsUri == '/configuration/document-types/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
34 | - $this->deleteRoute($request, $cmsComponent); |
|
35 | - } |
|
36 | - } |
|
18 | + /** |
|
19 | + * DocumentTypeRouting constructor. |
|
20 | + * |
|
21 | + * @param Request $request |
|
22 | + * @param String $relativeCmsUri |
|
23 | + * @param CmsComponent $cmsComponent |
|
24 | + */ |
|
25 | + public function __construct($request, $relativeCmsUri, $cmsComponent) |
|
26 | + { |
|
27 | + if ($relativeCmsUri == '/configuration/document-types') { |
|
28 | + $this->overviewRoute($cmsComponent); |
|
29 | + } elseif ($relativeCmsUri == '/configuration/document-types/new') { |
|
30 | + $this->newRoute($request, $cmsComponent); |
|
31 | + } elseif ($relativeCmsUri == '/configuration/document-types/edit' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
32 | + $this->editRoute($request, $cmsComponent); |
|
33 | + } elseif ($relativeCmsUri == '/configuration/document-types/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
34 | + $this->deleteRoute($request, $cmsComponent); |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param CmsComponent $cmsComponent |
|
40 | - */ |
|
41 | - private function overviewRoute($cmsComponent) |
|
42 | - { |
|
43 | - $cmsComponent->subTemplate = 'configuration/document-types'; |
|
44 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION); |
|
45 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENT_TYPES, $cmsComponent->storage->getDocumentTypes()->getDocumentTypes()); |
|
46 | - } |
|
38 | + /** |
|
39 | + * @param CmsComponent $cmsComponent |
|
40 | + */ |
|
41 | + private function overviewRoute($cmsComponent) |
|
42 | + { |
|
43 | + $cmsComponent->subTemplate = 'configuration/document-types'; |
|
44 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION); |
|
45 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENT_TYPES, $cmsComponent->storage->getDocumentTypes()->getDocumentTypes()); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param $request |
|
50 | - * @param CmsComponent $cmsComponent |
|
51 | - */ |
|
52 | - private function newRoute($request, $cmsComponent) |
|
53 | - { |
|
54 | - $cmsComponent->subTemplate = 'configuration/document-types-form'; |
|
55 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION); |
|
56 | - $bricks = $cmsComponent->storage->getBricks()->getBricks(); |
|
57 | - if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
|
58 | - $cmsComponent->storage->getDocumentTypes()->addDocumentType($request::$post); |
|
59 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/document-types'); |
|
60 | - exit; |
|
61 | - } |
|
62 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_BRICKS, $bricks); |
|
63 | - } |
|
48 | + /** |
|
49 | + * @param $request |
|
50 | + * @param CmsComponent $cmsComponent |
|
51 | + */ |
|
52 | + private function newRoute($request, $cmsComponent) |
|
53 | + { |
|
54 | + $cmsComponent->subTemplate = 'configuration/document-types-form'; |
|
55 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION); |
|
56 | + $bricks = $cmsComponent->storage->getBricks()->getBricks(); |
|
57 | + if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
|
58 | + $cmsComponent->storage->getDocumentTypes()->addDocumentType($request::$post); |
|
59 | + header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/document-types'); |
|
60 | + exit; |
|
61 | + } |
|
62 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_BRICKS, $bricks); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @param $request |
|
67 | - * @param CmsComponent $cmsComponent |
|
68 | - */ |
|
69 | - private function editRoute($request, $cmsComponent) |
|
70 | - { |
|
71 | - $cmsComponent->subTemplate = 'configuration/document-types-form'; |
|
72 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION); |
|
73 | - $documentType = $cmsComponent->storage->getDocumentTypes()->getDocumentTypeBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG], false); |
|
74 | - $bricks = $cmsComponent->storage->getBricks()->getBricks(); |
|
75 | - if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
|
76 | - $cmsComponent->storage->getDocumentTypes()->saveDocumentType($request::$get[CmsComponent::GET_PARAMETER_SLUG], $request::$post); |
|
77 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/document-types'); |
|
78 | - exit; |
|
79 | - } |
|
80 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENT_TYPE, $documentType); |
|
81 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_BRICKS, $bricks); |
|
82 | - } |
|
65 | + /** |
|
66 | + * @param $request |
|
67 | + * @param CmsComponent $cmsComponent |
|
68 | + */ |
|
69 | + private function editRoute($request, $cmsComponent) |
|
70 | + { |
|
71 | + $cmsComponent->subTemplate = 'configuration/document-types-form'; |
|
72 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION); |
|
73 | + $documentType = $cmsComponent->storage->getDocumentTypes()->getDocumentTypeBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG], false); |
|
74 | + $bricks = $cmsComponent->storage->getBricks()->getBricks(); |
|
75 | + if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
|
76 | + $cmsComponent->storage->getDocumentTypes()->saveDocumentType($request::$get[CmsComponent::GET_PARAMETER_SLUG], $request::$post); |
|
77 | + header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/document-types'); |
|
78 | + exit; |
|
79 | + } |
|
80 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENT_TYPE, $documentType); |
|
81 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_BRICKS, $bricks); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * @param $request |
|
86 | - * @param CmsComponent $cmsComponent |
|
87 | - */ |
|
88 | - private function deleteRoute($request, $cmsComponent) |
|
89 | - { |
|
90 | - $cmsComponent->storage->getDocumentTypes()->deleteDocumentTypeBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
|
91 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/document-types'); |
|
92 | - exit; |
|
93 | - } |
|
84 | + /** |
|
85 | + * @param $request |
|
86 | + * @param CmsComponent $cmsComponent |
|
87 | + */ |
|
88 | + private function deleteRoute($request, $cmsComponent) |
|
89 | + { |
|
90 | + $cmsComponent->storage->getDocumentTypes()->deleteDocumentTypeBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
|
91 | + header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/document-types'); |
|
92 | + exit; |
|
93 | + } |
|
94 | 94 | } |
95 | 95 | \ No newline at end of file |
@@ -14,76 +14,76 @@ |
||
14 | 14 | class BricksRouting implements CmsRouting |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * CmsRouting constructor. |
|
19 | - * |
|
20 | - * @param Request $request |
|
21 | - * @param string $relativeCmsUri |
|
22 | - * @param CmsComponent $cmsComponent |
|
23 | - */ |
|
24 | - public function __construct($request, $relativeCmsUri, $cmsComponent) |
|
25 | - { |
|
26 | - if ($relativeCmsUri == '/configuration/bricks') { |
|
27 | - $this->overviewRoute($cmsComponent); |
|
28 | - } elseif ($relativeCmsUri == '/configuration/bricks/new') { |
|
29 | - $this->newRoute($request, $cmsComponent); |
|
30 | - } elseif ($relativeCmsUri == '/configuration/bricks/edit' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
31 | - $this->editRoute($request, $cmsComponent); |
|
32 | - } elseif ($relativeCmsUri == '/configuration/bricks/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
33 | - $this->deleteRoute($request, $cmsComponent); |
|
34 | - } |
|
35 | - } |
|
17 | + /** |
|
18 | + * CmsRouting constructor. |
|
19 | + * |
|
20 | + * @param Request $request |
|
21 | + * @param string $relativeCmsUri |
|
22 | + * @param CmsComponent $cmsComponent |
|
23 | + */ |
|
24 | + public function __construct($request, $relativeCmsUri, $cmsComponent) |
|
25 | + { |
|
26 | + if ($relativeCmsUri == '/configuration/bricks') { |
|
27 | + $this->overviewRoute($cmsComponent); |
|
28 | + } elseif ($relativeCmsUri == '/configuration/bricks/new') { |
|
29 | + $this->newRoute($request, $cmsComponent); |
|
30 | + } elseif ($relativeCmsUri == '/configuration/bricks/edit' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
31 | + $this->editRoute($request, $cmsComponent); |
|
32 | + } elseif ($relativeCmsUri == '/configuration/bricks/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) { |
|
33 | + $this->deleteRoute($request, $cmsComponent); |
|
34 | + } |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param CmsComponent $cmsComponent |
|
39 | - */ |
|
40 | - private function overviewRoute($cmsComponent) |
|
41 | - { |
|
42 | - $cmsComponent->subTemplate = 'configuration/bricks'; |
|
43 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION); |
|
44 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_BRICKS, $cmsComponent->storage->getBricks()->getBricks()); |
|
45 | - } |
|
37 | + /** |
|
38 | + * @param CmsComponent $cmsComponent |
|
39 | + */ |
|
40 | + private function overviewRoute($cmsComponent) |
|
41 | + { |
|
42 | + $cmsComponent->subTemplate = 'configuration/bricks'; |
|
43 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION); |
|
44 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_BRICKS, $cmsComponent->storage->getBricks()->getBricks()); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param $request |
|
49 | - * @param CmsComponent $cmsComponent |
|
50 | - */ |
|
51 | - private function newRoute($request, $cmsComponent) |
|
52 | - { |
|
53 | - $cmsComponent->subTemplate = 'configuration/bricks-form'; |
|
54 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION); |
|
55 | - if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
|
56 | - $cmsComponent->storage->getBricks()->addBrick($request::$post); |
|
57 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/bricks'); |
|
58 | - exit; |
|
59 | - } |
|
60 | - } |
|
47 | + /** |
|
48 | + * @param $request |
|
49 | + * @param CmsComponent $cmsComponent |
|
50 | + */ |
|
51 | + private function newRoute($request, $cmsComponent) |
|
52 | + { |
|
53 | + $cmsComponent->subTemplate = 'configuration/bricks-form'; |
|
54 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION); |
|
55 | + if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
|
56 | + $cmsComponent->storage->getBricks()->addBrick($request::$post); |
|
57 | + header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/bricks'); |
|
58 | + exit; |
|
59 | + } |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @param $request |
|
64 | - * @param CmsComponent $cmsComponent |
|
65 | - */ |
|
66 | - private function editRoute($request, $cmsComponent) |
|
67 | - { |
|
68 | - $cmsComponent->subTemplate = 'configuration/bricks-form'; |
|
69 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION); |
|
70 | - $brick = $cmsComponent->storage->getBricks()->getBrickBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
|
71 | - if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
|
72 | - $cmsComponent->storage->getBricks()->saveBrick($request::$get[CmsComponent::GET_PARAMETER_SLUG], $request::$post); |
|
73 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/bricks'); |
|
74 | - exit; |
|
75 | - } |
|
76 | - $cmsComponent->setParameter(CmsComponent::PARAMETER_BRICK, $brick); |
|
77 | - } |
|
62 | + /** |
|
63 | + * @param $request |
|
64 | + * @param CmsComponent $cmsComponent |
|
65 | + */ |
|
66 | + private function editRoute($request, $cmsComponent) |
|
67 | + { |
|
68 | + $cmsComponent->subTemplate = 'configuration/bricks-form'; |
|
69 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION); |
|
70 | + $brick = $cmsComponent->storage->getBricks()->getBrickBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
|
71 | + if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) { |
|
72 | + $cmsComponent->storage->getBricks()->saveBrick($request::$get[CmsComponent::GET_PARAMETER_SLUG], $request::$post); |
|
73 | + header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/bricks'); |
|
74 | + exit; |
|
75 | + } |
|
76 | + $cmsComponent->setParameter(CmsComponent::PARAMETER_BRICK, $brick); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @param $request |
|
81 | - * @param CmsComponent $cmsComponent |
|
82 | - */ |
|
83 | - private function deleteRoute($request, $cmsComponent) |
|
84 | - { |
|
85 | - $cmsComponent->storage->getBricks()->deleteBrickBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
|
86 | - header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/bricks'); |
|
87 | - exit; |
|
88 | - } |
|
79 | + /** |
|
80 | + * @param $request |
|
81 | + * @param CmsComponent $cmsComponent |
|
82 | + */ |
|
83 | + private function deleteRoute($request, $cmsComponent) |
|
84 | + { |
|
85 | + $cmsComponent->storage->getBricks()->deleteBrickBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]); |
|
86 | + header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/bricks'); |
|
87 | + exit; |
|
88 | + } |
|
89 | 89 | } |
90 | 90 | \ No newline at end of file |
@@ -4,128 +4,128 @@ |
||
4 | 4 | use storage\Storage; |
5 | 5 | |
6 | 6 | /** |
7 | - * Class DocumentComponent |
|
8 | - * |
|
9 | - * Has optional parameter `folder` to prefix the relative url with a folder |
|
10 | - * Has optional parameter `document` to select a given document |
|
11 | - * Has optional parameter `documentParameterName` to select the parametername to be used |
|
12 | - * to set the found document to. |
|
13 | - * |
|
14 | - * @package CloudControl\Cms\components |
|
15 | - */ |
|
16 | - class DocumentComponent extends BaseComponent |
|
17 | - { |
|
18 | - protected $documentParameterName = 'document'; |
|
7 | + * Class DocumentComponent |
|
8 | + * |
|
9 | + * Has optional parameter `folder` to prefix the relative url with a folder |
|
10 | + * Has optional parameter `document` to select a given document |
|
11 | + * Has optional parameter `documentParameterName` to select the parametername to be used |
|
12 | + * to set the found document to. |
|
13 | + * |
|
14 | + * @package CloudControl\Cms\components |
|
15 | + */ |
|
16 | + class DocumentComponent extends BaseComponent |
|
17 | + { |
|
18 | + protected $documentParameterName = 'document'; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @param Storage $storage |
|
22 | - * |
|
23 | - * @return mixed|void |
|
24 | - * @throws \Exception |
|
25 | - */ |
|
26 | - public function run(Storage $storage) |
|
27 | - { |
|
28 | - parent::run($storage); |
|
20 | + /** |
|
21 | + * @param Storage $storage |
|
22 | + * |
|
23 | + * @return mixed|void |
|
24 | + * @throws \Exception |
|
25 | + */ |
|
26 | + public function run(Storage $storage) |
|
27 | + { |
|
28 | + parent::run($storage); |
|
29 | 29 | |
30 | - $this->checkParameters(); |
|
30 | + $this->checkParameters(); |
|
31 | 31 | |
32 | - if ($this->matchedSitemapItem === null) { // If no sitemapitem, its an application component |
|
33 | - $this->runLikeApplicationComponent(); |
|
34 | - } else { |
|
35 | - $this->runLikeRegularComponent(); |
|
36 | - } |
|
37 | - } |
|
32 | + if ($this->matchedSitemapItem === null) { // If no sitemapitem, its an application component |
|
33 | + $this->runLikeApplicationComponent(); |
|
34 | + } else { |
|
35 | + $this->runLikeRegularComponent(); |
|
36 | + } |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Checks to see if any parameters were defined in the cms and acts according |
|
41 | - */ |
|
42 | - private function checkParameters() |
|
43 | - { |
|
44 | - if (isset($this->parameters['documentParameterName'])) { |
|
45 | - $this->documentParameterName = $this->parameters['documentParameterName']; |
|
46 | - } |
|
47 | - } |
|
39 | + /** |
|
40 | + * Checks to see if any parameters were defined in the cms and acts according |
|
41 | + */ |
|
42 | + private function checkParameters() |
|
43 | + { |
|
44 | + if (isset($this->parameters['documentParameterName'])) { |
|
45 | + $this->documentParameterName = $this->parameters['documentParameterName']; |
|
46 | + } |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Run as application component |
|
51 | - * |
|
52 | - * @throws \Exception |
|
53 | - */ |
|
54 | - private function runLikeApplicationComponent() |
|
55 | - { |
|
56 | - if (isset($this->parameters['document'])) { |
|
57 | - $this->parameters[$this->documentParameterName] = $this->storage->getDocuments()->getDocumentBySlug($this->parameters['document']); |
|
58 | - unset($this->parameters['document']); |
|
59 | - } else { |
|
60 | - throw new \Exception('When used as application component, you need to specify a document.'); |
|
61 | - } |
|
62 | - } |
|
49 | + /** |
|
50 | + * Run as application component |
|
51 | + * |
|
52 | + * @throws \Exception |
|
53 | + */ |
|
54 | + private function runLikeApplicationComponent() |
|
55 | + { |
|
56 | + if (isset($this->parameters['document'])) { |
|
57 | + $this->parameters[$this->documentParameterName] = $this->storage->getDocuments()->getDocumentBySlug($this->parameters['document']); |
|
58 | + unset($this->parameters['document']); |
|
59 | + } else { |
|
60 | + throw new \Exception('When used as application component, you need to specify a document.'); |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Run as regular component |
|
66 | - * |
|
67 | - * @throws \Exception |
|
68 | - */ |
|
69 | - private function runLikeRegularComponent() |
|
70 | - { |
|
71 | - if ($this->matchedSitemapItem->regex == false) { |
|
72 | - $this->runWithoutRegex(); |
|
73 | - } else { |
|
74 | - $this->runWithRegex(); |
|
75 | - } |
|
76 | - } |
|
64 | + /** |
|
65 | + * Run as regular component |
|
66 | + * |
|
67 | + * @throws \Exception |
|
68 | + */ |
|
69 | + private function runLikeRegularComponent() |
|
70 | + { |
|
71 | + if ($this->matchedSitemapItem->regex == false) { |
|
72 | + $this->runWithoutRegex(); |
|
73 | + } else { |
|
74 | + $this->runWithRegex(); |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Run without regex |
|
80 | - * |
|
81 | - * @throws \Exception |
|
82 | - */ |
|
83 | - private function runWithoutRegex() |
|
84 | - { |
|
85 | - if (isset($this->parameters['document'])) { |
|
86 | - $this->runByDocumentParameter(); |
|
87 | - } else { |
|
88 | - throw new \Exception('When not using a regex, you need to set the parameter `document` with the path to the document in this sitemap item: ' . $this->matchedSitemapItem->title); |
|
89 | - } |
|
90 | - } |
|
78 | + /** |
|
79 | + * Run without regex |
|
80 | + * |
|
81 | + * @throws \Exception |
|
82 | + */ |
|
83 | + private function runWithoutRegex() |
|
84 | + { |
|
85 | + if (isset($this->parameters['document'])) { |
|
86 | + $this->runByDocumentParameter(); |
|
87 | + } else { |
|
88 | + throw new \Exception('When not using a regex, you need to set the parameter `document` with the path to the document in this sitemap item: ' . $this->matchedSitemapItem->title); |
|
89 | + } |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Run with regex |
|
94 | - * |
|
95 | - * @throws \Exception |
|
96 | - */ |
|
97 | - private function runWithRegex() |
|
98 | - { |
|
99 | - if (isset($this->parameters['document'])) { |
|
100 | - $this->runByDocumentParameter(); |
|
101 | - } else { |
|
102 | - $relativeDocumentUri = current($this->matchedSitemapItem->matches[1]); |
|
103 | - if (isset($this->parameters['folder'])) { |
|
104 | - if (substr($this->parameters['folder'], -1) !== '/') { |
|
105 | - $this->parameters['folder'] = $this->parameters['folder'] . '/'; |
|
106 | - } |
|
107 | - $relativeDocumentUri = $this->parameters['folder'] . $relativeDocumentUri; |
|
108 | - } |
|
92 | + /** |
|
93 | + * Run with regex |
|
94 | + * |
|
95 | + * @throws \Exception |
|
96 | + */ |
|
97 | + private function runWithRegex() |
|
98 | + { |
|
99 | + if (isset($this->parameters['document'])) { |
|
100 | + $this->runByDocumentParameter(); |
|
101 | + } else { |
|
102 | + $relativeDocumentUri = current($this->matchedSitemapItem->matches[1]); |
|
103 | + if (isset($this->parameters['folder'])) { |
|
104 | + if (substr($this->parameters['folder'], -1) !== '/') { |
|
105 | + $this->parameters['folder'] = $this->parameters['folder'] . '/'; |
|
106 | + } |
|
107 | + $relativeDocumentUri = $this->parameters['folder'] . $relativeDocumentUri; |
|
108 | + } |
|
109 | 109 | |
110 | - $document = $this->storage->getDocuments()->getDocumentBySlug($relativeDocumentUri); |
|
110 | + $document = $this->storage->getDocuments()->getDocumentBySlug($relativeDocumentUri); |
|
111 | 111 | |
112 | - if ($document->type == 'folder') { |
|
113 | - throw new \Exception('The found document is a folder.'); |
|
114 | - } |
|
112 | + if ($document->type == 'folder') { |
|
113 | + throw new \Exception('The found document is a folder.'); |
|
114 | + } |
|
115 | 115 | |
116 | - if ($document->state != 'published') { |
|
117 | - throw new \Exception('Found document is unpublished.'); |
|
118 | - } |
|
119 | - $this->parameters[$this->documentParameterName] = $document; |
|
120 | - } |
|
121 | - } |
|
116 | + if ($document->state != 'published') { |
|
117 | + throw new \Exception('Found document is unpublished.'); |
|
118 | + } |
|
119 | + $this->parameters[$this->documentParameterName] = $document; |
|
120 | + } |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * Run using the given `document` parameter |
|
125 | - */ |
|
126 | - private function runByDocumentParameter() |
|
127 | - { |
|
128 | - $this->parameters[$this->documentParameterName] = $this->storage->getDocuments()->getDocumentBySlug($this->parameters['document']); |
|
129 | - } |
|
130 | - } |
|
123 | + /** |
|
124 | + * Run using the given `document` parameter |
|
125 | + */ |
|
126 | + private function runByDocumentParameter() |
|
127 | + { |
|
128 | + $this->parameters[$this->documentParameterName] = $this->storage->getDocuments()->getDocumentBySlug($this->parameters['document']); |
|
129 | + } |
|
130 | + } |
|
131 | 131 | } |
132 | 132 | \ No newline at end of file |
@@ -6,39 +6,39 @@ |
||
6 | 6 | use CloudControl\Cms\storage\Storage; |
7 | 7 | |
8 | 8 | /** |
9 | - * Interface Component |
|
10 | - * @package CloudControl\Cms\components |
|
11 | - */ |
|
12 | - interface Component |
|
13 | - { |
|
14 | - /** |
|
15 | - * Component constructor. |
|
16 | - * |
|
17 | - * @param $template |
|
18 | - * @param Request $request |
|
19 | - * @param $parameters |
|
20 | - * @param $matchedSitemapItem |
|
21 | - */ |
|
22 | - function __construct($template, Request $request, $parameters, $matchedSitemapItem); |
|
9 | + * Interface Component |
|
10 | + * @package CloudControl\Cms\components |
|
11 | + */ |
|
12 | + interface Component |
|
13 | + { |
|
14 | + /** |
|
15 | + * Component constructor. |
|
16 | + * |
|
17 | + * @param $template |
|
18 | + * @param Request $request |
|
19 | + * @param $parameters |
|
20 | + * @param $matchedSitemapItem |
|
21 | + */ |
|
22 | + function __construct($template, Request $request, $parameters, $matchedSitemapItem); |
|
23 | 23 | |
24 | - /** |
|
25 | - * @param Storage $storage |
|
26 | - */ |
|
27 | - function run(Storage $storage); |
|
24 | + /** |
|
25 | + * @param Storage $storage |
|
26 | + */ |
|
27 | + function run(Storage $storage); |
|
28 | 28 | |
29 | - /** |
|
30 | - * @return void |
|
31 | - */ |
|
32 | - function render(); |
|
29 | + /** |
|
30 | + * @return void |
|
31 | + */ |
|
32 | + function render(); |
|
33 | 33 | |
34 | - /** |
|
35 | - * @return mixed |
|
36 | - */ |
|
37 | - function get(); |
|
34 | + /** |
|
35 | + * @return mixed |
|
36 | + */ |
|
37 | + function get(); |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return \stdClass |
|
41 | - */ |
|
42 | - function getParameters(); |
|
43 | - } |
|
39 | + /** |
|
40 | + * @return \stdClass |
|
41 | + */ |
|
42 | + function getParameters(); |
|
43 | + } |
|
44 | 44 | } |
45 | 45 | \ No newline at end of file |
@@ -1,129 +1,129 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace CloudControl\Cms\crypt |
3 | 3 | { |
4 | - /** |
|
5 | - * Class Crypt |
|
6 | - * @package CloudControl\Cms\crypt |
|
7 | - */ |
|
8 | - class Crypt |
|
9 | - { |
|
10 | - /** |
|
11 | - * @var string |
|
12 | - */ |
|
13 | - private $lastSalt; |
|
4 | + /** |
|
5 | + * Class Crypt |
|
6 | + * @package CloudControl\Cms\crypt |
|
7 | + */ |
|
8 | + class Crypt |
|
9 | + { |
|
10 | + /** |
|
11 | + * @var string |
|
12 | + */ |
|
13 | + private $lastSalt; |
|
14 | 14 | |
15 | - /** |
|
16 | - * Encrypts the given value using the blowfish algorithm |
|
17 | - * |
|
18 | - * @param string $value The sting to be encrypted |
|
19 | - * @param int $encryptionIterations The amount of iterations used for encryption, 13 by default, resulting in aprox. 0.5 seconds of encrypting. Each raise, will result in about double the time |
|
20 | - * @return string The hash |
|
21 | - */ |
|
22 | - public function encrypt($value, $encryptionIterations = 13) |
|
23 | - { |
|
24 | - $random = $this->getRandomBytes(16); |
|
25 | - $this->lastSalt = $this->getSalt($random, $encryptionIterations); |
|
26 | - $hash = crypt($value, $this->lastSalt); |
|
27 | - return $hash; |
|
28 | - } |
|
15 | + /** |
|
16 | + * Encrypts the given value using the blowfish algorithm |
|
17 | + * |
|
18 | + * @param string $value The sting to be encrypted |
|
19 | + * @param int $encryptionIterations The amount of iterations used for encryption, 13 by default, resulting in aprox. 0.5 seconds of encrypting. Each raise, will result in about double the time |
|
20 | + * @return string The hash |
|
21 | + */ |
|
22 | + public function encrypt($value, $encryptionIterations = 13) |
|
23 | + { |
|
24 | + $random = $this->getRandomBytes(16); |
|
25 | + $this->lastSalt = $this->getSalt($random, $encryptionIterations); |
|
26 | + $hash = crypt($value, $this->lastSalt); |
|
27 | + return $hash; |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * If on Linux, tries to use built in random byte feed |
|
32 | - * else generates its own feed |
|
33 | - * |
|
34 | - * @param int $count The amount of bytes to generates |
|
35 | - * @return string The bytes |
|
36 | - */ |
|
37 | - private function getRandomBytes($count) |
|
38 | - { |
|
39 | - $output = ''; |
|
40 | - $random_state = microtime(); |
|
30 | + /** |
|
31 | + * If on Linux, tries to use built in random byte feed |
|
32 | + * else generates its own feed |
|
33 | + * |
|
34 | + * @param int $count The amount of bytes to generates |
|
35 | + * @return string The bytes |
|
36 | + */ |
|
37 | + private function getRandomBytes($count) |
|
38 | + { |
|
39 | + $output = ''; |
|
40 | + $random_state = microtime(); |
|
41 | 41 | |
42 | - $openBasedir = ini_get('open_basedir'); |
|
43 | - if (empty($openBasedir) && |
|
44 | - is_readable('/dev/urandom') && |
|
45 | - ($fh = @fopen('/dev/urandom', 'rb'))) { |
|
46 | - $output = fread($fh, $count); |
|
47 | - fclose($fh); |
|
48 | - } |
|
42 | + $openBasedir = ini_get('open_basedir'); |
|
43 | + if (empty($openBasedir) && |
|
44 | + is_readable('/dev/urandom') && |
|
45 | + ($fh = @fopen('/dev/urandom', 'rb'))) { |
|
46 | + $output = fread($fh, $count); |
|
47 | + fclose($fh); |
|
48 | + } |
|
49 | 49 | |
50 | - if (strlen($output) < $count) { |
|
51 | - $output = ''; |
|
52 | - for ($i = 0; $i < $count; $i += 16) { |
|
53 | - $random_state = |
|
54 | - md5(microtime() . $random_state); |
|
55 | - $output .= |
|
56 | - pack('H*', md5($random_state)); |
|
57 | - } |
|
58 | - $output = substr($output, 0, $count); |
|
59 | - } |
|
50 | + if (strlen($output) < $count) { |
|
51 | + $output = ''; |
|
52 | + for ($i = 0; $i < $count; $i += 16) { |
|
53 | + $random_state = |
|
54 | + md5(microtime() . $random_state); |
|
55 | + $output .= |
|
56 | + pack('H*', md5($random_state)); |
|
57 | + } |
|
58 | + $output = substr($output, 0, $count); |
|
59 | + } |
|
60 | 60 | |
61 | - return $output; |
|
62 | - } |
|
61 | + return $output; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Generates the salt used for encryption |
|
66 | - * |
|
67 | - * @param string $input Feed for iteration |
|
68 | - * @param int $iterations Amount of iterations |
|
69 | - * |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - private function getSalt($input, $iterations) |
|
73 | - { |
|
74 | - $itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
64 | + /** |
|
65 | + * Generates the salt used for encryption |
|
66 | + * |
|
67 | + * @param string $input Feed for iteration |
|
68 | + * @param int $iterations Amount of iterations |
|
69 | + * |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + private function getSalt($input, $iterations) |
|
73 | + { |
|
74 | + $itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
75 | 75 | |
76 | - $output = '$2a$'; |
|
77 | - $output .= chr(ord('0') + $iterations / 10); |
|
78 | - $output .= chr(ord('0') + $iterations % 10); |
|
79 | - $output .= '$'; |
|
76 | + $output = '$2a$'; |
|
77 | + $output .= chr(ord('0') + $iterations / 10); |
|
78 | + $output .= chr(ord('0') + $iterations % 10); |
|
79 | + $output .= '$'; |
|
80 | 80 | |
81 | - $i = 0; |
|
82 | - do { |
|
83 | - $c1 = ord($input[$i++]); |
|
84 | - $output .= $itoa64[$c1 >> 2]; |
|
85 | - $c1 = ($c1 & 0x03) << 4; |
|
86 | - if ($i >= 16) { |
|
87 | - $output .= $itoa64[$c1]; |
|
88 | - break; |
|
89 | - } |
|
81 | + $i = 0; |
|
82 | + do { |
|
83 | + $c1 = ord($input[$i++]); |
|
84 | + $output .= $itoa64[$c1 >> 2]; |
|
85 | + $c1 = ($c1 & 0x03) << 4; |
|
86 | + if ($i >= 16) { |
|
87 | + $output .= $itoa64[$c1]; |
|
88 | + break; |
|
89 | + } |
|
90 | 90 | |
91 | - $c2 = ord($input[$i++]); |
|
92 | - $c1 |= $c2 >> 4; |
|
93 | - $output .= $itoa64[$c1]; |
|
94 | - $c1 = ($c2 & 0x0f) << 2; |
|
91 | + $c2 = ord($input[$i++]); |
|
92 | + $c1 |= $c2 >> 4; |
|
93 | + $output .= $itoa64[$c1]; |
|
94 | + $c1 = ($c2 & 0x0f) << 2; |
|
95 | 95 | |
96 | - $c2 = ord($input[$i++]); |
|
97 | - $c1 |= $c2 >> 6; |
|
98 | - $output .= $itoa64[$c1]; |
|
99 | - $output .= $itoa64[$c2 & 0x3f]; |
|
100 | - } while (1); |
|
96 | + $c2 = ord($input[$i++]); |
|
97 | + $c1 |= $c2 >> 6; |
|
98 | + $output .= $itoa64[$c1]; |
|
99 | + $output .= $itoa64[$c2 & 0x3f]; |
|
100 | + } while (1); |
|
101 | 101 | |
102 | - return $output; |
|
103 | - } |
|
102 | + return $output; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Returns the last used salt for encryption |
|
107 | - * |
|
108 | - * @return string | NULL |
|
109 | - */ |
|
110 | - public function getLastSalt() |
|
111 | - { |
|
112 | - return $this->lastSalt; |
|
113 | - } |
|
105 | + /** |
|
106 | + * Returns the last used salt for encryption |
|
107 | + * |
|
108 | + * @return string | NULL |
|
109 | + */ |
|
110 | + public function getLastSalt() |
|
111 | + { |
|
112 | + return $this->lastSalt; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Compare the input with a known hash and salt |
|
117 | - * |
|
118 | - * @param $input |
|
119 | - * @param $hash |
|
120 | - * @param $salt |
|
121 | - * @return bool |
|
122 | - */ |
|
123 | - public function compare($input, $hash, $salt) |
|
124 | - { |
|
125 | - $newHash = crypt($input, $salt); |
|
126 | - return $newHash == $hash; |
|
127 | - } |
|
128 | - } |
|
115 | + /** |
|
116 | + * Compare the input with a known hash and salt |
|
117 | + * |
|
118 | + * @param $input |
|
119 | + * @param $hash |
|
120 | + * @param $salt |
|
121 | + * @return bool |
|
122 | + */ |
|
123 | + public function compare($input, $hash, $salt) |
|
124 | + { |
|
125 | + $newHash = crypt($input, $salt); |
|
126 | + return $newHash == $hash; |
|
127 | + } |
|
128 | + } |
|
129 | 129 | } |
130 | 130 | \ No newline at end of file |
@@ -24,92 +24,92 @@ |
||
24 | 24 | */ |
25 | 25 | class TermFrequency |
26 | 26 | { |
27 | - /** |
|
28 | - * @var \PDO |
|
29 | - */ |
|
30 | - protected $dbHandle; |
|
27 | + /** |
|
28 | + * @var \PDO |
|
29 | + */ |
|
30 | + protected $dbHandle; |
|
31 | 31 | |
32 | - /** |
|
33 | - * TermFrequency constructor. |
|
34 | - * |
|
35 | - * @param \PDO $dbHandle |
|
36 | - */ |
|
37 | - public function __construct($dbHandle) |
|
38 | - { |
|
39 | - $this->dbHandle = $dbHandle; |
|
40 | - } |
|
32 | + /** |
|
33 | + * TermFrequency constructor. |
|
34 | + * |
|
35 | + * @param \PDO $dbHandle |
|
36 | + */ |
|
37 | + public function __construct($dbHandle) |
|
38 | + { |
|
39 | + $this->dbHandle = $dbHandle; |
|
40 | + } |
|
41 | 41 | |
42 | - public function execute() |
|
43 | - { |
|
44 | - $db = $this->dbHandle; |
|
45 | - $totalTermCountPerDocument = $this->getTotalTermCountPerDocument($db); |
|
46 | - foreach ($totalTermCountPerDocument as $documentField) { |
|
47 | - $termsForDocumentField = $this->getTermsForDocumentField($documentField->documentPath, $documentField->field); |
|
48 | - $sql = ' |
|
42 | + public function execute() |
|
43 | + { |
|
44 | + $db = $this->dbHandle; |
|
45 | + $totalTermCountPerDocument = $this->getTotalTermCountPerDocument($db); |
|
46 | + foreach ($totalTermCountPerDocument as $documentField) { |
|
47 | + $termsForDocumentField = $this->getTermsForDocumentField($documentField->documentPath, $documentField->field); |
|
48 | + $sql = ' |
|
49 | 49 | INSERT INTO term_frequency (documentPath, field, term, frequency) |
50 | 50 | VALUES |
51 | 51 | '; |
52 | - $quotedDocumentPath = $db->quote($documentField->documentPath); |
|
53 | - $quotedField = $db->quote($documentField->field); |
|
54 | - $values = array(); |
|
55 | - $i = 0; |
|
56 | - foreach ($termsForDocumentField as $term) { |
|
57 | - $frequency = intval($term->count) / $documentField->totalTermCount; |
|
58 | - $values[] = $quotedDocumentPath . ',' . $quotedField . ', ' . $db->quote($term->term) . ', ' . $db->quote($frequency); |
|
59 | - $i += 1; |
|
60 | - if ($i >= Indexer::SQLITE_MAX_COMPOUND_SELECT) { |
|
61 | - $this->executeStore($sql, $values, $db); |
|
62 | - $i = 0; |
|
63 | - $values = array(); |
|
64 | - } |
|
65 | - } |
|
66 | - if (count($values) != 0) { |
|
67 | - $this->executeStore($sql, $values, $db); |
|
68 | - } |
|
69 | - } |
|
70 | - } |
|
52 | + $quotedDocumentPath = $db->quote($documentField->documentPath); |
|
53 | + $quotedField = $db->quote($documentField->field); |
|
54 | + $values = array(); |
|
55 | + $i = 0; |
|
56 | + foreach ($termsForDocumentField as $term) { |
|
57 | + $frequency = intval($term->count) / $documentField->totalTermCount; |
|
58 | + $values[] = $quotedDocumentPath . ',' . $quotedField . ', ' . $db->quote($term->term) . ', ' . $db->quote($frequency); |
|
59 | + $i += 1; |
|
60 | + if ($i >= Indexer::SQLITE_MAX_COMPOUND_SELECT) { |
|
61 | + $this->executeStore($sql, $values, $db); |
|
62 | + $i = 0; |
|
63 | + $values = array(); |
|
64 | + } |
|
65 | + } |
|
66 | + if (count($values) != 0) { |
|
67 | + $this->executeStore($sql, $values, $db); |
|
68 | + } |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - private function getTermsForDocumentField($documentPath, $field) |
|
73 | - { |
|
74 | - $db = $this->dbHandle; |
|
75 | - $stmt = $db->prepare(' |
|
72 | + private function getTermsForDocumentField($documentPath, $field) |
|
73 | + { |
|
74 | + $db = $this->dbHandle; |
|
75 | + $stmt = $db->prepare(' |
|
76 | 76 | SELECT `term`, `count` |
77 | 77 | FROM `term_count` |
78 | 78 | WHERE `documentPath` = :documentPath |
79 | 79 | AND `field` = :field |
80 | 80 | '); |
81 | - $stmt->bindValue(':documentPath', $documentPath); |
|
82 | - $stmt->bindValue(':field', $field); |
|
83 | - $stmt->execute(); |
|
84 | - return $stmt->fetchAll(\PDO::FETCH_CLASS); |
|
85 | - } |
|
81 | + $stmt->bindValue(':documentPath', $documentPath); |
|
82 | + $stmt->bindValue(':field', $field); |
|
83 | + $stmt->execute(); |
|
84 | + return $stmt->fetchAll(\PDO::FETCH_CLASS); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @param $db |
|
89 | - * |
|
90 | - * @return mixed |
|
91 | - */ |
|
92 | - private function getTotalTermCountPerDocument($db) |
|
93 | - { |
|
94 | - $stmt = $db->prepare(' |
|
87 | + /** |
|
88 | + * @param $db |
|
89 | + * |
|
90 | + * @return mixed |
|
91 | + */ |
|
92 | + private function getTotalTermCountPerDocument($db) |
|
93 | + { |
|
94 | + $stmt = $db->prepare(' |
|
95 | 95 | SELECT documentPath, field, SUM(count) as totalTermCount |
96 | 96 | FROM term_count |
97 | 97 | GROUP BY documentPath, field |
98 | 98 | '); |
99 | - $stmt->execute(); |
|
100 | - $totalTermCountPerDocument = $stmt->fetchAll(\PDO::FETCH_CLASS); |
|
99 | + $stmt->execute(); |
|
100 | + $totalTermCountPerDocument = $stmt->fetchAll(\PDO::FETCH_CLASS); |
|
101 | 101 | |
102 | - return $totalTermCountPerDocument; |
|
103 | - } |
|
102 | + return $totalTermCountPerDocument; |
|
103 | + } |
|
104 | 104 | |
105 | - private function executeStore($sql, $values, $db) |
|
106 | - { |
|
107 | - $sql .= '(' . implode('),' . PHP_EOL . '(', $values) . ');'; |
|
108 | - if (!$db->query($sql)) { |
|
109 | - $errorInfo = $db->errorInfo(); |
|
110 | - $errorMsg = $errorInfo[2]; |
|
111 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
112 | - } |
|
113 | - } |
|
105 | + private function executeStore($sql, $values, $db) |
|
106 | + { |
|
107 | + $sql .= '(' . implode('),' . PHP_EOL . '(', $values) . ');'; |
|
108 | + if (!$db->query($sql)) { |
|
109 | + $errorInfo = $db->errorInfo(); |
|
110 | + $errorMsg = $errorInfo[2]; |
|
111 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
112 | + } |
|
113 | + } |
|
114 | 114 | |
115 | 115 | } |
116 | 116 | \ No newline at end of file |
@@ -10,51 +10,51 @@ |
||
10 | 10 | |
11 | 11 | class InverseDocumentFrequency |
12 | 12 | { |
13 | - /** |
|
14 | - * @var \PDO |
|
15 | - */ |
|
16 | - protected $dbHandle; |
|
17 | - protected $documentCount; |
|
13 | + /** |
|
14 | + * @var \PDO |
|
15 | + */ |
|
16 | + protected $dbHandle; |
|
17 | + protected $documentCount; |
|
18 | 18 | |
19 | - /** |
|
20 | - * InverseDocumentFrequency constructor. |
|
21 | - * |
|
22 | - * @param \PDO $dbHandle |
|
23 | - * @param int $documentCount |
|
24 | - */ |
|
25 | - public function __construct($dbHandle, $documentCount) |
|
26 | - { |
|
27 | - $this->dbHandle = $dbHandle; |
|
28 | - $this->documentCount = $documentCount; |
|
29 | - } |
|
19 | + /** |
|
20 | + * InverseDocumentFrequency constructor. |
|
21 | + * |
|
22 | + * @param \PDO $dbHandle |
|
23 | + * @param int $documentCount |
|
24 | + */ |
|
25 | + public function __construct($dbHandle, $documentCount) |
|
26 | + { |
|
27 | + $this->dbHandle = $dbHandle; |
|
28 | + $this->documentCount = $documentCount; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Formula to calculate: |
|
33 | - * idf(t) = 1 + log ( totalDocuments / (documentsThatContainTheTerm + 1)) |
|
34 | - * @throws \Exception |
|
35 | - */ |
|
36 | - public function execute() |
|
37 | - { |
|
38 | - $db = $this->dbHandle; |
|
39 | - $db->sqliteCreateFunction('log', 'log', 1); |
|
40 | - $sql = ' |
|
31 | + /** |
|
32 | + * Formula to calculate: |
|
33 | + * idf(t) = 1 + log ( totalDocuments / (documentsThatContainTheTerm + 1)) |
|
34 | + * @throws \Exception |
|
35 | + */ |
|
36 | + public function execute() |
|
37 | + { |
|
38 | + $db = $this->dbHandle; |
|
39 | + $db->sqliteCreateFunction('log', 'log', 1); |
|
40 | + $sql = ' |
|
41 | 41 | INSERT INTO inverse_document_frequency (term, inverseDocumentFrequency) |
42 | 42 | SELECT DISTINCT term, (1+(log(:documentCount / COUNT(documentPath) + 1))) as inverseDocumentFrequency |
43 | 43 | FROM term_count |
44 | 44 | GROUP BY term |
45 | 45 | '; |
46 | 46 | |
47 | - if (!$stmt = $db->prepare($sql)) { |
|
48 | - $errorInfo = $db->errorInfo(); |
|
49 | - $errorMsg = $errorInfo[2]; |
|
50 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
51 | - } |
|
52 | - $stmt->bindValue(':documentCount', $this->documentCount); |
|
53 | - $result = $stmt->execute(); |
|
54 | - if ($result === false) { |
|
55 | - $errorInfo = $db->errorInfo(); |
|
56 | - $errorMsg = $errorInfo[2]; |
|
57 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
58 | - } |
|
59 | - } |
|
47 | + if (!$stmt = $db->prepare($sql)) { |
|
48 | + $errorInfo = $db->errorInfo(); |
|
49 | + $errorMsg = $errorInfo[2]; |
|
50 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
51 | + } |
|
52 | + $stmt->bindValue(':documentCount', $this->documentCount); |
|
53 | + $result = $stmt->execute(); |
|
54 | + if ($result === false) { |
|
55 | + $errorInfo = $db->errorInfo(); |
|
56 | + $errorMsg = $errorInfo[2]; |
|
57 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
58 | + } |
|
59 | + } |
|
60 | 60 | } |
61 | 61 | \ No newline at end of file |
@@ -14,113 +14,113 @@ |
||
14 | 14 | |
15 | 15 | class TermCount |
16 | 16 | { |
17 | - /** |
|
18 | - * @var \PDO |
|
19 | - */ |
|
20 | - protected $dbHandle; |
|
21 | - protected $documents; |
|
22 | - protected $filters; |
|
23 | - protected $storage; |
|
17 | + /** |
|
18 | + * @var \PDO |
|
19 | + */ |
|
20 | + protected $dbHandle; |
|
21 | + protected $documents; |
|
22 | + protected $filters; |
|
23 | + protected $storage; |
|
24 | 24 | |
25 | - /** |
|
26 | - * TermCount constructor. |
|
27 | - * |
|
28 | - * @param \PDO $dbHandle |
|
29 | - * @param array $documents |
|
30 | - * @param array $filters |
|
31 | - * @param Storage $jsonStorage |
|
32 | - */ |
|
33 | - public function __construct($dbHandle, $documents, $filters, $jsonStorage) |
|
34 | - { |
|
35 | - $this->dbHandle = $dbHandle; |
|
36 | - $this->documents = $documents; |
|
37 | - $this->filters = $filters; |
|
38 | - $this->storage = $jsonStorage; |
|
39 | - } |
|
25 | + /** |
|
26 | + * TermCount constructor. |
|
27 | + * |
|
28 | + * @param \PDO $dbHandle |
|
29 | + * @param array $documents |
|
30 | + * @param array $filters |
|
31 | + * @param Storage $jsonStorage |
|
32 | + */ |
|
33 | + public function __construct($dbHandle, $documents, $filters, $jsonStorage) |
|
34 | + { |
|
35 | + $this->dbHandle = $dbHandle; |
|
36 | + $this->documents = $documents; |
|
37 | + $this->filters = $filters; |
|
38 | + $this->storage = $jsonStorage; |
|
39 | + } |
|
40 | 40 | |
41 | - public function execute() |
|
42 | - { |
|
43 | - $this->iterateDocumentsAndCreateTermCount($this->documents); |
|
44 | - } |
|
41 | + public function execute() |
|
42 | + { |
|
43 | + $this->iterateDocumentsAndCreateTermCount($this->documents); |
|
44 | + } |
|
45 | 45 | |
46 | - protected function applyFilters($tokens) |
|
47 | - { |
|
48 | - foreach ($this->filters as $filterName) { |
|
49 | - $filterClassName = '\CloudControl\Cms\search\filters\\' . $filterName; |
|
50 | - $filter = new $filterClassName($tokens); |
|
51 | - $tokens = $filter->getFilterResults(); |
|
52 | - } |
|
53 | - return $tokens; |
|
54 | - } |
|
46 | + protected function applyFilters($tokens) |
|
47 | + { |
|
48 | + foreach ($this->filters as $filterName) { |
|
49 | + $filterClassName = '\CloudControl\Cms\search\filters\\' . $filterName; |
|
50 | + $filter = new $filterClassName($tokens); |
|
51 | + $tokens = $filter->getFilterResults(); |
|
52 | + } |
|
53 | + return $tokens; |
|
54 | + } |
|
55 | 55 | |
56 | - protected function storeDocumentTermCount($document, $documentTermCount) |
|
57 | - { |
|
58 | - $db = $this->dbHandle; |
|
59 | - $sqlStart = ' |
|
56 | + protected function storeDocumentTermCount($document, $documentTermCount) |
|
57 | + { |
|
58 | + $db = $this->dbHandle; |
|
59 | + $sqlStart = ' |
|
60 | 60 | INSERT INTO `term_count` (`documentPath`, `term`, `count`, `field`) |
61 | 61 | VALUES '; |
62 | - $sql = $sqlStart; |
|
63 | - $values = array(); |
|
64 | - $quotedDocumentPath = $db->quote($document->path); |
|
65 | - $i = 0; |
|
66 | - foreach ($documentTermCount as $field => $countArray) { |
|
67 | - $quotedField = $db->quote($field); |
|
68 | - foreach ($countArray as $term => $count) { |
|
69 | - $values[] = $quotedDocumentPath . ', ' . $db->quote($term) . ', ' . $db->quote($count) . ', ' . $quotedField; |
|
70 | - $i += 1; |
|
71 | - if ($i >= Indexer::SQLITE_MAX_COMPOUND_SELECT) { |
|
72 | - $this->executeStoreDocumentTermCount($values, $sql, $db); |
|
73 | - $values = array(); |
|
74 | - $sql = $sqlStart; |
|
75 | - $i = 0; |
|
76 | - } |
|
77 | - } |
|
78 | - } |
|
79 | - if (count($values) != 0) { |
|
80 | - $this->executeStoreDocumentTermCount($values, $sql, $db); |
|
81 | - } |
|
82 | - } |
|
62 | + $sql = $sqlStart; |
|
63 | + $values = array(); |
|
64 | + $quotedDocumentPath = $db->quote($document->path); |
|
65 | + $i = 0; |
|
66 | + foreach ($documentTermCount as $field => $countArray) { |
|
67 | + $quotedField = $db->quote($field); |
|
68 | + foreach ($countArray as $term => $count) { |
|
69 | + $values[] = $quotedDocumentPath . ', ' . $db->quote($term) . ', ' . $db->quote($count) . ', ' . $quotedField; |
|
70 | + $i += 1; |
|
71 | + if ($i >= Indexer::SQLITE_MAX_COMPOUND_SELECT) { |
|
72 | + $this->executeStoreDocumentTermCount($values, $sql, $db); |
|
73 | + $values = array(); |
|
74 | + $sql = $sqlStart; |
|
75 | + $i = 0; |
|
76 | + } |
|
77 | + } |
|
78 | + } |
|
79 | + if (count($values) != 0) { |
|
80 | + $this->executeStoreDocumentTermCount($values, $sql, $db); |
|
81 | + } |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * @param $values |
|
86 | - * @param $sql |
|
87 | - * @param $db |
|
88 | - * |
|
89 | - * @throws \Exception |
|
90 | - */ |
|
91 | - protected function executeStoreDocumentTermCount($values, $sql, $db) |
|
92 | - { |
|
93 | - $sql .= '(' . implode('),' . PHP_EOL . '(', $values) . ');'; |
|
94 | - $stmt = $db->prepare($sql); |
|
95 | - if ($stmt === false || !$stmt->execute()) { |
|
96 | - $errorInfo = $db->errorInfo(); |
|
97 | - $errorMsg = $errorInfo[2]; |
|
98 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
99 | - } |
|
100 | - } |
|
84 | + /** |
|
85 | + * @param $values |
|
86 | + * @param $sql |
|
87 | + * @param $db |
|
88 | + * |
|
89 | + * @throws \Exception |
|
90 | + */ |
|
91 | + protected function executeStoreDocumentTermCount($values, $sql, $db) |
|
92 | + { |
|
93 | + $sql .= '(' . implode('),' . PHP_EOL . '(', $values) . ');'; |
|
94 | + $stmt = $db->prepare($sql); |
|
95 | + if ($stmt === false || !$stmt->execute()) { |
|
96 | + $errorInfo = $db->errorInfo(); |
|
97 | + $errorMsg = $errorInfo[2]; |
|
98 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
99 | + } |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * @param $document |
|
104 | - */ |
|
105 | - private function createTermCountForDocument($document) |
|
106 | - { |
|
107 | - $tokenizer = new DocumentTokenizer($document, $this->storage); |
|
108 | - $tokens = $tokenizer->getTokens(); |
|
109 | - $documentTermCount = $this->applyFilters($tokens); |
|
110 | - $this->storeDocumentTermCount($document, $documentTermCount); |
|
111 | - } |
|
102 | + /** |
|
103 | + * @param $document |
|
104 | + */ |
|
105 | + private function createTermCountForDocument($document) |
|
106 | + { |
|
107 | + $tokenizer = new DocumentTokenizer($document, $this->storage); |
|
108 | + $tokens = $tokenizer->getTokens(); |
|
109 | + $documentTermCount = $this->applyFilters($tokens); |
|
110 | + $this->storeDocumentTermCount($document, $documentTermCount); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * @param $documents |
|
115 | - */ |
|
116 | - private function iterateDocumentsAndCreateTermCount($documents) |
|
117 | - { |
|
118 | - foreach ($documents as $document) { |
|
119 | - if ($document->type === 'folder') { |
|
120 | - $this->iterateDocumentsAndCreateTermCount($document->content); |
|
121 | - } else { |
|
122 | - $this->createTermCountForDocument($document); |
|
123 | - } |
|
124 | - } |
|
125 | - } |
|
113 | + /** |
|
114 | + * @param $documents |
|
115 | + */ |
|
116 | + private function iterateDocumentsAndCreateTermCount($documents) |
|
117 | + { |
|
118 | + foreach ($documents as $document) { |
|
119 | + if ($document->type === 'folder') { |
|
120 | + $this->iterateDocumentsAndCreateTermCount($document->content); |
|
121 | + } else { |
|
122 | + $this->createTermCountForDocument($document); |
|
123 | + } |
|
124 | + } |
|
125 | + } |
|
126 | 126 | } |
127 | 127 | \ No newline at end of file |
@@ -17,72 +17,72 @@ |
||
17 | 17 | */ |
18 | 18 | class TermFieldLengthNorm |
19 | 19 | { |
20 | - /** |
|
21 | - * @var \PDO |
|
22 | - */ |
|
23 | - protected $dbHandle; |
|
20 | + /** |
|
21 | + * @var \PDO |
|
22 | + */ |
|
23 | + protected $dbHandle; |
|
24 | 24 | |
25 | - /** |
|
26 | - * TermFieldLengthNorm constructor. |
|
27 | - * |
|
28 | - * @param \PDO $dbHandle |
|
29 | - */ |
|
30 | - public function __construct($dbHandle) |
|
31 | - { |
|
32 | - $this->dbHandle = $dbHandle; |
|
33 | - } |
|
25 | + /** |
|
26 | + * TermFieldLengthNorm constructor. |
|
27 | + * |
|
28 | + * @param \PDO $dbHandle |
|
29 | + */ |
|
30 | + public function __construct($dbHandle) |
|
31 | + { |
|
32 | + $this->dbHandle = $dbHandle; |
|
33 | + } |
|
34 | 34 | |
35 | - public function execute() |
|
36 | - { |
|
37 | - $db = $this->dbHandle; |
|
38 | - $db->sqliteCreateFunction('sqrt', 'sqrt', 1); |
|
39 | - $sql = ' |
|
35 | + public function execute() |
|
36 | + { |
|
37 | + $db = $this->dbHandle; |
|
38 | + $db->sqliteCreateFunction('sqrt', 'sqrt', 1); |
|
39 | + $sql = ' |
|
40 | 40 | SELECT documentPath, field, COUNT(`count`) as termCount |
41 | 41 | FROM term_count |
42 | 42 | GROUP BY documentPath, field |
43 | 43 | '; |
44 | - $stmt = $db->prepare($sql); |
|
45 | - if ($stmt === false) { |
|
46 | - $errorInfo = $db->errorInfo(); |
|
47 | - $errorMsg = $errorInfo[2]; |
|
48 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
49 | - } |
|
50 | - if (($stmt->execute()) === false) { |
|
51 | - $errorInfo = $db->errorInfo(); |
|
52 | - $errorMsg = $errorInfo[2]; |
|
53 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
54 | - } |
|
55 | - $uniqueFieldsPerDocument = $stmt->fetchAll(\PDO::FETCH_OBJ); |
|
56 | - $values = array(); |
|
57 | - $i = 0; |
|
58 | - foreach ($uniqueFieldsPerDocument as $fieldRow) { |
|
59 | - $values[] = 'UPDATE term_frequency SET termNorm = 1/sqrt(' . intval($fieldRow->termCount) . ') WHERE documentPath = ' . $db->quote($fieldRow->documentPath) . ' AND field = ' . $db->quote($fieldRow->field) . ';'; |
|
60 | - $i += 1; |
|
61 | - if ($i >= Indexer::SQLITE_MAX_COMPOUND_SELECT) { |
|
62 | - $this->executeUpdateTermNorm($values, $db); |
|
63 | - $values = array(); |
|
64 | - $i = 0; |
|
65 | - } |
|
66 | - } |
|
67 | - if (count($values) != 0) { |
|
68 | - $this->executeUpdateTermNorm($values, $db); |
|
69 | - } |
|
70 | - } |
|
44 | + $stmt = $db->prepare($sql); |
|
45 | + if ($stmt === false) { |
|
46 | + $errorInfo = $db->errorInfo(); |
|
47 | + $errorMsg = $errorInfo[2]; |
|
48 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
49 | + } |
|
50 | + if (($stmt->execute()) === false) { |
|
51 | + $errorInfo = $db->errorInfo(); |
|
52 | + $errorMsg = $errorInfo[2]; |
|
53 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
54 | + } |
|
55 | + $uniqueFieldsPerDocument = $stmt->fetchAll(\PDO::FETCH_OBJ); |
|
56 | + $values = array(); |
|
57 | + $i = 0; |
|
58 | + foreach ($uniqueFieldsPerDocument as $fieldRow) { |
|
59 | + $values[] = 'UPDATE term_frequency SET termNorm = 1/sqrt(' . intval($fieldRow->termCount) . ') WHERE documentPath = ' . $db->quote($fieldRow->documentPath) . ' AND field = ' . $db->quote($fieldRow->field) . ';'; |
|
60 | + $i += 1; |
|
61 | + if ($i >= Indexer::SQLITE_MAX_COMPOUND_SELECT) { |
|
62 | + $this->executeUpdateTermNorm($values, $db); |
|
63 | + $values = array(); |
|
64 | + $i = 0; |
|
65 | + } |
|
66 | + } |
|
67 | + if (count($values) != 0) { |
|
68 | + $this->executeUpdateTermNorm($values, $db); |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @param array $values |
|
74 | - * @param \PDO $db |
|
75 | - * @throws \Exception |
|
76 | - */ |
|
77 | - private function executeUpdateTermNorm($values, $db) |
|
78 | - { |
|
79 | - $sql = 'BEGIN TRANSACTION;' . PHP_EOL; |
|
80 | - $sql .= implode(PHP_EOL, $values) . PHP_EOL; |
|
81 | - $sql .= 'COMMIT;'; |
|
82 | - if (($db->exec($sql)) === false) { |
|
83 | - $errorInfo = $db->errorInfo(); |
|
84 | - $errorMsg = $errorInfo[2]; |
|
85 | - throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
86 | - } |
|
87 | - } |
|
72 | + /** |
|
73 | + * @param array $values |
|
74 | + * @param \PDO $db |
|
75 | + * @throws \Exception |
|
76 | + */ |
|
77 | + private function executeUpdateTermNorm($values, $db) |
|
78 | + { |
|
79 | + $sql = 'BEGIN TRANSACTION;' . PHP_EOL; |
|
80 | + $sql .= implode(PHP_EOL, $values) . PHP_EOL; |
|
81 | + $sql .= 'COMMIT;'; |
|
82 | + if (($db->exec($sql)) === false) { |
|
83 | + $errorInfo = $db->errorInfo(); |
|
84 | + $errorMsg = $errorInfo[2]; |
|
85 | + throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); |
|
86 | + } |
|
87 | + } |
|
88 | 88 | } |
89 | 89 | \ No newline at end of file |