public static function registerPath($path) { if (!sy_path_is_absolute($path)) { $path = SY_DIR . '/' . $path; } array_unshift(self::$path, $path); }
/** * (non-PHPdoc) * @see RenderableInterface::getLayout() */ public function getLayout() { $filename = empty($this->layout) ? $this->getLayoutFilename() : $this->layout; if (is_null($filename) && \Simplify::request()->ajax() || $filename === false) { $layout = false; } elseif (sy_path_is_absolute($filename)) { $layout = sy_fix_extension($filename, 'html'); if (!file_exists($layout)) { throw new \Simplify\ViewException("Layout not found: file not found: <b>{$layout}</b>"); } } else { $layout = $filename; } return $layout; }
/** * (non-PHPdoc) * @see \Simplify\ViewInterface::render() */ public function render(\Simplify\RenderableInterface $object = null) { if (empty($object)) { $object = $this->object; } $template = $object->getTemplate(); if ($template === false) { return ''; } if (sy_path_is_absolute($template)) { if (!file_exists($template)) { throw new \Exception("Template not found: <b>{$template}</b>"); } } else { $filename = $template; $path = $object->getTemplatesPath(); $template = array(); do { $template[] = array_shift($path) . '/' . $filename . '.php'; } while (count($path) && !file_exists(end($template))); if (!file_exists(end($template))) { throw new \Exception("Template not found: <b>{$filename}</b><br/><br/>Using path:<br/><b>" . implode('</b><br/><b>', $template) . "</b>"); } $template = end($template); } $output = $this->internalRender($object, $template); $layout = $object->getLayout(); if ($layout !== false) { if (empty($layout)) { $layout = $this->getLayout(); } $view = new self(); $view->copyAll($object); $view->copyAll($this); $view->set('layout_content', $output); $view->setTemplate($layout); $view->setTemplatesPath($object->getLayoutsPath()); $view->setLayout(false); $output = $view->render(); } return $output; }
public static function loadAsset($asset, $group = null, $priority = 0, $minify = true) { if (empty($asset)) { throw new \Exception("Empty asset name"); } if (empty(self::$assets[$asset])) { $paths = \Simplify::config()->get('app:assets:path'); do { $path = array_shift($paths); $dir = \Simplify::config()->resolveReferences((sy_path_is_absolute($path) ? '' : '{www:dir}') . $path); } while (!empty($paths) && !file_exists($dir . $asset)); if (!file_exists($dir . $asset)) { throw new \Exception("Asset file not found: {$asset}. Search path: " . implode(';', \Simplify::config()->get('app:assets:path'))); } $url = \Simplify::config()->resolveReferences('{www:url}' . $path); self::$assets[$asset] = array('asset' => $asset, 'dir' => $dir . $asset, 'url' => $url . $asset, 'group' => $group, 'priority' => $priority, 'minify' => $minify); } return $asset; }
/** * Tries to delete the image file and all related cached thumbnails * * @param array $data form row */ protected function onDelete(&$data) { if ($this->deleteFile) { foreach ($this->fields as $field) { $file = $data[$field[self::FIELD_FILENAME]]; if (!empty($file)) { $this->getThumbComponent($file)->cleanCached(); if (!sy_path_is_absolute($file)) { $file = \Simplify::config()->get('www:dir') . $file; } if (file_exists($file)) { $this->getThumbComponent($file)->cleanCached(); @unlink($file); } } } } }
/** * * @throws UploadException */ protected function moveFile() { $path = $this->getUploadPath(); if (!sy_path_is_absolute($path)) { $path = \Simplify::config()->get('www:dir') . $path; } $filename = empty($this->filename) ? $this->file['name'] : $this->filename; $subpath = ''; if ($this->useDateBasedPath) { $subpath = $this->findDateBasedPath($path); } $subpath .= '/'; $dir = sy_fix_path($path . '/' . $subpath) . '/'; if (!is_dir($dir)) { if (!mkdir($dir, 0777, true)) { $this->error = __('Could not create upload path: <b>' . sy_fix_path($path . $subpath) . '</b>'); throw new \Simplify\UploadException($this->error); } } if (!is_writable($dir)) { $this->error = __('Upload path does not exist or is not writable: <b>' . sy_fix_path($path . $subpath) . '</b>'); throw new \Simplify\UploadException($this->error); } if ($this->hashFilename) { $filename = $this->genHashFilename($dir, '/' . $filename); } elseif ($this->replaceIfExists === false) { $filename = $this->findUniqueFilename($dir, '/' . $filename); } if (!@move_uploaded_file($this->file['tmp_name'], $dir . $filename)) { $this->error = __('Could not move uploaded file'); throw new \Simplify\UploadException($this->error); } chmod($dir . $filename, 0644); $this->uploadedPath = $subpath . $filename; }
protected function makeAbsolute($file) { if (!\sy_path_is_absolute($file)) { $file = $this->baseDir . $file; } return $file; }
/** * Tries to delete the image file and all related cached thumbnails * * @param array $data form row */ protected function onDelete(&$data) { if ($this->deleteFile) { $file = sy_get_param($data, $this->getFieldName()); if (!empty($file)) { if (!sy_path_is_absolute($file)) { $file = \Simplify::config()->get('www:dir') . $file; } if (file_exists($file)) { @unlink($file); } } } }