public function executeGet() { $valid = $this->hasRequiredParameters($this->requiredParams); if ($valid instanceof Frapi_Error) { return $valid; } /* get the url param and decode it */ $url = $this->getParam('url'); $url = urldecode($url); /* if we're missing 'http' at the beginning, add it */ if (!stristr($url, 'http')) { $url = 'http://' . $url; } if (!is_valid_url($url)) { throw new Frapi_Error('ERROR_INVALID_URL'); } try { $model = new Spaz_Urlinfo($url); $res = $model->get(); } catch (Exception $e) { throw new Frapi_Error($e->getMessage()); } $this->data = $res; return $this->toArray(); }
public function executeGet() { $valid = $this->hasRequiredParameters($this->requiredParams); if ($valid instanceof Frapi_Error) { return $valid; } /* get the url param and decode it */ $url = $this->getParam('url'); $url = urldecode($url); /* if we're missing 'http' at the beginning, add it */ if (!stristr($url, 'http')) { $url = 'http://' . $url; } if (!is_valid_url($url)) { throw new Frapi_Error('ERROR_INVALID_URL'); } try { $model = new Spaz_Urlinfo($url); $res = $model->get(); } catch (Exception $e) { throw new Frapi_Error($e->getMessage()); } /* is content type html? */ if (stripos($res['content_type'], 'text/html') !== FALSE || stripos($res['content_type'], 'application/xhtml+xml' !== FALSE)) { try { $model = new Spaz_Urltitle($url); $res = $model->get(); } catch (Exception $e) { throw new Frapi_Error($e->getMessage()); } } else { $title = $res['content_type']; $size = (int) $res['download_content_length']; if ($size > 0) { $title .= ' ' . $this->formatBytes($size); } $res = array('title' => $title); } $this->data = $res; return $this->toArray(); }