/** * */ public function indexAction() { $sql = 'SELECT SUM(fweight) AS totalWeight FROM filfiles WHERE safinstances_id = ' . $this->safinstancesId; $ttw = $this->_db->fetchAll($sql); $this->view->totalWeight = $ttw[0]['totalWeight']; $this->view->totalWeightAllowed = $this->_config->files->totalWeightAllowed * 1024 * 1024 * 1024; $this->view->weightPercent = round($this->view->totalWeight / $this->view->totalWeightAllowed, 2) * 100; $dbfiles = new Filfiles(); $where = 'safinstances_id = ' . $this->safinstancesId; $order = 'datecreated DESC'; // $order=null; $this->view->lastuploaded = $dbfiles->fetchAll($where, $order, 10, 0); }
/** * Register the file and location in the DB for quick search and indexing * * @param $path Path to the file * @param $fileName File name on the hard disk * @param $fileWeight Weight in bytes * @param $type 3 letters extension * @param $usersId * @param $safinstancesId * @param array $params * @param string $desc * @return bool|mixed|string id of the file or false on error */ public function registerFileToDb($path, $fileName, $fileWeight, $type, $usersId, $safinstancesId, $params = array(), $desc = '') { $fileTypeDb = new Filtype(); $fileTypeId = 1; $fileTypeRow = $fileTypeDb->fetchAll("ext = '" . substr($type, 0, 3) . "'"); if (count($fileTypeRow) == 1) { $fileTypeId = $fileTypeRow[0]->id; } $data = array('label' => $fileName, 'desc' => $desc, 'filename' => $fileName, 'type' => $type, 'fweight' => $fileWeight, 'filtype_id' => $fileTypeId, 'users_id' => $usersId, 'safinstances_id' => $safinstancesId, 'datecreated' => new Zend_Db_Expr('NOW()'), 'datemodified' => new Zend_Db_Expr('NOW()')); $fileFile = new Filfiles(); $files = $fileFile->fetchAll("filename = '{$fileName}' AND safinstances_id = '" . $safinstancesId . "' "); $countFiles = count($files); if ($countFiles == 1 && $params->calledBy == 'adminpeople' && isset($params->peopleId) && $params->peopleId > 0) { UsersOp::changeAvatar($params->peopleId, $files[0]['id']); return $files[0]['id']; } elseif ($countFiles == 1) { // Replace action, we should update the DB datas $fileId = $files->current()->id; if ($fileFile->update($data, 'id=' . $fileId)) { Sydney_Db_Trace::add('trace.event.upload_file [' . $data['filename'] . ']', 'adminfiles', Sydney_Tools::getTableName($fileFile), 'uploadfile', $fileId); return $files[0]['id']; } else { return false; } } elseif ($countFiles == 0) { if ($fileId = $fileFile->insert($data)) { // #18 - called by module adminpeople In this case, check if the category 'module > system > adminpeople' exist, if yes then link to this else first create new cat and link this new cat. if ($params->calledBy == 'adminpeople') { UsersOp::changeAvatar($params->peopleId, $fileId); } // add categories to file if (isset($params->catids)) { $foids = explode(',', $params->catids); $foids2 = array(); for ($i = 0; $i < count($foids); $i++) { if ($foids[$i] > 0) { $foids2[] = $foids[$i]; } } $fileDb = new FilfoldersFilfiles(); $fileDb->setFilfilesLinkedTo($fileId, $foids2); } Sydney_Db_Trace::add('trace.event.upload_file' . ' [' . $data['filename'] . ']', 'adminfiles', Sydney_Tools::getTableName($fileFile), 'uploadfile', $fileId); return $fileId; } else { return false; } } }
/** * Displays the content of a zip file (id passed as arg) */ public function showzipcontentAction() { $request = $this->getRequest(); if (isset($request->id) && preg_match('/^[0-9]{1,30}$/', $request->id)) { $id = $request->id; $fileModel = new Filfiles(); $where = "id = " . $id . " AND safinstances_id = '" . $this->safinstancesId . "' AND type = 'ZIP' "; $files = $fileModel->fetchAll($where); $this->view->ziplist = array(); if (count($files) == 1) { $file = $files[0]; //Définition dynamique du fullpath $fileType = $file->type; $fullpath = Sydney_Tools_Paths::getAppdataPath() . '/adminfiles/' . $fileType . '/' . $file->filename; $fileTypeInstance = Sydney_Medias_Filetypesfactory::createfiletype($fullpath); $this->view->ziplist = $fileTypeInstance->getZipContent(); } } }
/** * * @return void */ public function lastupdatesAction() { $this->view->ajaxurl .= 'lastupdates/'; $r = $this->getRequest(); $nbr = 10; $noviewswitch = 'Y'; $vmode = 'list'; $flm = 1; $ftyp = array_merge(Sydney_Medias_Utils::$filters[4], Sydney_Medias_Utils::$filters[5]); $way = 'DESC'; $dorder = 'datecreated'; $this->view->ajsrt = 'date'; if (isset($r->nbr) && preg_match('/^[0-9]{1,3}$/', $r->nbr)) { $nbr = $r->nbr; $this->view->ajaxurl .= 'nbr/' . $nbr . '/'; } if (isset($r->noviewswitch)) { $noviewswitch = $r->noviewswitch; $this->view->ajaxurl .= 'noviewswitch/' . $noviewswitch . '/'; } if (isset($r->vmode)) { $vmode = $r->vmode; $this->view->ajaxurl .= 'vmode/' . $vmode . '/'; } if (isset($r->flm) && isset(Sydney_Medias_Utils::$filters[$r->flm])) { $ftyp = Sydney_Medias_Utils::$filters[$r->flm]; $this->view->ajaxurl .= 'ftyp/' . $ftyp . '/'; } if (isset($r->ajsrt)) { if ($r->ajsrt == 'date') { $dorder = 'datecreated'; } if ($r->ajsrt == 'label') { $dorder = 'label'; } if ($r->ajsrt == 'size') { $dorder = 'fweight'; } $this->view->ajsrt = $dorder; } if (isset($r->way)) { if ($r->way == 'DESC') { $way = ''; } } $this->view->ajaxurl .= 'way/' . $way . '/'; $this->view->noviewswitch = $noviewswitch; $this->view->vmode = $vmode; $sql = "\tsafinstances_id = '" . $this->safinstancesId . "'\n\t\t\t\t\tAND type IN ('" . implode("','", $ftyp) . "') "; $filsDB = new Filfiles(); $this->view->files = $filsDB->fetchAll($sql, trim($dorder . ' ' . $way), $nbr, 0); $this->render('viewfolercontent'); }
/** * Show small images from uploaded pictures based on it's id and type size * * Type size : * 2 = 64x64 pixel * 3 = 32x32 pixel * 4 = 16x16 pixel * * Example : /publicms/file/thumb/id/1/ts/2 * where ts is the thumb size mode * amd id is the ID of the file to get */ public function thumbAction() { $this->initFileHeaders(); $request = $this->getRequest(); if (isset($request->id) && preg_match('/^[0-9]{1,30}$/', $request->id)) { if (isset($request->ts) && preg_match('/^[0-9]{1,30}$/', $request->ts)) { $typeSize = $request->ts; } else { $typeSize = 1; } $elementId = $request->id; $fileModel = new Filfiles(); $where = 'id = ' . $elementId . ' AND safinstances_id = ' . $this->safinstancesId; $result = $fileModel->fetchAll($where); if (count($result) == 1) { $file = $result[0]; $fileType = $file->type; $fullpath = Sydney_Tools_Paths::getAppdataPath() . '/adminfiles/' . $fileType . '/' . $file->filename; $fileTypeInstance = Sydney_Medias_Filetypesfactory::createfiletype($fullpath); // defines the thumb size if ($typeSize == 2) { $fileTypeInstance->thumbSize = array(64, 64); } if ($typeSize == 3) { $fileTypeInstance->thumbSize = array(32, 32); } if ($typeSize == 4) { $fileTypeInstance->thumbSize = array(16, 16); } if (!$fileTypeInstance->showThumb()) { print 'Image can not be processed'; } } else { print 'You do not have access to this information'; } } else { print 'Something is missing...'; } $this->render('index'); }
/** * */ protected function _getImageFromRequest() { $fltr = new Zend_Filter_Digits(); $re = $this->getRequest(); if (isset($re->id) && preg_match('/^[0-9]{1,30}$/', $re->id)) { $elid = $fltr->filter($re->id); $mdb = new Filfiles(); $where = 'id = ' . $elid . ' AND safinstances_id = ' . $this->safinstancesId; $r = $mdb->fetchAll($where); if (count($r) == 1) { return $r[0]; } else { return false; } } else { return false; } }
/** * Sets text data in the index field for a file */ public function setindexdataAction() { $r = $this->getRequest(); if (isset($r->id) && preg_match('/^[0-9]{1,30}$/', $r->id)) { $id = $r->id; $fileDb = new Filfiles(); $where = "id = " . $id . " AND safinstances_id = '" . $this->safinstancesId . "' "; $files = $fileDb->fetchAll($where); if (count($files) == 1) { $fileDb = $files[0]; $fileDb->idxcontent = $r->idxdt; $fileDb->save(); } } }