示例#1
0
 protected function getNode()
 {
     if (!isset($this->node)) {
         $this->node = \Concrete\Core\Tree\Node\Node::getByID(Loader::helper('security')->sanitizeInt($_REQUEST['treeNodeID']));
     }
     return $this->node;
 }
示例#2
0
 /**
  * Returns a path to the specified item, resized and/or cropped to meet max width and height. $obj can either be
  * a string (path) or a file object.
  * Returns an object with the following properties: src, width, height
  * @param mixed $obj
  * @param int $maxWidth
  * @param int $maxHeight
  * @param bool $crop
  */
 public function getThumbnail($obj, $maxWidth, $maxHeight, $crop = false)
 {
     $fID = false;
     $fh = Loader::helper('file');
     if ($obj instanceof File) {
         try {
             $fr = $obj->getFileResource();
             $fID = $obj->getFileID();
             $filename = md5(implode(':', array($fID, $maxWidth, $maxHeight, $crop, $fr->getTimestamp()))) . '.' . $fh->getExtension($fr->getPath());
         } catch (\Exception $e) {
             $filename = '';
         }
     } else {
         $filename = md5(implode(':', array($obj, $maxWidth, $maxHeight, $crop, filemtime($obj)))) . '.' . $fh->getExtension($obj);
     }
     if (!file_exists(Config::get('concrete.cache.directory') . '/' . $filename)) {
         if ($obj instanceof File) {
             $image = \Image::load($fr->read());
         } else {
             $image = \Image::open($obj);
         }
         // create image there
         $this->create($image, Config::get('concrete.cache.directory') . '/' . $filename, $maxWidth, $maxHeight, $crop);
     }
     $src = REL_DIR_FILES_CACHE . '/' . $filename;
     $abspath = Config::get('concrete.cache.directory') . '/' . $filename;
     $thumb = new \stdClass();
     if (isset($abspath) && file_exists($abspath)) {
         $thumb->src = $src;
         $dimensions = getimagesize($abspath);
         $thumb->width = $dimensions[0];
         $thumb->height = $dimensions[1];
         return $thumb;
     }
 }
示例#3
0
 protected function getNodes()
 {
     $sourceNodes = array();
     if (!isset($this->nodes)) {
         if (isset($_REQUEST['sourceTreeNodeID'])) {
             $sourceNode = Node::getByID(Loader::helper('security')->sanitizeInt($_REQUEST['sourceTreeNodeID']));
             if (is_object($sourceNode)) {
                 $sourceNodes[] = $sourceNode;
             }
         } else {
             if (isset($_REQUEST['sourceTreeNodeIDs'])) {
                 foreach ($_REQUEST['sourceTreeNodeIDs'] as $sourceTreeNodeID) {
                     $sourceNode = Node::getByID(Loader::helper('security')->sanitizeInt($sourceTreeNodeID));
                     if (is_object($sourceNode)) {
                         $sourceNodes[] = $sourceNode;
                     }
                 }
             }
         }
         $destNode = Node::getByID(Loader::helper('security')->sanitizeInt($_REQUEST['treeNodeParentID']));
         if (is_array($sourceNodes) && count($sourceNodes) && is_object($destNode)) {
             $this->nodes = array($sourceNodes, $destNode);
         } else {
             $this->nodes = false;
         }
     }
     return $this->nodes;
 }
示例#4
0
 public function clear()
 {
     if (Loader::helper('validation/token')->validate('clear')) {
         $l = new Logger();
         $l->clearQueryLog();
         $this->redirect('/dashboard/system/optimization/query_log', 'cleared');
     }
 }
 protected function getBaseURL($url = false)
 {
     $uh = Loader::helper('url');
     $args = array($this->queryStringPagingVariable => '%pageNum%');
     if (count($this->additionalVars) > 0) {
         foreach ($this->additionalVars as $k => $v) {
             $args[$k] = $v;
         }
     }
     $url = $uh->setVariable($args, false, $url);
     return $url;
 }
示例#6
0
 public function csv()
 {
     if (!Loader::helper('validation/token')->validate('csv')) {
         $this->redirect('/dashboard/system/optimization/query_log');
     } else {
         $l = new LogList();
         $entries = $l->get(0);
         $fileName = "Database Query Log Results";
         header("Content-Type: text/csv");
         header("Cache-control: private");
         header("Pragma: public");
         $date = date('Ymd');
         header("Content-Disposition: attachment; filename=" . $fileName . "_form_data_{$date}.csv");
         $fp = fopen('php://output', 'w');
         // write the columns
         $row = array(t('Times Run'), t('Query'));
         fputcsv($fp, $row);
         foreach ($entries as $ent) {
             fputcsv($fp, array($ent['queryTotal'], $ent['query']));
         }
         fclose($fp);
         die;
     }
 }
示例#7
0
 public function filterByNumberOfChildren($num, $comparison = '>')
 {
     if (!Loader::helper('validation/numbers')->integer($num)) {
         $num = 0;
     }
     if ($this->includeAliases) {
         $this->filter(false, '(p1.cChildren ' . $comparison . ' ' . $num . ' or p2.cChildren ' . $comparison . ' ' . $num . ')');
     } else {
         $this->filter('p1.cChildren', $num, $comparison);
     }
 }
示例#8
0
 public function getPagination($url = false, $additionalVars = array())
 {
     $pagination = Loader::helper('pagination');
     if ($this->currentPage == false) {
         $this->setCurrentPage();
     }
     if (count($additionalVars) > 0) {
         $pagination->setAdditionalQueryStringVariables($additionalVars);
     }
     if (!isset($this->queryStringPagingVariable)) {
         $this->loadQueryStringPagingVariable();
     }
     $pagination->queryStringPagingVariable = $this->queryStringPagingVariable;
     $pagination->init($this->currentPage, $this->getTotal(), $url, $this->itemsPerPage);
     return $pagination;
 }
示例#9
0
 public static function exportArchive($archive)
 {
     $fl = new FileList();
     $files = $fl->get();
     $fh = Loader::helper('file');
     $filename = $fh->getTemporaryDirectory() . '/' . $archive . '.zip';
     if (count($files) > 0) {
         try {
             $zip = new ZipArchive();
             $res = $zip->open($filename, ZipArchive::CREATE);
             if ($res === TRUE) {
                 foreach ($files as $f) {
                     $zip->addFromString($f->getFilename(), $f->getFileContents());
                 }
                 $zip->close();
                 $fh->forceDownload($filename);
             } else {
                 throw new Exception(t('Could not open with ZipArchive::CREATE'));
             }
         } catch (Exception $e) {
             throw new Exception(t('Failed to create zip file as "%s": %s', $filename, $e->getMessage()));
         }
     }
 }
示例#10
0
 public function __call($nm, $a)
 {
     if (substr($nm, 0, 8) == 'filterBy') {
         $txt = Loader::helper('text');
         $attrib = $txt->uncamelcase(substr($nm, 8));
         if (count($a) == 2) {
             $this->filterByAttribute($attrib, $a[0], $a[1]);
         } else {
             $this->filterByAttribute($attrib, $a[0]);
         }
     }
 }