33 abstract public function loadView($viewName, $pData = NULL, $asString =
false);
35 abstract public function seo();
37 abstract protected function _seo();
39 abstract protected function showConfMessage($content, $type,$title, $url, $responseElement, $data, $attributes = NULL): HtmlMessage;
41 abstract protected function showSimpleMessage($content, $type, $title=null,$icon =
"info", $timeout = NULL, $staticName = null): HtmlMessage;
43 abstract protected function _createController($controllerName, $variables = [], $ctrlTemplate =
'controller.tpl', $hasView =
false, $jsCallback =
"");
46 $controllerClass = \implode (
"\\", $params );
47 if (\class_exists ( $controllerClass )) {
48 $controllerSeo =
new $controllerClass ();
50 $array = $controllerSeo->_getArrayUrls ();
52 $parser->parseArray ( $array,
true );
54 $urls = $parser->getUrls ();
55 $dt = $this->jquery->semantic ()->dataTable (
"dtSiteMap",
'Ubiquity\seo\Url', $urls );
56 $dt->setFields ( [
'location',
'lastModified',
'changeFrequency',
'priority' ] );
57 $dt->setCaptions ( [
'Location',
'Last Modified',
'Change Frequency',
'Priority' ] );
58 $dt->fieldAsInput (
"location" );
59 $dt->setValueFunction (
"lastModified",
function ($v, $o, $i) {
60 $d = date (
'Y-m-d\TH:i', $v );
61 $input =
new HtmlInput (
"date-" . $i,
'datetime-local', $d );
62 $input->setName (
"lastModified[]" );
66 $dt->fieldAsDropDown (
'changeFrequency', \array_combine ( $freq, $freq ) );
67 $dt->setValueFunction (
"priority",
function ($v, $o, $i) {
68 $input =
new HtmlInput (
"priority-" . $i,
'number', $v );
69 $f = $input->getDataField ();
70 $f->setProperty (
'name',
'priority[]' );
71 $f->setProperty (
'max',
'1' )->setProperty (
'min',
'0' )->setProperty (
'step',
'0.1' );
74 $dt->onNewRow (
function ($row, $instance) {
75 if ($instance->getExisting ()) {
76 $row->addClass (
'positive' );
78 $row->setProperty (
'style',
'display: none;' )->addClass (
'toToggle' );
81 $dt->setHasCheckboxes (
true );
82 $dt->setCheckedCallback (
function ($object) {
83 return $object->getExisting ();
86 $dt->setSubmitParams ( $this->
_getAdminFiles ()->getAdminBaseRoute () .
"/saveUrls",
"#seo-details", [
'attr' =>
'' ] );
87 $this->jquery->execOn (
"click",
"#saveUrls",
'$("#frm-dtSiteMap").form("submit");' );
88 $this->jquery->exec (
'$("#displayAllRoutes").checkbox();',
true );
89 $this->jquery->execOn (
'change',
'input[name="selection[]"]',
'$(this).parents("tr").toggleClass("_checked",$(this).prop("checked"));' );
90 $this->jquery->click (
'#displayAllRoutes',
'$(".toToggle:not(._checked)").toggle();' );
91 $this->jquery->execAtLast ( $this->jquery->execOn (
'change',
'#frm-dtSiteMap input',
'$("#saveUrls").show();', [
"immediatly" =>
false ] ) );
92 $this->jquery->compile ( $this->view );
94 $this->
loadView ( $this->
_getAdminFiles ()->getViewSeoDetails (), [
"controllerClass" => $controllerClass,
"urlsFile" => $controllerSeo->_getUrlsFilename () ] );
96 echo $this->
showSimpleMessage (
"The controller <b>`{$controllerClass}`</b> does not exists!",
"warning",
"warning circle" );
97 echo $this->jquery->compile ( $this->view );
104 $siteUrl = $config [
"siteUrl"];
109 foreach ( $seoCtrls as $ctrl ) {
110 if (\class_exists ( $ctrl )) {
112 $content [] = \str_replace (
"%url%",
URequest::cleanUrl ( $siteUrl . $controllerSeo->getPath () ), $template );
115 if (\
sizeof ( $content ) > 0) {
117 $content = \implode (
"\n", $content );
119 $msg = $this->
showSimpleMessage (
"The file <b>robots.txt</b> has been generated in " . $appDir,
"success",
"info circle" );
120 $this->jquery->get ( $this->
_getAdminFiles ()->getAdminBaseRoute () .
"/seoRefresh",
"#seoCtrls", [
'hasLoader' =>
false,
'jqueryDone' =>
'replaceWith' ] );
122 $msg = $this->
showSimpleMessage (
"Can not generate <b>robots.txt</b> if no SEO controller is selected.",
"warning",
"warning circle" );
125 echo $this->jquery->compile ( $this->view );
131 echo $this->jquery->compile ( $this->view );
135 $modal = $this->jquery->semantic ()->htmlModal (
"modalNewSeo",
"Creating a new Seo controller" );
136 $modal->setInverted ();
137 $frm = $this->jquery->semantic ()->htmlForm (
"frmNewSeo" );
138 $fc = $frm->addField (
'controllerName' )->addRule ( [
"checkController",
"Controller {value} already exists!" ] );
140 $fields = $frm->addFields ( [
"urlsFile",
"sitemapTemplate" ],
"Urls file & sitemap twig template" );
141 $fields->setFieldsPropertyValues (
"value", [
"urls",
"@framework/Seo/sitemap.xml.html" ] );
142 $fields->getItem ( 0 )->addRules ( [
"empty" ] );
144 $frm->addCheckbox (
"ck-add-route",
"Add route..." );
146 $frm->addContent (
"<div id='div-new-route' style='display: none;'>" );
148 $frm->addInput (
"path",
"",
"text",
"" )->addRule ( [
"checkRoute",
"Route {value} already exists!" ] );
149 $frm->addContent (
"</div>" );
151 $frm->setValidationParams ( [
"on" =>
"blur",
"inline" =>
true ] );
152 $frm->setSubmitParams ( $this->
_getAdminFiles ()->getAdminBaseRoute () .
"/createSeoController",
"#messages", [
"hasLoader" =>
false ] );
153 $modal->setContent ( $frm );
154 $modal->addAction (
"Validate" );
155 $this->jquery->click (
"#action-modalNewSeo-0",
"$('#frmNewSeo').form('submit');",
false,
false );
156 $modal->addAction (
"Close" );
157 $this->jquery->change (
'#controllerName',
'if($("#ck-add-route").is(":checked")){$("#path").val($(this).val());}' );
158 $this->jquery->exec (
"$('.dimmer.modals.page').html('');$('#modalNewSeo').modal('show');",
true );
159 $this->jquery->jsonOn (
"change",
"#ck-add-route", $this->
_getAdminFiles ()->getAdminBaseRoute () .
"/_addRouteWithNewAction",
"post", [
"context" =>
"$('#frmNewSeo')",
"params" =>
"$('#frmNewSeo').serialize()",
"jsCondition" =>
"$('#ck-add-route').is(':checked')" ] );
160 $this->jquery->exec ( Rule::ajax ( $this->jquery,
"checkRoute", $this->
_getAdminFiles ()->getAdminBaseRoute () .
"/_checkRoute",
"{}",
"result=data.result;",
"postForm", [
"form" =>
"frmNewSeo" ] ),
true );
161 $this->jquery->exec ( Rule::ajax ( $this->jquery,
"checkController", $this->
_getAdminFiles ()->getAdminBaseRoute () .
"/_checkController",
"{}",
"result=data.result;",
"postForm", [
"form" =>
"frmNewSeo" ] ),
true );
162 $this->jquery->change (
"#ck-add-route",
'$("#div-new-route").toggle($(this).is(":checked"));if($(this).is(":checked")){$("#path").val($("#controllerName").val());}' );
164 echo $this->jquery->compile ( $this->view );
171 $variables [
"%path%"] = $path;
172 if (isset ( $path )) {
173 $variables [
"%route%"] =
'@route("' . $path .
'")';
175 $variables [
"%urlsFile%"] =
URequest::post (
"urlsFile",
"urls" );
176 $variables [
"%sitemapTemplate%"] =
URequest::post (
"sitemapTemplate",
"@framework/Seo/sitemap.xml.html" );
178 echo $this->
_createController ( $_POST [
"controllerName"], $variables,
'seoController.tpl',
false, $this->jquery->getDeferred ( $this->_getAdminFiles ()->getAdminBaseRoute () .
"/seoRefresh",
"#seoCtrls", [
'hasLoader' =>
false,
'jqueryDone' =>
'replaceWith',
179 'jsCallback' =>
'$("#seo-details").html("");' ] ) );
181 $this->jquery->get ( $this->
_getAdminFiles ()->getAdminBaseRoute () .
"/seoRefresh",
"#seoCtrls", [
'hasLoader' =>
false,
'jqueryDone' =>
'replaceWith',
'jsCallback' =>
'$("#seo-details").html("");' ] );
182 echo $this->jquery->compile ( $this->view );
190 header (
'Content-type: application/json' );
191 $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.
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...
showConfMessage($content, $type, $title, $url, $responseElement, $data, $attributes=NULL)
static getNS($part="controllers")
createSeoController($force=null)
showSimpleMessage($content, $type, $title=null, $icon="info", $timeout=NULL, $staticName=null)
static set($key, $value)
Adds or sets a value to the Session at position $key.
static getControllers($subClass="\biquity\ontrollers\ontroller", $backslash=false, $includeSubclass=false)
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)