Server IP : 104.21.14.103 / Your IP : 3.141.201.111 Web Server : LiteSpeed System : Linux business53.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : giankuin ( 1871) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/giankuin/thietke365.net/wp-content/plugins/loco-translate/src/data/ |
Upload File : |
<?php /** * Recently items to display on home page */ class Loco_data_RecentItems extends Loco_data_Option { /** * Global instance of recent items * @var Loco_data_RecentItems */ private static $current; /** * {@inheritdoc} */ public function getKey(){ return 'recent'; } /** * @return Loco_data_RecentItems */ public static function get(){ if( ! self::$current ){ self::$current = new Loco_data_RecentItems; self::$current->fetch(); } return self::$current; } /** * Trash data and remove from memory */ public static function destroy(){ $tmp = new Loco_data_RecentItems; $tmp->remove(); self::$current = null; } /** * @internal * @return Loco_data_RecentItems */ private function push( $object, array $indexes ){ foreach( $indexes as $key => $id ){ $stack = isset($this[$key]) ? $this[$key] : []; // remove before add ensures latest item appended to hashmap unset($stack[$id]); $stack[$id] = time(); $this[$key] = $stack; // TODO prune stack to maximum length } return $this; } /** * @return array */ private function getItems( $key, $offset, $count ){ $stack = isset($this[$key]) ? $this[$key] : []; // hash map should automatically be in "push" order, meaning most recent last // sorting gives wrong order for same-second updates (only relevent in tests, but still..) // asort( $stack, SORT_NUMERIC ); $stack = array_reverse( array_keys( $stack ) ); if( is_null($count) && 0 === $offset ){ return $stack; } return array_slice( $stack, $offset, $count, false ); } /** * @return int */ private function hasItem( $key, $id ){ if( isset($this[$key]) && ( $items = $this[$key] ) && isset($items[$id]) ){ return $items[$id]; } return 0; } /** * Push bundle to the front of recent bundles stack * @return Loco_data_RecentItems */ public function pushBundle( Loco_package_Bundle $bundle ){ return $this->push( $bundle, [ 'bundle' => $bundle->getId() ] ); } /** * Get bundle IDs * @return array */ public function getBundles( $offset = 0, $count = null ){ return $this->getItems('bundle', $offset, $count ); } /** * Check if a bundle has been recently used * @return int timestamp item was added, 0 if absent */ public function hasBundle( $id ){ return $this->hasItem( 'bundle', $id ); } /** * TODO other types of item * Push project to the front of recent bundles stack * @return Loco_data_RecentItems * public function pushProject( Loco_package_Project $project ){ return $this; }*/ }