*/
class wsLinks
{
- protected static $_testLinkCache = null;
- protected static $_linksKey = null;
-
- public static function linksToExcel($links, $rulers, $pages = null)
- {
- set_time_limit(0);
-
- $cols = array(
- 'uid' => __('Identifiant unique'),
- 'page' => __('Page de la publication'), 'left' => __('x'), 'top' => __('y'), 'width' => __('Largeur'), 'height' => __('Hauteur'), 'rot' => __('Rotation'),
- 'type' => __('Type'), 'to' => __('Destination'), 'target' => __('Cible'),
- 'infobulle' => __('Infobulle'), 'numerotation' => __('Numérotation'),
- 'display_area' => __('Activer la surbrillance'),
- 'video_loop' => __('Video : boucle'), 'video_auto_start' => __('Video : démarrage automatique'), 'video_controls' => __('Vidéo : afficher les contrôles'), 'video_sound_on' => __('Vidéo : activer le son'),
- 'inline' => __('Vidéo : afficher dans la page'), 'video_width' => __('Vidéo : Largeur du popup'), 'video_height' => __('Vidéo : Hauteur du popup'),
- 'interactive' => __('Interactivité'), 'video_service' => __('Webvideo : service'),
- 'display_area' => __('Afficher le lien au rollover'),
- 'extra' => __('Paramètre supplémentaire'),
- 'alternative' => __('Alternative'),
- 'read_mode' => __('Mode de lecture'),
- 'image' => __('Image'), 'image_rollover' => __('Animation au survol'),
- 'group' => __('Groupe'),
- );
-
- /* $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_memcache;
- $cacheSettings = array('memcacheServer' => 'localhost',
- 'memcachePort' => 11211,
- 'cacheTime' => 600
- );
- PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings); */
-
-
- $comments = array();
-
- $xls = new PHPExcel();
- $s = $xls->setActiveSheetIndex(0);
- $s->setTitle('Links');
-
- // Labels
- $i = 0;
- foreach ($cols as $id => $label) {
- $s->setCellValueByColumnAndRow($i, 1, $id);
- $s->getColumnDimensionByColumn($i)->setAutoSize(true);
- $s->getStyleByColumnAndRow($i, 1)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $i++;
- }
-
- // Links
- $j = 2;
- foreach ($links as $l) {
- $i = 0;
- foreach ($cols as $id => $label) {
- if (($id == 'document_id' || $id == 'document_page')) {
- if (!is_null($pages)) {
- $infos = $pages[$l['page']];
- $value = $infos[$id];
- } else {
- $value = '';
- }
- } else {
-
- if (isset($l[$id])) {
- if (is_bool($l[$id])) {
- $l[$id] = $l[$id] ? 1 : 0;
- }
- if ($id == 'numerotation') {
- if ($l[$id] == 'false') {
- $l[$id] = 'physical';
- }
- }
- if ($id == 'to' && in_array($l['type'], array(2))) {
- $comment = false;
- if (!Zend_Uri_Http::check($l[$id])) {
- $comment = 'Invalid URI';
- } else {
- $comment = self::testLink($l[$id]);
- }
- if ($comment) {
- $s->getComment(PHPExcel_Cell::stringFromColumnIndex($j - 1) . $i)->getText()->createTextRun($comment);
- }
-
- }
- $value = $l[$id];
- } else {
- $value = '';
- }
- }
- if ($value != '') {
- $s->setCellValueByColumnAndRow($i, $j, $value);
- //$s->getStyleByColumnAndRow($i, $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- }
- $i++;
- }
- $j++;
- }
- // Rulers
- $s = $xls->createSheet();
- $s->setTitle('Rulers');
-
- $rcols = array('page', 'type', 'pos');
- $i = 0;
- // Labels
- foreach ($rcols as $id) {
- $s->setCellValueByColumnAndRow($i, 1, $id);
- $s->getColumnDimensionByColumn($i)->setAutoSize(true);
- //$s->getStyleByColumnAndRow($i, 1)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $i++;
- }
-
- // Contents
- $j = 2;
- foreach ($rulers as $r) {
- $i = 0;
- foreach ($rcols as $id) {
- if (!is_null($pages) && ($id == 'document_id' || $id == 'document_page')) {
- $infos = $pages[$r['page']];
- $value = $infos[$id];
- } else {
- $value = $r[$id];
- }
- $s->setCellValueByColumnAndRow($i, $j, $value);
- $s->getStyleByColumnAndRow($i, $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $i++;
- }
- $j++;
- }
-
- $xls->setActiveSheetIndex(0);
- return $xls;
- }
-
- public static function testLink($uri)
- {
- $client = new Zend_Http_Client($uri);
- try {
- $client->request('head');
- } catch (Exception $e) {
- return $e->getMessage();
- }
- return false;
- }
-
- public static function setDocumentLinks($document_id, $links, $rulers, $user, $comments, $time)
- {
- global $core;
- $c = $core->con->openCursor('document_links_versions');
- $c1 = $core->con->openCursor('document_links');
- $c1->document_id = $c->document_id = $document_id;
- $c1->links = $c->links = $links;
- $c1->rulers = $c->rulers = $rulers;
- $c->comments = $comments;
- $c->user = $user;
- $c->update = $time;
- $c->insert();
-
- $core->con->execute('DELETE FROM document_links WHERE document_id=' . $document_id);
- $c1->insert();
- }
-
- public static function getDocumentLastLinks($document_id)
- {
- global $core;
-
- $r = $core->con->select('SELECT * FROM document_links WHERE document_id=\'' . $document_id . '\'');
- if (!$r->count()) {
- $r = $core->con->select('SELECT * FROM document_links_versions WHERE document_id=' . $document_id . ' ORDER BY `update` DESC LIMIT 1');
- $c = $core->con->openCursor('document_links');
- $c->document_id = $document_id;
- $c->links = $r->links;
- $c->rulers = $r->rulers;
- try {
- $c->insert();
- } catch (Exception $e) {
- fb($e);
- }
- }
-
- return self::_recordToLinks($r);
- }
-
- public static function getDocumentVersionLinks($document_id, $time)
- {
- global $core;
- $r = $core->con->select('SELECT * FROM document_links_versions WHERE document_id=' . $document_id . ' AND `update`<=' . $time . ' ORDER BY `update` DESC LIMIT 1');
- return self::_recordToLinks($r);
- }
-
- protected static function _recordToLinks($r)
- {
- if (mb_substr($r->links, 1, 1) == ':') {
- $ll = unserialize($r->links);
- $rr = unserialize($r->rulers);
- } else {
- $ll = json_decode($r->links, true);
- $rr = json_decode($r->rulers, true);
- }
-
- return array('links' => $ll, 'rulers' => $rr);
- }
-
- public static function getLinksAndRulers($book_id, &$links, &$rulers, $time = null)
- {
-
- global $core;
-
- $daoBook = new wsDAOBook($core->con);
- $pages = $daoBook->getPagesOfBookAt($book_id, $time);
-
- $documents = [];
- foreach ($pages as $p => $infos) {
- $documents[] = $infos['document_id'];
- }
- $documents = array_unique($documents);
-
- $tlinks = array();
- $trulers = array();
-
- $links = array();
- $rulers = array();
-
- foreach ($documents as $d) {
- if (is_null($time)) {
- $lr = self::getDocumentLastLinks($d);
- } else {
- $lr = self::getDocumentVersionLinks($d, $time);
- }
- $tlinks[$d] = $lr['links'];
- $trulers[$d] = $lr['rulers'];
- }
-
- $i = 1;
- foreach ($pages as $p => $infos) {
- if (isset($tlinks[$infos['document_id']][$infos['document_page']])) {
- $l = $tlinks[$infos['document_id']][$infos['document_page']];
- foreach ($l as $link) {
- $link = (array)$link;
- $link['page'] = $p;
- $link['id'] = $i;
- if (!isset($link['rot'])) {
- $link['rot'] = 0;
- }
- $links[] = $link;
- }
- }
- if (isset($trulers[$infos['document_id']][$infos['document_page']])) {
- $ru = $trulers[$infos['document_id']][$infos['document_page']];
- foreach ($ru as $ruler) {
- $ruler['page'] = $p;
- $rulers[] = $ruler;
- }
- }
- }
-
- $daoBook = new wsDAOBook($core->con);
- $book = $daoBook->selectById($book_id);
-
- $rulers = array_merge($rulers, $book->specialRulers);
- $links = array_merge($links, $book->specialLinks);
- }
-
- public static function getLinksFromExcel($xls, &$links, &$rulers)
- {
- $s = $xls->setActiveSheetIndexByName('Links');
- $i = 0;
- $links = array();
- foreach ($s->getRowIterator() as $row) {
- $cellIterator = $row->getCellIterator();
- $cellIterator->setIterateOnlyExistingCells(false);
- if ($i == 0) {
- $cols = array();
- foreach ($cellIterator as $cell) {
- $cols[] = $cell->getValue();
- }
- } else {
- $link = array();
- $j = 0;
- foreach ($cellIterator as $cell) {
- $link[$cols[$j]] = $cell->getValue();
- $j++;
- }
- if ($link['display_area'] == '') {
- $link['display_area'] = '1';
- }
- if (trim($link['infobulle']) == '') {
- $link['infobulle'] = '';
- }
- $links[] = $link;
- }
-
- $i++;
- }
-
- $i = 0;
- $rulers = array();
- $s = $xls->setActiveSheetIndexByName('Rulers');
- foreach ($s->getRowIterator() as $row) {
- $cellIterator = $row->getCellIterator();
- $cellIterator->setIterateOnlyExistingCells(false);
- if ($i == 0) {
- $cols = array();
- foreach ($cellIterator as $cell) {
- $cols[] = $cell->getValue();
- }
- } else {
- $link = array();
- $j = 0;
- foreach ($cellIterator as $cell) {
- $ruler[$cols[$j]] = $cell->getValue();
- $j++;
- }
-
- $rulers[] = $ruler;
- }
- $i++;
- }
- }
-
- public static function getLinksFromAutobookmarkText($txt, &$links, &$rulers)
- {
- $links = array();
- $rulers = array();
-
- $lines = explode("\n", $txt);
-
- $protocols = array('mailto' => 3, 'custom' => 7, 'cart' => 12, 'pagelabel' => 26);
-
- foreach ($lines as $line) {
- $line = trim($line);
- if ($line == '') {
- continue;
- }
- if (strpos('#', $line) === 0) {
- continue;
- }
- $target = $numerotation = '';
- list($page, $left, $top, $width, $height, $type, $to) = explode(';', $line);
- if ($type <= 2) {
- $target = '_blank';
- } elseif ($type == 5) {
- $numerotation = 'physical';
- }
-
- $links[] = array(
- 'page' => $page,
- 'left' => $left, 'top' => $top, 'width' => $width, 'height' => $height, 'rot' => '',
- 'type' => $type, 'to' => $to, 'target' => $target,
- 'infobulle' => '', 'numerotation' => $numerotation, 'display_area' => '1');
- }
- }
-
- public static function _getLinkKey()
- {
- if (self::$_linksKey === null) {
- self::$_linksKey = base64_decode('o2p2yYGI8yMEHf+Y5/e6NdTINbbXg3NIo8BODgdhPxI=');
- }
- return self::$_linksKey;
- }
-
- public static function encryptLinks($links)
- {
- $res = [];
- foreach ($links as $key => $link) {
- $res[$key] = self::encryptLinkAttrs($link);
- }
- return $res;
- }
-
- public static function encryptLinkAttrs($link)
- {
- if (is_array($link)) {
- $link = CubeIT_Util_Object::asObject($link);
- }
-
- if ($link->type != 13 && $link->type != 14) {
- return $link;
- }
-
- $attrs = ['image_rollover'];
- foreach ($attrs as $attr) {
- $link->$attr = trim($link->$attr);
- if (strpos($link->$attr, '///') === 0 || $link->$attr == '') {
- continue;
- }
- $link->$attr = '///' . CubeIT_Crypt::safeEncrypt($link->uid . '|||' . $link->$attr, self::_getLinkKey());
- }
- return $link;
- }
-
- public static function decryptLink($link)
- {
- if (is_array($link)) {
- $link = CubeIT_Util_Object::asObject($link);
- }
-
- foreach ($link as $attr => $item) {
- if (strpos($item, '///') !== 0) {
- continue;
- }
- $v = CubeIT_Crypt::safeDecrypt(substr($item, 3), self::_getLinkKey());
- $e = explode('|||', $v);
- if ($e[0] === $link->uid) {
- $link->$attr = $e[1];
- } else {
- $link->$attr = '';
- }
- }
- return $link;
- }
-
- public static function decryptLinks($links)
- {
- $res = [];
- foreach ($links as $key => $link) {
- $res[$key] = self::decryptLink($link);
- }
- return $res;
- }
+ protected static $_testLinkCache = null;
+ protected static $_linksKey = null;
+
+ public static function linksToExcel($links, $rulers, $pages = null)
+ {
+ set_time_limit(0);
+
+ $cols = array(
+ 'uid' => __('Identifiant unique'),
+ 'page' => __('Page de la publication'), 'left' => __('x'), 'top' => __('y'), 'width' => __('Largeur'), 'height' => __('Hauteur'), 'rot' => __('Rotation'),
+ 'type' => __('Type'), 'to' => __('Destination'), 'target' => __('Cible'),
+ 'infobulle' => __('Infobulle'), 'numerotation' => __('Numérotation'),
+ 'display_area' => __('Activer la surbrillance'),
+ 'video_loop' => __('Video : boucle'), 'video_auto_start' => __('Video : démarrage automatique'), 'video_controls' => __('Vidéo : afficher les contrôles'), 'video_sound_on' => __('Vidéo : activer le son'),
+ 'inline' => __('Vidéo : afficher dans la page'), 'video_width' => __('Vidéo : Largeur du popup'), 'video_height' => __('Vidéo : Hauteur du popup'),
+ 'interactive' => __('Interactivité'), 'video_service' => __('Webvideo : service'),
+ 'display_area' => __('Afficher le lien au rollover'),
+ 'extra' => __('Paramètre supplémentaire'),
+ 'alternative' => __('Alternative'),
+ 'read_mode' => __('Mode de lecture'),
+ 'image' => __('Image'), 'image_rollover' => __('Animation au survol'),
+ 'group' => __('Groupe'),
+ );
+
+ /* $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_memcache;
+ $cacheSettings = array('memcacheServer' => 'localhost',
+ 'memcachePort' => 11211,
+ 'cacheTime' => 600
+ );
+ PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings); */
+
+
+ $comments = array();
+
+ $xls = new PHPExcel();
+ $s = $xls->setActiveSheetIndex(0);
+ $s->setTitle('Links');
+
+ // Labels
+ $i = 0;
+ foreach ($cols as $id => $label) {
+ $s->setCellValueByColumnAndRow($i, 1, $id);
+ $s->getColumnDimensionByColumn($i)->setAutoSize(true);
+ $s->getStyleByColumnAndRow($i, 1)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+ $i++;
+ }
+
+ // Links
+ $j = 2;
+ foreach ($links as $l) {
+ $i = 0;
+ foreach ($cols as $id => $label) {
+ if (($id == 'document_id' || $id == 'document_page')) {
+ if (!is_null($pages)) {
+ $infos = $pages[$l['page']];
+ $value = $infos[$id];
+ } else {
+ $value = '';
+ }
+ } else {
+
+ if (isset($l[$id])) {
+ if (is_bool($l[$id])) {
+ $l[$id] = $l[$id] ? 1 : 0;
+ }
+ if ($id == 'numerotation') {
+ if ($l[$id] == 'false') {
+ $l[$id] = 'physical';
+ }
+ }
+ if ($id == 'to' && in_array($l['type'], array(2))) {
+ $comment = false;
+ if (!Zend_Uri_Http::check($l[$id])) {
+ $comment = 'Invalid URI';
+ } else {
+ $comment = self::testLink($l[$id]);
+ }
+ if ($comment) {
+ $s->getComment(PHPExcel_Cell::stringFromColumnIndex($j - 1) . $i)->getText()->createTextRun($comment);
+ }
+
+ }
+ $value = $l[$id];
+ } else {
+ $value = '';
+ }
+ }
+ if ($value != '') {
+ $s->setCellValueByColumnAndRow($i, $j, $value);
+ //$s->getStyleByColumnAndRow($i, $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
+ }
+ $i++;
+ }
+ $j++;
+ }
+ // Rulers
+ $s = $xls->createSheet();
+ $s->setTitle('Rulers');
+
+ $rcols = array('page', 'type', 'pos');
+ $i = 0;
+ // Labels
+ foreach ($rcols as $id) {
+ $s->setCellValueByColumnAndRow($i, 1, $id);
+ $s->getColumnDimensionByColumn($i)->setAutoSize(true);
+ //$s->getStyleByColumnAndRow($i, 1)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+ $i++;
+ }
+
+ // Contents
+ $j = 2;
+ foreach ($rulers as $r) {
+ $i = 0;
+ foreach ($rcols as $id) {
+ if (!is_null($pages) && ($id == 'document_id' || $id == 'document_page')) {
+ $infos = $pages[$r['page']];
+ $value = $infos[$id];
+ } else {
+ $value = $r[$id];
+ }
+ $s->setCellValueByColumnAndRow($i, $j, $value);
+ $s->getStyleByColumnAndRow($i, $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
+ $i++;
+ }
+ $j++;
+ }
+
+ $xls->setActiveSheetIndex(0);
+ return $xls;
+ }
+
+ public static function testLink($uri)
+ {
+ $client = new Zend_Http_Client($uri);
+ try {
+ $client->request('head');
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+ return false;
+ }
+
+ public static function setDocumentLinks($document_id, $links, $rulers, $user, $comments, $time)
+ {
+ global $core;
+ $c = $core->con->openCursor('document_links_versions');
+ $c1 = $core->con->openCursor('document_links');
+ $c1->document_id = $c->document_id = $document_id;
+ $c1->links = $c->links = $links;
+ $c1->rulers = $c->rulers = $rulers;
+ $c->comments = $comments;
+ $c->user = $user;
+ $c->update = $time;
+ $c->insert();
+
+ $core->con->execute('DELETE FROM document_links WHERE document_id=' . $document_id);
+ $c1->insert();
+ }
+
+ public static function getDocumentLastLinks($document_id)
+ {
+ global $core;
+
+ $r = $core->con->select('SELECT * FROM document_links WHERE document_id=\'' . $document_id . '\'');
+ if (!$r->count()) {
+ $r = $core->con->select('SELECT * FROM document_links_versions WHERE document_id=' . $document_id . ' ORDER BY `update` DESC LIMIT 1');
+ $c = $core->con->openCursor('document_links');
+ $c->document_id = $document_id;
+ $c->links = $r->links;
+ $c->rulers = $r->rulers;
+ try {
+ $c->insert();
+ } catch (Exception $e) {
+ fb($e);
+ }
+ }
+
+ return self::_recordToLinks($r);
+ }
+
+ public static function getDocumentVersionLinks($document_id, $time)
+ {
+ global $core;
+ $r = $core->con->select('SELECT * FROM document_links_versions WHERE document_id=' . $document_id . ' AND `update`<=' . $time . ' ORDER BY `update` DESC LIMIT 1');
+ return self::_recordToLinks($r);
+ }
+
+ protected static function _recordToLinks($r)
+ {
+ if (mb_substr($r->links, 1, 1) == ':') {
+ $ll = unserialize($r->links);
+ $rr = unserialize($r->rulers);
+ } else {
+ $ll = json_decode($r->links, true);
+ $rr = json_decode($r->rulers, true);
+ }
+
+ return array('links' => $ll, 'rulers' => $rr);
+ }
+
+ public static function getLinksAndRulers($book_id, &$links, &$rulers, $time = null)
+ {
+
+ global $core;
+
+ $daoBook = new wsDAOBook($core->con);
+ $pages = $daoBook->getPagesOfBookAt($book_id, $time);
+
+ $documents = [];
+ foreach ($pages as $p => $infos) {
+ $documents[] = $infos['document_id'];
+ }
+ $documents = array_unique($documents);
+
+ $tlinks = array();
+ $trulers = array();
+
+ $links = array();
+ $rulers = array();
+
+ foreach ($documents as $d) {
+ if (is_null($time)) {
+ $lr = self::getDocumentLastLinks($d);
+ } else {
+ $lr = self::getDocumentVersionLinks($d, $time);
+ }
+ $tlinks[$d] = $lr['links'];
+ $trulers[$d] = $lr['rulers'];
+ }
+
+ $i = 1;
+ foreach ($pages as $p => $infos) {
+ if (isset($tlinks[$infos['document_id']][$infos['document_page']])) {
+ $l = $tlinks[$infos['document_id']][$infos['document_page']];
+ foreach ($l as $link) {
+ $link = (array)$link;
+ $link['page'] = $p;
+ $link['id'] = $i;
+ if (!isset($link['rot'])) {
+ $link['rot'] = 0;
+ }
+ $links[] = $link;
+ }
+ }
+ if (isset($trulers[$infos['document_id']][$infos['document_page']])) {
+ $ru = $trulers[$infos['document_id']][$infos['document_page']];
+ foreach ($ru as $ruler) {
+ $ruler['page'] = $p;
+ $rulers[] = $ruler;
+ }
+ }
+ }
+
+ $daoBook = new wsDAOBook($core->con);
+ $book = $daoBook->selectById($book_id);
+
+ $rulers = array_merge($rulers, $book->specialRulers);
+ $links = array_merge($links, $book->specialLinks);
+ }
+
+ public static function getLinksFromExcel($xls, &$links, &$rulers)
+ {
+ $s = $xls->setActiveSheetIndexByName('Links');
+ $i = 0;
+ $links = array();
+ foreach ($s->getRowIterator() as $row) {
+ $cellIterator = $row->getCellIterator();
+ $cellIterator->setIterateOnlyExistingCells(false);
+ if ($i == 0) {
+ $cols = array();
+ foreach ($cellIterator as $cell) {
+ $cols[] = $cell->getValue();
+ }
+ } else {
+ $link = array();
+ $j = 0;
+ foreach ($cellIterator as $cell) {
+ $link[$cols[$j]] = $cell->getValue();
+ $j++;
+ }
+ if ($link['display_area'] == '') {
+ $link['display_area'] = '1';
+ }
+ if (trim($link['infobulle']) == '') {
+ $link['infobulle'] = '';
+ }
+ $links[] = $link;
+ }
+
+ $i++;
+ }
+
+ $i = 0;
+ $rulers = array();
+ $s = $xls->setActiveSheetIndexByName('Rulers');
+ foreach ($s->getRowIterator() as $row) {
+ $cellIterator = $row->getCellIterator();
+ $cellIterator->setIterateOnlyExistingCells(false);
+ if ($i == 0) {
+ $cols = array();
+ foreach ($cellIterator as $cell) {
+ $cols[] = $cell->getValue();
+ }
+ } else {
+ $link = array();
+ $j = 0;
+ foreach ($cellIterator as $cell) {
+ $ruler[$cols[$j]] = $cell->getValue();
+ $j++;
+ }
+
+ $rulers[] = $ruler;
+ }
+ $i++;
+ }
+ }
+
+ public static function getLinksFromAutobookmarkText($txt, &$links, &$rulers)
+ {
+ $links = array();
+ $rulers = array();
+
+ $lines = explode("\n", $txt);
+
+ $protocols = array('mailto' => 3, 'custom' => 7, 'cart' => 12, 'pagelabel' => 26);
+
+ foreach ($lines as $line) {
+ $line = trim($line);
+ if ($line == '') {
+ continue;
+ }
+ if (strpos('#', $line) === 0) {
+ continue;
+ }
+ $target = $numerotation = '';
+ list($page, $left, $top, $width, $height, $type, $to) = explode(';', $line);
+ if ($type <= 2) {
+ $target = '_blank';
+ } elseif ($type == 5) {
+ $numerotation = 'physical';
+ }
+
+ $links[] = array(
+ 'page' => $page,
+ 'left' => $left, 'top' => $top, 'width' => $width, 'height' => $height, 'rot' => '',
+ 'type' => $type, 'to' => $to, 'target' => $target,
+ 'infobulle' => '', 'numerotation' => $numerotation, 'display_area' => '1');
+ }
+ }
+
+ public static function _getLinkKey()
+ {
+ if (self::$_linksKey === null) {
+ self::$_linksKey = base64_decode('o2p2yYGI8yMEHf+Y5/e6NdTINbbXg3NIo8BODgdhPxI=');
+ }
+ return self::$_linksKey;
+ }
+
+ public static function encryptLinks($links)
+ {
+ $res = [];
+ foreach ($links as $key => $link) {
+ $res[$key] = self::encryptLinkAttrs($link);
+ }
+ return $res;
+ }
+
+ public static function encryptLinkAttrs($link)
+ {
+ if (is_array($link)) {
+ $link = CubeIT_Util_Object::asObject($link);
+ }
+
+ $crypted = [13, 14, 35];
+
+ if (!in_array($link->type, $crypted)) {
+ return $link;
+ }
+
+ $attrs = ['image_rollover'];
+ foreach ($attrs as $attr) {
+ $link->$attr = trim($link->$attr);
+ if (strpos($link->$attr, '///') === 0 || $link->$attr == '') {
+ continue;
+ }
+ $link->$attr = '///' . CubeIT_Crypt::safeEncrypt($link->uid . '|||' . $link->$attr, self::_getLinkKey());
+ }
+ return $link;
+ }
+
+ public static function decryptLink($link)
+ {
+ $array = false;
+ if (is_array($link)) {
+ $array = true;
+ $link = CubeIT_Util_Object::asObject($link);
+ }
+
+ foreach ($link as $attr => $item) {
+ if (strpos($item, '///') !== 0) {
+ continue;
+ }
+ $v = CubeIT_Crypt::safeDecrypt(substr($item, 3), self::_getLinkKey());
+ $e = explode('|||', $v);
+ if ($e[0] === $link->uid) {
+ $link->$attr = $e[1];
+ } else {
+ $link->$attr = '';
+ }
+ }
+ if (!$array) {
+ return $link;
+ }
+ return CubeIT_Util_Array::asArray($link);
+ }
+
+ public static function decryptLinks($links)
+ {
+ $res = [];
+ foreach ($links as $key => $link) {
+ $res[$key] = self::decryptLink($link);
+ }
+ return $res;
+ }
}
\ No newline at end of file