Skip to content

Commit f62df36

Browse files
committed
sitemaps - missing files
1 parent 5b69699 commit f62df36

File tree

8 files changed

+1006
-0
lines changed

8 files changed

+1006
-0
lines changed

app/base/abstracts/BaseXMLPage.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* SiteBase
4+
* PHP Version 7.0
5+
*
6+
* @category CMS / Framework
7+
* @package Degami\Sitebase
8+
* @author Mirko De Grandis <degami@github.com>
9+
* @license MIT https://opensource.org/licenses/mit-license.php
10+
* @link https://github.com/degami/sitebase
11+
*/
12+
namespace App\Base\Abstracts;
13+
14+
use \Psr\Container\ContainerInterface;
15+
use \App\App;
16+
use \App\Site\Routing\RouteInfo;
17+
use \Symfony\Component\HttpFoundation\Response;
18+
use \Spatie\ArrayToXml\ArrayToXml;
19+
use \Exception;
20+
21+
/**
22+
* Base for pages rendering an XML response
23+
*/
24+
abstract class BaseXMLPage extends BasePage
25+
{
26+
/**
27+
* {@inheritdocs}
28+
*
29+
* @param ContainerInterface $container
30+
*/
31+
public function __construct(ContainerInterface $container)
32+
{
33+
parent::__construct($container);
34+
$this->response = $this->getContainer()->get(Response::class);
35+
}
36+
37+
/**
38+
* {@inheritdocs}
39+
*
40+
* @param RouteInfo|null $route_info
41+
* @param array $route_data
42+
* @return Response
43+
*/
44+
public function process(RouteInfo $route_info = null, $route_data = [])
45+
{
46+
$result = parent::process($route_info);
47+
if ($result instanceof Response) {
48+
return $result;
49+
}
50+
try {
51+
return $this
52+
->getResponse()
53+
->prepare($this->getRequest())
54+
->setContent(ArrayToXml::convert($getXMLData))
55+
->headers->set('Content-Type', 'text/xml');
56+
} catch (Exception $e) {
57+
return $this->getUtils()->exceptionXml($e);
58+
}
59+
}
60+
61+
/**
62+
* gets XML data
63+
*
64+
* @return mixed
65+
*/
66+
abstract protected function getXMLData();
67+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
/**
3+
* SiteBase
4+
* PHP Version 7.0
5+
*
6+
* @category CMS / Framework
7+
* @package Degami\Sitebase
8+
* @author Mirko De Grandis <degami@github.com>
9+
* @license MIT https://opensource.org/licenses/mit-license.php
10+
* @link https://github.com/degami/sitebase
11+
*/
12+
namespace App\Site\Controllers\Admin\Json;
13+
14+
use \Psr\Container\ContainerInterface;
15+
use \App\Base\Abstracts\AdminJsonPage;
16+
use \App\Site\Models\Contact;
17+
use \App\Site\Routing\RouteInfo;
18+
use \Degami\PHPFormsApi as FAPI;
19+
use \App\Site\Controllers\Admin\Sitemaps as SitemapsController;
20+
21+
/**
22+
* Contact Form AJAX callback
23+
*/
24+
class SitemapCallback extends AdminJsonPage
25+
{
26+
/**
27+
* @var FAPI\Form form object
28+
*/
29+
protected $form;
30+
31+
/**
32+
* @var Contact contact object
33+
*/
34+
protected $contact = null;
35+
36+
/**
37+
* {@inheritdocs}
38+
*
39+
* @return string
40+
*/
41+
protected function getAccessPermission()
42+
{
43+
return 'administer_sitemaps';
44+
}
45+
46+
/**
47+
* returns an empty form
48+
*
49+
* @param FAPI\Form $form
50+
* @param array &$form_state
51+
* @return FAPI\Form
52+
*/
53+
public function emptyForm(FAPI\Form $form, &$form_state)
54+
{
55+
return $form;
56+
}
57+
58+
/**
59+
* {@inheritdocs}
60+
*
61+
* @param RouteInfo|null $route_info
62+
* @param array $route_data
63+
* @return Response
64+
*/
65+
public function process(RouteInfo $route_info = null, $route_data = [])
66+
{
67+
$result = parent::process($route_info);
68+
if ($result instanceof Response) {
69+
return $result;
70+
}
71+
try {
72+
$sitemap_controller = $this->getContainer()->make(SitemapsController::class);
73+
$this->form = $sitemap_controller->getForm();
74+
$out = json_decode($this->form->render());
75+
76+
if ($out == null) {
77+
$out = ['html'=>'', 'js'=>'', 'is_submitted'=> false];
78+
}
79+
80+
return $this
81+
->getResponse()
82+
->prepare($this->getRequest())
83+
->setData($out);
84+
} catch (Exception $e) {
85+
return $this->getUtils()->exceptionJson($e);
86+
}
87+
}
88+
89+
/**
90+
* ajax callback
91+
*
92+
* @param FAPI\Form $form
93+
* @return FAPI\Abstracts\App\Base\Element
94+
*/
95+
public static function sitemapFormsCallback(FAPI\Form $form)
96+
{
97+
return $form->getField('urlset');
98+
}
99+
100+
//not used on this class
101+
/**
102+
* {@inheritdocs}
103+
*
104+
* @return array
105+
*/
106+
protected function getJsonData()
107+
{
108+
return [];
109+
}
110+
}

0 commit comments

Comments
 (0)