/** * Return a link to the atom feeder * * In $params you can specify a query to perform, a date field or leave it * blank to use the default behavior (that is use the $creation_field). * * The default behaviour is to keep the last three days or * (for empty result set) the last ten records. */ protected function tagAtom($params) { $failed = TIP_Application::getGlobal('fatal_uri'); $template =& TIP_Type::singleton(array('type' => array('template'), 'path' => array($this->id, $this->atom_template))); if (!$template) { return $failed; } // Check for cache presence if (!is_null($uri = $this->engine->getCacheUri($template))) { return $uri; } // Check for usable cache path $path = $this->engine->buildCachePath($template); $dir = dirname($path); if (!is_dir($dir) && !mkdir($dir, 0777, true)) { return $failed; } // To make life easier, $params will be a query if contains a space if (strpos($params, ' ') !== false) { // $params is a query if (is_null($view =& $this->startDataView($params, array('fields' => null)))) { return $failed; } } else { // $params is a field or it is empty $date_field = empty($params) ? $this->creation_field : $params; // Check for the last 3 days interval $query = $this->data->filter($date_field, array('NOW() - INTERVAL 3 DAY'), '>'); if (is_null($view =& $this->startDataView($query, array('fields' => null)))) { return $failed; } if ($view->nRows() <= 0) { // Empty result set: get the last 10 rows $this->endView(); $query = $this->data->order($date_field, true); $query .= $this->data->limit(10); if (is_null($view =& $this->startDataView($query, array('fields' => null)))) { return $failed; } } } if ($view->nRows() <= 0) { $this->endView(); return $failed; } ob_start(); if (!$template->run($this) || !$this->endView()) { ob_end_clean(); return $failed; } // Store the cached atom feed if (!file_put_contents($path, ob_get_clean(), LOCK_EX)) { return $failed; } return $this->engine->getCacheUri($template); }