public function exportTopics(Application $app, Request $request) { $lng = $app['locale']; $obr = explode(';', $request->get('obr')); $t_lng = []; if ($request->get('ofm') == 'tofiles') { $t_lng = array_map(function ($code) { $lng_code = explode('_', $code); return $lng_code[0]; }, array_keys($app['locales.available'])); } else { $t_lng[] = $request->get('piv'); } switch ($request->get('obrf')) { case 'from_itf_closable': $default_display = 'closed'; $opened_display = 'opened'; break; case 'from_itf_static': $default_display = 'closed'; $opened_display = 'static'; break; case 'all_opened_closable': $default_display = 'opened'; $opened_display = ''; break; case 'all_opened_static': $default_display = 'static'; $opened_display = ''; break; case 'all_closed': $default_display = 'closed'; $opened_display = ''; break; } $now = date('YmdHis'); $lngs = []; try { $databox = $app['phraseanet.appbox']->get_databox((int) $request->get("bid")); if ($request->get("typ") == "TH") { $domth = $databox->get_dom_thesaurus(); } else { $domth = $databox->get_dom_cterms(); } if ($domth) { $xpathth = new \DOMXPath($domth); if ($request->get("id") == "T") { $q = "/thesaurus"; } elseif ($request->get("id") == "C") { $q = "/cterms"; } else { $q = "//te[@id='" . $request->get("id") . "']"; } if ($request->get('ofm') == 'toscreen') { printf("<pre style='font-size: 12px;'>\n"); } foreach ($t_lng as $lng) { $dom = new \DOMDocument("1.0", "UTF-8"); $dom->standalone = true; $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $root = $dom->appendChild($dom->createElementNS('www.phraseanet.com', 'phraseanet:topics')); $root->appendChild($dom->createComment($app->trans('thesaurus:: fichier genere le %date%', ['%date%' => $now]))); $root->appendChild($dom->createElement('display'))->appendChild($dom->createElement('defaultview'))->appendChild($dom->createTextNode($default_display)); $this->export0Topics($app, $xpathth->query($q)->item(0), $dom, $root, $lng, $request->get("srt"), $request->get("sth"), $request->get("sand"), $opened_display, $obr); if ($request->get("ofm") == 'toscreen') { $lngs[$lng] = str_replace(['&', '<', '>'], ['&', '<', '>'], $dom->saveXML()); } elseif ($request->get("ofm") == 'tofiles') { $fname = 'topics_' . $lng . '.xml'; @rename($app['root.path'] . '/config/topics/' . $fname, $app['root.path'] . '/config/topics/topics_' . $lng . '_BKP_' . $now . '.xml'); if ($dom->save($app['root.path'] . '/config/topics/' . $fname)) { $lngs[$lng] = \p4string::MakeString($app->trans('thesaurus:: fichier genere : %filename%', ['%filename%' => $fname])); } else { $lngs[$lng] = \p4string::MakeString($app->trans('thesaurus:: erreur lors de l\'enregsitrement du fichier')); } } } } } catch (\Exception $e) { } return $app['twig']->render('thesaurus/export-topics.html.twig', ['lngs' => $lngs, 'ofm' => $request->get('ofm')]); }
public function calcSQL(Application $app, $sxtask, $playTest = false) { $sbas_id = (int) $sxtask['sbas_id']; $ret = ['name' => $sxtask['name'] ? (string) $sxtask['name'] : 'sans nom', 'name_htmlencoded' => \p4string::MakeString($sxtask['name'] ? $sxtask['name'] : 'sans nom', 'html'), 'active' => trim($sxtask['active']) === '1', 'sbas_id' => $sbas_id, 'basename' => '', 'basename_htmlencoded' => '', 'action' => strtoupper($sxtask['action']), 'sql' => null, 'err' => '', 'err_htmlencoded' => '']; try { $dbox = $app['phraseanet.appbox']->get_databox($sbas_id); $ret['basename'] = $dbox->get_label($app['locale']); $ret['basename_htmlencoded'] = htmlentities($ret['basename']); switch ($ret['action']) { case 'UPDATE': $ret['sql'] = $this->calcUPDATE($app, $sbas_id, $sxtask, $playTest); break; case 'DELETE': $ret['sql'] = $this->calcDELETE($app, $sbas_id, $sxtask, $playTest); $ret['deletechildren'] = (int) $sxtask['deletechildren']; break; default: $ret['err'] = "bad action '" . $ret['action'] . "'"; $ret['err_htmlencoded'] = htmlentities($ret['err']); break; } } catch (\Exception $e) { $ret['err'] = "bad sbas '" . $sbas_id . "'"; $ret['err_htmlencoded'] = htmlentities($ret['err']); } return $ret; }
private static function drawTopics($topics, $depth = 0, $triid = '', $defaultview) { $n = 0; $out = ''; foreach ($topics->topic as $subtopic) { $tid = $triid . '_' . $n; $s = $subtopic->label; $l = p4string::MakeString($s, 'html'); $l = '<span class=\'topic_' . $depth . '\'>' . $l . '</span>'; if ($subtopic->query) { $q = str_replace(["\\", "\"", "'", "\r", "\n"], ["\\\\", """, "\\'", "\\r", "\\n"], $subtopic->query); $q = '<a href="javascript:void();" onClick="doSpecialSearch(\'' . $q . '\',true);">' . $l . '</a>'; } else { $q = $l; } if (self::hastopics($subtopic)) { $view = mb_strtolower($subtopic['view']); if (!$view) { $view = $defaultview; } switch ($view) { case 'opened': $out .= '<li><a id=\'TOPIC_TRI' . $tid . '\' class="opened" href="javascript:void();" onclick="clktri(\'' . $tid . '\');return(false);"></a> ' . $q . '</li>' . "\n"; $out .= "<ul id='TOPIC_UL{$tid}' class='opened'>\n"; $out .= self::drawTopics($subtopic->topics, $depth + 1, $tid, $defaultview); $out .= "</ul>\n<div style='height:1px;'></div>\n"; break; case 'closed': $out .= '<li><a id=\'TOPIC_TRI' . $tid . '\' class="closed" href="javascript:void();" onclick="clktri(\'' . $tid . '\');return(false);"></a> ' . $q . '</li>' . "\n"; $out .= "<ul id='TOPIC_UL{$tid}' class='closed'>\n"; $out .= self::drawTopics($subtopic->topics, $depth + 1, $tid, $defaultview); $out .= "</ul>\n<div style='height:1px;'></div>\n"; break; case 'static': default: $out .= '<li><span id=\'TOPIC_TRI' . $tid . '\' class="static"> </span> ' . $q . '</li>' . "\n"; $out .= "<ul id='TOPIC_UL{$tid}' class='static'>\n"; $out .= self::drawTopics($subtopic->topics, $depth + 1, $tid, $defaultview); $out .= "</ul>\n<div style='height:1px;'></div>\n"; break; } } else { $out .= '<li><span id=\'TOPIC_TRI' . $tid . '\' class="none"> </span> ' . $q . '</li>' . "\n"; } $n++; } return $out; }