public function run($thumb) { $key = key($_GET); if (NULL == ($file = Files::model()->findByPk($key))) { throw new CException('Page not found', 404); } $path = Yii::getPathOfAlias('webroot') . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'photos'; $src_file = $file->id . '.' . $file->extension; $in_file = $path . DIRECTORY_SEPARATOR . $src_file; $out_file = $path . DIRECTORY_SEPARATOR . $thumb . DIRECTORY_SEPARATOR . $src_file; if (is_file($out_file)) { $mime = CFileHelper::getMimeType($out_file); header('Content-Type: ' . $mime); readfile($out_file); exit; } if (is_file($in_file)) { $dir = $path . DIRECTORY_SEPARATOR . $thumb; if (YII_DEBUG && !file_exists($dir)) { mkdir($dir, 0777); } if (file_exists($dir)) { if (($out_file = $file->resize($thumb)) == 0) { throw new CException('Page not found', 404); } $mime = CFileHelper::getMimeType($in_file); header('Content-Type: ' . $mime); readfile($out_file); exit; } } return parent::run($thumb); }
public function create_item($page_id = null, $model) { $controller = Yii::app()->getController(); if (isset($_POST['ModuleList3'])) { $_POST['ModuleList3']['mpage_id'] = ModulesInPages::model()->getLink($page_id, $this->module_id); $model->attributes = $_POST['ModuleList3']; if ((int) $_POST['ModuleList3']['img_id']) { Files::model()->saveTempFile((int) $_POST['ModuleList3']['img_id']); } if ($model->save()) { $item_id = $model->primaryKey; // обработка input-параметров if (isset($_POST['ModuleList3Values']) && is_array($_POST['ModuleList3Values']) && count($_POST['ModuleList3Values'])) { foreach ($_POST['ModuleList3Values'] as $key => $value) { if (is_array($value) && count($value)) { foreach ($value as $key2 => $value2) { $params_value = new ModuleList3Values(); $params_value->attributes = array('param_id' => (int) $key, 'item_id' => $item_id, 'value' => $value2); $params_value->save(); } } else { $params_value = new ModuleList3Values(); $params_value->attributes = array('param_id' => (int) $key, 'item_id' => $item_id, 'value' => $value); $params_value->save(); } } } Yii::app()->user->setFlash($this->module_id . '_add_message', '<p style="color:green;">Добавлено</p>'); $controller->redirect(Yii::app()->baseUrl . '?r=pages/update&id=' . $page_id . '&/#!/tab_' . $this->module_id); } else { Yii::app()->user->setFlash($this->module_id . '_add_message', '<p style="color:red;">Ошибка</p>'); } } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Issues(); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); if (isset($_POST['Issues'])) { $model->attributes = $_POST['Issues']; if ($model->save()) { if ($model->attachments != null) { $fileids = explode(",", $model->attachments); for ($i = 1; $i < sizeof($fileids); $i++) { $file = Files::model()->findByPk($fileids[$i]); if ($file->uploadedby == Yii::app()->user->id) { $file->objecttype = "issues"; $file->objectid = $model->id; $file->save(); } } } //$this->redirect(array('view','id'=>$model->id)); echo CJSON::encode(array('errors' => $model->getErrors(), 'redirect' => $this->createURL("/issues/view", array('id' => $model->id)))); exit; } } if (!Yii::app()->request->isAjaxRequest) { $this->render('create', array('model' => $model)); } else { $string = $this->renderPartial('_formajax', array('model' => $model), true); echo CJSON::encode(array('html' => $string, 'errors' => $model->getErrors())); } }
public function loadModel($id) { $model = Files::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
private static function findFile($model, $name) { $files = Files::model()->findAllByAttributes(array("parent_type" => 'Docs', "parent_id" => $model->id, "name" => $name)); foreach ($files as $file) { if ($file->name == $name) { return $file; } } return false; }
public function actionDelete($page_id = null, $item_id = null, $id = null) { $model = ModuleList4Files::model()->findByPk($id); if ($model != null) { $fileId = $model->file_id; if ($model->delete()) { Files::model()->deleteFile($fileId, $this->module->id); } } $this->redirect(Yii::app()->baseUrl . '?r=' . $this->module->id . '/main/update&page_id=' . $page_id . '&id=' . $item_id . '&/#!/tab_third'); }
public static function showAttachments($model) { $x = $model->attachments; //echo $x; $y = explode(",", $x); $str = "<ul>"; for ($i = 1; $i < sizeof($y); $i++) { $files = Files::model()->findByPk($y[$i]); $str .= "<li>" . CHtml::link($files->originalname, Ccontroller::createUrl('/files/file', array('id' => $y[$i]))); } $str .= "</ul>"; return $str; }
public function actionCreate() { Yii::app()->clientScript->registerPackage('items-edit'); if (!isset($_GET['id']) || NULL == ($model = Items::model()->findByAttributes(array('user_id' => Yii::app()->user->id, 'id' => (int) $_GET['id'])))) { $model = new Items(); } if (isset($_POST['Items'])) { $model->attributes = $_POST['Items']; $fn = Files::model()->uploadFile('Items[image]'); if ($fn) { $model->image = $fn['filename']; } elseif (isset($_POST['Items']['image_src'])) { $model->image = $_POST['Items']['image_src']; } $new = $model->isNewRecord; if ($model->save()) { $cats = isset($_POST['categories']) ? $_POST['categories'] : array(); if (!$new && empty($cats)) { ItemsCategory::model()->deleteAllByAttributes(array('item_id' => $model->id)); } else { if (!$new) { $dbcats = ItemsCategory::model()->findAll('item_id=:iid', array('iid' => $model->id)); $ids = array(); foreach ($dbcats as $i => $dbc) { if (false !== ($k = array_search($dbc->category_id, $cats))) { unset($cats[$k]); unset($dbc[$i]); } else { $ids[] = $dbc->category_id; } } //deleteing corresponding categories if (!empty($ids)) { $ids = implode(",", $ids); ItemsCategory::model()->deleteAll('item_id=:iid AND category_id IN (:cid)', array('iid' => $model->id, 'cid' => $ids)); } } if (!empty($cats)) { foreach ($cats as $cat) { $c = new ItemsCategory(); $c->attributes = array('category_id' => $cat, 'item_id' => $model->id); $c->save(); } } } Yii::app()->user->setFlash('ItemSaved', '1'); $this->refresh(); } } $this->render('_form', array('model' => $model)); }
public function create_item($page_id = null, $model) { $controller = Yii::app()->getController(); if (isset($_POST['ModuleList2'])) { $_POST['ModuleList2']['mpage_id'] = ModulesInPages::model()->getLink($page_id, $this->module_id); $model->attributes = $_POST['ModuleList2']; if ((int) $_POST['ModuleList2']['img_id']) { Files::model()->saveTempFile((int) $_POST['ModuleList2']['img_id']); } if ($model->save()) { Yii::app()->user->setFlash($this->module_id . '_add_message', '<p style="color:green;">Добавлено</p>'); $controller->redirect(Yii::app()->baseUrl . '?r=pages/update&id=' . $page_id . '&/#!/tab_' . $this->module_id); } else { Yii::app()->user->setFlash($this->module_id . '_add_message', '<p style="color:red;">Ошибка</p>'); } } }
public function actionUpdate($page_id = null, $id = null) { if (!is_null($page_id) && Pages::model()->existsPage($page_id)) { $link_id = ModulesInPages::model()->getLink((int) $page_id, $this->module->id); if (!is_null($id) && ModuleFiles::model()->existsItem($link_id, $id)) { $model = ModuleFiles::model()->findByPk($id); if (isset($_POST['ModuleFiles'])) { $old_file_id = $model->file_id; if ($_POST['ModuleFiles']['file_id'] == 'NULL') { $_POST['ModuleFiles']['file_id'] = ''; } if ((int) $old_file_id && (int) $old_file_id != (int) $_POST['ModuleFiles']['file_id']) { $_POST['ModuleFiles']['link'] = NULL; $_POST['ModuleFiles']['extension'] = NULL; $_POST['ModuleFiles']['size'] = 0; Files::model()->deleteFile($old_file_id, $this->module->id); } if ((int) $_POST['ModuleFiles']['file_id']) { $file_name = Files::model()->findByPk($_POST['ModuleFiles']['file_id'])->file_name; $_POST['ModuleFiles']['link'] = '/upload/' . md5($this->module->id) . '/' . $file_name; $_POST['ModuleFiles']['extension'] = explode('.', $file_name); $_POST['ModuleFiles']['extension'] = $_POST['ModuleFiles']['extension'][count($_POST['ModuleFiles']['extension']) - 1]; $_POST['ModuleFiles']['size'] = round(filesize($_SERVER['DOCUMENT_ROOT'] . rawurldecode($_POST['ModuleFiles']['link'])) / 1024); Files::model()->saveTempFile((int) $_POST['ModuleFiles']['file_id']); } if (isset($_POST['ModuleFiles']['group_id']) && empty($_POST['ModuleFiles']['group_id'])) { $_POST['ModuleFiles']['group_id'] = NULL; } $model->attributes = $_POST['ModuleFiles']; if ($model->save()) { Yii::app()->user->setFlash('message', '<p style="color:green;">Сохранено</p>'); $this->redirect(Yii::app()->baseUrl . '?r=' . $this->module->id . '/main/update&page_id=' . $page_id . '&id=' . $id); } else { Yii::app()->user->setFlash('message', '<p style="color:red;">Ошибка</p>'); } } $model = ModuleFiles::model()->getItem($id, $link_id); $this->render('update', array('page_id' => $page_id, 'model' => $model)); } else { $this->redirect(Yii::app()->baseUrl . '?r=pages/update&id=' . $page_id . '&/#!/tab_' . $this->module->id); } } else { $this->redirect(Yii::app()->request->scriptUrl); } }
public function getList($id = null) { if ($id === null) { return false; } $files = $this->findAllByAttributes(array('item_id' => $id)); if (count($files) == 0) { return false; } $list = array(); foreach ($files as $file) { $list[$file->id]['file_id'] = $file->file_id; $list[$file->id]['short'] = $file->short; $list[$file->id]['ref'] = Files::model()->getVirtualPath('list3', $file->file_id); $list[$file->id]['file_name'] = Files::model()->findByPk($file->file_id)->file_name; } return $list; }
public function send() { Yii::import('application.extensions.smtpmail.PHPMailer'); $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = Yii::app()->user->getSetting('company.mail.server'); $mail->SMTPAuth = Yii::app()->user->getSetting('company.mail.user') != '' ? true : false; $mail->SMTPSecure = Yii::app()->user->getSetting('company.mail.ssl') ? 'tls' : ''; $mail->CharSet = 'utf-8'; $mail->Port = Yii::app()->user->getSetting('company.mail.port'); $mail->Username = Yii::app()->user->getSetting('company.mail.user'); $mail->Password = Yii::app()->user->getSetting('company.mail.password'); //$mail->SetFrom($this->from); //echo $this->files; if ($this->files != '') { $file = Files::model()->findByPk($this->files); if ($file != null) { //echo $file->getFullPath().";;".$file->name; $mail->AddAttachment($file->getFullFilePath(), $file->name); } } $mail->SetFrom(Yii::app()->user->settings['company.mail.address']); $mail->AddCC($this->cc); //.$this->cc $mail->AddBcc($this->bcc); $mail->Subject = $this->subject; $mail->MsgHTML($this->body); $mail->AddAddress($this->to, ""); if (!$mail->Send()) { //echo "Mailer Error: " . $mail->ErrorInfo; throw new CHttpException(501, Yii::t('app', "Mailer Error: ") . $mail->ErrorInfo . $mail->Username); } else { $this->sent++; $this->save(); Yii::app()->user->setFlash('success', Yii::t('app', 'Message sent!')); //echo "Message sent!"; } //*/ //Yii::app()->end(); }
public function actionUpdate($page_id = null, $id = null) { if (!is_null($page_id) && Pages::model()->existsPage($page_id)) { $link_id = ModulesInPages::model()->getLink((int) $page_id, $this->module->id); if (!is_null($id) && ModuleList2::model()->existsItem($link_id, $id)) { $model = ModuleList2::model()->findByPk($id); if (isset($_POST['ModuleList2'])) { $old_file_id = $model->img_id; if ($_POST['ModuleList2']['img_id'] == 'NULL') { $_POST['ModuleList2']['img_id'] = ''; } $model->attributes = $_POST['ModuleList2']; if ((int) $_POST['ModuleList2']['img_id']) { Files::model()->saveTempFile((int) $_POST['ModuleList2']['img_id']); } elseif ($_POST['ModuleList2']['img_id'] == '') { Files::model()->deleteFile($old_file_id, $this->module->id); } if ($model->save()) { if ($old_file_id != $model->img_id) { Files::model()->deleteFile($old_file_id, $this->module->id); } Yii::app()->user->setFlash('message', '<p style="color:green;">Сохранено</p>'); $this->redirect(Yii::app()->baseUrl . '?r=' . $this->module->id . '/main/update&page_id=' . $page_id . '&id=' . $id); } else { Yii::app()->user->setFlash('message', '<p style="color:red;">Ошибка</p>'); } } $model = ModuleList2::model()->getItem($id, $link_id); $this->render('update', array('page_id' => $page_id, 'model' => $model)); } else { $this->redirect(Yii::app()->baseUrl . '?r=pages/update&id=' . $page_id . '&/#!/tab_' . $this->module->id); } } else { $this->redirect(Yii::app()->request->scriptUrl); } }
public function getImageById($id) { $result = null; if (!empty($id)) { $result = '/' . Files::model()->getUploadFolder('list2', false, true) . Files::model()->findByPk($id)->file_name; } else { $result = null; } if (!file_exists($_SERVER['DOCUMENT_ROOT'] . $result)) { $result = null; } if ($result != null) { $images = array(); $i = 0; $result = $_SERVER['DOCUMENT_ROOT'] . $result; foreach (array(array(93, 60), array(205, 0), array(96, 96), array(220, 220)) as $size) { // [0] - админка список, [1] - админка редактир, [2] - сайт (мини в списке), [3] — сайт (страница конкретной акции) $i++; $cache_folder = explode('/', $result); $cache_folder[count($cache_folder) - 1] = 'cache'; $cache_folder = implode('/', $cache_folder); $img = explode('/', $result); $img[count($img) - 1] = 'cache/size' . $i . '_' . $img[count($img) - 1]; $img = implode('/', $img); if (!is_dir($cache_folder)) { mkdir($cache_folder, 777); } if (!file_exists($img)) { $thumb = Yii::app()->thumb->create($result); $thumb->resize($size[0], $size[1]); $thumb->save($img); } $img = explode($_SERVER['DOCUMENT_ROOT'], $img); $images[] = $img[1]; } } else { $images = $this->img_default; } return $images; }
<?php } else { ?> <?php echo $full; ?> <?php } ?> </div> <div class="all_posts_files"> <?php $multimedia = json_decode($item->multimedia); if (is_array($multimedia)) { foreach ($multimedia as $ind => $file) { $image = Files::model()->findByPk($file->id); ?> <div class="all_posts_files_item"><a href="/id<?php echo $item->authors->id; ?> /aphotos/showposts/<?php echo $file->nomber; ?> /<?php echo $item->id; ?> "><img src="<?php echo Yii::app()->request->baseUrl; ?> /upload/photos/80x80/<?php echo $image->id;
public function actionEditBackground() { Yii::import('ext.iwi.Iwi'); $id = Yii::app()->user->id; if (!$id > 0) { throw new CException('Not Found', 404); } Yii::app()->log->routes[3]->enabled = false; if (isset($_GET['ajax'])) { $upload = Files::model()->uploadFile('avatar'); if ($upload !== false) { echo CJSON::encode(array('message' => $upload['filename'] . '.' . $upload['extension'], 'status' => 'OK')); } else { echo CJSON::encode(array('message' => 'Ошибка загрузки файла', 'status' => 'ERROR')); } exit; } if (Yii::app()->request->getPost('height') > 0) { $post = array('height' => (int) Yii::app()->request->getPost('height'), 'width' => (int) Yii::app()->request->getPost('width'), 'left' => (int) Yii::app()->request->getPost('left'), 'top' => (int) Yii::app()->request->getPost('top'), 'image' => trim(Yii::app()->request->getPost('image', ''), '/')); $filename = pathinfo($post['image'], PATHINFO_FILENAME); $path = realpath(Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR); $file = Files::model()->findByPk($filename); $userpath = $path . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'photos' . DIRECTORY_SEPARATOR; $image = new Iwi($userpath . $file->id . '.' . $file->extension); $image->resize($post['width'], $post['height']); if ($image->save($userpath . 'cover' . DIRECTORY_SEPARATOR . $file->id . '.' . $file->extension)) { $user = UserProfile::model()->find("user_id=:uid", array('uid' => $id)); $oldavatar = false; if ($user->background != $filename) { $oldavatar = $user->background; } $user->background = $filename; $user->bgposition = $post['left'] . ' ' . $post['top']; if ($user->save()) { // if($oldavatar!=false && $oldavatar != 'userTestBG.png' && is_file($userpath . $oldavatar)) // FileHelper::cleanUpload('UserProfile', $oldavatar); echo CJSON::encode(array('message' => $filename, 'status' => 'OK')); } else { echo CJSON::encode(array('message' => $user->getErrors(), 'status' => 'ERROR')); } exit; } else { //System error must be handled by administration. Yii::log("Ошибка при создании файла аватара '{$post['image']}'. Пользователь #{$id}", 'email'); echo CJSON::encode(array('status' => 'ERROR', 'message' => 'Ну удалось сохранить аватар. Попробуйте позже.')); } } //else // echo CJSON::encode(array('status'=>'ERROR','message'=>'Не хватает параметров.')); //if(isset($_GET['ajax'])) exit; //$this->render('edit_avatar'); }
public function actionRender() { Yii::import("application.modules.my.models.Files"); $model = Files::model()->findByPk($_POST['id']); $back_url = $_POST['b_url']; $res = '<figure class="plus__add__auto-park__img"> <a href="#"><img src="/users/' . Yii::app()->user->id . '/' . $model->file . '" alt="" /></a> <input type="radio" id="avto_cover_' . $model->id . '" name="avto_cover" value="' . $model->file . '" onClick="setCover(' . $_POST['m_id'] . ',\'' . $model->file . '\');"> <label for="avto_cover_' . $model->id . '">Обложка на главной</label> ' . CHtml::link('удалить фото', '/my/avto/deletefile/id/' . $model->id . '/pid/' . $_POST['m_id'] . '?back_url=' . $back_url, array('confirm' => 'Точно хотите удалить?')) . ' </figure>'; echo $res; }
public function create_item($page_id = null, $model) { $controller = Yii::app()->getController(); if (isset($_POST['ModuleFiles'])) { $_POST['ModuleFiles']['mpage_id'] = ModulesInPages::model()->getLink($page_id, $this->module_id); if ((int) $_POST['ModuleFiles']['file_id']) { $file_name = Files::model()->findByPk($_POST['ModuleFiles']['file_id'])->file_name; $_POST['ModuleFiles']['link'] = '/upload/' . md5($this->module_id) . '/' . $file_name; $_POST['ModuleFiles']['extension'] = explode('.', $file_name); $_POST['ModuleFiles']['extension'] = $_POST['ModuleFiles']['extension'][count($_POST['ModuleFiles']['extension']) - 1]; $_POST['ModuleFiles']['size'] = round(filesize($_SERVER['DOCUMENT_ROOT'] . rawurldecode($_POST['ModuleFiles']['link'])) / 1024); Files::model()->saveTempFile((int) $_POST['ModuleFiles']['file_id']); } if (isset($_POST['ModuleFiles']['group_id']) && empty($_POST['ModuleFiles']['group_id'])) { $_POST['ModuleFiles']['group_id'] = NULL; } $model->attributes = $_POST['ModuleFiles']; if ($model->save()) { Yii::app()->user->setFlash($this->module_id . '_add_message', '<p style="color:green;">Добавлено</p>'); $controller->redirect(Yii::app()->baseUrl . '?r=pages/update&id=' . $page_id . '&/#!/tab_' . $this->module_id); } else { Yii::app()->user->setFlash($this->module_id . '_add_message', '<p style="color:red;">Ошибка</p>'); } } }
} } else { if ($file->photo != '') { //echo '<a href="/id'.$data->id.'" class="cat-photo-img__link"><img class="cat-photo-img" src="/users/'.$data->id.'/370_'.$img.'" alt="'.$data->name.' - '.Occupation::getName($data->occupation_id).'"></a>'; echo '<a href="' . $img_link . '" class="cat-photo-img__link"><img class="cat-photo-img" src="/users/' . $data->id . '/370_' . $img . '" alt="' . $data->name . ' - ' . Occupation::getName($data->occupation_id) . '"></a>'; } else { echo '<a href="/id' . $data->id . '" class="cat-photo-img__link"><img class="cat-photo-img" src="/img/zaglushka.png" alt="' . $data->name . ' - ' . Occupation::getName($data->occupation_id) . '"></a>'; } } $i++; } } else { $i = 1; foreach ($data->files as $file) { $img = $file->file; $link_data = Files::model()->findBySql('select id, portfolio_id from {{files}} where uid=' . $data->id . ' and type="photo" and source="portfolio" and visible=1 and file="' . $img . '"'); $img_link = $this->createUrl('/user/album', array('id' => $link_data->portfolio_id)) . '?photo=photo' . $link_data->id; if ($file->type == 'photo') { if ($i == 4) { if ($file->file != '') { //echo '<a href="/id'.$data->id.'" class="cat-photo-img__link last"><img class="cat-photo-img" src="/users/'.$data->id.'/370_'.$img.'" alt="'.$data->name.' - '.Occupation::getName($data->occupation_id).'"></a>'; echo '<a href="' . $img_link . '" class="cat-photo-img__link last"><img class="cat-photo-img" src="/users/' . $data->id . '/370_' . $img . '" alt="' . $data->name . ' - ' . Occupation::getName($data->occupation_id) . '"></a>'; } else { echo '<a href="/id' . $data->id . '" class="cat-photo-img__link last"><img class="cat-photo-img" src="/img/zaglushka.png" alt="' . $data->name . ' - ' . Occupation::getName($data->occupation_id) . '"></a>'; } } else { if ($file->file != '') { //echo '<a href="/id'.$data->id.'" class="cat-photo-img__link"><img class="cat-photo-img" src="/users/'.$data->id.'/370_'.$img.'" alt="'.$data->name.' - '.Occupation::getName($data->occupation_id).'"></a>'; echo '<a href="' . $img_link . '" class="cat-photo-img__link"><img class="cat-photo-img" src="/users/' . $data->id . '/370_' . $img . '" alt="' . $data->name . ' - ' . Occupation::getName($data->occupation_id) . '"></a>'; } else { echo '<a href="/id' . $data->id . '" class="cat-photo-img__link"><img class="cat-photo-img" src="/img/zaglushka.png" alt="' . $data->name . ' - ' . Occupation::getName($data->occupation_id) . '"></a>';
private function findFiles() { $this->Files = Files::model()->findByAttributes(array('parent_type' => 'Docs', 'parent_id' => $this->id)); }
/** * Вывод инфы о бане * @param integer $id ID бана */ public function actionView($id) { // Подгружаем комментарии и файлы $files = new Files(); //$this->performAjaxValidation($files); $files->unsetAttributes(); $comments = new Comments(); $comments->unsetAttributes(); // Подгружаем баны $model = Bans::model()->with('admin')->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } $geo = false; // Проверка прав на просмотр IP $ipaccess = Webadmins::checkAccess('ip_view'); if ($ipaccess) { $geo = array('city' => 'Не определен', 'region' => 'Не определен', 'country' => 'Не определена', 'lat' => 0, 'lng' => 0, 'zoom' => 10); $get = @file_get_contents('http://ipgeobase.ru:7020/geo?ip=' . $model->player_ip); if ($get) { $xml = @simplexml_load_string($get); if (!empty($xml->ip)) { $geo['city'] = isset($xml->ip->city) ? $xml->ip->city : $geo['city']; $geo['region'] = isset($xml->ip->region) ? $xml->ip->region : $geo['region']; $geo['country'] = isset($xml->ip->country) ? $xml->ip->country : $geo['country']; $geo['lat'] = isset($xml->ip->lat) ? $xml->ip->lat : $geo['lat']; $geo['lng'] = isset($xml->ip->lng) ? $xml->ip->lng : $geo['lng']; } } if ($geo['lat'] == 0 && $geo['lng'] == 0) { if ($geo['country'] !== 'Не определена') { $lat_lng = Yii::app()->CountryToLatLng->lookup($geo['country']); $geo['lat'] = $lat_lng['lat']; $geo['lng'] = $lat_lng['lng']; $geo['zoom'] = $lat_lng['zoom']; } } } // Добавление файла if (isset($_POST['Files']) && !empty($_POST['Files']['name'])) { // Задаем аттрибуты $files->attributes = $_POST['Files']; $files->bid = intval($id); $files->save(); $this->refresh(); } // Добавление комментария if (isset($_POST['Comments'])) { //exit(print_r($_POST['Comments'])); $comments->attributes = $_POST['Comments']; $comments->bid = $id; if ($comments->save()) { $this->refresh(); } } // Выборка комментариев $c = new CActiveDataProvider($comments, array('criteria' => array('condition' => 'bid = :bid', 'params' => array(':bid' => $id)))); // Выборка файлов $f = new CActiveDataProvider(Files::model(), array('criteria' => array('condition' => 'bid = :bid', 'params' => array(':bid' => $id)))); // История банов $history = new CActiveDataProvider('History', array('criteria' => array('condition' => '`player_ip` = :hip OR `player_id` = :hid', 'params' => array(':hip' => $model->player_ip, ':hid' => $model->player_id)), 'pagination' => array('pageSize' => 5))); // Вывод всего на вьюху $this->render('view', array('geo' => $geo, 'ipaccess' => $ipaccess, 'model' => $model, 'files' => $files, 'comments' => $comments, 'f' => $f, 'c' => $c, 'history' => $history)); }
public function actionDownload($id) { $id = (int) $id; $model = Files::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } //$configPath=Yii::app()->user->settings["company.path"]; $file = $model->getFullFilePath(); //????.$model->id; //echo $file.'end'; return Yii::app()->getRequest()->sendFile($model->name, file_get_contents($file)); }
public function actionResize() { $image = Yii::app()->request->getPost('image', false); $type = Yii::app()->request->getPost('type', false); if ($image !== false && in_array($type, array('avatar'))) { $file = pathinfo($image, PATHINFO_FILENAME); $file = Files::model()->findByPk($file); if ($file != NULL) { $tmp = TemporaryFiles::model()->find('md5file=:md5f', array(':md5f' => $md5file)); if ($tmp == null) { $to = realpath(Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'TemporaryFiles') . DIRECTORY_SEPARATOR . $filename; if ($to && @copy($image, $to)) { $image = $to; $size = getimagesize($image); if ($size[0] > 656 || $size[1] > 520) { Yii::import('ext.iwi.Iwi'); $img = new Iwi($image); $img->resize(656, 520, 2); $img->save(); } $tmp = new TemporaryFiles(); $tmp->md5file = $md5file; $tmp->filename = $filename; $tmp->upload_date = time(); $tmp->save(); } else { if (!is_file($to)) { echo CJSON::encode(array('message' => 'Ошибка копирования файла!', 'status' => 'ERROR')); exit; } else { echo CJSON::encode(array('message' => basename($to), 'status' => 'OK')); exit; } } } echo CJSON::encode(array('message' => $tmp->filename, 'status' => 'OK')); } echo CJSON::encode(array('message' => 'Файл не найден', 'status' => 'ERROR')); } exit; }
?> <li id="bus" class="<?php echo isset($_GET['class']) && $_GET['class'] == 'bus' ? 'active' : ''; ?> " onclick="window.location.href='/id<?php echo $model->id; ?> ?class=bus';">Автобусы</li> <?php } ?> </ul> <div class="accaunt-plus__service__list"> <?php foreach ($avto as $item) { $cnt = Files::model()->findAllByAttributes(array('uid' => $model->id, 'portfolio_id' => $item->id)); ?> <div class="accaunt-plus__service__item"> <div class="accaunt-plus__service__item-img"> <a href="/users/<?php echo $model->id; ?> /avto350_<?php echo $item->picture; ?> " rel="gallery1" class="avto__zoom"><img src="/users/<?php echo $model->id; ?> /<?php echo $item->picture; ?>
public function actionUpdate($id = false, $page = 1) { $role_id = Users::model()->findByPk(Yii::app()->user->id)->role_id; if ($role_id != 7 || $role_id == 7 && $id == 1) { $pages = new Pages(); if (!empty($id) && Pages::model()->existsPage($id)) { $active = Modules::model()->getActiveModule($id); $model = $pages->findByPk($id); if (isset($_POST['Pages'])) { if ($model->validate()) { $old_file_id = $model->image_id; if ($_POST['Pages']['image_id'] == 'NULL') { $_POST['Pages']['image_id'] = ''; } $model->attributes = $_POST['Pages']; if ($model->save()) { if ((int) $_POST['Pages']['image_id']) { Files::model()->saveTempFile((int) $_POST['Pages']['image_id']); } elseif ($_POST['Pages']['image_id'] == '') { Files::model()->deleteFile($old_file_id, 'page'); } if ($old_file_id != $model->image_id) { Files::model()->deleteFile($old_file_id, 'page'); } // Yii::app()->user->setFlash('message','<p style="color:green;">Сохранено</p>'); $this->redirect(YII::app()->baseUrl . '/admin.php?r=pages/update&id=' . $id); } else { // Yii::app()->user->setFlash('message','<p style="color:red;">Ошибка</p>'); } } } $image = Pages::model()->getImage($id, 'page'); $this->pageTitle = 'Редактирование раздела — ' . $model->name; $this->render('update', array('model' => $model, 'name' => $model->getPageNameById($id), 'active' => $active, 'image' => $image, 'page' => $page)); } else { $this->redirect(Yii::app()->request->baseUrl); } } else { $this->redirect(Yii::app()->baseUrl . '/admin.php?r=pages/access'); } }
private function findMd5($md5) { $model = Files::model()->findByAttributes(array('md5' => $md5)); if ($model === null) { return false; } else { return true; } }
?> :</b> <?php echo CHtml::encode($data->description); ?> <br /> <b><?php echo CHtml::encode("Attachments:"); ?> :</b> <?php $x = $data->attachments; $y = explode(",", $x); echo "<ul>"; for ($i = 1; $i < sizeof($y); $i++) { $files = Files::model()->findByPk($y[$i]); echo "<li>" . CHtml::link($files->originalname, Ccontroller::createUrl('/files/file', array('id' => $y[$i]))); } echo "</ul>"; ?> <br /> <?php /* <b><?php echo CHtml::encode($data->getAttributeLabel('status')); ?>:</b> <?php echo CHtml::encode($data->status); ?> <br /> <b><?php echo CHtml::encode($data->getAttributeLabel('history')); ?>:</b> <?php echo CHtml::encode($data->history); ?> <br /> */
public function actionDownload($id) { $model = Download::model()->findByPk($id); if ($model == null) { throw new CHttpException(404, 'The requested page does not exist.'); } $comp = Company::model()->findByPk($model->company_id); $comp->select($model->company_id); $id = (int) $model->file_id; $model = Files::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } $file = $model->getFullPath() . $model->id; return Yii::app()->getRequest()->sendFile($model->name, file_get_contents($file)); }
/** * Главная страница админцентра * @throws CHttpException */ public function actionIndex() { // Если гость, выдаем эксепшн if (Yii::app()->user->isGuest) { throw new CHttpException(403, 'У Вас недостаточно прав'); } // Только главный админ имеет право входить в аминцентр if (Yii::app()->user->id != '1') { throw new CHttpException(403, 'У Вас недостаточно прав'); } $this->render('index', array('sysinfo' => array('bancount' => History::model()->cache(300)->count(), 'activebans' => Bans::model()->cache(300)->count(), 'filescount' => Files::model()->cache(300)->count(), 'commentscount' => Comments::model()->cache(300)->count()))); }
public function preview($hash) { //查询是否已经存在该资源 $criteria = new CDbCriteria(); $criteria->addCondition('hash_code = "' . $hash . '"'); $model = Files::model()->find($criteria); if (empty($model)) { $this->error = '数据库查询为空'; throw new CHttpException(404, '此页面不存在'); return false; } //加载源文件,生成新文件 $file = $this->getPath($hash); if (!file_exists($file)) { $this->error = '源文件不存在'; throw new CHttpException(404, '此页面不存在'); return false; } switch (strtolower($model->file_extension)) { case 'doc': $this->renderFile($hash, 'swf'); break; case 'docx': $this->renderFile($hash, 'swf'); break; case 'xls': $this->renderFile($hash, 'swf'); break; case 'xlsx': $this->renderFile($hash, 'swf'); break; case 'pdf': $this->renderFile($hash, 'swf'); break; case 'jpg': $this->renderImage($hash, 'jpg'); break; case 'jpeg': $this->renderImage($hash, 'jpg'); break; case 'png': $this->renderImage($hash, 'png'); break; case 'gif': $this->renderImage($hash, 'gif'); break; case 'txt': $this->renderFile($hash, 'txt'); break; default: $this->renderFile($hash, $model->file_extension); break; $this->error = '数据库查询为空'; //throw new CHttpException(404,'此页面不存在'); return false; } }