Example #1
0
 public function _fetchData($id)
 {
     $data = array('resource' => 'article', 'id' => $id);
     $response = OstoolbarRequest::makeRequest($data);
     if ($response->hasError()) {
         JFactory::getApplication()->enqueueMessage(JText::_('COM_OSTOOLBAR_API_KEY_ERROR'), 'error');
         return false;
     }
     $body = $response->getBody();
     $body->introtext = OstoolbarRequest::filter($body->introtext);
     $body->fulltext = OstoolbarRequest::filter($body->fulltext);
     return $body;
 }
Example #2
0
 public function _fetchList()
 {
     $data = array('resource' => 'articles');
     $response = OstoolbarRequest::makeRequest($data);
     if ($response->hasError()) {
         JFactory::getApplication()->enqueueMessage(JText::_('COM_OSTOOLBAR_API_KEY_ERROR'), 'error');
         return false;
     }
     $list = $response->getBody();
     for ($i = 0; $i < count($list); $i++) {
         $list[$i]->link = 'index.php?option=com_ostoolbar&view=tutorial&id=' . $list[$i]->id;
     }
     return $list;
 }
Example #3
0
 public static function callback($object, $method, $args = array(), $cache_lifetime = null, $overrideConfig = false)
 {
     $conf = JFactory::getConfig();
     $cacheactive = $conf->get('config.caching');
     $cachetime = $conf->get('config.cachetime');
     $cache = JFactory::getCache(static::CACHE_GROUP, 'callback');
     $key_error = false;
     $response = OstoolbarRequest::makeRequest(array('resource' => 'checkapi'));
     if ($response->hasError() || $response->getBody() == 0) {
         $key_error = true;
         $cache = JFactory::getCache(static::CACHE_GROUP . "_trial", 'callback');
         OstoolbarRequest::$isTrial = true;
     }
     if ($overrideConfig) {
         $cache->setCaching(1);
         //enable caching
     }
     if ($cache_lifetime) {
         $cache->setLifeTime($cache_lifetime);
     }
     $data = static::getCache($object, $method, $args, $cache);
     if ($data !== false) {
         // In this case we have data in cache but just send minimum request to check update
         $response = OstoolbarRequest::makeRequest(array('resource' => 'lastupdate'));
         if (!$response->hasError()) {
             $last_update = strtotime($response->getBody());
             if (is_array($data)) {
                 if (count($data) && strtotime($data[0]->last_update_date) < $last_update || count($data) == 0) {
                     $cache->clean();
                     $data = static::getCache($object, $method, $args, $cache);
                 }
             }
         }
     }
     if (get_class($object) == "OSToolbarModelTutorial" && !empty($data)) {
         $data->jversion = $key_error ? "1.6_trial" : "1.6";
     }
     if ($overrideConfig) {
         $cache->setCaching($cacheactive);
     }
     if ($cache_lifetime) {
         $cache->setLifeTime($cachetime);
     }
     return $data;
 }