PluginProbe
Vimeography: Vimeo Video Gallery WordPress Plugin / 0.7
Vimeography: Vimeo Video Gallery WordPress Plugin v0.7
2.4.9 2.4.8 trunk 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 0.6 0.6.1 0.6.2 0.6.3 0.6.4 0.6.5 0.6.6 0.6.7 0.6.8 0.6.8.1 0.6.9 0.6.9.1 0.6.9.2 0.7 0.8 All 103 releases
vimeography / lib / helpers.php

helpers.php in Vimeography: Vimeo Video Gallery WordPress Plugin 0.7, at lib/helpers.php

93 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Vimeography_Helpers
4 {
5 /**
6 * Converts the video's duration in seconds to the MM:SS format.
7 *
8 * @access public
9 * @param mixed $seconds
10 * @return void
11 */
12 public function seconds_to_minutes($seconds)
13 {
14 /// get minutes
15 $minResult = floor($seconds/60);
16
17 /// if minutes is between 0-9, add a "0" --> 00-09
18 if($minResult < 10){$minResult = 0 . $minResult;}
19
20 /// get sec
21 $secResult = ($seconds/60 - $minResult)*60;
22
23 /// if secondes is between 0-9, add a "0" --> 00-09
24 if($secResult < 10){$secResult = 0 . $secResult;}
25
26 /// return result
27 return $minResult . ":" . $secResult;
28 }
29
30 /**
31 * Truncate strings to defined limit.
32 * Original PHP code by Chirp Internet: www.chirp.com.au
33 *
34 * @access public
35 * @param mixed $string
36 * @param mixed $limit
37 * @param string $break (default: " ")
38 * @param string $pad (default: "...")
39 * @return void
40 */
41 public function truncate($string, $limit, $break = ' ', $pad = '...')
42 {
43 // return with no change if string is shorter than $limit
44 if (strlen($string) <= $limit)
45 return $string;
46
47 $string = substr($string, 0, $limit);
48
49 if (false !== ($breakpoint = strrpos($string, $break)))
50 {
51 $string = substr($string, 0, $breakpoint);
52 }
53
54 return $string . $pad;
55 }
56
57 /**
58 * Restore HTML tags to truncated strings.
59 * Original PHP code by Chirp Internet: www.chirp.com.au
60 *
61 * @access public
62 * @param mixed $input
63 * @return void
64 */
65 public function restore_tags($input)
66 {
67 $opened = array();
68 // loop through opened and closed tags in order
69 if(preg_match_all("/<(\/?[a-z]+)>?/i", $input, $matches))
70 {
71 foreach($matches[1] as $tag)
72 {
73 if(preg_match("/^[a-z]+$/i", $tag, $regs))
74 {
75 // a tag has been opened
76 if(strtolower($regs[0]) != 'br') $opened[] = $regs[0];
77 }
78 elseif(preg_match("/^\/([a-z]+)$/i", $tag, $regs))
79 {
80 // a tag has been closed
81 unset($opened[array_pop(array_keys($opened, $regs[1]))]);
82 }
83 }
84 }
85 // close tags that are still open
86 if($opened)
87 {
88 $tagstoclose = array_reverse($opened);
89 foreach($tagstoclose as $tag) $input .= "</$tag>";
90 }
91 return $input;
92 }
93 }