From ea414137ede275ff66a656ac0614e1bae99eb769 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Wed, 15 Dec 2010 14:55:43 +0000 Subject: [PATCH] --- inc/config.inc.php | 1 + inc/ws/Controlleur/class.ws.services.php | 55 +++++++++++++++++++--- inc/ws/Controlleur/class.ws.url.php | 17 +++++-- inc/ws/DAO/class.ws.dao.book.php | 3 ++ inc/ws/Metier/class.ws.book.parametres.php | 13 +++-- inc/ws/Metier/class.ws.parametres.php | 3 ++ index.php | 3 +- 7 files changed, 80 insertions(+), 15 deletions(-) diff --git a/inc/config.inc.php b/inc/config.inc.php index 5fb2d4441..b338c41c5 100644 --- a/inc/config.inc.php +++ b/inc/config.inc.php @@ -65,6 +65,7 @@ define('WS_BOOKS', WS_FILES . '/books'); define('WS_DOCS', WS_FILES . '/docs'); define('WS_ICONS', WS_FILES . '/icones'); define('WS_THEMES', WS_FILES . '/themes'); +define('WS_CACHE', WS_FILES . '/cache'); define('WS_COMPILE_ASSETS', WS_FILES . '/compile'); // define('MINIMIZE_JS', false); define('WORKER_PREFIX', 'worker.'); diff --git a/inc/ws/Controlleur/class.ws.services.php b/inc/ws/Controlleur/class.ws.services.php index 58a93f73e..e55e10c0a 100644 --- a/inc/ws/Controlleur/class.ws.services.php +++ b/inc/ws/Controlleur/class.ws.services.php @@ -33,30 +33,71 @@ class wsServices extends cubeFlashGateway { $this->xml->addChild('ok', $mail->send()?'1':'0'); } - public function shortenURL() + protected function shortenURL($url, $id) { $bitLyUser = 'fluidbook'; $bitLyKey = 'R_3858dd1c9884d5c6a5fe386d7e95cf1d'; // Recherche dans le cache - $r = $this->con->select('SELECT * FROM book_short_url WHERE long_url=\'' . $this->con->escape($this->args['url']) . '\' LIMIT 1'); + $r = $this->con->select('SELECT * FROM book_short_url WHERE long_url=\'' . $this->con->escape($url) . '\' LIMIT 1'); if ($r->count() > 0) { $this->xml->addChild('shortURL', $r->short_url); return; } // Si pas dans le cache, on le recherche - $short_url = cubeURLShortener::bitLy($this->args['url'], $bitLyUser, $bitLyKey); + $short_url = cubeURLShortener::bitLy($url, $bitLyUser, $bitLyKey); if (is_null($short_url) || empty($short_url) || !$short_url) { - $short_url = cubeURLShortener::tinyURL($this->args['url']); + $short_url = cubeURLShortener::tinyURL($url); } $short_url = trim($short_url); $c = $this->con->openCursor('book_short_url'); - $c->long_url = $this->args['url']; - $c->book_id = $this->args['id']; + $c->long_url = $url; + $c->book_id = $id; $c->short_url = $short_url; $c->insert(); - $this->xml->addChild('shortURL', $short_url); + return $short_url; + } + + /** + * wsServices::facebook_thumbnail() + * + * @return + */ + public function facebook_thumbnail() + { + $this->outputXML = false; + $dao = new wsDAOBook($this->con); + $pages = $dao->getPagesOfBook($this->args['id']); + + $dest = WS_CACHE . '/thumbnails/' . $this->args['id'] . '_' . $pages[1]['document_id'] . '_' . $pages[1]['document_page'] . '.jpg'; + $cover = WS_DOCS . '/' . $pages[1]['document_id'] . '/p' . $pages[1]['document_page'] . '.jpg'; + + if (!file_exists($dest) || filemtime($dest) < filemtime($cover)) { + $it = new imageTools(); + $it->loadImage($cover); + $it->resize(130, 110, 'crop', true); + $it->output('jpeg', $dest, 90); + } + + cubeHTTP::relayFile($dest); + exit; + } + + public function facebookShare() + { + http::redirect('http://www.facebook.com/sharer.php?u=' . $this->args['url']); + exit; + } + + public function twitterShare() + { + $url = $this->shortenURL($this->args['url'], $this->args['id']); + $post = str_replace('%short%', $url, $this->args['post']); + $post = rawurlencode($post); + + http::redirect('http://twitter.com/?status=' . $post); + exit; } public function getPDF() diff --git a/inc/ws/Controlleur/class.ws.url.php b/inc/ws/Controlleur/class.ws.url.php index b14d0c7d7..943e09eda 100644 --- a/inc/ws/Controlleur/class.ws.url.php +++ b/inc/ws/Controlleur/class.ws.url.php @@ -125,6 +125,7 @@ html{height:100%}' . "\n"; global $css; global $js; global $standard; + global $meta; $args = cubePage::getArgs($args); @@ -152,16 +153,24 @@ html{height:100%}' . "\n"; $standard = 'XHTML 1.0 Transitional'; $css[] = $webcompile . '/style.css'; cubePage::swfaddress(); - - //$fv = array('base' => WEBROOT . '/fluidbook/books/final/' . $e[0]); + // $fv = array('base' => WEBROOT . '/fluidbook/books/final/' . $e[0]); $fv = array(); $res = ''; $res .= ''; - $res .= '' . $book->nom . ''; + $res .= '' . $book->parametres->title . ''; + if ($book->parametres->facebook) { + $meta['og:title'] = ($book->parametres->facebook_title == '')?$book->parametres->title:$book->parametres->facebook_title; + + if ($book->parametres->facebook_description != '') { + $meta['og:description'] = $book->parametres->facebook_description; + } + $meta['og:image'] = 'http://dev.ws.fluidbook.com/services/facebook_thumbnail?id=' . $book->book_id; + } + $res .= ''; $res .= ''; - $res .= cubeMedia::flash2($webcompile.'index.swf?junk='.TIME, '100%', '100%', $fv, 'fluidbook', '', 10, '#ffffff', '', true); + $res .= cubeMedia::flash2($webcompile . 'index.swf?junk=' . TIME, '100%', '100%', $fv, 'fluidbook', '', 10, '#ffffff', '', true); $res .= ''; $res .= ''; diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index 64a2096f1..7747f63e8 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -327,6 +327,9 @@ class wsDAOBook extends extranetDAO { $parametres = $book->parametres; $new = json_decode($settings, false); foreach($new as $k => $v) { + if($k=='_empty_'){ + continue; + } $parametres->$k = $v; } $c = $this->con->openCursor('books'); diff --git a/inc/ws/Metier/class.ws.book.parametres.php b/inc/ws/Metier/class.ws.book.parametres.php index bb9aa7937..49550537f 100644 --- a/inc/ws/Metier/class.ws.book.parametres.php +++ b/inc/ws/Metier/class.ws.book.parametres.php @@ -28,10 +28,17 @@ class wsBookParametres extends wsParametres { $this->fields['askAcknowledge'] = array('type' => 'boolean', 'default' => false, 'editable' => true, 'label' => __("Demander au destinataire un accusé de réception"), 'extra' => true, 'grade' => 4); $this->fields['attachPDFInEmail'] = array('type' => 'boolean', 'default' => false, 'editable' => true, 'label' => __("Joindre le fichier PDF de la page en cours à l'email"), 'extra' => true, 'grade' => 4); $this->fields['attachmentName'] = array('type' => 'text', 'default' => '', 'editable' => false, 'label' => __('Nom de la pièce jointe'), 'extra' => true, 'grade' => 4); - $this->fields['addThis'] = array('type' => 'text', 'default' => '', 'editable' => true, 'label' => __("Identifiant addThis"), 'extra' => false, 'grade' => 4); - $this->fields['addThisOptions'] = array('type' => 'textarea', 'default' => '', 'editable' => true, 'label' => __("Paramètres addThis"), 'extra' => false, 'grade' => 4); + // $this->fields['addThis'] = array('type' => 'text', 'default' => '', 'editable' => true, 'label' => __("Identifiant addThis"), 'extra' => false, 'grade' => 4); + // $this->fields['addThisOptions'] = array('type' => 'textarea', 'default' => '', 'editable' => true, 'label' => __("Paramètres addThis"), 'extra' => false, 'grade' => 4); + $this->fields['facebook'] = array('type' => 'boolean', 'default' => true, 'editable' => true, 'label' => __('Facebook'), 'extra' => false, 'grade' => 1); + $this->fields['facebook_title'] = array('type' => 'text', 'default' => '', 'editable' => true, 'label' => __("Titre facebook"), 'extra' => false, 'grade' => 1, 'hint' => __('Titre proposé sur la fonction de partage facebook (par défaut, titre de la publication)')); + $this->fields['facebook_description'] = array('type' => 'textarea', 'default' => '', 'editable' => true, 'label' => __("Description facebook"), 'extra' => false, 'grade' => 1, 'hint' => __('Description proposée sur la fonction de partage facebook (par défaut, vide)')); + $this->fields['twitter'] = array('type' => 'boolean', 'default' => true, 'editable' => true, 'label' => __('Twitter'), 'extra' => false, 'grade' => 1); + $this->fields['twitter_description'] = array('type' => 'textarea', 'default' => '%title% : %short%', 'editable' => true, 'label' => __("Contenu Twitter"), 'extra' => false, 'grade' => 1, 'hint' => __('Contenu du Twit')); $this->forms['share'] = array('label' => __('Fonctions de partage'), - 'fieldsnames' => array('friend', 'email_title', 'email_body', 'email_editable', 'askAcknowledge', 'attachPDFInEmail', 'attachmentName', 'addThis', 'addThisOptions')); + 'fieldsnames' => array('friend', 'email_title', 'email_body', 'email_editable', 'askAcknowledge', '|', + 'facebook', 'facebook_title', 'facebook_description', '|', + 'twitter', 'twitter_description')); // . $this->fields['pages'] = array('type' => 'integer', 'default' => '', 'editable' => false, 'label' => __('Nombre de pages'), 'extra' => false, 'grade' => 0); $this->fields['width'] = array('type' => 'float', 'default' => '', 'editable' => false, 'label' => __('Largeur'), 'extra' => false, 'grade' => 0); diff --git a/inc/ws/Metier/class.ws.parametres.php b/inc/ws/Metier/class.ws.parametres.php index 319df1647..1267868da 100644 --- a/inc/ws/Metier/class.ws.parametres.php +++ b/inc/ws/Metier/class.ws.parametres.php @@ -25,6 +25,9 @@ class wsParametres extends cubeMetier implements Iterator { public function __set($varname, $value) { + if(empty($varname)){ + return; + } $this->set($varname, $value); } diff --git a/index.php b/index.php index cb2627712..0f9b8546f 100644 --- a/index.php +++ b/index.php @@ -2,6 +2,7 @@ require_once(dirname(__FILE__) . '/inc/prepend.php'); ob_start(); +$meta=array(); $js[] = JS_PATH . '/common.js'; $js[] = JS_PATH . '/' . MODE . '.js'; $jsvar['IMG'] = IMG; @@ -15,7 +16,7 @@ $buffer = ob_get_contents(); ob_clean(); // $css['IE'] = CSS_PATH . '/ie.css'; -echo cubePage::page($buffer, $js, $jsvar, $css, array(), 6,false,array(),array(),$standard); +echo cubePage::page($buffer, $js, $jsvar, $css, array(), 6,false,$meta,array(),$standard); fb($core->debug()); ?> \ No newline at end of file -- 2.39.5