32 abstract public function loadView($viewName, $pData=NULL, $asString=
false);
34 abstract public function seo();
36 abstract protected function _seo();
38 abstract protected function showConfMessage($content, $type, $url, $responseElement, $data, $attributes=NULL);
40 abstract protected function showSimpleMessage($content, $type, $icon=
"info", $timeout=NULL, $staticName=null);
42 abstract protected function _createController($controllerName,$variables=[],$ctrlTemplate=
'controller.tpl',$hasView=
false,$jsCallback=
"");
45 $controllerClass=\implode(
"\\", $params);
46 if(\class_exists($controllerClass)){
47 $controllerSeo=
new $controllerClass();
49 $array=$controllerSeo->_getArrayUrls();
51 $parser->parseArray($array,
true);
53 $urls=$parser->getUrls();
54 $dt=$this->jquery->semantic()->dataTable(
"dtSiteMap",
'Ubiquity\seo\Url', $urls);
55 $dt->setFields([
'location',
'lastModified',
'changeFrequency',
'priority']);
56 $dt->setCaptions([
'Location',
'Last Modified',
'Change Frequency',
'Priority']);
57 $dt->fieldAsInput(
"location");
58 $dt->setValueFunction(
"lastModified",
function ($v, $o, $i) {
59 $d=date(
'Y-m-d\TH:i', $v);
60 $input=
new HtmlInput(
"date-" . $i,
'datetime-local', $d);
61 $input->setName(
"lastModified[]");
65 $dt->fieldAsDropDown(
'changeFrequency', \array_combine($freq, $freq));
66 $dt->setValueFunction(
"priority",
function ($v, $o, $i) {
67 $input=
new HtmlInput(
"priority-" . $i,
'number', $v);
68 $f=$input->getDataField();
69 $f->setProperty(
'name',
'priority[]');
70 $f->setProperty(
'max',
'1')->setProperty(
'min',
'0')->setProperty(
'step',
'0.1');
73 $dt->onNewRow(
function ($row, $instance) {
74 if ($instance->getExisting()) {
75 $row->addClass(
'positive');
77 $row->setProperty(
'style',
'display: none;')->addClass(
'toToggle');
80 $dt->setHasCheckboxes(
true);
81 $dt->setCheckedCallback(
function ($object) {
82 return $object->getExisting();
85 $dt->setSubmitParams($this->
_getAdminFiles()->getAdminBaseRoute() .
"/saveUrls",
"#seo-details", [
'attr' =>
'' ]);
86 $this->jquery->execOn(
"click",
"#saveUrls",
'$("#frm-dtSiteMap").form("submit");');
87 $this->jquery->exec(
'$("#displayAllRoutes").checkbox();',
true);
88 $this->jquery->execOn(
'change',
'input[name="selection[]"]',
'$(this).parents("tr").toggleClass("_checked",$(this).prop("checked"));');
89 $this->jquery->click(
'#displayAllRoutes',
'$(".toToggle:not(._checked)").toggle();');
90 $this->jquery->execAtLast($this->jquery->execOn(
'change',
'#frm-dtSiteMap input',
'$("#saveUrls").show();',[
"immediatly"=>
false]));
91 $this->jquery->compile($this->view);
93 $this->
loadView($this->
_getAdminFiles()->getViewSeoDetails(), [
"controllerClass" => $controllerClass,
"urlsFile" => $controllerSeo->_getUrlsFilename() ]);
95 echo $this->
showSimpleMessage(
"The controller <b>`{$controllerClass}`</b> does not exists!",
"warning",
"warning circle");
96 echo $this->jquery->compile($this->view);
103 $siteUrl=$config[
"siteUrl"];
108 foreach ( $seoCtrls as $ctrl ) {
109 if(\class_exists($ctrl)){
111 $content[]=\str_replace(
"%url%",
URequest::cleanUrl($siteUrl . $controllerSeo->getPath()), $template);
114 if (\
sizeof($content) > 0) {
116 $content=\implode(
"\n", $content);
118 $msg=$this->
showSimpleMessage(
"The file <b>robots.txt</b> has been generated in " . $appDir,
"success",
"info circle");
119 $this->jquery->get($this->
_getAdminFiles()->getAdminBaseRoute() .
"/seoRefresh",
"#seoCtrls",[
'hasLoader'=>
false,
'jqueryDone'=>
'replaceWith']);
121 $msg=$this->
showSimpleMessage(
"Can not generate <b>robots.txt</b> if no SEO controller is selected.",
"warning",
"warning circle");
124 echo $this->jquery->compile($this->view);
130 echo $this->jquery->compile($this->view);
134 $modal=$this->jquery->semantic()->htmlModal(
"modalNewSeo",
"Creating a new Seo controller");
135 $modal->setInverted();
136 $frm=$this->jquery->semantic()->htmlForm(
"frmNewSeo");
137 $fc=$frm->addField(
'controllerName')->addRule([
"checkController",
"Controller {value} already exists!" ]);
139 $fields=$frm->addFields([
"urlsFile",
"sitemapTemplate" ],
"Urls file & sitemap twig template");
140 $fields->setFieldsPropertyValues(
"value", [
"urls",
"Seo/sitemap.xml.html" ]);
141 $fields->getItem(0)->addRules([
"empty" ]);
143 $frm->addCheckbox(
"ck-add-route",
"Add route...");
145 $frm->addContent(
"<div id='div-new-route' style='display: none;'>");
147 $frm->addInput(
"path",
"",
"text",
"")->addRule([
"checkRoute",
"Route {value} already exists!" ]);
148 $frm->addContent(
"</div>");
150 $frm->setValidationParams([
"on" =>
"blur",
"inline" =>
true ]);
151 $frm->setSubmitParams($this->
_getAdminFiles()->getAdminBaseRoute() .
"/createSeoController",
"#messages",[
"hasLoader"=>
false]);
152 $modal->setContent($frm);
153 $modal->addAction(
"Validate");
154 $this->jquery->click(
"#action-modalNewSeo-0",
"$('#frmNewSeo').form('submit');",
false,
false);
155 $modal->addAction(
"Close");
156 $this->jquery->change(
'#controllerName',
'if($("#ck-add-route").is(":checked")){$("#path").val($(this).val());}');
157 $this->jquery->exec(
"$('.dimmer.modals.page').html('');$('#modalNewSeo').modal('show');",
true);
158 $this->jquery->jsonOn(
"change",
"#ck-add-route", $this->
_getAdminFiles()->getAdminBaseRoute() .
"/_addRouteWithNewAction",
"post", [
"context" =>
"$('#frmNewSeo')",
"params" =>
"$('#frmNewSeo').serialize()",
"jsCondition" =>
"$('#ck-add-route').is(':checked')" ]);
159 $this->jquery->exec(Rule::ajax($this->jquery,
"checkRoute", $this->
_getAdminFiles()->getAdminBaseRoute() .
"/_checkRoute",
"{}",
"result=data.result;",
"postForm", [
"form" =>
"frmNewSeo" ]),
true);
160 $this->jquery->exec(Rule::ajax($this->jquery,
"checkController", $this->
_getAdminFiles()->getAdminBaseRoute() .
"/_checkController",
"{}",
"result=data.result;",
"postForm", [
"form" =>
"frmNewSeo" ]),
true);
161 $this->jquery->change(
"#ck-add-route",
'$("#div-new-route").toggle($(this).is(":checked"));if($(this).is(":checked")){$("#path").val($("#controllerName").val());}');
163 echo $this->jquery->compile($this->view);
170 $variables[
"%path%"]=$path;
172 $variables[
"%route%"]=
'@route("' . $path .
'")';
175 $variables[
"%sitemapTemplate%"]=
URequest::post(
"sitemapTemplate",
"Seo/sitemap.xml.html");
177 echo $this->
_createController($_POST[
"controllerName"], $variables,
'seoController.tpl',
false,
178 $this->jquery->getDeferred($this->_getAdminFiles()->getAdminBaseRoute() .
"/seoRefresh",
"#seoCtrls",[
'hasLoader'=>
false,
'jqueryDone'=>
'replaceWith',
'jsCallback'=>
'$("#seo-details").html("");']));
180 $this->jquery->get($this->
_getAdminFiles()->getAdminBaseRoute() .
"/seoRefresh",
"#seoCtrls",[
'hasLoader'=>
false,
'jqueryDone'=>
'replaceWith',
'jsCallback'=>
'$("#seo-details").html("");']);
181 echo $this->jquery->compile($this->view);
189 header(
'Content-type: application/json');
190 $controller=$ctrlNS . $_POST[
"controllerName"];
192 $result[
"result"]=(\array_search($controller, $controllers) ===
false);
193 echo json_encode($result);
204 foreach ( $selections as $index ) {
205 $result[]=[
"location" => $locations[$index - 1],
"lastModified" => \strtotime($lastModified[$index - 1]),
"changeFrequency" => $changeFrequency[$index - 1],
"priority" => $priority[$index - 1] ];
208 if (isset($seoController) && $seoController instanceof
SeoController) {
210 $seoController->_save($result);
211 $r=new \ReflectionClass($seoController);
212 $this->
displaySiteMap($r->getNamespaceName(), $r->getShortName());
213 $filename=$seoController->_getUrlsFilename();
214 $message=$this->
showSimpleMessage(
UString::pluralize(\
sizeof($selections),
'<b>`'.$filename.
'`</b> saved with no url.',
'<b>`'.$filename.
'`</b> saved with {count} url.',
'<b>`'.$filename.
'`</b> saved with {count} urls.'),
"success",
"info circle");
215 }
catch(\
Ubiquity\exceptions\CacheException $e){
216 $message=$this->
showSimpleMessage(
"Unable to write urls file `" . $filename .
"`",
"warning",
"warning");
218 $this->jquery->html(
"#messages",$message,
true);
219 echo $this->jquery->compile($this->view);
224 $controllerName=\implode(
"\\", $params);
225 if (
sizeof($_POST) > 0) {
226 $controllerName=\urldecode($_POST[
"data"]);
228 $message=$this->
showSimpleMessage(
"Deletion of SEO controller `<b>" . $controllerName .
"</b>`",
"info",
"info", 4000);
229 $this->jquery->get($this->
_getAdminFiles()->getAdminBaseRoute() .
"/seoRefresh",
"#seoCtrls",[
'hasLoader'=>
false,
'jqueryDone'=>
'replaceWith',
'jsCallback'=>
'$("#seo-details").html("");']);
231 $message=$this->
showSimpleMessage(
"Can not delete SEO controller `" . $controllerName .
"`",
"warning",
"warning");
234 $message=$this->
showConfMessage(
"Do you confirm the deletion of SEO controller `<b>" . $controllerName .
"</b>`?",
"error", $this->
_getAdminFiles()->getAdminBaseRoute() .
"/deleteSeoController/{$params[0]}/{$params[1]}",
"#messages", \urlencode($controllerName));
237 echo $this->jquery->compile($this->view);
241 $controllerName=\urldecode($controllerName);
242 if(\class_exists($controllerName)){
243 $rClass=new \ReflectionClass($controllerName);
250 $controllerName=\implode(
"\\", $params);
251 $ctrl=
new $controllerName();
254 $content=\ob_get_clean();
256 $modal=$this->jquery->semantic()->htmlModal(
"seeSeo",
"sitemap file for {$ctrl->getPath()} url");
257 $modal->setInverted();
258 $modal->setContent(
"<pre><code>".\htmlentities($content).
"</pre></code>");
259 $modal->addAction(
"Close");
260 $this->jquery->exec(
"$('.dimmer.modals.page').html('');$('#seeSeo').modal('show');",
true);
262 echo $this->jquery->compile($this->view);
static isPost()
Returns true if the request is sent by the POST method.
_deleteController($controllerName)
_createController($controllerName, $variables=[], $ctrlTemplate='controller.tpl', $hasView=false, $jsCallback="")
static asHtml($encoding='utf-8')
Sets the response content-type to text/html.
showConfMessage($content, $type, $url, $responseElement, $data, $attributes=NULL)
loadView($viewName, $pData=NULL, $asString=false)
static pluralize($count, $zero, $one, $other)
Pluralize an expression.
static post($key, $default=NULL)
Returns the value of the $key variable passed by the post method or $default if the $key variable doe...
static getNS($part="controllers")
createSeoController($force=null)
showSimpleMessage($content, $type, $icon="info", $timeout=NULL, $staticName=null)
static set($key, $value)
Adds or sets a value to the Session at position $key.
displaySiteMap(... $params)
static get($key, $default=NULL)
Returns the value stored at the key position in session.
deleteSeoController(... $params)
static getApplicationDir()
static deleteFile($filename)
static save($filename, $content, $flags=LOCK_EX)