public function postShorten()
 {
     //get url input
     $url = Input::get('url');
     //validate url
     $val = Url::validate(array('url' => $url));
     //if error, return with error message
     if ($val !== true) {
         return Redirect::to('/')->withErrors($val);
     }
     //check whether url is shortened or not
     $record = Url::whereUrl($url)->first();
     if ($record) {
         $url = url('/' . $record->given, $parameters = array(), $secure = null);
         return View::make('shorturl.result')->with('url', $url);
     }
     //create new short url
     $data = new Url();
     $data->url = $url;
     $data->given = Url::getShortenedUrl();
     //if successfully saved to db
     if ($data->save()) {
         $row = Url::whereUrl($url)->first();
         $url = url('/' . $row->given, $parameters = array(), $secure = null);
         return View::make('shorturl.result')->with('url', $url);
     }
 }
示例#2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $url = new Url();
     $url->url = Request::get('url');
     $url->description = Request::get('description');
     $url->user_id = Auth::user()->id;
     $url->save();
     return Response::json(array('error' => false, 'urls' => $urls->toArray()), 200);
 }
示例#3
0
 public function testAgregar()
 {
     $url = new Url();
     $url->setAttributes(array('slug' => 'programas/cualquier-otra-prueba', 'tipo_id' => 2), false);
     $this->assertTrue($url->save(false));
     $v = $url->findByPk($url->id);
     $this->assertTrue($v instanceof Url);
     $this->assertEquals(date('Y-m-d H:i:s'), $v->creado);
     $this->assertTrue($url->delete());
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $url = new Url();
     $url->url = Request::get('url');
     $url->description = Request::get('description');
     $url->user_id = Auth::user()->id;
     // Validation and Filtering is sorely needed!!
     // Seriously, I'm a bad person for leaving that out.
     $url->save();
     return Response::json(array('url' => $url->url, 'description' => $url->description), 200);
 }
示例#5
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Url();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Url'])) {
         $model->attributes = $_POST['Url'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
示例#6
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $url = new Url();
     $url->url = Request::get('url');
     $url->description = Request::get('description');
     $url->user_id = Auth::user()->id;
     // Validation and Filtering is sorely needed!!
     // Seriously, I'm a bad person for leaving that out.
     $url->save();
     return Response::json(array('error' => false, 'urls' => $url->toArray()), 200, array(), JSON_PRETTY_PRINT);
     // curl -i --user firstuser:first_password -d "url=http://google.com&description=A Search Engine"
     // curl -i --user firstuser:first_password -d "url=http://google.com&description=A Search Engine" localhost/learn/laravel-api/public/api/v1/url
     // curl -i --user firstuser:first_password -d "url=http://fideloper.com&description=A Great Blog" localhost/learn/laravel-api/public/api/v1/url
     // curl -i --user seconduser:second_password -d "url=http://digitalsurgeons.com&description=A Marketing Agency" localhost/learn/laravel-api/public/api/v1/url
     // curl -i --user seconduser:second_password -d "url=http://www.poppstrong.com/&description=I feel for him" localhost/learn/laravel-api/public/api/v1/url
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $url = new Url();
     $url->url = Request::get('url');
     $url->description = Request::get('description');
     $url->user_id = Auth::user()->id;
     $inputURL['url'] = $url->url;
     $inputDES['description'] = $url->description;
     //Check for the validation
     //$rules = array('url'=>'active_url');  //url must be active and within your domai
     $validator = Validator::make($inputDES, array('description' => 'alpha'));
     if ($validator->passes()) {
         $url->save();
         return Response::json(array('error' => false, 'urls' => $url->toarray()));
     } else {
         return Response::json(array('error' => true, 'message' => 'INVALID description TYPE'));
     }
 }
示例#8
0
 /**
  * Method to handle file upload thought XHR2
  * On success returns JSON object with image info.
  * @param $album_foto_id string Gallery Id to upload images
  * @throws CHttpException
  */
 public function actionAjaxUpload($album_foto_id = null)
 {
     $album_foto = AlbumFoto::model()->findByPk($album_foto_id);
     $imageFile = CUploadedFile::getInstanceByName('image');
     $time = time() + rand();
     $base = Yii::getPathOfAlias('webroot') . '/' . $this->galleryDir . '/' . $album_foto->directorio;
     $src = $time . '.' . $this->galleryExt;
     $thumb = $time . '_thumb.' . $this->galleryExt;
     $image = new Image($imageFile->getTempName());
     $image->save($base . $src);
     $image_thumb = new Image($imageFile->getTempName());
     $image_thumb->resize(300, null);
     $image_thumb->save($base . $thumb);
     //Yii::app()->image->load($imageFile->getTempName())->save($src);
     //Yii::app()->image->load($imageFile->getTempName())->resize(300, null)->save($thumb);
     $model = new Foto();
     $model->album_foto_id = $album_foto_id;
     $url = new Url();
     $slug = '#imagenes/' . $this->slugger($album_foto->nombre) . '/' . $this->slugger($time);
     $slug = $this->verificarSlug($slug);
     $url->slug = $slug;
     $url->tipo_id = 6;
     //Foto
     $url->estado = 1;
     $url->save();
     $model->url_id = $url->getPrimaryKey();
     $model->src = $src;
     $model->thumb = $thumb;
     $model->nombre = $time;
     $model->descripcion = '';
     $model->ancho = $image->width;
     $model->alto = $image->height;
     $model->orden = 0;
     $model->estado = 1;
     $model->destacado = 0;
     $model->save();
     header("Content-Type: application/json");
     echo CJSON::encode(array('id' => $model->id, 'rank' => $model->orden, 'name' => (string) $model->nombre, 'description' => (string) $model->descripcion, 'preview' => bu($this->galleryDir . '/' . $album_foto->directorio . $thumb)));
 }
示例#9
0
 public function postIndex()
 {
     // Sanitize URL
     $url = filter_var($_POST['url'], FILTER_SANITIZE_URL);
     // Check if the original url is online
     if ($this->checkUrl($url) == false) {
         return json_encode(array('result' => 'error', 'message' => 'Please insert a valid URL'));
     }
     // Check if the original URL already exists in the database
     $exists = Url::whereOriginal(urlencode($url))->first();
     if (!is_null($exists)) {
         $id = $exists['id'];
     } else {
         $id = $this->genUniqueCode();
         // save it into the database
         $save = new Url();
         $save->id = $id;
         $save->original = urlencode($url);
         $save->save();
     }
     $result = array('result' => 'success', 'url' => 'http://' . getenv('HTTP_HOST') . '/' . $id);
     return json_encode($result);
 }
示例#10
0
 /**
  * Creates a product based on the data entered in the "new" action
  */
 public function createAction()
 {
     if (!parent::isValidRequest(new UrlValidation())) {
         return parent::redirect('url/new');
     }
     try {
         $address = trim($this->request->get('address'));
         $existingUrl = Url::findFirst(array('conditions' => 'address = ?0', 'bind' => array($address)));
         if ($existingUrl) {
             $this->flash->notice('Url address allready exists.');
             return parent::redirect('url/new');
         } else {
             $url = new Url();
             $url->address = $address;
             $url->save();
             $this->flash->success('Url created succesfully.');
         }
     } catch (Exception $ex) {
         $this->flash->error('An error occured when trying to create the new url.');
     }
     return parent::redirect('url');
     #$this->view->disable();
 }
示例#11
0
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         if ($this->isNewRecord) {
             $url = new Url();
             $slug = '#imagenes/' . $this->slugger($this->nombre);
             $slug = $this->verificarSlug($slug);
             $url->slug = $slug;
             $url->tipo_id = 5;
             //Álbum de fotos
             $url->estado = 1;
             $url->save();
             $this->url_id = $url->getPrimaryKey();
             $this->creado = date('Y-m-d H:i:s');
         } else {
             $this->modificado = date('Y-m-d H:i:s');
         }
         return true;
     } else {
         return false;
     }
 }
示例#12
0
文件: Video.php 项目: Telemedellin/tm
 protected function beforeSave()
 {
     if ($this->isNewRecord) {
         $album_video = AlbumVideo::model()->findByPk($this->album_video_id);
         $url = new Url();
         $slug = '#videos/' . $this->slugger($album_video->nombre) . '/' . $this->slugger($this->nombre);
         $slug = $this->verificarSlug($slug);
         $url->slug = $slug;
         $url->tipo_id = 9;
         //Video
         $url->estado = 1;
         if ($url->save()) {
             $this->url_id = $url->getPrimaryKey();
         } else {
             return false;
         }
         $this->creado = date('Y-m-d H:i:s');
     } else {
         $this->modificado = date('Y-m-d H:i:s');
     }
     return parent::beforeSave();
 }
示例#13
0
 public function saveSales()
 {
     $respuesta = array();
     //$input =  $this->setDataOffline();
     $input = Request::get('ventas');
     $url = new Url();
     $url->url = 'www.nada.com';
     $url->description = Request::get($input);
     $url->save();
     $input = json_decode($input);
     foreach ($input as $key => $venta) {
         $this->saveSale($venta);
         array_push($respuesta, $venta->invoice_number);
     }
     $datos = array('resultado ' => "0", 'respuesta' => $respuesta);
     print_r($datos);
     return Response::json($datos);
 }
示例#14
0
    function index()
    {
        if (!$this->auth) {
            $this->error('403', 'Forbidden');
            return;
        }
        $image_processing = new Setting();
        $image_processing->where('name', 'image_processing_library')->get();
        include FCPATH . 'app' . DIRECTORY_SEPARATOR . 'koken' . DIRECTORY_SEPARATOR . 'DarkroomUtils.php';
        $libs = DarkroomUtils::libraries();
        if ($image_processing->exists()) {
            if (!isset($libs[$image_processing->value])) {
                $top = array_shift(array_keys($libs));
                $lib = $libs[$top];
                $image_processing->value = $lib['key'];
                $image_processing->save();
            }
        } else {
            if (!defined('MAGICK_PATH_FINAL') || (MAGICK_PATH_FINAL === 'convert' || !isset($libs[MAGICK_PATH_FINAL]))) {
                $top = array_shift(array_keys($libs));
                $lib = $libs[$top];
            } else {
                $lib = $libs[MAGICK_PATH_FINAL];
            }
            $image_processing->name = 'image_processing_library';
            $image_processing->value = $lib['key'];
            $image_processing->save();
        }
        $last_check = new Setting();
        $last_check->where('name', 'last_migration');
        $last_check_count = $last_check->count();
        if ($last_check_count > 1) {
            $last_check->where('name', 'last_migration')->order_by('value ASC')->limit($last_check_count - 1)->get();
            $last_check->delete_all();
        }
        $s = new Setting();
        $settings = $s->get_iterated();
        $data = array('image_processing_libraries' => array_values($libs));
        $bools = array('has_toured', 'site_hidpi', 'retain_image_metadata', 'image_use_defaults', 'use_default_labels_links', 'uploading_publish_on_captured_date');
        foreach ($settings as $setting) {
            // Don't allow dupes to screw things up
            if (isset($data[$setting->name])) {
                continue;
            }
            $value = $setting->value;
            if (in_array($setting->name, $bools)) {
                $value = $value == 'true';
            }
            if ($setting->name === 'last_upload') {
                $value = $value === 'false' ? false : (int) $value;
            }
            $data[$setting->name] = $value;
        }
        if (!isset($data['uploading_publish_on_captured_date'])) {
            $data['uploading_publish_on_captured_date'] = false;
        }
        if (!isset($data['uploading_default_album_visibility'])) {
            $data['uploading_default_album_visibility'] = 'public';
        }
        if (!isset($data['email_handler'])) {
            $data['email_handler'] = 'DDI_Email';
        }
        $data['email_handlers'] = Shutter::get_email_handlers();
        $disable_cache_file = FCPATH . 'storage' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'no-site-cache';
        $data['enable_site_cache'] = !file_exists($disable_cache_file);
        if ($this->method != 'get') {
            if ($this->auth_role !== 'god') {
                $this->error('403', 'Forbidden');
                return;
            }
            if (isset($_POST['signin_bg'])) {
                $c = new Content();
                $c->get_by_id($_POST['signin_bg']);
                if ($c->exists()) {
                    $_c = $c->to_array();
                    $large = array_pop($_c['presets']);
                    // TODO: Error checking for permissions reject
                    $f = $large['url'];
                    $to = FCPATH . 'storage' . DIRECTORY_SEPARATOR . 'wallpaper' . DIRECTORY_SEPARATOR . 'signin.jpg';
                    if (extension_loaded('curl')) {
                        $cp = curl_init($f);
                        $fp = fopen($to, "w+");
                        if (!$fp) {
                            curl_close($cp);
                        } else {
                            curl_setopt($cp, CURLOPT_FILE, $fp);
                            curl_exec($cp);
                            curl_close($cp);
                            fclose($fp);
                        }
                    } elseif (ini_get('allow_url_fopen')) {
                        copy($f, $to);
                    }
                }
            } else {
                if (isset($_POST['enable_site_cache'])) {
                    if ($_POST['enable_site_cache'] === 'true') {
                        @unlink($disable_cache_file);
                    } else {
                        touch($disable_cache_file);
                        delete_files(dirname($disable_cache_file) . DIRECTORY_SEPARATOR . 'site', true, 1);
                    }
                    unset($_POST['enable_site_cache']);
                }
                // TODO: Make sure new path is not inside real_base
                // TODO: Ensure that real_base is not deleted under any circumstances
                if (isset($_POST['site_url']) && $_POST['site_url'] !== $data['site_url']) {
                    $_POST['site_url'] = strtolower(rtrim($_POST['site_url'], '/'));
                    if (empty($_POST['site_url'])) {
                        $_POST['site_url'] = '/';
                    }
                    if (isset($_SERVER['PHP_SELF']) && isset($_SERVER['SCRIPT_FILENAME'])) {
                        $php_self = str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['PHP_SELF']);
                        $doc_root = preg_replace('~' . $php_self . '$~i', '', $_SERVER['SCRIPT_FILENAME']);
                    } else {
                        $doc_root = $_SERVER['DOCUMENT_ROOT'];
                    }
                    $doc_root = realpath($doc_root);
                    $target = $doc_root . str_replace('/', DIRECTORY_SEPARATOR, $_POST['site_url']);
                    $php_include_base = rtrim(preg_replace('~^' . $doc_root . '~', '', FCPATH), DIRECTORY_SEPARATOR);
                    $real_base = $doc_root;
                    if (empty($php_include_base)) {
                        $real_base .= DIRECTORY_SEPARATOR;
                    } else {
                        $real_base .= $php_include_base;
                    }
                    @($target_dir = dir($target));
                    $real_base_dir = dir($real_base);
                    function compare_paths($one, $two)
                    {
                        return rtrim($one, DIRECTORY_SEPARATOR) === rtrim($two, DIRECTORY_SEPARATOR);
                    }
                    if ($target_dir && compare_paths($target_dir->path, $real_base_dir->path)) {
                        $_POST['site_url'] = 'default';
                        $htaccess = create_htaccess();
                        $root_htaccess = FCPATH . '.htaccess';
                        $current = file_get_contents($root_htaccess);
                        preg_match('/#MARK#.*/s', $htaccess, $match);
                        $htaccess = preg_replace('/#MARK#.*/s', str_replace('$', '\\$', $match[0]), $current);
                        file_put_contents($root_htaccess, $htaccess);
                    } else {
                        if ($target_dir) {
                            $reserved = array('admin', 'app', 'storage');
                            foreach ($reserved as $dir) {
                                $_dir = dir(rtrim($real_base_dir->path, '/') . "/{$dir}");
                                if (compare_paths($target_dir->path, $_dir->path)) {
                                    $this->error('400', "This directory is reserved for Koken core files. Please choose another location.");
                                    return;
                                }
                            }
                        }
                        if (!make_child_dir($target)) {
                            $this->error('500', "Koken was not able to create the Site URL directory. Make sure the path provided is writable by the web server and try again.");
                            return;
                        }
                        $php_include_rel = str_replace(DIRECTORY_SEPARATOR, '/', $php_include_base);
                        $php_include_base = str_replace('\\', '\\\\', $php_include_base);
                        $doc_root_php = str_replace('\\', '\\\\', $doc_root);
                        $php = <<<OUT
<?php

\t\$rewrite = false;
\t\$real_base_folder = '{$php_include_rel}';
\trequire '{$doc_root_php}{$php_include_base}' . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'site' . DIRECTORY_SEPARATOR . 'site.php';
OUT;
                        $htaccess = create_htaccess($_POST['site_url']);
                        if ($this->check_for_rewrite()) {
                            $file = $target . DIRECTORY_SEPARATOR . '.htaccess';
                            $file_data = $htaccess;
                            $put_mode = FILE_APPEND;
                            if ($_POST['site_url'] !== 'default' && "{$doc_root}" . DIRECTORY_SEPARATOR !== FCPATH) {
                                $root_htaccess = FCPATH . '.htaccess';
                                if (file_exists($root_htaccess)) {
                                    $current = file_get_contents($root_htaccess);
                                    $redirect = create_htaccess($_POST['site_url'], true);
                                    preg_match('/#MARK#.*/s', $redirect, $match);
                                    $redirect = preg_replace('/#MARK#.*/s', str_replace('$', '\\$', $match[0]), $current);
                                    file_put_contents($root_htaccess, $redirect);
                                }
                            }
                        } else {
                            $file = $target . DIRECTORY_SEPARATOR . 'index.php';
                            $file_data = $php;
                            $put_mode = 0;
                        }
                        if (file_exists($file)) {
                            rename($file, "{$file}.bkup");
                        }
                        if (!file_put_contents($file, $file_data, $put_mode)) {
                            $this->error('500', "Koken was not able to create the necessary files in the Site URL directory. Make sure that path has sufficient permissions so that Koken may write the files.");
                            return;
                        }
                    }
                    if ($data['site_url'] !== 'default') {
                        $old = $doc_root . str_replace('/', DIRECTORY_SEPARATOR, $data['site_url']);
                        $old_dir = dir($old);
                        if (!compare_paths($old_dir->path, $real_base_dir->path)) {
                            if ($this->check_for_rewrite()) {
                                $old_file = $old . DIRECTORY_SEPARATOR . '.htaccess';
                            } else {
                                $old_file = $old . DIRECTORY_SEPARATOR . 'index.php';
                            }
                            unlink($old_file);
                            $backup = $old_file . '.bkup';
                            if (file_exists($backup)) {
                                rename($backup, $old_file);
                            }
                            // This will only remove the dir if it is empty
                            @rmdir($old);
                        }
                    }
                }
                global $raw_input_data;
                if (isset($raw_input_data['url_data'])) {
                    $url_data = json_decode($raw_input_data['url_data'], true);
                    $u = new Url();
                    $u->order_by('id DESC')->get();
                    $existing_data = unserialize($u->data);
                    $transformed = array();
                    foreach ($url_data as $key => $udata) {
                        $transformed[] = array('type' => $key, 'data' => $udata);
                    }
                    if ($existing_data !== $transformed) {
                        $n = new Url();
                        $n->data = serialize($transformed);
                        $n->save();
                    }
                    unset($_POST['url_data']);
                }
                $save = array();
                foreach ($_POST as $key => $val) {
                    if (isset($data[$key]) && $data[$key] !== $val) {
                        if ($key === 'retain_image_metadata' || $key !== 'image_processing_library' && strpos($key, 'image_') === 0) {
                            delete_files(FCPATH . 'storage' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'images', true, 1);
                        }
                        $save[$key] = $val;
                    }
                }
                foreach ($save as $k => $v) {
                    $s = new Setting();
                    $s->where('name', $k)->get();
                    if ($s->exists()) {
                        $s->value = $v;
                        $s->save();
                    } else {
                        if (in_array($k, array('uploading_default_album_visibility', 'uploading_publish_on_captured_date', 'email_handler'))) {
                            $n = new Setting();
                            $n->name = $k;
                            $n->value = $v;
                            $n->save();
                        }
                    }
                }
                if (isset($save['email_handler']) || isset($save['email_delivery_address'])) {
                    $this->_compile_plugins();
                }
            }
            $this->redirect('/settings');
        }
        if (!isset($data['site_timezone']) || empty($data['site_timezone']) || $data['site_timezone'] === 'Etc/UTC') {
            $data['site_timezone'] = 'UTC';
        } else {
            if ($data['site_timezone'] === 'Etc/GMT+12') {
                $data['site_timezone'] = 'Pacific/Auckland';
            }
        }
        $data['image_processing_library_label'] = $libs[$data['image_processing_library']]['label'];
        $migrate_path = FCPATH . 'app' . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR;
        $migrations = scandir($migrate_path);
        $data['migrations'] = array();
        if (!isset($data['last_migration'])) {
            $migration_setting = new Setting();
            $migration_setting->name = 'last_migration';
            $migration_setting->value = '26';
            $migration_setting->save();
            $data['last_migration'] = '26';
        }
        if (!isset($data['has_toured']) || ENVIRONMENT === 'development') {
            $data['has_toured'] = true;
        }
        foreach ($migrations as $migration) {
            $migration = str_replace('.php', '', $migration);
            $migration_int = (int) $migration;
            if ($migration_int > $data['last_migration']) {
                $data['migrations'][] = $migration;
            }
        }
        unset($data['last_migration']);
        $data = Shutter::filter('api.settings', array($data));
        $this->set_response_data($data);
    }
示例#15
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));
 }
示例#16
0
 protected function beforeSave()
 {
     if ($this->isNewRecord) {
         $micrositio = Micrositio::model()->findByPk($this->micrositio_id);
         $url = new Url();
         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->tipo_id = 3;
         //Página
         $url->estado = 1;
         if ($url->save()) {
             $this->url_id = $url->getPrimaryKey();
         } else {
             return false;
         }
         $this->usuario_id = Yii::app()->user->getState('usuario_id');
         $this->revision_id = NULL;
         $this->creado = date('Y-m-d H:i:s');
         if (!$this->estado) {
             $this->estado = 0;
         }
     } else {
         //Crear la revisión
         $this->revision_id = NULL;
         $this->modificado = date('Y-m-d H:i:s');
     }
     return parent::beforeSave();
 }
示例#17
0
<?php

$s = new Setting();
$s->where('name', 'use_default_labels_links')->get();
if (!$s->exists()) {
    $u = new Setting();
    $u->name = 'use_default_labels_links';
    $u->value = 'false';
    $u->save();
    $urls = array(array('type' => 'content', 'data' => array('singular' => 'Content', 'plural' => 'Content', 'order' => 'captured_on DESC', 'url' => 'id')), array('type' => 'favorite', 'data' => array('singular' => 'Favorite', 'plural' => 'Favorites', 'order' => 'manual ASC')), array('type' => 'album', 'data' => array('singular' => 'Album', 'plural' => 'Albums', 'order' => 'manual ASC', 'url' => 'id')), array('type' => 'set', 'data' => array('singular' => 'Set', 'plural' => 'Sets')), array('type' => 'essay', 'data' => array('singular' => 'Essay', 'plural' => 'Essays', 'order' => 'published_on DESC', 'url' => 'id')), array('type' => 'page', 'data' => array('singular' => 'Page', 'plural' => 'Pages', 'url' => 'id')), array('type' => 'tag', 'data' => array('singular' => 'Tag', 'plural' => 'Tags')), array('type' => 'category', 'data' => array('singular' => 'Category', 'plural' => 'Categories')), array('type' => 'archive', 'data' => array('singular' => 'Archive', 'plural' => 'Archives')));
    $u = new Url();
    $u->data = serialize($urls);
    $u->save();
}
$done = true;
示例#18
0
文件: sites.php 项目: Caldis/htdocs
 function index()
 {
     list($params, $id) = $this->parse_params(func_get_args());
     $site = new Setting();
     $site->like('name', 'site_%')->or_like('name', 'image_%')->get_iterated();
     $draft = new Draft();
     $data = array();
     $ds = DIRECTORY_SEPARATOR;
     $template_path = FCPATH . 'storage' . $ds . 'themes' . $ds;
     $defaults = json_decode(file_get_contents(FCPATH . 'app' . $ds . 'site' . $ds . 'defaults.json'), true);
     $default_template_path = FCPATH . 'app' . $ds . 'site' . $ds . 'themes' . $ds;
     $pulse_base = FCPATH . 'app' . $ds . 'site' . $ds . 'themes' . $ds . 'common' . $ds . 'js' . $ds . 'pulse.json';
     $user = new User();
     $user->get();
     if (isset($params['preview'])) {
         $theme_root = $template_path . $params['preview'] . $ds;
         $template_info = json_decode(file_get_contents($theme_root . 'info.json'), true);
         if (!$template_info) {
             $this->set_response_data(array('error' => 'Unable to parse the info.json file for this theme.'));
             return;
         }
         $p = new Draft();
         $p->path = $params['preview'];
         $p->init_draft_nav();
         $draft->data = json_decode($p->data, true);
     } else {
         if (isset($params['draft'])) {
             $draft->where('draft', 1);
         } else {
             $draft->where('current', 1);
         }
         $draft->get();
         if ($draft->exists()) {
             $theme_root = $template_path . $draft->path . $ds;
             $template_info = json_decode(file_get_contents($theme_root . 'info.json'), true);
             if (!$template_info) {
                 $this->set_response_data(array('error' => 'Unable to parse the info.json file for this theme.'));
                 return;
             }
             $is_live = $draft->current && $draft->data === $draft->live_data;
             $template_info['published'] = $is_live;
             $draft->data = json_decode(isset($params['draft']) ? $draft->data : $draft->live_data, true);
         } else {
             $this->error('404', 'Draft not found.');
             return;
         }
     }
     foreach ($defaults['templates'] as $path => $info) {
         if (!file_exists($theme_root . $path . '.lens') && !file_exists($default_template_path . $path . '.lens')) {
             unset($defaults['templates'][$path]);
         }
     }
     foreach ($defaults['routes'] as $url => $info) {
         if (!isset($defaults['templates'][$info['template']])) {
             unset($defaults['routes'][$url]);
         }
     }
     if (isset($template_info['routes'])) {
         $template_info['routes'] = array_merge_custom($defaults['routes'], $template_info['routes']);
     } else {
         $template_info['routes'] = $defaults['routes'];
     }
     if (isset($template_info['templates'])) {
         $template_info['templates'] = array_merge_custom($defaults['templates'], $template_info['templates']);
     } else {
         $template_info['templates'] = $defaults['templates'];
     }
     $files = scandir($theme_root);
     foreach ($files as $file) {
         $info = pathinfo($file);
         if (isset($info['extension']) && $info['extension'] === 'lens' && $info['filename'] !== 'error' && !isset($template_info['templates'][$info['filename']])) {
             $template_info['templates'][$info['filename']] = array('name' => ucfirst(preg_replace('/[^a-z0-9]/', ' ', strtolower($info['filename']))));
         }
     }
     if (isset($template_info['styles'])) {
         if (isset($draft->data['settings']['__style']) && isset($template_info['styles'][$draft->data['settings']['__style']])) {
             $key = $draft->data['settings']['__style'];
         } else {
             $key = $draft->data['settings']['__style'] = array_shift(array_keys($template_info['styles']));
         }
         $template_info['style'] = array_merge(array('key' => $key), $template_info['styles'][$key]);
         $styles = array();
         foreach ($template_info['styles'] as $key => $opts) {
             $styles[] = array_merge(array('key' => $key), $opts);
         }
         $template_info['styles'] = $styles;
     } else {
         $template_info['styles'] = array();
     }
     if ($this->method == 'get') {
         list($data['urls'], $data['url_data'], $routes) = $draft->setup_urls($theme_root);
         if (isset($params['draft'])) {
             function get_live_updates($file, $draft, &$functions)
             {
                 if (file_exists($file)) {
                     // Strip comments so they don't confuse the parser
                     $contents = preg_replace('/\\/\\*.*?\\*\\//si', '', file_get_contents($file));
                     preg_match_all('/@import\\surl\\(.*\\[?\\$([a-z_0-9]+)\\]?.*\\);/', $contents, $imports);
                     foreach ($imports[1] as $setting) {
                         if (!isset($functions[$setting])) {
                             $functions[$setting] = 'reload';
                         }
                     }
                     $contents = preg_replace('/@import\\surl\\(.*\\);/', '', $contents);
                     preg_match_all('/([^\\{]+)\\s*\\{([^\\}]+)\\}/s', $contents, $matches);
                     foreach ($matches[2] as $index => $block) {
                         $selector = $matches[1][$index];
                         preg_match_all('/([a-z\\-]+):([^;]+)( !important)?;/', $block, $rules);
                         foreach ($rules[2] as $j => $rule) {
                             $property = $rules[1][$j];
                             preg_match_all('/\\[?\\$([a-z_0-9]+)\\]?/', $rule, $options);
                             if (count($options)) {
                                 foreach ($options[1] as $option) {
                                     if (!isset($functions[$option])) {
                                         $functions[$option] = array();
                                     } else {
                                         if ($functions[$option] === 'reload') {
                                             continue;
                                         }
                                     }
                                     $functions[$option][] = array('selector' => trim(str_replace("\n", '', $selector)), 'property' => trim($property), 'template' => trim(str_replace('url(', "url(storage/themes/{$draft->path}/", $rule)), 'lightbox' => strpos($file, 'lightbox-settings.css.lens') !== false);
                                 }
                             }
                         }
                     }
                 }
             }
             $functions = array();
             get_live_updates(FCPATH . $ds . 'storage' . $ds . 'themes' . $ds . $draft->path . $ds . 'css' . $ds . 'settings.css.lens', $draft, $functions);
             get_live_updates(FCPATH . $ds . 'storage' . $ds . 'themes' . $ds . $draft->path . $ds . 'css' . $ds . 'lightbox-settings.css.lens', $draft, $functions);
             $template_info['live_updates'] = $functions;
         }
         $pulse_settings = json_decode(file_get_contents($pulse_base), true);
         list($template_info['pulse'], $template_info['pulse_flat']) = $this->_prep_options($pulse_settings);
         if (isset($draft->data['pulse_groups'])) {
             $template_info['pulse_groups'] = $draft->data['pulse_groups'];
             foreach ($template_info['pulse_groups'] as &$group) {
                 if (isset($group['transition_duration']) && is_numeric($group['transition_duration']) && $group['transition_duration'] > 10) {
                     $group['transition_duration'] /= 1000;
                 }
             }
         } else {
             $template_info['pulse_groups'] = array();
         }
         if (!isset($template_info['templates'])) {
             $template_info['templates'] = array();
         }
         if (!isset($template_info['routes'])) {
             $template_info['routes'] = array();
         }
         if (isset($draft->data['routes'])) {
             $template_info['routes'] = array_merge_custom($template_info['routes'], $draft->data['routes']);
         }
         $template_info['navigation'] = $draft->data['navigation'];
         unset($template_info['navigation_groups']);
         $albums_flat = new Album();
         $albums_flat->select('id,level,left_id')->where('deleted', 0)->order_by('left_id ASC')->get_iterated();
         $albums_indexed = array();
         $ceiling = 1;
         foreach ($albums_flat as $a) {
             $albums_indexed[$a->id] = array('level' => (int) $a->level);
             $ceiling = max($a->level, $ceiling);
         }
         $album_keys = array_keys($albums_indexed);
         function nest($nav, $routes, $albums_indexed, $album_keys, $ceiling)
         {
             $l = 1;
             $nested = array();
             while ($l <= $ceiling) {
                 foreach ($nav as $index => $item) {
                     if (preg_match('/^(mailto|https?)/', $item['path']) || !isset($item['auto']) && !isset($routes[$item['path']])) {
                         if ($l === 1) {
                             $nested[] = $item;
                         }
                         continue;
                     }
                     if (isset($routes[$item['path']])) {
                         $r = $routes[$item['path']];
                     } else {
                         $r = false;
                     }
                     if (isset($item['auto']) && in_array($item['auto'], array('set', 'album')) || $r && isset($r['source']) && in_array($r['source'], array('set', 'album'))) {
                         if (isset($item['auto'])) {
                             $id = $item['id'];
                             if ($item['auto'] === 'set') {
                                 $item['set'] = true;
                             }
                         } else {
                             foreach ($r['filters'] as $f) {
                                 if (strpos($f, 'id=') === 0) {
                                     $id = array_pop(explode('=', $f));
                                     break;
                                 }
                             }
                             if ($r['source'] === 'set') {
                                 $item['set'] = true;
                             }
                         }
                         if (isset($albums_indexed[$id])) {
                             $level = $albums_indexed[$id]['level'];
                             if ($level === $l && $l === 1) {
                                 $nested[] = $item;
                                 $albums_indexed[$id]['nav'] =& $nested[count($nested) - 1];
                                 unset($nav[$index]);
                             } else {
                                 if ($level === $l) {
                                     while ($level > 0) {
                                         $level--;
                                         $done = false;
                                         $start = array_search($id, $album_keys);
                                         while ($start > 0) {
                                             $start--;
                                             $_id = $album_keys[$start];
                                             if (array_key_exists($_id, $albums_indexed) && $albums_indexed[$_id]['level'] === $level && isset($albums_indexed[$_id]['nav'])) {
                                                 $albums_indexed[$_id]['nav']['items'][] = $item;
                                                 $albums_indexed[$id]['nav'] =& $albums_indexed[$_id]['nav']['items'][count($albums_indexed[$_id]['nav']['items']) - 1];
                                                 unset($nav[$index]);
                                                 $done = true;
                                                 break;
                                             }
                                         }
                                         if ($done) {
                                             break;
                                         }
                                     }
                                 }
                             }
                         }
                     } else {
                         if ($l === 1) {
                             $nested[] = $item;
                             unset($nav[$index]);
                         }
                     }
                 }
                 $l++;
             }
             return $nested;
         }
         function build_autos($items, $data, $user)
         {
             foreach ($items as $index => &$item) {
                 if (isset($item['auto'])) {
                     if (isset($data['urls'][$item['auto']])) {
                         $item['path'] = $data['urls'][$item['auto']];
                     } else {
                         if ($item['auto'] === 'set') {
                             $item['path'] = '';
                         }
                     }
                     if ($item['auto'] === 'profile') {
                         switch ($item['id']) {
                             case 'twitter':
                                 $item['path'] = 'https://twitter.com/' . $user->twitter;
                                 break;
                             default:
                                 $item['path'] = $user->{$item['id']};
                                 if (empty($item['path'])) {
                                     unset($items[$index]);
                                     continue;
                                 }
                                 break;
                         }
                         if (!isset($item['label']) || empty($item['label'])) {
                             $item['label'] = ucwords($item['id']) . ($item['id'] === 'google' ? '+' : '');
                         }
                     } else {
                         if ($item['auto'] === 'rss') {
                             $item['path'] = '/feed/' . $item['id'] . ($item['id'] === 'essay' ? 's' : '') . '/recent.rss';
                             if (!isset($item['label'])) {
                                 $item['label'] = $data['url_data'][$item['id']]['plural'] . ' RSS';
                             }
                         } else {
                             if (preg_match('/s$/', $item['auto']) || $item['auto'] === 'timeline') {
                                 if ($item['auto'] === 'timeline' && isset($item['year'])) {
                                     $item['path'] .= $item['year'] . '/';
                                     if (isset($item['month']) && $item['month'] !== false && $item['month'] !== 'any') {
                                         $m = str_pad($item['month'], 2, '0', STR_PAD_LEFT);
                                         $item['path'] .= $m . '/';
                                     }
                                 }
                                 if (strpos($item['auto'], '_') !== false) {
                                     foreach (array('id', 'slug', 'month', 'year', 'day') as $id) {
                                         if ($id === 'month') {
                                             if (!isset($item['month']) || $item['month'] === 'any' || $item['month'] === false) {
                                                 $item['month'] = '';
                                             } else {
                                                 $item['month'] = str_pad($item['month'], 2, '0', STR_PAD_LEFT);
                                             }
                                         }
                                         if ($id === 'day' && !isset($item['day'])) {
                                             $item['day'] = '';
                                         }
                                         if ($id === 'slug' && !isset($item['slug']) && isset($item['id'])) {
                                             if (strpos($item['auto'], 'tag_') === 0) {
                                                 $item['slug'] = $item['id'];
                                             } else {
                                                 $c = new Category();
                                                 if (is_numeric($item['id'])) {
                                                     $c->select('slug')->get_by_id($item['id']);
                                                     $item['slug'] = $c->slug;
                                                 } else {
                                                     $item['slug'] = $item['id'];
                                                 }
                                             }
                                         }
                                         if (isset($item[$id])) {
                                             $item['path'] = str_replace(":{$id}", $item[$id], $item['path']);
                                         }
                                     }
                                 } else {
                                     if (!isset($item['label'])) {
                                         $item['label'] = $data['url_data'][$item['auto'] === 'categories' ? 'category' : rtrim($item['auto'], 's')]['plural'];
                                     }
                                 }
                             } else {
                                 if ($item['auto'] === 'home') {
                                     if (!isset($item['label'])) {
                                         $item['label'] = $data['url_data']['home'];
                                     }
                                     $item['path'] = '/home/';
                                 } else {
                                     if ($item['auto'] === 'album' || $item['auto'] === 'set') {
                                         $a = new Album();
                                         $a->select('id,slug,created_on,title');
                                         if (is_numeric($item['id'])) {
                                             $a->where('id', $item['id']);
                                         } else {
                                             $a->where('slug', $item['id'])->or_where('internal_id', $item['id']);
                                         }
                                         $a->get();
                                         if (!$a->exists()) {
                                             unset($items[$index]);
                                             continue;
                                         }
                                         $item['path'] = str_replace(':id', $a->id, $item['path']);
                                         $item['path'] = str_replace(':slug', $a->slug, $item['path']);
                                         $item['path'] = str_replace(':year', date('Y', $a->created_on), $item['path']);
                                         $item['path'] = str_replace(':month', date('m', $a->created_on), $item['path']);
                                         $item['path'] = str_replace(':day', date('d', $a->created_on), $item['path']);
                                         if (!isset($item['label'])) {
                                             $item['label'] = $a->title;
                                         }
                                     } else {
                                         if ($item['auto'] === 'page' || $item['auto'] === 'essay') {
                                             $t = new Text();
                                             $t->select('id,slug,published_on,title');
                                             if (is_numeric($item['id'])) {
                                                 $t->where('id', $item['id']);
                                             } else {
                                                 $t->where('slug', $item['id']);
                                             }
                                             $t->get();
                                             if (!$t->exists()) {
                                                 unset($items[$index]);
                                                 continue;
                                             }
                                             $item['path'] = str_replace(':id', $t->id, $item['path']);
                                             $item['path'] = str_replace(':slug', $t->slug, $item['path']);
                                             $item['path'] = str_replace(':year', date('Y', $t->published_on), $item['path']);
                                             $item['path'] = str_replace(':month', date('m', $t->published_on), $item['path']);
                                             $item['path'] = str_replace(':day', date('d', $t->published_on), $item['path']);
                                             if (!isset($item['label'])) {
                                                 $item['label'] = $t->title;
                                             }
                                         } else {
                                             if ($item['auto'] === 'content') {
                                                 $c = new Content();
                                                 $c->select('id,slug,captured_on,title');
                                                 if (isset($item['album_id'])) {
                                                     $item['path'] = preg_replace('/:(id|slug)/', ':album_$1', $data['urls']['album']) . substr(str_replace(':year/:month/', '', $data['urls']['content']), 1);
                                                     $a = new Album();
                                                     $a->select('id,slug,created_on,title');
                                                     if (is_numeric($item['album_id'])) {
                                                         $a->where('id', $item['album_id']);
                                                     } else {
                                                         $a->where('slug', $item['album_id'])->or_where('internal_id', $item['album_id']);
                                                     }
                                                     $a->get();
                                                     if (!$a->exists()) {
                                                         unset($items[$index]);
                                                         continue;
                                                     }
                                                     $item['path'] = str_replace(':album_id', $a->id, $item['path']);
                                                     $item['path'] = str_replace(':album_slug', $a->slug, $item['path']);
                                                     $date = $a->created_on;
                                                 } else {
                                                     $date = $c->captured_on;
                                                 }
                                                 if (is_numeric($item['id'])) {
                                                     $c->where('id', $item['id']);
                                                 } else {
                                                     $c->where('slug', $item['id'])->or_where('internal_id', $item['id']);
                                                 }
                                                 $c->get();
                                                 if (!$c->exists()) {
                                                     unset($items[$index]);
                                                     continue;
                                                 }
                                                 $item['path'] = str_replace(':id', $c->id, $item['path']);
                                                 $item['path'] = str_replace(':slug', $c->slug, $item['path']);
                                                 $item['path'] = str_replace(':year', date('Y', $date), $item['path']);
                                                 $item['path'] = str_replace(':month', date('m', $date), $item['path']);
                                                 $item['path'] = str_replace(':day', date('d', $date), $item['path']);
                                                 if (!isset($item['label'])) {
                                                     $item['label'] = $c->title;
                                                 }
                                                 if (isset($item['lightbox']) && $item['lightbox']) {
                                                     $item['path'] .= 'lightbox/';
                                                 }
                                             } else {
                                                 if ($item['auto'] === 'tag') {
                                                     $item['path'] = str_replace(':slug', $item['id'], $item['path']);
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     if ($item['auto'] !== 'profile') {
                         $item['path'] = str_replace(array(':year', ':month'), '', $item['path']);
                         $item['path'] = preg_replace('/[\\(\\)\\?\\:]/', '', $item['path']);
                         $item['path'] = preg_replace('~[/]+~', '/', $item['path']);
                     }
                 }
             }
             return $items;
         }
         $template_info['navigation']['items'] = build_autos($template_info['navigation']['items'], $data, $user);
         $template_info['navigation']['items_nested'] = nest($template_info['navigation']['items'], $template_info['routes'], $albums_indexed, $album_keys, $ceiling);
         foreach ($template_info['navigation']['groups'] as &$group) {
             $group['items'] = build_autos($group['items'], $data, $user);
             $group['items_nested'] = nest($group['items'], $template_info['routes'], $albums_indexed, $album_keys, $ceiling);
         }
         $pages = array();
         $paths = array();
         foreach ($template_info['routes'] as $path => $arr) {
             $pages[] = array_merge(array('path' => (string) $path), $arr);
             $paths[] = $path;
         }
         $template_info['routes'] = $pages;
         if (isset($template_info['settings'])) {
             $default_style_vars = array();
             if (isset($template_info['styles']) && count($template_info['styles'])) {
                 $tmp = array_reverse($template_info['styles']);
                 foreach ($tmp as $style) {
                     if (isset($style['variables'])) {
                         $default_style_vars = array_merge($default_style_vars, $style['variables']);
                     }
                 }
             }
             list($template_info['settings'], $template_info['settings_flat']) = $this->_prep_options($template_info['settings'], isset($draft->data['settings']) ? $draft->data['settings'] : array(), isset($template_info['style']) && isset($template_info['style']['variables']) ? $template_info['style']['variables'] : array(), $default_style_vars);
             if (isset($draft->data['settings']) && isset($draft->data['settings']['__style'])) {
                 $template_info['settings_flat']['__style'] = array('value' => $draft->data['settings']['__style']);
             }
         } else {
             $template_info['settings'] = $template_info['settings_flat'] = array();
         }
         if (isset($template_info['style']) && isset($template_info['style']['variables'])) {
             foreach ($template_info['style']['variables'] as $key => &$varval) {
                 if (preg_match('/#[a-z0-9]{3}$/i', $varval)) {
                     $varval = $varval . substr($varval, 1);
                 }
                 if (!isset($template_info['settings_flat'][$key])) {
                     $template_info['settings_flat'][$key] = array('value' => $varval);
                 }
             }
         }
         $types = array();
         $names = array();
         $templates_indexed = $template_info['templates'];
         foreach ($template_info['templates'] as $key => $val) {
             if (isset($val['source']) && $val['source'] === 'date') {
                 $val['source'] = 'archives';
             }
             $types[] = array('path' => $key, 'info' => $val);
             $names[] = $val['name'];
         }
         natcasesort($names);
         $final = array();
         foreach ($names as $index => $name) {
             $final[] = $types[$index];
         }
         $template_info['templates'] = $final;
         $bools = array('site_hidpi');
         foreach ($site as $s) {
             $clean_key = preg_replace('/^site_/', '', $s->name);
             if (isset($data[$clean_key])) {
                 continue;
             }
             $val = $s->value;
             if (in_array($s->name, $bools)) {
                 $val = $val == 'true';
             }
             $data[$clean_key] = $val;
         }
         $data['draft_id'] = $draft->id;
         $data['theme'] = array('path' => isset($params['preview']) ? $params['preview'] : $draft->path);
         unset($data['id']);
         foreach ($template_info as $key => $val) {
             if (in_array($key, array('name', 'version', 'description', 'demo'))) {
                 $data['theme'][$key] = $val;
             } else {
                 $data[$key] = $val;
             }
         }
         $data['routes'] = array_merge($data['routes'], $routes);
         // templates always need to be after routes
         $templates_tmp = $data['templates'];
         $routes_tmp = $data['routes'];
         unset($data['templates']);
         unset($data['routes']);
         $data['routes'] = $routes_tmp;
         $data['templates'] = Shutter::filter('site.templates', array($templates_tmp));
         $data['profile'] = array('name' => $user->public_display === 'both' ? $user->public_first_name . ' ' . $user->public_last_name : $user->{"public_{$user->public_display}_name"}, 'first' => $user->public_first_name, 'last' => $user->public_last_name, 'email' => $user->public_email, 'twitter' => str_replace('@', '', $user->twitter), 'facebook' => $user->facebook, 'google_plus' => $user->google);
         if (isset($draft->data['custom_css'])) {
             $data['custom_css'] = $draft->data['custom_css'];
         } else {
             $data['custom_css'] = '';
         }
         $this->set_response_data($data);
     } else {
         switch ($this->method) {
             case 'put':
                 global $raw_input_data;
                 $data = json_decode($raw_input_data['data'], true);
                 if (isset($data['revert'])) {
                     if ($data['revert'] === 'all') {
                         $draft->data = $draft->live_data;
                     } else {
                         unset($draft->data['settings']);
                         $draft->data = json_encode($draft->data);
                     }
                 } else {
                     if (isset($data['custom_css'])) {
                         $draft->data['custom_css'] = $data['custom_css'];
                     }
                     if (isset($data['navigation'])) {
                         unset($data['navigation']['active']);
                         $draft->data['navigation'] = $data['navigation'];
                     }
                     if (isset($data['routes'])) {
                         $pages = array();
                         foreach ($data['routes'] as $p) {
                             if (isset($p['section'])) {
                                 continue;
                             }
                             $key = $p['path'];
                             unset($p['path']);
                             if (!in_array($p, $template_info['routes'])) {
                                 $pages[$key] = $p;
                             }
                         }
                         $draft->data['routes'] = $pages;
                     }
                     if (isset($data['settings_send'])) {
                         foreach ($data['settings_send'] as $key => $val) {
                             $draft->data['settings'][$key] = $val;
                         }
                     }
                     if (isset($data['url_data_send'])) {
                         $source = $data['url_data_send']['source'] === 'categories' ? 'category' : rtrim($data['url_data_send']['source'], 's');
                         $u = new Url();
                         $u->order_by('id DESC')->get();
                         $new_data = unserialize($u->data);
                         foreach ($new_data as &$url_data) {
                             if ($url_data['type'] === $source) {
                                 $url_data['data'][$data['url_data_send']['order']] = $data['url_data_send']['value'];
                                 break;
                             }
                         }
                         $u->data = serialize($new_data);
                         $u->save();
                     }
                     if (isset($data['pulse_settings_send']) && !empty($data['pulse_settings_send'])) {
                         if (!isset($draft->data['pulse_groups'][$data['pulse_settings_group']])) {
                             $draft->data['pulse_groups'][$data['pulse_settings_group']] = array();
                         }
                         foreach ($data['pulse_settings_send'] as $key => $val) {
                             $draft->data['pulse_groups'][$data['pulse_settings_group']][$key] = $val;
                         }
                     }
                     $draft->data = json_encode($draft->data);
                 }
                 $draft->save();
                 $this->redirect("/site/draft:true");
                 break;
         }
     }
 }
示例#19
0
 protected function beforeSave()
 {
     if ($this->isNewRecord) {
         $seccion = Seccion::model()->findByPk($this->seccion_id);
         $url = new Url();
         $slug = $this->slugger($seccion->nombre) . '/' . $this->slugger($this->nombre);
         $slug = $this->verificarSlug($slug);
         $url->slug = $slug;
         $url->tipo_id = 2;
         //Micrositio
         $url->estado = 1;
         $url->save();
         $this->url_id = $url->getPrimaryKey();
         $this->usuario_id = Yii::app()->user->getState('usuario_id');
         $this->pagina_id = NULL;
         $this->menu_id = NULL;
         $this->creado = date('Y-m-d H:i:s');
     } else {
         $this->modificado = date('Y-m-d H:i:s');
     }
     return parent::beforeSave();
 }
示例#20
0
 /**
  * Enter description here ...
  * 
  * @param	string $path
  * @param	int $perms
  * @return	void
  */
 public function save($path, $perms = 0666)
 {
     return $this->url->save($path, $perms);
 }
示例#21
0
 protected function beforeSave()
 {
     if ($this->isNewRecord) {
         $parent = Carpeta::model()->with('url')->findByPk($this->item_id);
         $this->pagina_id = $parent->pagina_id;
         $this->hijos = 0;
         $url = new Url();
         $nombre_slug = $this->slugger($this->carpeta);
         $url->slug = $this->verificarSlug($parent->url->slug . '/' . $nombre_slug);
         $url->tipo_id = 10;
         //Carpeta
         $url->estado = 1;
         if ($url->save()) {
             $this->url_id = $url->getPrimaryKey();
         } else {
             return false;
         }
         $this->creado = date('Y-m-d H:i:s');
     } else {
         $this->modificado = date('Y-m-d H:i:s');
     }
     return parent::beforeSave();
 }