Skip to content
Snippets Groups Projects

Stable

Merged Patrick Barroca requested to merge stable into hotline-master
Compare and
+ 63
35
Preferences
Compare changes
Files
@@ -16,31 +16,39 @@
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_WebService_Fnac extends Class_WebService_Abstract {
private $url = 'http://www3.fnac.com/advanced/book.do?isbn=';
protected $_search_url = 'http://recherche.fnac.com/r/';
public function getResumes($notice) {
if (!$service = $notice->getIsbnOrEan())
return array();
return [];
if ($resume = $this->getResume($service))
return array(array('source' => 'Editeur',
'texte' => $resume));
return array();
return [ ['source' => 'Editeur',
'texte' => $resume]];
return [];
}
//------------------------------------------------------------------------------------------------------
// Résumé de l'editeur
//------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------
public function getResume($isbn) {
if(!$isbn) return false;
$isbn=str_replace("-","",$isbn);
if(!$isbn)
return false;
$isbn = trim(str_replace("-","",$isbn));
$url = $this->_search_url . $isbn;
$data = self::getHttpClient()->open_url($url);
$data = self::getHttpClient()->open_url($this->url.$isbn);
$url_lire_la_suite = $this->getUrlLireLaSuite($data);
if(!$url_lire_la_suite = $this->getUrlLireLaSuite($data))
return '';
if (!($url_lire_la_suite && (new ZendAfi_Validate_Url())->isValid($url_lire_la_suite)))
return '';
@@ -51,8 +59,8 @@ class Class_WebService_Fnac extends Class_WebService_Abstract {
public function getUrlLireLaSuite($data) {
$pos=striPos($data,"resume");
if(!$pos)
$pos = striPos($data,"resume");
if(!$pos)
return '';
$pos = strPos($data,"a href=\"",$pos)+8;
@@ -62,6 +70,9 @@ class Class_WebService_Fnac extends Class_WebService_Abstract {
public function extractResumeFromHTML($html) {
if($pos = striPos($html, 'resMarkContent'))
return $this->extractResumeFormBlk($html);
if ($pos = striPos($html, "avisEdContent"))
return $this->extractLireLaSuiteDivAvisEditeurFromHTML($html);
@@ -80,6 +91,22 @@ class Class_WebService_Fnac extends Class_WebService_Abstract {
}
protected function extractResumeFormBlk($html) {
$start_string = 'resMarkContent">';
if (!$pos = striPos($html, $start_string))
return '';
$pos = $pos + strlen($start_string);
$posfin = strPos($html, "</", $pos);
$resume = substr($html, $pos, ($posfin - $pos));
return trim($resume);
}
public function extractLireLaSuiteDivAvisEditeurFromHTML($html) {
$pos = strPos($html, "avisEdContent") + 15;
$posfin = strPos($html, "</div>", $pos);