Esempio n. 1
0
 /**
  * Link to a help book page
  *
  * @param  array       $params
  * @param  string      $content
  * @param  Smarty      $smarty
  * @param  boolean     $repeat
  * @return string|null
  * @throws ParamRequiredError
  */
 public static function block_page($params, $content, &$smarty, &$repeat)
 {
     if ($repeat) {
         return null;
     }
     $name = isset($params['name']) && $params['name'] ? $params['name'] : null;
     if (empty($name)) {
         throw new ParamRequiredError('name');
     }
     $book_name = isset($params['book']) ? $params['book'] : null;
     $section = isset($params['section']) && $params['section'] ? '#s-' . Shade::slug($params['section']) : null;
     if (empty($book_name)) {
         if (self::$current_element instanceof Book) {
             $book_name = self::$current_element->getShortName();
         } elseif (self::$current_element instanceof BookPage) {
             $book_name = self::$current_element->getBookName();
         }
     }
     $book = $book_name ? self::getCurrentProject()->getBook($book_name) : null;
     if ($book instanceof Book) {
         $page = $book->getPage($name);
         if ($page instanceof BookPage) {
             $params['href'] = self::getBookPageUrl($book->getShortName(), $page->getShortName()) . $section;
             if (empty($params['class'])) {
                 $params['class'] = 'link_to_book_page';
             } else {
                 $params['class'] .= ' link_to_book_page';
             }
             $params['data-page-name'] = $page->getShortName();
             $params['data-book-name'] = $book->getShortName();
             return Shade::htmlTag('a', $params, $content);
         } else {
             $development_error_message = 'Page not found';
         }
     } else {
         $development_error_message = 'Book not found';
     }
     if (Shade::isTesting() && isset($development_error_message)) {
         return '<span style="color: red; border-bottom: 1px dotted red; cursor: help;" title="Invalid page link: ' . Shade::clean($development_error_message) . '">' . $content . '</span>';
     } else {
         return $content;
     }
 }
Esempio n. 2
0
 /**
  * @param string $locale
  * @return Book[]
  */
 function getBooks($locale = null)
 {
     if (empty($locale)) {
         $locale = $this->project->getDefaultLocale();
     }
     $dirs = call_user_func($this->finders['findBookDirs'], $this->getBooksPath($locale), $locale);
     $result = [];
     foreach ($dirs as $dir) {
         $book = new Book($this->project, $dir);
         if ($book->isLoaded()) {
             $result[$book->getShortName()] = $book;
         }
     }
     if (count($result)) {
         uasort($result, function (Book $a, Book $b) {
             if ($a->getPosition() == $b->getPosition()) {
                 return 0;
             } else {
                 return $a->getPosition() > $b->getPosition() ? 1 : -1;
             }
         });
     }
     return $result;
 }
Esempio n. 3
0
 /**
  * @param Project         $project
  * @param Book            $book
  * @param string          $target_path
  * @param string          $locale
  * @param OutputInterface $output
  */
 private function copyBookImages(Project $project, Book $book, $target_path, $locale, OutputInterface $output)
 {
     $book_path = $book->getPath();
     $book_name = $book->getShortName();
     if (is_dir("{$book_path}/images")) {
         $book_images_path = $locale === $project->getDefaultLocale() ? "{$target_path}/assets/images/books/{$book_name}" : "{$target_path}/assets/images/{$locale}/books/{$book_name}";
         Shade::copyDir("{$book_path}/images", $book_images_path, null, function ($path) use(&$output) {
             $output->writeln("{$path} copied");
         });
     }
 }
Esempio n. 4
0
 /**
  * Construct and load help element
  *
  * @param string      $module
  * @param Book|string $book
  * @param string      $path
  * @param bool        $load
  */
 public function __construct($module, $book, $path, $load = true)
 {
     $this->book_name = $book instanceof Book ? $book->getShortName() : $book;
     parent::__construct($module, $path, $load);
 }