PluginProbe ʕ •ᴥ•ʔ
Loco Translate / 2.8.0
Loco Translate v2.8.0
2.8.5 2.8.4 2.5.8 2.6.0 2.6.1 2.6.10 2.6.11 2.6.12 2.6.13 2.6.14 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.9 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0 2.8.1 2.8.2 2.8.3 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2 1.2.1 1.2.2 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.17 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7
loco-translate / src / data / RecentItems.php
loco-translate / src / data Last commit date
CompiledData.php 3 years ago Cookie.php 4 years ago Option.php 9 years ago Permissions.php 1 year ago Preferences.php 4 years ago RecentItems.php 2 years ago Serializable.php 3 years ago Session.php 4 years ago Settings.php 1 year ago Transient.php 7 years ago Upload.php 2 years ago
RecentItems.php
129 lines
1 <?php
2 /**
3 * Recently items to display on home page
4 */
5 class Loco_data_RecentItems extends Loco_data_Option {
6
7 /**
8 * Global instance of recent items
9 * @var Loco_data_RecentItems
10 */
11 private static $current;
12
13
14 /**
15 * {@inheritdoc}
16 */
17 public function getKey(){
18 return 'recent';
19 }
20
21
22 /**
23 * @return Loco_data_RecentItems
24 */
25 public static function get(){
26 if( ! self::$current ){
27 self::$current = new Loco_data_RecentItems;
28 self::$current->fetch();
29 }
30 return self::$current;
31 }
32
33
34
35 /**
36 * Trash data and remove from memory
37 */
38 public static function destroy(){
39 $tmp = new Loco_data_RecentItems;
40 $tmp->remove();
41 self::$current = null;
42 }
43
44
45
46 /**
47 * @internal
48 * @return Loco_data_RecentItems
49 */
50 private function push( $object, array $indexes ){
51 foreach( $indexes as $key => $id ){
52 $stack = isset($this[$key]) ? $this[$key] : [];
53 // remove before add ensures latest item appended to hashmap
54 unset($stack[$id]);
55 $stack[$id] = time();
56 $this[$key] = $stack;
57 // TODO prune stack to maximum length
58 }
59 return $this;
60 }
61
62
63
64 /**
65 * @return array
66 */
67 private function getItems( $key, $offset, $count ){
68 $stack = isset($this[$key]) ? $this[$key] : [];
69 // hash map should automatically be in "push" order, meaning most recent last
70 // sorting gives wrong order for same-second updates (only relevant in tests, but still..)
71 // asort( $stack, SORT_NUMERIC );
72 $stack = array_reverse( array_keys( $stack ) );
73 if( is_null($count) && 0 === $offset ){
74 return $stack;
75 }
76 return array_slice( $stack, $offset, $count, false );
77 }
78
79
80 /**
81 * @return int
82 */
83 private function hasItem( $key, $id ){
84 if( isset($this[$key]) && ( $items = $this[$key] ) && isset($items[$id]) ){
85 return $items[$id];
86 }
87 return 0;
88 }
89
90
91 /**
92 * Push bundle to the front of recent bundles stack
93 * @return Loco_data_RecentItems
94 */
95 public function pushBundle( Loco_package_Bundle $bundle ){
96 return $this->push( $bundle, [ 'bundle' => $bundle->getId() ] );
97 }
98
99
100 /**
101 * Get bundle IDs
102 * @return array
103 */
104 public function getBundles( $offset = 0, $count = null ){
105 return $this->getItems('bundle', $offset, $count );
106 }
107
108
109 /**
110 * Check if a bundle has been recently used
111 * @return int timestamp item was added, 0 if absent
112 */
113 public function hasBundle( $id ){
114 return $this->hasItem( 'bundle', $id );
115 }
116
117
118 /**
119 * TODO other types of item
120 * Push project to the front of recent bundles stack
121 * @return Loco_data_RecentItems
122 *
123 public function pushProject( Loco_package_Project $project ){
124 return $this;
125 }*/
126
127
128 }
129