Ejemplo n.º 1
0
 public function edit($itemID)
 {
     parent::edit($itemID);
     $tags = $this->db->selectAll('Tag', 'ORDER BY Value');
     if (is_null($tags)) {
         throw new DatabaseException('Error loading tags.', 500);
     }
     $records = $this->db->fetchAll('SELECT TagID FROM BlogPost_Tag WHERE BlogPostID = :BlogPostID', array('BlogPostID' => $this->view->getData('BlogPost')->ID));
     if ($records === false) {
         throw new DatabaseException('Failed to retrieve blog post tag IDs.', 500);
     }
     $itemTagIDs = array();
     foreach ($records as $record) {
         $itemTagIDs[] = $record['TagID'];
     }
     try {
         require_once \CWA\LIB_PATH . 'cwa/io/FileManager.php';
         $fileManager = new \CWA\IO\FileManager("../public/images{$this->pathInURL}");
         $slug = $this->view->getData('BlogPost')->Slug;
         $images = $fileManager->getDirectoryListing("{$slug['0']}/{$slug}")->Files;
     } catch (Exception $ex) {
         $images = array();
     }
     $this->view->setData(array('BlogPostTagIDs' => $itemTagIDs, 'Images' => $images, 'Tags' => $tags));
 }
Ejemplo n.º 2
0
 public function code($params = null)
 {
     if (!is_array($params)) {
         // This is a GET for a dir or file. -- cwells
         if (is_null($params)) {
             $params = '';
             $path = '.';
         } else {
             $path = $params;
         }
         require_once \CWA\LIB_PATH . 'cwa/io/FileManager.php';
         $fileManager = new \CWA\IO\FileManager('.');
         if (!$fileManager->exists($params)) {
             throw new InvalidArgumentException('The specified file does not exist within this application.', 400);
         } else {
             if ($fileManager->isFile($params)) {
                 $this->loadView('code-file');
                 $this->view->setData(array('FileContents' => file_get_contents($path), 'FilePath' => $path, 'ReadOnly' => !is_writable($path)));
             } else {
                 if ($fileManager->isDirectory($params)) {
                     $this->loadView('code-dir');
                     $this->view->setData(array('DirectoryPath' => $path, 'Directory' => $fileManager->getDirectoryListing($params), 'PathPrefix' => "{$this->pathInURL}/code/" . (empty($params) ? '' : "{$params}/")));
                 } else {
                     throw new InvalidArgumentException('You must specify a valid file or directory path.', 400);
                 }
             }
         }
     } else {
         // This is a POST with the contents of a file. -- cwells
         if (!isset($params['file-path']) || empty($params['file-path'])) {
             throw new InvalidArgumentException('You must specify a file path.', 400);
         } else {
             if (strpos(realpath($params['file-path']), realpath('.')) !== 0) {
                 throw new InvalidArgumentException('The specified file does not exist within this application.', 400);
             } else {
                 if (!is_file($params['file-path'])) {
                     throw new InvalidArgumentException('You must specify a valid file path.', 400);
                 } else {
                     if (file_put_contents($params['file-path'], utf8_encode($params['file-contents'])) === false) {
                         $this->loadView('code-file');
                         $this->view->setStatus('Failed to update the specified file.', 500);
                         $this->view->setData(array('FileContents' => $params['file-contents'], 'FilePath' => $params['file-path']));
                     } else {
                         $this->loadView('code-file-save');
                         $this->view->setData('FilePath', $params['file-path']);
                     }
                 }
             }
         }
     }
 }