Test url notizie con titolo

Signed-off-by: Riccardo Di Dato <r.didato@asdynamics.it>
This commit is contained in:
Riccardo Di Dato
2017-07-27 12:07:08 +02:00
parent febdb300c5
commit 77a8f94c50
4 changed files with 37 additions and 1 deletions
@@ -0,0 +1,23 @@
#!/usr/bin/php
<?php
/*
* regenerateAutoUrlsForIndexing.php
* Author: Riccardo Di Dato
* Creation Date: 27 lug 2017
*/
require_once(dirname(__FILE__)."/../load.php");
$options = ['limit'=>100, 'skip'=>0, 'sort'=> [ 'creationDate' => 1 ] ];
$notizie = GlobalVariables::get("dao")->query("NotiziaModel", [], $options);
while (sizeof($notizie)>0 ){
foreach ($notizie as $notizia){
$notizia->buildAutoShortenedUrl();
GlobalVariables::get("dao")->save($notizia);
}
$options['skip']+=$options['limit'];
}
?>
+7
View File
@@ -78,6 +78,13 @@ class NotiziaModel extends HasMediaModel{
return parent::__set($attr, $value);
}
public function buildAutoShortenedUrl(){
$shortened = preg_replace("/[^a-z0-9-_]/", "", $this->titolo);
$shortened = preg_replace("/\s+/", " ", trim($shortened) );
$eles = explode(" ", $shortened);
$eles = array_slice($eles, 0, 15);
$this->shortenedUrl = implode("_", $eles);
}
}
?>
+2
View File
@@ -75,6 +75,8 @@ try{
$notizia->about->owner = AdminLoginManager::getLogged()->id;
}
$notizia->buildAutoShortenedUrl();
if (!array_key_exists($notizia->category,NotiziaModel::$NOTIZIE_CATEGORY)){
throw new GUIException("La categoria inserita non è valida");
}
+5 -1
View File
@@ -12,7 +12,11 @@ try {
$articolo = null;
if (array_key_exists("id", $_GET)){
$articolo = GlobalVariables::get("dao")->getFirst("NotiziaModel",array("id"=>$_GET["id"],"status"=>NotiziaModel::STATUS_ACCEPTED));
$articolo = GlobalVariables::get("dao")->getFirst("NotiziaModel",array("id"=>strval($_GET["id"]),"status"=>NotiziaModel::STATUS_ACCEPTED));
}
else if (array_key_exists("short", $_GET) ) {
$short = strval($_GET["short"]);
$articolo = GlobalVariables::get("dao")->getFirst("NotiziaModel",array("shortenedUrl"=> $short ,"status"=>NotiziaModel::STATUS_ACCEPTED));
}
if (is_null($articolo)){
GUIHandler::redirect("index.php");