4require_once(
"./Services/Preview/classes/class.ilPreviewSettings.php");
 
    5require_once(
"./Services/Preview/classes/class.ilPreview.php");
 
   61    public function __construct($a_node_id = 
null, $a_context = self::CONTEXT_REPOSITORY, $a_obj_id = 
null, $a_access_handler = 
null)
 
   64        $ilCtrl = 
$DIC[
'ilCtrl'];
 
   66        $ilAccess = 
$DIC[
'ilAccess'];
 
   69        if (strtolower(
$_GET[
"baseClass"]) == 
"ilpreviewgui") {
 
   70            $this->node_id = (int) 
$_GET[
"node_id"];
 
   71            $this->context = (int) 
$_GET[
"context"];
 
   72            $a_obj_id = (int) 
$_GET[
'obj_id'];
 
   74            $this->node_id = $a_node_id;
 
   75            $this->context = $a_context;
 
   79        $this->ctrl = $ilCtrl;
 
   83        if ($a_access_handler == 
null) {
 
   84            if ($this->context == self::CONTEXT_WORKSPACE) {
 
   85                include_once(
"./Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php");
 
   88                $a_access_handler = $ilAccess;
 
   91        $this->access_handler = $a_access_handler;
 
   94        if ($a_obj_id == 
null) {
 
   95            if ($this->context == self::CONTEXT_WORKSPACE) {
 
   96                $a_obj_id = $this->access_handler->getTree()->lookupObjectId($this->node_id);
 
  101        $this->obj_id = $a_obj_id;
 
  104        $this->preview = 
new ilPreview($this->obj_id);
 
  107        if (!$ilCtrl->isAsynch()) {
 
  118        $cmd = $this->ctrl->getCmd(
"getPreviewHTML");
 
  119        $next_class = $this->ctrl->getNextClass($this);
 
  121        switch ($next_class) {
 
  123                return $this->$cmd();
 
  135        $status = $this->preview->getRenderStatus();
 
  141        return "il.Preview.toggle(event, { id: '{$this->node_id}', htmlId: '{$a_html_id}', url: '$link', status: '$status', loadingText: '$loading_text' });";
 
  150        require_once(
'./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
 
  152        $tmpl = 
new ilTemplate(
"tpl.preview.html", 
true, 
true, 
"Services/Preview");
 
  153        $tmpl->setVariable(
"PREVIEW_ID", $this->
getHtmlId());
 
  156        $preview_status = $this->preview->getRenderStatus();
 
  159        if ($this->access_handler->checkAccess(
"read", 
"", $this->node_id)) {
 
  161            $images = $this->preview->getImages();
 
  162            if (count($images) > 0) {
 
  165                foreach ($images as $image) {
 
  166                    $tmpl->setCurrentBlock(
"preview_item");
 
  168                    $tmpl->setVariable(
"WIDTH", $image[
"width"]);
 
  169                    $tmpl->setVariable(
"HEIGHT", $image[
"height"]);
 
  170                    $tmpl->setVariable(
"ALT_TEXT", sprintf(
 
  171                        $this->lng->txt(
'preview_caption'),
 
  175                    $tmpl->parseCurrentBlock();
 
  180                $tmpl->setCurrentBlock(
"no_preview");
 
  181                switch ($preview_status) {
 
  183                        $tmpl->setVariable(
"TXT_NO_PREVIEW", $this->lng->txt(
"preview_status_pending"));
 
  187                        $tmpl->setVariable(
"TXT_NO_PREVIEW", $this->lng->txt(
"preview_status_failed"));
 
  191                        $tmpl->setVariable(
"TXT_NO_PREVIEW", $this->lng->txt(
"preview_status_missing"));
 
  194                $tmpl->parseCurrentBlock();
 
  198            $tmpl->setVariable(
"TXT_NO_PREVIEW", $this->lng->txt(
"no_access_item"));
 
  202        if ($this->ctrl->isAsynch()) {
 
  203            include_once(
"./Services/JSON/classes/class.ilJsonUtil.php");
 
  210            header(
'Vary: Accept');
 
  211            header(
'Content-type: text/plain');
 
  227        $tmpl = 
new ilTemplate(
"tpl.preview_inline.html", 
true, 
true, 
"Services/Preview");
 
  231        if ($this->access_handler->checkAccess(
"read", 
"", $this->node_id)) {
 
  236                "preview_status_creating",
 
  242        if ($this->access_handler->checkAccess(
"write", 
"", $this->node_id)) {
 
  247                "preview_status_deleting",
 
  263    private function renderCommand($tmpl, $a_cmd, $btn_topic, $loading_topic, $a_display_status)
 
  266        $preview_status = $this->preview->getRenderStatus();
 
  269        $link = $this->
buildUrl($a_cmd . 
"Preview");
 
  270        $script_args = 
"event, { id: '{$this->node_id}', htmlId: '$preview_html_id', url: '$link', loadingText: '$loading_text' }";
 
  273        if (!is_array($a_display_status) || !in_array($preview_status, $a_display_status)) {
 
  274            $action_class = 
"ilPreviewActionHidden";
 
  277        $tmpl->setCurrentBlock(
"preview_action");
 
  278        $tmpl->setVariable(
"CLICK_ACTION", 
"il.Preview.$a_cmd($script_args);");
 
  279        $tmpl->setVariable(
"ACTION_CLASS", 
"$action_class");
 
  280        $tmpl->setVariable(
"ACTION_ID", 
"preview_{$a_cmd}_" . $preview_html_id);
 
  281        $tmpl->setVariable(
"TXT_ACTION", $this->lng->txt($btn_topic));
 
  282        $tmpl->parseCurrentBlock();
 
  292        if ($this->access_handler->checkAccess(
"read", 
"", $this->node_id)) {
 
  295            $this->preview->create($obj);
 
  308        if ($this->access_handler->checkAccess(
"write", 
"", $this->node_id)) {
 
  310            require_once(
"./Services/Preview/classes/class.ilPreview.php");
 
  311            $this->preview->delete();
 
  332    private function buildUrl($a_cmd = 
"", $a_async = 
true)
 
  334        $link = 
"ilias.php?baseClass=ilPreviewGUI&node_id={$this->node_id}&context={$this->context}&obj_id={$this->obj_id}";
 
  337            $link .= 
"&cmdMode=asynch";
 
  340        if (!empty($a_cmd)) {
 
  341            $link .= 
"&cmd=$a_cmd";
 
  353        if (self::$initialized) {
 
  365        $DIC->ui()->mainTemplate()->addJavaScript(
"./libs/bower/bower_components/jquery-mousewheel/jquery.mousewheel.js");
 
  366        $DIC->ui()->mainTemplate()->addJavaScript(
"./Services/Preview/js/ilPreview.js");
 
  369        $tmpl = 
new ilTemplate(
"tpl.preview.html", 
true, 
true, 
"Services/Preview");
 
  370        $tmpl->setCurrentBlock(
"no_preview");
 
  371        $tmpl->setVariable(
"TXT_NO_PREVIEW", 
"%%0%%");
 
  372        $tmpl->parseCurrentBlock();
 
  374        $initialHtml = str_replace(array(
"\r\n", 
"\r"), 
"\n", $tmpl->get());
 
  375        $lines = explode(
"\n", $initialHtml);
 
  376        $new_lines = array();
 
  377        foreach ($lines as 
$i => $line) {
 
  379                $new_lines[] = trim($line);
 
  382        $initialHtml = implode($new_lines);
 
  385        $DIC->ui()->mainTemplate()->addOnLoadCode(
"il.Preview.texts.preview = \"" . self::jsonSafeString(
$DIC->language()->txt(
"preview")) . 
"\";");
 
  386        $DIC->ui()->mainTemplate()->addOnLoadCode(
"il.Preview.texts.showPreview = \"" . self::jsonSafeString(
$DIC->language()->txt(
"preview_show"))
 
  390        $DIC->ui()->mainTemplate()->addOnLoadCode(
"il.Preview.initialHtml = " . json_encode($initialHtml) . 
";");
 
  391        $DIC->ui()->mainTemplate()->addOnLoadCode(
"il.Preview.highlightClass = \"ilContainerListItemOuterHighlight\";");
 
  392        $DIC->ui()->mainTemplate()->addOnLoadCode(
"il.Preview.init();");
 
  394        self::$initialized = 
true;
 
  405        if (!is_string($text)) {
 
  409        $text = htmlentities($text, ENT_COMPAT | ENT_HTML401, 
"UTF-8");
 
  410        $text = str_replace(
"'", 
"'", $text);
 
An exception for terminatinating execution or to throw for unit testing.
static encode($mixed, $suppress_native=false)
static _lookupTitle($a_id)
lookup object title
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupObjId($a_id)
getInlineHTML()
Gets the HTML that is used for displaying the preview inline.
renderPreview()
Renders the preview and returns the HTML code that displays the preview.
static jsonSafeString($text)
Makes the specified string safe for JSON.
deletePreview()
Deletes the preview and returns the HTML code that displays the preview.
getHtmlId()
Gets the HTML id for the preview.
getPreviewHTML()
Gets the HTML that displays the preview.
executeCommand()
execute command
static initPreview()
Initializes the preview and loads the needed javascripts and styles.
__construct($a_node_id=null, $a_context=self::CONTEXT_REPOSITORY, $a_obj_id=null, $a_access_handler=null)
Creates a new preview GUI.
getJSCall($a_html_id)
Gets the JavaScript code to show the preview.
renderCommand($tmpl, $a_cmd, $btn_topic, $loading_topic, $a_display_status)
Renders a command to the specified template.
buildUrl($a_cmd="", $a_async=true)
Builds the URL to call the preview GUI.
static getImageSize()
Gets the size of the preview images in pixels.
const RENDER_STATUS_FAILED
const RENDER_STATUS_CREATED
const RENDER_STATUS_PENDING
special template class to simplify handling of ITX/PEAR
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
static signFile($path_to_file)
Access handler for personal workspace.
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template