Test url notizie con titolo
Signed-off-by: Riccardo Di Dato <r.didato@asdynamics.it>
This commit is contained in:
@@ -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'];
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -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
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user