name = $this->type . "_" . $name; } public function getItems() { $contents = $this->getContents(); if (empty($contents->entry)) { return []; } return $contents->entry; } public function listItemNames() { $result = []; foreach ($this->getItems() as $item) { if (! empty($item->name)) { $result[] = addslashes(htmlspecialchars($item->name)); } } return $result; } public function getItem($name) { foreach ($this->getItems() as $item) { if ($name == $item->name) { return $item; } } return []; } public function replace() { } public function setEncoding($contents) { if (is_array($contents)) { throw new Exception('die'); } $this->encoding = mb_detect_encoding($contents, "ASCII, UTF-8, ISO-8859-1"); } private function open() { if ($this->isFileGal == true) { $contents = FileGallery\File::filename($this->name)->data(); } else { $contents = TikiLib::lib("cache")->getCached($this->name, get_class($this)); } $this->setEncoding($contents); $contents = json_decode($contents); if (empty($contents)) { return []; } return $contents; } private function save($contents) { $contents = json_encode($contents); if ($this->isFileGal == true) { //TODO: abstract FileGallery\File::filename($this->name) ->setParam('description', '') ->replace($contents); } else { //TODO: abstract TikiLib::lib("cache")->cacheItem($this->name, $contents, get_class($this)); } return $this; } public function getContents() { global $tikilib; $contents = $this->open(); if (! empty($contents)) { return $contents; } //at this point contents is empty, so lets fill it $this->replace(); $contents = $this->open(); return $contents; } public function delete() { global $tikilib; if ($this->isFileGal == true) { FileGallery\File::filename($this->name)->delete(); } else { TikiLib::lib("cache")->empty_type_cache(get_class($this)); } } public function appendToContents(&$contents, $items) { if (isset($items->feed->entry)) { $contents->entry[] = $items->feed->entry; } elseif (isset($items)) { $contents->entry[] = $items; } } public function addItem($item) { global $tikilib; $contents = $this->open(); if (empty($contents)) { $contents = new Feed_Contents($this->type); } //this allows us to intercept the contents and do things like check the validity of the content being appended to the contents $this->appendToContents($contents, $item); $this->save($contents); return $this; } public function feed($origin = '') { global $tikilib; $contents = $this->getContents(); //TODO: convert to actual object $feed = new Feed_Container( $this->version, $this->encoding, //we get this from the above call to open $contents, (! empty($origin) ? $origin : $tikilib->tikiUrl() . 'tiki-feed.php'), $this->type ); return $feed; } public function listArchives() { $archives = []; if ($this->isFileGal == true) { $file = FileGallery\File::filename($this->name); foreach ($file->listArchives() as $archive) { $archive = $this->open(); $archives[$archive->feed->date] = $archive->feed->entry; } } return $archives; } public function getItemsFromDate($date) { $archives = $this->listArchives(); $archive = $archives[$date]; return $archive; } public function getItemFromDate($name, $date) { $archive = $this->getItemsFromDate($date); foreach ($archive as $item) { if ($name == $item->name) { return $item; } } } public function getItemFromDates($name) { $archives = []; foreach ($this->listArchives() as $archive) { foreach ($archive as $item) { if ($name == $item->name) { $archives[] = $item; } } } return $archives; } }