PluginProbe
Vimeography: Vimeo Video Gallery WordPress Plugin / 0.5.2
Vimeography: Vimeo Video Gallery WordPress Plugin v0.5.2
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.5.2, at lib/helpers.php

92 lines 2.3 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) return $string;
45 // is $break present between $limit and the end of the string?
46 if(false !== ($breakpoint = strpos($string, $break, $limit)))
47 {
48 if($breakpoint < strlen($string) - 1)
49 {
50 $string = substr($string, 0, $breakpoint) . $pad;
51 }
52 }
53 return $string;
54 }
55
56 /**
57 * Restore HTML tags to truncated strings.
58 * Original PHP code by Chirp Internet: www.chirp.com.au
59 *
60 * @access public
61 * @param mixed $input
62 * @return void
63 */
64 public function restore_tags($input)
65 {
66 $opened = array();
67 // loop through opened and closed tags in order
68 if(preg_match_all("/<(\/?[a-z]+)>?/i", $input, $matches))
69 {
70 foreach($matches[1] as $tag)
71 {
72 if(preg_match("/^[a-z]+$/i", $tag, $regs))
73 {
74 // a tag has been opened
75 if(strtolower($regs[0]) != 'br') $opened[] = $regs[0];
76 }
77 elseif(preg_match("/^\/([a-z]+)$/i", $tag, $regs))
78 {
79 // a tag has been closed
80 unset($opened[array_pop(array_keys($opened, $regs[1]))]);
81 }
82 }
83 }
84 // close tags that are still open
85 if($opened)
86 {
87 $tagstoclose = array_reverse($opened);
88 foreach($tagstoclose as $tag) $input .= "</$tag>";
89 }
90 return $input;
91 }
92 }