enrolled
4 years ago
add-to-cart-edd.php
4 years ago
add-to-cart-woocommerce.php
4 years ago
add-to-cart.php
4 years ago
continue-lesson.php
4 years ago
course-benefits.php
4 years ago
course-content.php
4 years ago
course-enrolled-box.php
4 years ago
course-entry-box.php
4 years ago
course-requirements.php
4 years ago
course-target-audience.php
4 years ago
course-topics.php
4 years ago
instructors.php
4 years ago
lead-info.php
4 years ago
material-includes.php
4 years ago
q_and_a_turned_off.php
5 years ago
reviews-loop.php
4 years ago
reviews.php
4 years ago
social_share.php
4 years ago
tags.php
4 years ago
wc-price-html.php
4 years ago
course-content.php
144 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Template for displaying course content |
| 5 | * |
| 6 | * @since v.1.0.0 |
| 7 | * |
| 8 | * @author Themeum |
| 9 | * @url https://themeum.com |
| 10 | * |
| 11 | * @package TutorLMS/Templates |
| 12 | * @version 1.4.3 |
| 13 | */ |
| 14 | |
| 15 | global $post; |
| 16 | |
| 17 | function truncate($text, $length = 100, $ending = '...', $exact = true, $considerHtml = true) |
| 18 | { |
| 19 | if (is_array($ending)) { |
| 20 | extract($ending); |
| 21 | } |
| 22 | if ($considerHtml) { |
| 23 | if (mb_strlen(preg_replace('/<.*?>/', '', $text)) <= $length) { |
| 24 | return $text; |
| 25 | } |
| 26 | $totalLength = mb_strlen($ending); |
| 27 | $openTags = array(); |
| 28 | $truncate = ''; |
| 29 | preg_match_all('/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $text, $tags, PREG_SET_ORDER); |
| 30 | foreach ($tags as $tag) { |
| 31 | if (!preg_match('/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/s', $tag[2])) { |
| 32 | if (preg_match('/<[\w]+[^>]*>/s', $tag[0])) { |
| 33 | array_unshift($openTags, $tag[2]); |
| 34 | } else if (preg_match('/<\/([\w]+)[^>]*>/s', $tag[0], $closeTag)) { |
| 35 | $pos = array_search($closeTag[1], $openTags); |
| 36 | if ($pos !== false) { |
| 37 | array_splice($openTags, $pos, 1); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | $truncate .= $tag[1]; |
| 42 | |
| 43 | $contentLength = mb_strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', ' ', $tag[3])); |
| 44 | if ($contentLength + $totalLength > $length) { |
| 45 | $left = $length - $totalLength; |
| 46 | $entitiesLength = 0; |
| 47 | if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', $tag[3], $entities, PREG_OFFSET_CAPTURE)) { |
| 48 | foreach ($entities[0] as $entity) { |
| 49 | if ($entity[1] + 1 - $entitiesLength <= $left) { |
| 50 | $left--; |
| 51 | $entitiesLength += mb_strlen($entity[0]); |
| 52 | } else { |
| 53 | break; |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | $truncate .= mb_substr($tag[3], 0 , $left + $entitiesLength); |
| 59 | break; |
| 60 | } else { |
| 61 | $truncate .= $tag[3]; |
| 62 | $totalLength += $contentLength; |
| 63 | } |
| 64 | if ($totalLength >= $length) { |
| 65 | break; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | } else { |
| 70 | if (mb_strlen($text) <= $length) { |
| 71 | return $text; |
| 72 | } else { |
| 73 | $truncate = mb_substr($text, 0, $length - strlen($ending)); |
| 74 | } |
| 75 | } |
| 76 | if (!$exact) { |
| 77 | $spacepos = mb_strrpos($truncate, ' '); |
| 78 | if (isset($spacepos)) { |
| 79 | if ($considerHtml) { |
| 80 | $bits = mb_substr($truncate, $spacepos); |
| 81 | preg_match_all('/<\/([a-z]+)>/', $bits, $droppedTags, PREG_SET_ORDER); |
| 82 | if (!empty($droppedTags)) { |
| 83 | foreach ($droppedTags as $closingTag) { |
| 84 | if (!in_array($closingTag[1], $openTags)) { |
| 85 | array_unshift($openTags, $closingTag[1]); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | $truncate = mb_substr($truncate, 0, $spacepos); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | $truncate .= $ending; |
| 95 | |
| 96 | if ($considerHtml) { |
| 97 | foreach ($openTags as $tag) { |
| 98 | $truncate .= '</'.$tag.'>'; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | return $truncate; |
| 103 | } |
| 104 | |
| 105 | |
| 106 | |
| 107 | do_action('tutor_course/single/before/content'); |
| 108 | |
| 109 | if (tutor_utils()->get_option('enable_course_about', true, true)) { |
| 110 | $string = get_the_content(); |
| 111 | $limit = 500; |
| 112 | $has_readmore = false; |
| 113 | if (strlen($string) > $limit) { |
| 114 | $has_readmore = true; |
| 115 | // truncate string |
| 116 | $first_part = truncate($string, $limit); |
| 117 | } |
| 118 | ?> |
| 119 | <div class='tab-item-content <?php echo $has_readmore ? 'tutor-has-showmore' : '' ?>'> |
| 120 | <div class='tutor-showmore-content'> |
| 121 | <div class="text-medium-h6 tutor-color-black"> |
| 122 | <?php _e('About Course', 'tutor'); ?> |
| 123 | </div> |
| 124 | <div class="text-regular-body tutor-color-black-60 tutor-mt-12"> |
| 125 | <?php |
| 126 | if ($has_readmore) { |
| 127 | echo "<div class='showmore-short-text'>{$first_part}</div>"; |
| 128 | echo "<div class='showmore-text'>{$string}</div>"; |
| 129 | } else { |
| 130 | echo $string; |
| 131 | } |
| 132 | ?> |
| 133 | </div> |
| 134 | </div> |
| 135 | <?php |
| 136 | if ($has_readmore) : |
| 137 | echo '<div class="tutor-showmore-btn tutor-mt-24" data-showmore="true"><button class="tutor-btn tutor-btn-icon tutor-btn-disable-outline tutor-btn-ghost tutor-no-hover tutor-btn-md btn-showmore"><span class="btn-icon tutor-icon-plus-filled tutor-color-design-brand"></span><span class="tutor-color-black-60">Show More</span></button><button class="tutor-btn tutor-btn-icon tutor-btn-disable-outline tutor-btn-ghost tutor-no-hover tutor-btn-md btn-showless"><span class="btn-icon tutor-icon-minus-filled tutor-color-design-brand"></span><span class="tutor-color-black-60">Show Less</span></button></div>'; |
| 138 | endif; |
| 139 | ?> |
| 140 | </div> |
| 141 | <?php |
| 142 | } |
| 143 | |
| 144 | do_action('tutor_course/single/after/content'); ?> |