Пример #1
0
 protected function afterDelete()
 {
     $url = Url::model()->findByPk($this->url_id);
     $url->delete();
     @unlink(Yii::getPathOfAlias('webroot') . '/archivos/' . $this->carpeta->ruta . '/' . $this->archivo);
     return parent::afterDelete();
 }
Пример #2
0
 private function verificar_slug($slug)
 {
     if ($slug == 'radio/emisora') {
         Yii::app()->request->redirect('http://radio.telemedellin.tv', true, 301);
     }
     return Url::model()->findByAttributes(array('slug' => $slug));
 }
Пример #3
0
 protected function getUrl($item)
 {
     if (!$item) {
         return false;
     }
     if (isset($item->tipo_link_id) && $item->tipo_link_id == 2) {
         $url = $this->parseExtUrl($item->url);
     } else {
         $u = Url::model()->findByPk($item->url_id);
         $url = bu($u->slug);
     }
     return $url;
 }
Пример #4
0
 public function verificarSlug($slug, $baseUrl = '')
 {
     $slug = trim($slug);
     $c = Url::model()->findByAttributes(array('slug' => $baseUrl . $slug));
     if ($c) {
         $lc = substr($slug, -1);
         if (is_numeric($lc)) {
             $slug = substr($slug, 0, -1) . ((int) $lc + 1);
         } else {
             $slug = $slug . '-1';
         }
         $slug = $this->verificarSlug($slug);
     }
     return $slug;
 }
Пример #5
0
 protected function getUrl($item)
 {
     if (!$item) {
         return false;
     }
     switch ($item->tipo_link_id) {
         case 1:
             $u = Url::model()->findByPk($item->url_id);
             $url = bu($u->slug);
             break;
         case 2:
             $url = $this->parseExtUrl($item->url);
             break;
     }
     return $url;
 }
Пример #6
0
 protected function afterSave()
 {
     if (!$this->isNewRecord) {
         if (isset($this->oldAttributes['nombre']) && $this->nombre != $this->oldAttributes['nombre']) {
             $url = Url::model()->findByPk($this->url_id);
             $slug = '#imagenes/' . $this->slugger($this->nombre);
             $slug = $this->verificarSlug($slug);
             $url->slug = $slug;
             $url->save();
             foreach ($this->fotos as $foto) {
                 $uid = $foto->url_id;
                 $u = Url::model()->findByPk($uid);
                 $nslug = '#imagenes/' . $this->slugger($this->nombre) . '/' . $this->slugger($foto->nombre);
                 $nslug = $this->verificarSlug($nslug);
                 $u->slug = $nslug;
                 $u->save();
             }
         }
     }
     parent::afterSave();
 }
Пример #7
0
 protected function afterSave()
 {
     if (!$this->isNewRecord) {
         if (isset($this->oldAttributes['nombre']) && $this->nombre != $this->oldAttributes['nombre']) {
             $url = Url::model()->findByPk($this->url_id);
             $slug = '#videos/' . $this->slugger($this->albumVideo->nombre) . '/' . $this->slugger($this->nombre);
             $slug = $this->verificarSlug($slug);
             $url->slug = $slug;
             $url->save();
         }
     }
     parent::afterSave();
 }
Пример #8
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     $jarId = "";
     $apkId = "";
     $ipaId = "";
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $fileForm = new FileForm();
     $fileForm->name = $model->name;
     foreach ($model['url'] as $url) {
         if ($url->type == 'jar') {
             $jarId = $url->id;
             $fileForm->jar = $url->url;
         } else {
             if ($url->type == 'apk') {
                 $apkId = $url->id;
                 $fileForm->apk = $url->url;
             } else {
                 if ($url->type == 'ipa') {
                     $ipaId = $url->id;
                     $fileForm->ipa = $url->url;
                 }
             }
         }
     }
     if (isset($_POST['FileForm'])) {
         $model->name = $_POST['FileForm']['name'];
         if ($model->save()) {
             $fileFormTypeArray = $model->fileType();
             foreach ($fileFormTypeArray as $fileType) {
                 if (trim($_POST['FileForm'][$fileType]) != "") {
                     $urlId = "";
                     if ($fileType == "apk") {
                         $urlId = $apkId;
                     } else {
                         if ($fileType == "jar") {
                             $urlId = $jarId;
                         } else {
                             $urlId = $ipaId;
                         }
                     }
                     $url = Url::model()->findByPk($urlId);
                     if ($url) {
                         $url->url = $_POST['FileForm'][$fileType];
                         $url->save();
                     } else {
                         $url = new Url();
                         $url->file_id = $model->id;
                         $url->type = $fileType;
                         $url->url = $_POST['FileForm'][$fileType];
                         $url->save();
                     }
                 }
             }
         }
         $this->redirect(array('file/admin'));
     }
     $this->render('update', array('model' => $fileForm));
 }
Пример #9
0
 protected function afterSave()
 {
     if (!$this->isNewRecord) {
         if (isset($this->oldAttributes['nombre']) && $this->nombre != $this->oldAttributes['nombre']) {
             $micrositio = Micrositio::model()->findByPk($this->micrositio_id);
             $url = Url::model()->findByPk($this->url_id);
             if ($micrositio->seccion->nombre == 'sin-seccion') {
                 $slug = $this->slugger($micrositio->nombre) . '/' . $this->slugger($this->nombre);
             } else {
                 $slug = $this->slugger($micrositio->seccion->nombre) . '/' . $this->slugger($micrositio->nombre) . '/' . $this->slugger($this->nombre);
             }
             $slug = $this->verificarSlug($slug);
             $url->slug = $slug;
             $url->save();
         }
     }
     parent::afterSave();
 }
Пример #10
0
 public function actionUrls_mass()
 {
     if (!Yii::app()->request->isPostRequest) {
         throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
     }
     $action = $_GET['action'];
     if (isset($_POST['extendedSelect'])) {
         AdvancedSelectableGridView::mapUrlToGET();
         $dataProvider = Url::searchDataProvider();
         $criteria = AdvancedSelectableGridView::getExtendedSelectCriteria('Url', $dataProvider);
         if (!$criteria->condition) {
             $criteria->condition = "1=1";
         }
         if ($action == 'download') {
             Url::model()->downloadUrls($criteria->condition, $criteria->params);
         } elseif ($action == 'delete') {
             Url::model()->deleteUrls($criteria->condition, $criteria->params);
         } elseif ($action == 'enable') {
             Yii::app()->db->createCommand("UPDATE urls_url SET enabled_url=1 WHERE " . $criteria->condition)->execute($criteria->params);
         } elseif ($action == 'disable') {
             Yii::app()->db->createCommand("UPDATE urls_url SET enabled_url=0 WHERE " . $criteria->condition)->execute($criteria->params);
         }
     } elseif (isset($_POST['selected']) && is_array($_POST['selected']) && count($_POST['selected'])) {
         foreach ($_POST['selected'] as $k => $v) {
             // value must be integer
             $_POST['selected'][$k] = (int) $v;
         }
         if (count($_POST['selected']) == 1) {
             $condition = "id_url=" . $_POST['selected'][0];
         } else {
             $condition = "id_url='" . implode("' OR id_url='", $_POST['selected']) . '\'';
         }
         if ($action == 'download') {
             Url::model()->downloadUrls($condition);
         } elseif ($action == 'delete') {
             Url::model()->deleteUrls($condition);
         } elseif ($action == 'enable') {
             Yii::app()->db->createCommand("UPDATE urls_url SET enabled_url=1 WHERE " . $condition)->execute();
         } elseif ($action == 'disable') {
             Yii::app()->db->createCommand("UPDATE urls_url SET enabled_url=0 WHERE " . $condition)->execute();
         }
     } else {
         throw new CHttpException(400, 'Bad request.');
     }
     header("Location: " . $_SERVER['HTTP_REFERER']);
     die;
 }
Пример #11
0
 public function actionArchivo()
 {
     if (!$_GET['hash']) {
         throw new CHttpException(404, 'No se encontró la página solicitada');
     }
     $hash = $_GET['hash'];
     $url = Url::model()->findByAttributes(array('slug' => $hash));
     $params = array();
     if ($url->tipo_id == 10) {
         $c = Carpeta::model()->findByAttributes(array('url_id' => $url->id));
         if ($c) {
             $params['carpeta_id'] = $c->id;
             $w = ' carpeta_id = ' . $c->id . ' AND ';
         }
     } else {
         if ($url->tipo_id == 11) {
             $params['url_id'] = $url->id;
             $w = ' url_id = ' . $url->id . ' AND ';
         }
     }
     $json = '';
     $dependencia = new CDbCacheDependency("SELECT GREATEST(MAX(creado), MAX(modificado)) FROM archivo WHERE estado <> 0");
     $a = Archivo::model()->findAllByAttributes($params, array('order' => 'nombre ASC'));
     if ($a) {
         $json .= '[';
         foreach ($a as $archivo) {
             $json .= '{';
             $json .= '"id":"' . CHtml::encode($archivo->id) . '",';
             $json .= '"url":"' . CHtml::encode($archivo->url->slug) . '",';
             $json .= '"tipo_archivo":"' . $archivo->tipoArchivo->nombre . '",';
             //$json .= '"carpeta":"'.CHtml::encode($archivo->carpeta->ruta).'",';
             $json .= '"carpeta":';
             $json .= '{';
             $json .= '"ruta":"' . CHtml::encode($archivo->carpeta->ruta) . '",';
             $json .= '"url":"' . CHtml::encode($archivo->carpeta->url->slug) . '"';
             $json .= '},';
             $json .= '"nombre":"' . CHtml::encode($archivo->nombre) . '",';
             $json .= '"archivo":"' . $archivo->archivo . '"';
             $json .= '},';
         }
         $json = substr($json, 0, -1);
         $json .= ']';
     }
     $this->_sendResponse(200, $json, 'application/json');
     Yii::app()->end();
 }
Пример #12
0
 protected function afterSave()
 {
     if (!$this->isNewRecord) {
         if (isset($this->oldAttributes['nombre']) && $this->nombre != $this->oldAttributes['nombre']) {
             $url = Url::model()->findByPk($this->url_id);
             $slug = '#videos/' . $this->slugger($this->nombre);
             $slug = $this->verificarSlug($slug);
             $url->slug = $slug;
             $url->save();
             foreach ($this->videos as $video) {
                 $uid = $video->url_id;
                 $u = Url::model()->findByPk($uid);
                 $nslug = '#videos/' . $this->slugger($this->nombre) . '/' . $this->slugger($video->nombre);
                 $nslug = $this->verificarSlug($nslug);
                 $u->slug = $nslug;
                 $u->save();
             }
             //Recorrer los videos y cambiarles el slug de la URL
         }
     }
     parent::afterSave();
 }
Пример #13
0
 public function resetClick()
 {
     $url = Url::model()->findBySql("SELECT * FROM " . $this->tableName() . " ORDER BY id DESC");
     if ($url->day_update != date('d')) {
         Url::model()->updateAll(array('day_update' => date('d'), 'day_click' => 0, 'total' => 0));
         if ($url->month_update != date('m')) {
             Url::model()->updateAll(array('month_update' => date('m'), 'month_click' => 0));
         }
         $files = File::model()->findAll(array('order' => 'id'));
         foreach ($files as $file) {
             $statistic = new Statistic();
             $statistic->file_id = $file->id;
             $statistic->date = date('dmY');
             $statistic->save();
         }
     }
 }
Пример #14
0
 public function actionRenamearchivo()
 {
     if (!Yii::app()->request->isAjaxRequest || !isset($_POST['name']) || !isset($_POST['new_name'])) {
         throw new CHttpException(404, 'No se encontró la página solicitada');
     }
     $new_name = $_POST['new_name'];
     $archivo = Archivo::model()->with('carpeta')->findByAttributes(array('archivo' => $_POST['name']));
     $parent = Carpeta::model()->findByPk($archivo->carpeta_id);
     $nombre_slug = $this->slugger($new_name);
     $nueva_ruta = $parent->ruta . '/' . $nombre_slug;
     $url = Url::model()->findByPk($archivo->url_id);
     $slug = $parent->url->slug . '/' . $nombre_slug;
     $slug = $this->verificarSlug($slug);
     $url->slug = $slug;
     $url->save();
     $base = Yii::getPathOfAlias('webroot') . '/archivos/';
     header('HTTP/1.1 200 OK');
     $archivo->archivo = $new_name;
     $archivo->nombre = $new_name;
     if (!$archivo->save()) {
         $json = array('error' => '1');
         echo json_encode($json);
     }
     Yii::app()->end();
 }
Пример #15
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Url the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Url::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Пример #16
0
 protected function afterSave()
 {
     if ($this->isNewRecord) {
         $menu = new Menu();
         $menu->nombre = $this->nombre;
         $menu->estado = 1;
         $menu->save();
         $this->menu_id = $menu->getPrimaryKey();
     } else {
         if (isset($this->oldAttributes['nombre']) && $this->nombre != $this->oldAttributes['nombre']) {
             $seccion = Seccion::model()->findByPk($this->seccion_id);
             $url = Url::model()->findByPk($this->url_id);
             $slug = $this->slugger($seccion->nombre) . '/' . $this->slugger($this->nombre);
             $slug = $this->verificarSlug($slug);
             $url->slug = $slug;
             $url->save();
             foreach ($this->paginas as $pagina) {
                 $uid = $pagina->url_id;
                 $u = Url::model()->findByPk($uid);
                 $nslug = $this->slugger($seccion->nombre) . '/' . $this->slugger($this->nombre) . '/' . $this->slugger($pagina->nombre);
                 $nslug = $this->verificarSlug($nslug);
                 $u->slug = $nslug;
                 $u->save();
             }
         }
     }
     return parent::afterSave();
 }
Пример #17
0
echo $form->labelEx($model, 'menu_id');
?>
		<?php 
echo $form->dropDownList($model, 'menu_id', CHtml::listData(Menu::model()->findAll(), 'id', 'nombre'), array('empty' => 'Elija un menú si aplica'));
?>
		<?php 
echo $form->error($model, 'menu_id');
?>
	</div>

	<div class="row">
		<?php 
echo $form->labelEx($model, 'url_id');
?>
		<?php 
echo $form->dropDownList($model, 'url_id', CHtml::listData(Url::model()->findAllByAttributes(array('tipo_id' => 2)), 'id', 'slug'));
?>
		<?php 
echo $form->error($model, 'url_id');
?>
	</div>

	<div class="row">
		<?php 
echo $form->labelEx($model, 'background');
?>
		<?php 
echo $form->fileField($model, 'background');
?>
		<?php 
echo $form->error($model, 'background');
Пример #18
0
 protected function afterSave()
 {
     $parent = Carpeta::model()->findByPk($this->item_id);
     if (!$this->isNewRecord) {
         if (isset($this->oldAttributes['carpeta']) && $this->carpeta != $this->oldAttributes['carpeta'] || isset($this->oldAttributes['ruta']) && $this->ruta != $this->oldAttributes['ruta']) {
             $url = Url::model()->findByPk($this->url_id);
             $slug = $parent->url->slug . '/' . $this->slugger($this->carpeta);
             $slug = $this->verificarSlug($slug);
             $url->slug = $slug;
             $url->save();
             if ($this->oldAttributes['hijos'] === 1) {
                 $hijos = Carpeta::model()->findAllByAttributes(array('item_id' => $this->id));
                 foreach ($hijos as $h) {
                     $h->ruta = $this->ruta . '/' . $this->slugger($h->carpeta);
                     $h->save();
                 }
             }
         }
     } else {
         $parent->hijos = 1;
         $parent->save();
     }
     parent::afterSave();
 }