public function __invoke($entries, $mediasTable = array(), $mediaInUse = array()) { if (empty($entries)) { $html = '<p>' . $this->view->translate('No documents or images found') . '</p>'; } else { $url = 'http://' . $this->view->host . '/mcwork/medias/download/'; $disablefolder = $this->view->disablefolder; if (!is_array($disablefolder)) { $disablefolder = array('_alternate'); } $cddownload = ''; if ($this->view->currentFolder) { $cddownload = str_replace(DS, $this->view->seperator, $this->view->currentFolder); } $tableFactory = new HtmlTable(new FactoryTable()); $tableFactory->setAttributes('class', 'mcworkBackendTable table display'); $i = 0; $iClass = 0; $headlines = array('#' => array(), 'Filename' => array('body' => array('class' => 'filename')), 'Size' => array('head' => array('class' => 'hide-for-small text-right'), 'body' => array('class' => 'hide-for-small text-right')), 'Date' => array('head' => array('class' => 'hide-for-small text-right'), 'body' => array('class' => 'hide-for-small text-right')), ' ' => array('head' => array('class' => 'cellToolbar'), 'body' => array('class' => 'cellToolbar'))); $ihead = count($headlines); foreach ($headlines as $column => $attributes) { $columns[] = $this->view->translate($column); if (is_array($attributes) && !empty($attributes)) { foreach ($attributes as $area => $attribute) { switch ($area) { case 'head': $tableFactory->setHeadlineAttributtes('class', $attribute['class'], $i); break; case 'body': $tableFactory->setTagAttributtes('class', $attribute['class'], $i); break; default: break; } } } $i++; } $tableFactory->setHeadline($columns); $i = 0; if (null != $this->view->currentFolder) { foreach ($entries as $entry) { if ('..' == $entry->filename) { $i++; $rowContent = array(); $rowContent[] = ' '; $up = ''; if ($this->view->currentFolder) { $array = explode(DS, $this->view->currentFolder); if (null != array_pop($array)) { $up = implode($this->view->seperator, $array); } } $rowContent[] = '<a href="' . self::MEDIA_DIR_PATH . '/' . $up . '" class="small button"><i class="fa fa-arrow-up"></i></a>'; $rowContent[] = ' '; $rowContent[] = ' '; $rowContent[] = ' '; $tableFactory->setHtmlContent($rowContent); break; } } } foreach ($entries as $entry) { if ('.' != $entry->filename && '..' != $entry->filename && !in_array($entry->filename, $disablefolder) && 'dir' == $entry->type) { $i++; $rowContent = array(); $dataAttribInUse = 'data-inuse="0"'; $label = ''; $keys = preg_grep('/' . $entry->filename . '/', array_keys($mediasTable)); foreach ($keys as $values) { if (!empty($mediaInUse) && isset($mediaInUse[$mediasTable[$values]['id']])) { $label = ' <sup><i class="fa fa-asterisk alizarin-color"></i></sup>'; $dataAttribInUse = 'data-inuse="1"'; break; } } $numberItems = $label . $this->numbersItems($entry->counts); if (true == $entry->childs && strlen($numberItems) > 0) { $dataAttribChilds = ' data-childs="yes"'; $icon = '<i class="fa fa-folder-open"></i>'; } else { $dataAttribChilds = ' data-childs="no"'; $icon = '<i class="fa fa-folder"></i>'; } $rowContent[] = '<input type="checkbox" value="' . $entry->filename . '" name="cb[]" data-type="dir" ' . $dataAttribInUse . $dataAttribChilds . '>'; $down = $entry->filename; if ($this->view->currentFolder) { $down = $this->view->currentFolder . DS . $entry->filename; } $rowContent[] = '<a href="' . self::MEDIA_DIR_PATH . '/' . str_replace(DS, $this->view->seperator, $down) . '">' . $icon . ' ' . $entry->filename . '</a>' . $numberItems; $rowContent[] = ' '; $rowContent[] = date("d.m.Y H:i:s", $entry->time); $btn = '<button class="tbl-info tiny" data-time="' . date("d.m.Y H:i:s", $entry->time) . '" '; $btn .= $dataAttribInUse . ' '; $btn .= 'data-ident="folder" '; if (true == $entry->childs && strlen($numberItems) > 0) { $btn .= 'data-childs="y" '; } else { $btn .= 'data-childs="n" '; } $btn .= 'data-originalname="' . $entry->filename . '" '; $btn .= 'data-crypt="' . $entry->filename . '" data-name="' . $entry->filename . '" '; $btn .= 'data-type="dir" type="button"><i class="fa fa-gear"></i></button>'; $rowContent[] = $btn; $tableFactory->setHtmlContent($rowContent); } } foreach ($entries as $entry) { if ('.' != $entry->filename && '..' != $entry->filename && 'file' == $entry->type && 'index.html' != $entry->filename) { $i++; $rowContent = array(); $label = ''; $pathname = \ContentinumComponents\Path\Clean::get($entry->pathname); $compareItem = str_replace($this->view->docroot, '', $pathname); if (isset($mediasTable[$compareItem]['id']) && isset($mediaInUse[$mediasTable[$compareItem]['id']])) { $label = ' <sup><i class="fa fa-asterisk alizarin-color"></i></sup>'; $dataAttribInUse = 'data-inuse="1"'; } else { $dataAttribInUse = 'data-inuse="0"'; } $dataIdent = ''; if (isset($mediasTable[$compareItem]) && isset($mediasTable[$compareItem]['id'])) { $dataIdent = 'data-ident="' . $mediasTable[$compareItem]['id'] . '" '; } $rowContent[] = '<input type="checkbox" value="' . $entry->filename . '" name="cb[]" data-type="file" ' . $dataIdent . $dataAttribInUse . '>'; switch ($entry->mimetype) { case 'application/zip': $icon = '<i class="fa fa-archive"></i> '; break; case 'image/jpeg': $icon = '<i class="fa fa-picture-o"></i> '; break; default: $icon = '<i class="fa fa-file"></i> '; } switch ($entry->extension) { case 'wmv': case 'mp4': case 'ogv': case 'webm': $icon = '<i class="fa-film"></i> '; break; case 'jpeg': case 'jpg': case 'png': case 'JPG': case 'JPEG': $icon = '<i class="fa fa-picture-o"></i> '; break; default: } $rowContent[] = $icon . $entry->filename . $label; $size = ''; if ($entry->width && $entry->height) { $size = '(' . $entry->width . ' x ' . $entry->height . ' px) '; } $filesize = $this->view->filesize($entry->size); $rowContent[] = $size . $filesize; $rowContent[] = date("d.m.Y H:i:s", $entry->time); $btn = '<button class="tbl-info tiny" data-time="' . date("d.m.Y H:i:s", $entry->time) . '" '; $btn .= $dataIdent; if (isset($mediasTable[$compareItem]) && isset($mediasTable[$compareItem]['mediaName'])) { $btn .= 'data-originalname="' . $mediasTable[$compareItem]['mediaName'] . '" '; } $btn .= $dataAttribInUse . ' '; $btn .= 'data-size="' . $filesize . '" '; $btn .= 'data-crypt="' . $entry->filename . '" data-name="' . $entry->filename . '" '; $btn .= 'data-link="' . $pathname . '" '; $btn .= 'data-childs="file" '; $btn .= 'data-download="' . $url . $entry->filename . '/' . $cddownload . '" '; $btn .= 'data-type="' . $entry->mimetype . '" type="button"><i class="fa fa-gear"></i></button>'; $rowContent[] = $btn; $tableFactory->setHtmlContent($rowContent); } } $html = $tableFactory->display(); $element = new \Zend\Form\Element\Hidden('current-folder'); $element->setAttribute('id', 'current-folder'); if ($this->view->currentFolder) { $element->setValue($this->view->currentFolder); } $html .= $this->view->formhidden($element); } return $html; }
public function multipleUpload($fs, $k, $fsTmpName) { $this->addInsert('mediaName', $fs['file']['name'][$k]); $this->setMediaName($fs['file']['name'][$k]); $this->addInsert('mediaType', $fs['file']['type'][$k]); $this->setMediaType($fs['file']['type'][$k]); $this->addInsert('mediaSizes', $fs['file']['size'][$k]); if (false === $this->moveUploadFile($fsTmpName, $this->buildTargetFile($this->buildTargetName($fs['file']['name'][$k])))) { throw new ErrorLogicModelException('Error upload file'); } else { if (in_array($this->ext, $this->imageExtensions)) { $imageFile = Clean::get($this->getTargetPathFileName()); $imgSize = new Size($imageFile); $imgSize->imgSize(); if ($this->resizeImage > 0) { $resize = new \ContentinumComponents\Images\CalculateResize($this->getResizeImage(), $imgSize->getWidth(), $imgSize->getHeight()); $nSize = $resize->getNewSize(); $nWidth = $nSize['width']; $nHeight = $nSize['height']; } else { $nWidth = $imgSize->getWidth(); $nHeight = $imgSize->getHeight(); } $newImage = @imagecreatetruecolor($nWidth, $nHeight); switch ($this->ext) { case 'JPG': case 'JPEG': case 'jpeg': case 'jpg': $jpegOptim = new \PHPImageOptim\Tools\Jpeg\JpegOptim(); $jpegOptim->setBinaryPath('/usr/bin/jpegoptim'); $jpegOptim->setOptimisationLevel(3); imagecopyresampled($newImage, imagecreatefromjpeg($imageFile), 0, 0, 0, 0, $nWidth, $nHeight, $imgSize->getWidth(), $imgSize->getHeight()); imagejpeg($newImage, $imageFile, $this->getImageQuality()); $optim = new \PHPImageOptim\PHPImageOptim(); $optim->setImage($imageFile); $optim->chainCommand($jpegOptim); $optim->optimise(); break; case "PNG": case "png": if ($this->resizeImage > 0) { imageAlphaBlending($newImage, false); imageSaveAlpha($newImage, true); imagecopyresampled($newImage, imageCreateFromPng($imageFile), 0, 0, 0, 0, $nWidth, $nHeight, $imgSize->getWidth(), $imgSize->getHeight()); imagepng($newImage, $imageFile); } $pngQuant = new \PHPImageOptim\Tools\Png\PngQuant(); $pngQuant->setBinaryPath('/usr/bin/pngquant'); $optim = new \PHPImageOptim\PHPImageOptim(); $optim->setImage($imageFile); $optim->chainCommand($pngQuant); $optim->optimise(); break; case "GIF": case "gif": if ($this->resizeImage > 0) { imageAlphaBlending($newImage, false); imageSaveAlpha($newImage, true); imagecopyresampled($newImage, imagecreatefromgif($imageFile), 0, 0, 0, 0, $nWidth, $nHeight, $imgSize->getWidth(), $imgSize->getHeight()); imagegif($newImage, $imageFile); } $gifsicle = new \PHPImageOptim\Tools\Gif\Gifsicle(); $gifsicle->setBinaryPath('/usr/bin/gifsicle'); $optim = new \PHPImageOptim\PHPImageOptim(); $optim->setImage($imageFile); $optim->chainCommand($gifsicle); $optim->optimise(); break; default: break; } if ($this->resizeImage > 0) { $this->addInsert('mediaDimensions', $nWidth . 'x' . $nHeight, true); } $this->addInsert('mediaSizes', filesize($imageFile), true); } if (in_array($this->ext, $this->imageExtensions)) { return 1; } } }
/** * Check if the file is present in the database and * whether they should be displayed this user * * @param string $filename * @param ContentinumComponents\Entity\AbstractEntity $entry * @param string $type * @param string $resource * @param number $usr * @return Ambigous <\Mcwork\Model\the, boolean, multitype:>|boolean */ protected function checkAccess($filename, $entry, $type, $resource, $usr, $files) { if (false === $type || $type == $entry->type) { $fileKey = str_replace($this->getDocumentRoot(), '', Clean::get($entry->pathname)); if (isset($files[$fileKey]) && 0 == $files[$fileKey]->parentMedia) { return $this->checkAcl($files[$fileKey], $resource, $usr); } else { return false; } } else { return false; } return false; }
/** * * @param unknown $path * @return Ambigous <string, mixed> */ public function cleanPath($path) { return \ContentinumComponents\Path\Clean::get($path); }