|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Axstrad library. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Dan Kempster <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* @copyright 2014-2015 Dan Kempster <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Axstrad\Component\Content\Traits; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Axstrad\Bundle\ContentBundle\Traits\CopyBasedIntroduction |
|
18
|
|
|
* |
|
19
|
|
|
* Property requirements |
|
20
|
|
|
* - $copy = null |
|
21
|
|
|
* - $introduction = null |
|
22
|
|
|
* - $copyIntroWordCount = <integer> |
|
23
|
|
|
* |
|
24
|
|
|
* @author Dan Kempster <[email protected]> |
|
25
|
|
|
* @license MIT |
|
26
|
|
|
* @package Axstrad/Content |
|
27
|
|
|
* @since 0.4 |
|
28
|
|
|
*/ |
|
29
|
|
|
trait CopyBasedIntroduction |
|
30
|
|
|
{ |
|
31
|
|
|
use Copy; |
|
32
|
|
|
use Introduction { |
|
33
|
|
|
Introduction::getIntroduction as private internalGetIntroduction; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Get introduction. |
|
39
|
|
|
* |
|
40
|
|
|
* If an introduction hasn't been set, the first {@see $copyIntroWordCount |
|
41
|
|
|
* X words} from the {@see getCopy copy} are returned. |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $ellipse |
|
44
|
|
|
* @return string |
|
45
|
|
|
*/ |
|
46
|
19 |
|
public function getIntroduction($ellipse = "...") |
|
47
|
|
|
{ |
|
48
|
19 |
|
$intro = $this->internalGetIntroduction(); |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
19 |
|
if ($intro === null && ($copy = $this->getCopy()) !== null) { |
|
51
|
3 |
|
$copy = trim(strip_tags($this->getCopy())); |
|
52
|
|
|
|
|
53
|
3 |
|
if ( ! empty($copy)) { |
|
54
|
3 |
|
$intro = $this->truncateWords($copy, $ellipse); |
|
55
|
3 |
|
} |
|
56
|
3 |
|
} |
|
57
|
|
|
|
|
58
|
19 |
|
return $intro; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param string $copy |
|
64
|
|
|
* @param string $ellipse |
|
65
|
|
|
* @return mixed |
|
66
|
|
|
*/ |
|
67
|
3 |
|
protected function truncateWords($copy, $ellipse) |
|
68
|
|
|
{ |
|
69
|
|
|
/** @noinspection PhpUndefinedFieldInspection */ |
|
70
|
3 |
|
$words = explode(" ", trim($copy), $this->copyIntroWordCount + 1); |
|
|
|
|
|
|
71
|
|
|
/** @noinspection PhpUndefinedFieldInspection */ |
|
72
|
3 |
|
if (count($words) > $this->copyIntroWordCount) { |
|
73
|
2 |
|
array_pop($words); |
|
74
|
2 |
|
$intro = trim(implode(" ", $words)).$ellipse; |
|
75
|
2 |
|
} |
|
76
|
|
|
else { |
|
77
|
1 |
|
$intro = $copy; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
3 |
|
return $intro; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.