#!/usr/bin/php
"SET NAMES utf8") );
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$admin = GlobalVariables::get("dao")->getFirst("AdminModel",array("username"=>"antonio.pianelli"));
if (is_null($admin)){
$statement = $pdo->query("select * from admin where id = 2;");
$data = reset($statement->fetchALL(PDO::FETCH_CLASS,"stdClass"));
$admin = new stdClass();
$admin->username = $data->username;
$admin->password = $data->password;
$admin->nome = $data->nome;
$admin->cognome = $data->cognome;
$admin->roles = 1022;
$admin->active = true;
$admin->activationSent = true;
$admin->email = "info@ifattidinapoli.it";
$admin = new AdminModel($admin);
GlobalVariables::get("dao")->save($admin);
}
else {
$admin->email = "info@ifattidinapoli.it";
GlobalVariables::get("dao")->save($admin);
}
$count = 0;
$imgDir = "/home/r.didato/mediaimg/notizie";
$statement = $pdo->query("select * from notizia order by id desc limit $count,100");
$dati = $statement->fetchALL(PDO::FETCH_CLASS,"stdClass");
while (is_array($dati) && sizeof($dati)>0){
foreach ($dati as $ele){
$notizia = new stdClass();
$notizia->status = NotiziaModel::STATUS_ACCEPTED;
$notizia->about = new stdClass();
$notizia->about->owner = $admin->id;
$notizia->about->author = $admin->nome." ".$admin->cognome;
$notizia->isAnsa = $ele->primaPagina==1;
// $notizia->about->data = new MongoDate(strtotime($ele->data));
$notizia->about->data = new MongoDB\BSON\UTCDateTime(strtotime($ele->data)*1000) ; //New version
$notizia->titolo = $ele->mainTitle;
$notizia->sottotitolo = $ele->secTitle;
$corpo = $ele->corpo;
$corpo = preg_replace("~link[(]([^,]+),([^)]+)[)];~", '$1', $corpo);
$corpo = preg_replace("~mail[(]([^,]+),([^)]+)[)];~", '$1', $corpo);
$notizia->testo = $corpo;
switch ($ele->menu){
case 1://POLITICA
$notizia->category = NotiziaModel::CATEGORY_POLITICA;
break;
case 2://CRONACA
$notizia->category = NotiziaModel::CATEGORY_CRONACA;
break;
case 3://SPORT
$notizia->category = NotiziaModel::CATEGORY_SPORT;
break;
case 4://CULTURA
$notizia->category = NotiziaModel::CATEGORY_CULTURA;
break;
case 5://SPETTACOLO
$notizia->category = NotiziaModel::CATEGORY_CULTURA;
break;
case 4://FISCO E LAVORO
$notizia->category = NotiziaModel::CATEGORY_FISCOELAVORO;
break;
}
$notizia = new NotiziaModel($notizia);
GlobalVariables::get("dao")->save($notizia);
if (preg_match("/^http/",$ele->img)){
$media = new stdClass();
$media->mediaType = MediaModel::TYPE_YOUTUBE;
$matches = array();
if ( preg_match("~^http[s]?[:]//youtu\.be/(.+)$~", trim($ele->img), $matches) ){
$media->link = $matches[1];
}
else if (preg_match("~http[s]?[:]//www\.youtube\.com/embed/([^\"]++)~", trim($ele->img), $matches)){
$media->link = $matches[1];
}
else if (preg_match("~http[s]?[:]//www\.youtube\.com/watch[?]v[=](.+)$~", trim($ele->img), $matches)){
$media->link = $matches[1];
}
// LEGACY FORMAT http://www.youtube.com/v/c0B1snrcoPk&hl=it_IT&fs=1&
else if (preg_match("~http[:]//www\.youtube\.com/v/([^&]++)~", trim($ele->img), $matches)){
$media->link = $matches[1];
}
// $media->link = $ele->img;
$media = new MediaModel($media);
GlobalVariables::get("dao")->save($media);
DaoMediaHandler::addMedia($notizia, $media);
}
$curDir = $imgDir."/".$ele->id;
if (is_dir($curDir) && is_dir($curDir."/big")){
$i=0;
$continue = true;
$curFile = $curDir."/big/".$i++.".jpg";
while(file_exists($curFile)){
$media = new stdClass();
$media->mediaType = MediaModel::TYPE_IMAGE;
$media = DaoMediaHandler::createNewFileBasedMedia($media, $curFile, "jpg");
DaoMediaHandler::addMedia($notizia, $media);
$curFile = $curDir."/big/".$i++.".jpg";
}
}
// $statement = $pdo->query("select * from commenti where notizia = ".$ele->id);
// $commenti = $statement->fetchALL(PDO::FETCH_CLASS,"stdClass");
// if (sizeof($commenti)>0){
// foreach ($commenti as $commento){
// $comm = new stdClass();
// $comm->notizia = $notizia->id;
// $comm->status = CommentoModel::STATUS_ACCEPTED;
// $comm->date = new MongoDate(strtotime($commento->data));
// $comm->titolo = $commento->titolo;
// $comm->testo = $commento->testo;
// }
// }
}
$count+=100;
$statement = $pdo->query("select * from notizia order by id desc limit $count,100");
$dati = $statement->fetchALL(PDO::FETCH_CLASS,"stdClass");
}
?>