コード例 #1
0
ファイル: SmartyHelpers.php プロジェクト: activecollab/shade
 /**
  * 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;
     }
 }