Пример #1
0
 /**
  * Test {@link strmaxwords()}
  */
 function test_strmaxwords()
 {
     $this->assertEqual(strmaxwords('foo bar', 2), 'foo bar');
     $this->assertEqual(strmaxwords('foo  bar', 2), 'foo  bar');
     $this->assertEqual(strmaxwords('foo  bar  ', 2), 'foo  bar  ');
     $this->assertEqual(strmaxwords('  foo  bar  ', 2), '  foo  bar  ');
     $this->assertEqual(strmaxwords('  <img />foo  bar  ', 2), '  <img />foo  bar  ');
     $this->assertEqual(strmaxwords('  <img />foo  bar  ', 1), '  <img />foo  &hellip;');
 }
 /**
  * Support function for above
  *
  * @param Item
  * @param boolean set to true if Items are displayed grouped by chapters, false otherwise
  * @return boolean TRUE - if content is displayed
  */
 function disp_contents(&$disp_Item, $chapter_mode = false)
 {
     global $disp, $Item;
     // Set this var to TRUE when some content(title, excerpt or picture) is displayed
     $content_is_displayed = false;
     // Set a 'group_' prefix for param keys if the items are grouped by chapters
     $disp_param_prefix = $chapter_mode ? 'group_' : '';
     // Is this the current item?
     if (!empty($Item) && $disp_Item->ID == $Item->ID) {
         // The current page is currently displaying the Item this link is pointing to
         // Let's display it as selected
         $link_class = $this->disp_params['link_selected_class'];
     } else {
         // Default link class
         $link_class = $this->disp_params['link_default_class'];
     }
     if ($link_class == $this->disp_params['link_selected_class']) {
         echo $this->disp_params[$disp_param_prefix . 'item_selected_start'];
     } else {
         echo $this->disp_params[$disp_param_prefix . 'item_start'];
     }
     if ($this->disp_params['disp_first_image'] == 'special') {
         // If we should display first picture before title then get "Cover" images and order them at top:
         $cover_image_params = array('restrict_to_image_position' => 'cover,teaser,teaserperm,teaserlink,aftermore,inline', 'links_sql_select' => ', CASE ' . 'WHEN link_position = "cover"      THEN "1" ' . 'WHEN link_position = "teaser"     THEN "2" ' . 'WHEN link_position = "teaserperm" THEN "3" ' . 'WHEN link_position = "teaserlink" THEN "4" ' . 'WHEN link_position = "aftermore"  THEN "5" ' . 'WHEN link_position = "inline"     THEN "6" ' . 'END AS position_order', 'links_sql_orderby' => 'position_order, link_order');
     } else {
         $cover_image_params = array();
     }
     if ($this->disp_params['attached_pics'] != 'none' && $this->disp_params['disp_first_image'] == 'special') {
         // We want to display first image separately before the title
         // Display before/after even if there is no image so we can use it as a placeholder.
         $this->disp_images(array_merge(array('before' => $this->disp_params['item_first_image_before'], 'after' => $this->disp_params['item_first_image_after'], 'placeholder' => $this->disp_params['item_first_image_placeholder'], 'Item' => $disp_Item, 'start' => 1, 'limit' => 1), $cover_image_params), $content_is_displayed);
     }
     if ($this->disp_params['disp_title']) {
         // Display title
         $disp_Item->title(array('before' => $this->disp_params['disp_only_title'] ? $this->disp_params['item_title_single_before'] : $this->disp_params['item_title_before'], 'after' => $this->disp_params['disp_only_title'] ? $this->disp_params['item_title_single_after'] : $this->disp_params['item_title_after'], 'link_type' => $this->disp_params['item_title_link_type'], 'link_class' => $link_class));
         $content_is_displayed = true;
     }
     if ($this->disp_params['disp_excerpt']) {
         // Display excerpt
         $excerpt = $disp_Item->dget('excerpt', 'htmlbody');
         if (!empty($excerpt)) {
             // Note: Excerpts are plain text -- no html (at least for now)
             echo $this->disp_params['item_excerpt_before'] . $excerpt . $this->disp_params['item_excerpt_after'];
             $content_is_displayed = true;
         }
     }
     if ($this->disp_params['disp_teaser']) {
         // we want to show some or all of the post content
         $content = $disp_Item->get_content_teaser(1, false, 'htmlbody');
         if ($words = $this->disp_params['disp_teaser_maxwords']) {
             // limit number of words
             $content = strmaxwords($content, $words, array('continued_link' => $disp_Item->get_permanent_url(), 'continued_text' => '&hellip;'));
         }
         echo $this->disp_params['item_content_before'] . $content . $this->disp_params['item_content_after'];
         $content_is_displayed = true;
         /* fp> does that really make sense?
         				we're no longer in a linkblog/linkroll use case here, are we?
         			$disp_Item->more_link( array(
         					'before'    => '',
         					'after'     => '',
         					'link_text' => T_('more').' &raquo;',
         				) );
         				*/
     }
     if ($this->disp_params['attached_pics'] == 'all' || $this->disp_params['attached_pics'] == 'first' && $this->disp_params['disp_first_image'] == 'normal') {
         // Display attached pictures
         if ($this->disp_params['attached_pics'] == 'first') {
             // Display only one first image:
             $picture_limit = 1;
         } else {
             $max_pics = intval($this->disp_params['max_pics']);
             if ($max_pics > 0) {
                 // Limit images after title with widget param:
                 $picture_limit = $max_pics;
                 if ($this->disp_params['disp_first_image'] == 'special') {
                     // If first image is already displayed before title, then we should skip this first to get next images:
                     $picture_limit += 1;
                 }
             } else {
                 // Don't limit the images:
                 $picture_limit = 1000;
             }
         }
         $this->disp_images(array_merge(array('before' => $this->disp_params['item_images_before'], 'after' => $this->disp_params['item_images_after'], 'Item' => $disp_Item, 'start' => $this->disp_params['disp_first_image'] == 'special' ? 2 : 1, 'limit' => $picture_limit), $cover_image_params), $content_is_displayed);
     }
     if ($link_class == $this->disp_params['link_selected_class']) {
         echo $this->disp_params[$disp_param_prefix . 'item_selected_end'];
     } else {
         echo $this->disp_params[$disp_param_prefix . 'item_end'];
     }
     return $content_is_displayed;
 }
Пример #3
0
 /**
  * Support function for above
  *
  * @param Item
  * @return boolean TRUE - if content is displayed
  */
 function disp_contents(&$disp_Item)
 {
     // Check if only the title was displayed before the first picture
     $displayed_only_title = false;
     // Set this var to TRUE when some content(title, excerpt or picture) is displayed
     $content_is_displayed = false;
     echo $this->disp_params['item_start'];
     // Is this the current item?
     global $disp, $Item;
     if (!empty($Item) && $disp_Item->ID == $Item->ID) {
         // The current page is currently displaying the Item this link is pointing to
         // Let's display it as selected
         $link_class = $this->disp_params['link_selected_class'];
     } else {
         // Default link class
         $link_class = $this->disp_params['link_default_class'];
     }
     if ($this->disp_params['disp_title']) {
         // Display title
         $disp_Item->title(array('link_type' => $this->disp_params['item_title_link_type'], 'link_class' => $link_class));
         $displayed_only_title = true;
         $content_is_displayed = true;
     }
     if ($this->disp_params['disp_excerpt']) {
         $excerpt = $disp_Item->dget('excerpt', 'htmlbody');
         if (!empty($excerpt)) {
             // Note: Excerpts are plain text -- no html (at least for now)
             echo '<div class="item_excerpt">' . $excerpt . '</div>';
             $displayed_only_title = false;
             $content_is_displayed = true;
         }
     }
     if ($this->disp_params['disp_teaser']) {
         // we want to show some or all of the post content
         $content = $disp_Item->get_content_teaser(1, false, 'htmlbody');
         if ($words = $this->disp_params['disp_teaser_maxwords']) {
             // limit number of words
             $content = strmaxwords($content, $words, array('continued_link' => $disp_Item->get_permanent_url(), 'continued_text' => '&hellip;'));
         }
         echo '<div class="item_content">' . $content . '</div>';
         $displayed_only_title = false;
         $content_is_displayed = true;
         /* fp> does that really make sense?
         				we're no longer in a linkblog/linkroll use case here, are we?
         			$disp_Item->more_link( array(
         					'before'    => '',
         					'after'     => '',
         					'link_text' => T_('more').' &raquo;',
         				) );
         				*/
     }
     if (in_array($this->disp_params['attached_pics'], array('first', 'all'))) {
         // Display attached pictures
         $picture_limit = $this->disp_params['attached_pics'] == 'first' ? 1 : 1000;
         $LinkOnwer = new LinkItem($disp_Item);
         if ($FileList = $LinkOnwer->get_attachment_FileList($picture_limit)) {
             // Get list of attached files
             while ($File =& $FileList->get_next()) {
                 if ($File->is_image()) {
                     // Get only images
                     switch ($this->disp_params['item_pic_link_type']) {
                         // Set url for picture link
                         case 'none':
                             $pic_url = NULL;
                             break;
                         case 'permalink':
                             $pic_url = $disp_Item->get_permanent_url();
                             break;
                         case 'linkto_url':
                             $pic_url = $disp_Item->url;
                             break;
                         case 'auto':
                         default:
                             $pic_url = empty($disp_Item->url) ? $disp_Item->get_permanent_url() : $disp_Item->url;
                             break;
                     }
                     if ($displayed_only_title) {
                         // If only the title was displayed - Insert new line before the first picture
                         echo '<br />';
                         $displayed_only_title = false;
                     }
                     // Print attached picture
                     echo $File->get_tag('', '', '', '', $this->disp_params['thumb_size'], $pic_url);
                     $content_is_displayed = true;
                 }
             }
         }
     }
     echo $this->disp_params['item_end'];
     return $content_is_displayed;
 }