00001 <?php
00002
00013 class SnapContentMediaFile extends SnapContent {
00021 protected function getSuffix() {
00022 if(!$this->validate())
00023 return false;
00024
00025 return $this->get('suffix');
00026 }
00027
00035 protected function doDelete() {
00036 if(!$this->validate())
00037 return true;
00038
00039 $file = new SnapExternalFile($this->version, $this->get('file'));
00040 $file->delete();
00041
00042 return true;
00043 }
00044
00052 protected function doCopy() {
00053 $newCM = new SnapContentMediaFile($this->version);
00054 $file = new SnapExternalFile($this->version, $this->get('file'));
00055 $newCM->set('file', $file->copy()->getArray());
00056 return $newCM;
00057 }
00058
00066 protected function validate() {
00067 $values = $this->getAll();
00068 if(!isset($values['file']) || !isset($values['suffix']))
00069 return false;
00070 else
00071 return true;
00072 }
00073
00082 protected function doGetHTML($params) {
00083 if(!$this->validate())
00084 return false;
00085
00086 $file = new SnapExternalFile($this->version, $this->get('file'));
00087 $class = isset($params['class']) ? " class=\"$params[class]\"" : "";
00088 $style = isset($params['style']) ? " style=\"$params[style]\"" : "";
00089
00090
00091 $title = isset($params['title']) ? $params['title'] : 'Download File';
00092 return "<a$class$style href=\"" . $this->getLinkURL() . "\">$title</a>";
00093 }
00094
00101 public function uploadFile($tmpFile, $fileName) {
00102 if(!is_readable($tmpFile)) {
00103 $this->setError("File '$tmpFile' does not exist "
00104 . "or is not accessible");
00105 return false;
00106 }
00107
00108 $file = new SnapExternalFile($this->version);
00109 $file->create($tmpFile, $fileName);
00110 $this->set('file', $file->getArray());
00111
00112 $suffix = substr(strrchr($fileName, '.'), 1);
00113 $this->set('suffix', $suffix);
00114
00115 $size = filesize($tmpFile);
00116 $this->set('size', $size);
00117
00118 return true;
00119 }
00120
00128 public function getURL() {
00129 if(!$this->validate())
00130 return false;
00131 $file = new SnapExternalFile($this->version, $this->get('file'));
00132 return $file->getURL();
00133 }
00134
00142 public function getPath() {
00143 if(!$this->validate())
00144 return false;
00145 $file = new SnapExternalFile($this->version, $this->get('file'));
00146 return $file->getPath();
00147 }
00148
00156 public function getFileSuffix() {
00157 if(!$this->validate())
00158 return false;
00159 return $this->get('suffix');
00160 }
00161
00169 public function getSize() {
00170 if(!$this->validate())
00171 return false;
00172 if(!$this->get('size')) {
00173 $file = new SnapExternalFile($this->version, $this->get('file'));
00174 return filesize($file->getPath());
00175 }
00176 else
00177 return $this->get('size');
00178 }
00179
00187 public function checkMedia() {
00188 if($this->get('file') == '')
00189 return true;
00190 if(!$this->validate())
00191 return false;
00192 $file = new SnapExternalFile($this->version, $this->get('file'));
00193 $path = $file->getPath();
00194 if(is_readable($path) && is_file($path))
00195 return true;
00196 else
00197 return false;
00198 }
00199
00207 public function updateFileList() {
00208 if(!$this->validate())
00209 return 'no files to insert';
00210 SnapDBI::startTransaction();
00211 $file = new SnapExternalFile($this->version, $this->get('file'));
00212 $ret = $file->updateDB();
00213 if($ret)
00214 SnapDBI::commitTransaction();
00215 else {
00216 $ret = 'database failure';
00217 SnapDBI::cancelTransaction();
00218 }
00219 return $ret;
00220 }
00221
00222 }
00223
00224 ?>