Inheritance: extends Controller
Esempio n. 1
0
function getDirContaints($dir, $results = array(), $backDir = "")
{
    $allfiles = scandir($dir);
    $files = new Files();
    foreach ($allfiles as $key => $value) {
        if (!in_array($value, array(".", ".."))) {
            $timestamp = strtotime($value);
            $path = realpath($dir . DIRECTORY_SEPARATOR . $value);
            $uploadDirInfo = explode("_", basename($path));
            if (is_dir($path)) {
                $dir_files = scandir($path);
                foreach ($dir_files as $k => $v) {
                    if (!in_array($v, array(".", ".."))) {
                        $pth = realpath($path . DIRECTORY_SEPARATOR . $v);
                        if (!is_dir($pth)) {
                            $data['filename'] = basename($pth);
                            $data['filepath'] = $path;
                            $data['user_id'] = $uploadDirInfo['1'];
                            $data['user_name'] = $uploadDirInfo['0'];
                            $files->uploadBulkFiles($data);
                        }
                    }
                }
            }
        }
    }
    return 'Files uploaded successfuly';
}
Esempio n. 2
0
 /**
  * @remotable
  */
 public function read($id, $cat)
 {
     $out = array();
     if ($cat == "projects") {
         $projects = $this->db->select("SELECT id, name, dir, date FROM projects ORDER BY date DESC");
         foreach ($projects as $item) {
             $children = array();
             $text = "<b>Date</b>: {$item['date']}<br>";
             $text .= "<b>Dir/File</b>: {$item['dir']}<br>";
             if (is_dir($item['dir'])) {
                 array_push($children, array('id' => $item['dir'], 'text' => 'Work Directory', 'cat' => 'dir', 'qtip' => $item['dir'], iconCls => 'work-dir', 'leaf' => false));
             } elseif (is_file($item['dir'])) {
                 array_push($children, array('id' => $item['dir'], 'text' => basename($item['dir']), 'hash' => md5($item['dir']), 'iconCls' => 'php-file', 'leaf' => true));
             }
             array_push($children, array('id' => 'scans' . $item['id'], 'text' => 'Scannings', 'cat' => 'scans', 'iconCls' => 'scannings', 'leaf' => false));
             array_push($children, array('id' => 'vulns' . $item['id'], 'text' => 'Vulnerabilities', 'cat' => 'vulns', 'iconCls' => 'vulns', 'leaf' => false));
             array_push($out, array('id' => $item['id'], 'text' => $item['name'], 'iconCls' => 'project', 'cat' => 'project', 'qtipCfg' => array('shadow' => 'frame', 'text' => $text, 'dismissDelay' => 10000), 'leaf' => false, 'children' => $children));
         }
     } elseif ($cat == "dir") {
         include 'Files.php';
         $f = new Files();
         $out = $f->getList($id);
     } elseif ($cat == "scans") {
         include 'ScanHistory.php';
         $s = new ScanHistory();
         $out = $s->read(substr($id, 5));
     } elseif ($cat == "vulns") {
         include 'Vulnerabilities.php';
         $v = new Vulnerabilities();
         $out = $v->read(substr($id, 5));
     }
     return $out;
 }
Esempio n. 3
0
 public function testNot()
 {
     $kirby = $this->kirbyInstance();
     $site = $this->siteInstance($kirby);
     $page = new Page($site, 'tests/file-extension-case-test');
     // unset by a single filename
     $files = new Files($page);
     $this->assertEquals(2, $files->count());
     $modified = $files->not('a.json');
     $this->assertEquals(1, $modified->count());
     // unset by multiple filenames
     $files = new Files($page);
     $this->assertEquals(2, $files->count());
     $modified = $files->not('a.json', 'b.json');
     $this->assertEquals(0, $modified->count());
     // unset by array
     $files = new Files($page);
     $this->assertEquals(2, $files->count());
     $modified = $files->not(['a.json', 'b.json']);
     $this->assertEquals(0, $modified->count());
     // unset by a collection
     $files = new Files($page);
     $this->assertEquals(2, $files->count());
     $modified = $files->not($files);
     $this->assertEquals(0, $modified->count());
 }
Esempio n. 4
0
 public function noavatarAction()
 {
     $files = new Files();
     $file = $this->_properties->getProperty('avatar_image');
     $this->_properties->deleteProperty('avatar_image');
     $files->deleteFile($file);
     $this->_forward('index');
 }
Esempio n. 5
0
 /**
  * Constructor
  *
  * @param Files The parent files collection
  * @param string The filename
  */
 public function __construct(Files $files, $filename)
 {
     $this->site = $files->site();
     $this->page = $files->page();
     $this->files = $files;
     $this->root = $this->files->page()->root() . DS . $filename;
     parent::__construct($this->root);
 }
Esempio n. 6
0
 /**
  * Вывод инфы о бане
  * @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);
         $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'] = $xml->ip->city;
                 $geo['region'] = $xml->ip->region;
                 $geo['country'] = $xml->ip->country;
                 $geo['lat'] = $xml->ip->lat;
                 $geo['lng'] = $xml->ip->lng;
             }
         }
     }
     // Добавление файла
     if (isset($_POST['Files'])) {
         // Задаем аттрибуты
         $files->attributes = $_POST['Files'];
         $files->bid = intval($id);
         if ($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('Bans', array('criteria' => array('condition' => '`bid` <> :hbid AND (`player_ip` = :hip OR `player_id` = :hid)', 'params' => array(':hbid' => $id, ':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));
 }
Esempio n. 7
0
 /**
  * Delete the cached config. If no locale is given the whole related cache is removed.
  *
  * @param int         $formId The form id.
  * @param string|null $locale The locale.
  *
  * @return void
  */
 public function remove($formId, $locale = null)
 {
     if ($locale) {
         $this->fileSystem->delete($this->filename($formId, $locale));
     } else {
         $pattern = sprintf('%s/%s/formvalidation-*-%s.js', TL_ROOT, static::BASE_PATH, $formId);
         foreach (glob($pattern) as $path) {
             $this->fileSystem->delete(substr($path, strlen(TL_ROOT) + 1));
         }
     }
 }
Esempio n. 8
0
 public function backupDB()
 {
     $dumper = new dbMaster();
     $sql = $dumper->getDump(false);
     $file = new Files();
     $file->name = "DB Backup " . date("d-m-Y_H_i") . ".sql";
     $file->path = '.';
     $file->save();
     $file->writeFile($sql);
     $this->DBback = $file->id;
 }
Esempio n. 9
0
 public function action_index()
 {
     $record = new Files();
     $record->parent_id = $_POST['parent_id'];
     $record->text = $_POST['text'];
     $record->extension = $_POST['extension'];
     $record->leaf = $_POST['leaf'];
     $record->save();
     $array = array('success' => 'true', 'msg' => 'Record added successfully');
     $json = json_encode($array);
     return $json;
 }
 /**
  * Helper function to use within theme files for hardcoded links
  * 
  * @param url $file_url URL of file
  * @param boolean $force_download Wheather to force download or not
  * @return url Parsed link
  */
 function sqhrdm_get_download_link($file_url = null, $force_download = true)
 {
     if (!$file_url) {
         return '#';
     }
     require_once SQHR_DM_PLUGIN_PATH . 'system/controllers/class.files.php';
     $files = new Files();
     $file_id = $files->get_file_id($file_url);
     $return .= '?process_download=';
     $return .= $file_id;
     $return .= !$force_download ? '&pd_force=no' : '';
     return $return;
 }
Esempio n. 11
0
 public function add($data)
 {
     $data['addtime'] = time();
     $File = new Files();
     foreach ($data as $field => $value) {
         $File->{$field} = $value;
     }
     if (!$File->create()) {
         $this->outputErrors($File);
         return false;
     }
     return true;
 }
 public function upload(Request $request)
 {
     $file = $request->file;
     $imageName = md5(time() * rand(1, 100)) . '.' . $file->getClientOriginalExtension();
     $f = new Files();
     $f->name = $imageName;
     $f->mimeType = $file->getMimeType();
     $f->size = $file->getSize();
     $f->user_id = 1;
     $f->produto_id = $request->input('produto_id');
     $file->move(base_path() . '/public/imagens/', $imageName);
     $f->save();
     return 'OK';
 }
Esempio n. 13
0
 public function renderDefault()
 {
     $files = $this->files->order($this->order . " " . $this->sort);
     // vyhledavani
     if ($this->q) {
         $files->where("file.name LIKE ?", "%" . $this->q . "%");
         $this['search']['q']->setDefaultValue($this->q);
         $this->template->search = TRUE;
     } else {
         $this->template->search = FALSE;
     }
     $this->pagerFiles->itemCount = $files->count();
     $this->template->files = $files->limit($this->pagerFiles->getLimit(), $this->pagerFiles->getOffset());
 }
Esempio n. 14
0
 public function listFiles()
 {
     Zend_Loader::loadClass('Files');
     $files = new Files();
     $list = $files->listFiles('public/files/uploaded/');
     sort($list);
     $all = array();
     foreach ($list as $filename) {
         $row['name'] = $filename;
         $row['filesize'] = filesize('public/files/uploaded/' . $filename);
         array_push($all, $row);
     }
     return $all;
 }
Esempio n. 15
0
 public function createMongoAction()
 {
     $file = new Files();
     $file->type = "video";
     $file->name = "Astro Boy";
     $file->year = 1952;
     if ($file->save() == false) {
         echo "Umh, We can't store files right now: \n";
         foreach ($file->getMessages() as $message) {
             echo $message, "\n";
         }
     } else {
         echo "Great, a new file was saved successfully !";
     }
 }
Esempio n. 16
0
 public function listAction()
 {
     $format = $this->_getParam('format', 'ajax');
     switch ($format) {
         case 'xml':
             $this->_helper->layout->setLayout('xml');
             $this->_helper->viewRenderer('list-xml');
             break;
         default:
             $this->_helper->layout->setLayout('ajax');
     }
     Zend_Loader::loadClass('Files');
     $files = new Files();
     $this->view->list = $files->listFiles('public/files/uploaded/');
 }
Esempio n. 17
0
 /**
  * @constructor
  */
 public function __construct($data_folder = '')
 {
     // load the config file.
     $this->config = new Config();
     $this->config->load($data_folder);
     // load the templates.
     $this->templates = new Templates();
     $this->templates->load($data_folder);
     // loading data files.
     $this->files = new Files();
     $this->files->load($data_folder, $this->config->get('pages_data'));
     // initialize database.
     $this->db = new Database();
     //
     $this->renders = new Renders();
 }
Esempio n. 18
0
/**
 * Draw the files in an table.
 */
function drawFiles($list, &$manager)
{
    global $relative;
    foreach ($list as $entry => $file) {
        ?>
		<td><table width="100" cellpadding="0" cellspacing="0"><tr><td class="block">
		<a href="javascript:;" onclick="selectImage('<?php 
        echo $file['relative'];
        ?>
', '<?php 
        echo $entry;
        ?>
', <?php 
        echo $file['image'][0];
        ?>
, <?php 
        echo $file['image'][1];
        ?>
);"title="<?php 
        echo $entry;
        ?>
 - <?php 
        echo Files::formatSize($file['stat']['size']);
        ?>
"><img src="<?php 
        echo $manager->getThumbnail($file['relative']);
        ?>
" alt="<?php 
        echo $entry;
        ?>
 - <?php 
        echo Files::formatSize($file['stat']['size']);
        ?>
"/></a>
		</td></tr><tr><td class="edit">
			<a href="images.php?dir=<?php 
        echo $relative;
        ?>
&amp;delf=<?php 
        echo rawurlencode($file['relative']);
        ?>
" title="Trash" onclick="return confirmDeleteFile('<?php 
        echo $entry;
        ?>
');"><img src="img/edit_trash.gif" height="15" width="15" alt="Trash"/></a><a href="javascript:;" title="Edit" onclick="editImage('<?php 
        echo rawurlencode($file['relative']);
        ?>
');"><img src="img/edit_pencil.gif" height="15" width="15" alt="Edit"/></a>
		<?php 
        if ($file['image']) {
            echo $file['image'][0] . 'x' . $file['image'][1];
        } else {
            echo $entry;
        }
        ?>
		</td></tr></table></td> 
	  <?php 
    }
    //foreach
}
Esempio n. 19
0
 protected static function personPrepare()
 {
     return PersonModel::join(PersonLangModel::getTableName(), PersonLangModel::getField("person_id"), '=', PersonModel::getField("id"))->join(PersonRelModel::getTableName(), PersonRelModel::getField("person_id"), '=', PersonModel::getField("id"))->leftJoin(Files::getTableName(), function ($join) {
         $join->on(Files::getField("module_id"), '=', PersonModel::getField("id"));
         $join->on(Files::getField("module_name"), '=', DB::raw("'person'"));
     })->where(PersonLangModel::getField("lang_id"), \WebAPL\Language::getId())->orderBy('first_name', 'asc')->orderBy('last_name', 'asc');
 }
Esempio n. 20
0
 /**
  * Get all folders and files within a folder
  *
  * @param   int     $parent The id of this folder
  * @return  array
  *
  **/
 public static function folder_contents($parent = 0, $type = null)
 {
     // they can also pass a url hash such as #foo/bar/some-other-folder-slug
     if (!is_numeric($parent)) {
         $segment = explode('/', trim($parent, '/#'));
         $result = ci()->file_folders_m->get_by('slug', array_pop($segment));
         $parent = $result ? $result->id : 0;
     }
     $folders = ci()->file_folders_m->where('parent_id', $parent)->where('hidden', 0)->order_by('sort')->get_all();
     // $files = ci()->file_m->where(array('folder_id' => $parent))
     //     ->order_by('sort')
     //     ->get_all();
     $files = ci()->file_m->where(array('folder_id' => $parent, 'type' => $type))->order_by('sort')->get_all();
     // let's be nice and add a date in that's formatted like the rest of the CMS
     if ($folders) {
         foreach ($folders as &$folder) {
             $folder->formatted_date = format_date($folder->date_added);
             $folder->file_count = ci()->file_m->count_by('folder_id', $folder->id);
         }
     }
     if ($files) {
         ci()->load->library('keywords/keywords');
         foreach ($files as &$file) {
             $file->keywords_hash = $file->keywords;
             $file->keywords = ci()->keywords->get_string($file->keywords);
             $file->formatted_date = format_date($file->date_added);
         }
     }
     return Files::result(true, null, null, array('folder' => $folders, 'file' => $files, 'parent_id' => $parent));
 }
Esempio n. 21
0
 /**
  * Sets up internal variables with the arguments given
  * @param string $label The (human-readable) label for the form element
  * @param string $name The (machine-readable) name of the element
  * @param array $data The url to the image-object
  * @param string $validate Adds a validation class to the element
  * @param string $description Add a description to the form element
  * @param bool $preview Adds a preview of the choosen image
  * @return void
  */
 function __construct($label, $name, $value = '', $validate = false, $description = false, $preview = true, $dir = false, $class = false)
 {
     $this->label = $label;
     $this->value = $value;
     $this->name = $name;
     $this->validate = $validate;
     $this->preview = $preview;
     $this->description = $description;
     $this->class = $class;
     global $Controller;
     if ($dir && (is_a($dir, 'User') || is_a($dir, 'Group'))) {
         $dir = Files::userDir($dir);
     }
     if ($dir) {
         if (!is_object($dir)) {
             $dir = $Controller->{(string) $dir};
         }
         if (!$dir->mayI(READ)) {
             $dir = false;
         }
         $this->dir = $dir->ID;
     } else {
         $this->dir = false;
     }
 }
Esempio n. 22
0
 private function watermark($data = array())
 {
     $this->load->library('files/files');
     $mark_text = isset($data['text']) ? $data['text'] : Settings::get('site_name');
     $font_color = isset($data['font_color']) ? $data['font_color'] : 'ffffff';
     $opacity = isset($data['opacity']) ? (int) $data['opacity'] : 100;
     $font_size = isset($data['font_size']) ? (int) $data['font_size'] : 12;
     $files = $data['files'];
     $font_path = './' . SHARED_ADDONPATH . 'modules/watermark/fonts/Gabrielle.ttf';
     if (is_array($files) && count($files) > 0) {
         foreach ($files as $file) {
             $filedata = Files::get_file($file);
             if ($filedata['status'] === TRUE) {
                 $dirpath = FCPATH . '/uploads/default/files/';
                 $source = $dirpath . $filedata['data']->filename;
                 $imageLayer = ImageWorkshop::initFromPath($source);
                 //var_dump($imageLayer);exit;
                 $textLayer = ImageWorkshop::initTextLayer($mark_text, $font_path, $font_size, $font_color, $data['rotation']);
                 $textLayer->opacity($opacity);
                 $imageLayer->addLayerOnTop($textLayer, 12, 12, $data['position']);
                 $image = $imageLayer->getResult();
                 $imageLayer->save($dirpath, $filedata['data']->filename, false, null, 100);
                 $wm_data = array('file_id' => $filedata['data']->id, 'folder_id' => $filedata['data']->folder_id);
                 $this->watermark_m->insert($wm_data);
             }
         }
         $this->session->set_flashdata('success', lang('watermark:submit_success'));
         redirect('admin/watermark');
     } else {
         $this->session->set_flashdata('error', lang('watermark:no_files_remaining'));
         redirect('admin/watermark');
     }
 }
Esempio n. 23
0
 public function interpret_request($POST, $FILES)
 {
     $image = null;
     if (isset($FILES['image']) && isset($FILES['image']['error']) && $FILES['image']['error'] == 0) {
         $image = $FILES['image'];
         $uploaddir = PATH . "images_dir/";
         $ext = pathinfo(basename($image['name']), PATHINFO_EXTENSION);
         $uniqueId = uniqid();
         $uploadfile = $uploaddir . $uniqueId . basename($image['name']);
         $allowed_extensions = Files::get_allowed_extensions();
         if (in_array($image['type'], $allowed_extensions[strtolower($ext)]['mime'])) {
             if (move_uploaded_file($image['tmp_name'], $uploadfile)) {
                 $image = $uniqueId . basename($image['name']);
                 fixOrientation($uploadfile);
             } else {
                 $image = null;
             }
         } else {
             $image = null;
         }
     }
     if (!isset($image)) {
         $this->errors[] = 'image';
     }
     if (!empty($this->errors)) {
         throw new ValidationError($this->errors);
     }
     if (isset($image)) {
         $this->set_path($image);
     }
     return $this;
 }
Esempio n. 24
0
 public function webpageTextChecker()
 {
     $this->deleteOldFiles();
     $site = Files::fileToArray('sites.txt')[0];
     Curl::cookieCreation($site);
     $pageNumber = -1;
     $pages = self::clearPages();
     $pagesUnique = array_unique($pages);
     foreach ($pagesUnique as $page) {
         self::setTextForSearch($page);
         /* check if page does not start with
            slash then add it */
         if ($page[0] !== "/") {
             if (in_array("/{$page}", $pages)) {
                 continue;
             }
             $page = "/{$page}";
         }
         $textForSearch = self::getTextForSearch();
         $pageNumber++;
         $sitePage = $site . $page;
         echo count($pagesUnique) - $pageNumber . ".", $sitePage . "\n";
         $this->pageTextChecker($page, $pages, $site, $sitePage, $textForSearch);
     }
     $logFileName = 'ptc_log_';
     $log = $this->getLog();
     LogCreation::logFileCreator($log, $logFileName);
 }
Esempio n. 25
0
 /**
  * Regarde si un objet a déjà été instancier,
  * si c'est le cas alors il retourne l'objet déjà existant
  * sinon il en créer un autre.
  * @return $instance
  */
 public static function getInstance()
 {
     if (!self::$instance instanceof self) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Esempio n. 26
0
 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>');
         }
     }
 }
Esempio n. 27
0
 /**
  * add or remove folders.
  * 
  * @access public
  * @param $action add|remove (default: 'add')
  * @return void
  */
 public function folders($action = 'add')
 {
     $this->load->library('files/files');
     $this->load->model('files/file_folders_m');
     //$this->load->model('settings/settings_m');
     $folder_slug = 'photo-gallery';
     if ($action == 'add') {
         $parent_id = 0;
         //users uploaded image folder
         $user_folder = $this->file_folders_m->get_by(array('slug' => $folder_slug));
         if ($user_folder) {
             $folder = (array) $user_folder;
         } else {
             $user_folder = Files::create_folder($parent_id, 'Photo Gallery');
             $folder = $user_folder['data'];
         }
         if ($folder) {
             $setting_data = array('slug' => $folder['slug'], 'title' => $folder['name'], 'description' => 'Folder id for ' . $folder['name'], 'default' => 0, 'value' => $folder['id'], 'type' => 'text', 'options' => '', 'is_required' => 1, 'is_gui' => 1, 'module' => 'galleries');
         }
         $folder_setting = $this->db->where('slug', $folder_slug)->get('settings')->num_rows;
         if ($folder_setting == 0) {
             $this->db->insert('settings', $setting_data);
         } else {
             $this->db->where('slug', $folder_slug)->update('settings', $setting_data);
         }
         return TRUE;
     } else {
         // remove folder settings
         return (bool) $this->file_folders_m->delete_by('slug', $folder_slug);
     }
 }
Esempio n. 28
0
 /**
  * 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()));
     }
 }
Esempio n. 29
0
 public static function findFiles($directory, $include = null, $exclude = null)
 {
     self::$search_results = array();
     self::$search_filters = array('include' => $include, 'exclude' => $exclude);
     self::urecurse($directory, array('Files', 'searchCallback'));
     return self::$search_results;
 }
 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);
 }