GithubHelp home page GithubHelp logo

Comments (3)

Jako avatar Jako commented on June 14, 2024

What is inside of plugin with the id 17?

from pdfresource.

ufabooks avatar ufabooks commented on June 14, 2024

I haven't found the recursion reason.
by means of the friend have rewritten a plug-in

`<?php

$pdfresourceCorePath = $modx->getOption('pdfresource.core_path', null, $modx->getOption('core_path') . 'components/pdfresource/');
$pdfresource = $modx->getService('pdfresource', 'PDFResource', $pdfresourceCorePath . 'model/pdfresource/', $scriptProperties);

if (!function_exists('checkTvAssigned')) {
function checkTvAssigned(&$pdfresource, &$resource, $tvOptName, $tvDefVal) {
global $modx;
$tplVarTmplTbl = $modx->getTableName('modTemplateVarTemplate');
$tplVarTbl = $modx->getTableName('modTemplateVar');
$pdfTvName = $modx->quote($pdfresource->getOption($tvOptName, null, $tvDefVal));
$tplId = $resource->get('template');

    $assocRes = $modx->query("SELECT `modTemplateVar`.`name`, `modTemplateVarTemplate`.`templateid`
      FROM $tplVarTmplTbl AS `modTemplateVarTemplate`
      LEFT JOIN $tplVarTbl `modTemplateVar`
        ON `modTemplateVarTemplate`.`tmplvarid` = `modTemplateVar`.`id` 
     WHERE (`modTemplateVar`.`name` = $pdfTvName AND `modTemplateVarTemplate`.`templateid` = $tplId );");
    $assigned = $assocRes->fetch(PDO::FETCH_ASSOC);
    return !!$assigned;
}

}

$eventName = $modx->event->name;
switch ($eventName) {
case 'OnDocFormSave':
/** @var modResource $resource */
$assigned = checkTvAssigned($pdfresource, $resource, 'pdfTv', 'create_pdf');

    if ($assigned) {
        $modx->switchContext($resource->context_key);
        $aliasPath = $resource->get('parent') ? preg_replace('#(\.[^./]*)$#', '/', $modx->makeUrl($resource->get('parent'))) : '';
        $modx->switchContext('mgr');

        $createPDF = intval($resource->getTVValue($pdfresource->getOption('pdfTv', null, 'create_pdf')));
        $pdfDirPath = $pdfresource->getOption('pdfPath') . $aliasPath;
        $pdfFilePath = $pdfDirPath . $resource->get('alias') . '.pdf';

        if ($createPDF) {
            if (!file_exists($pdfDirPath)){
                mkdir(rtrim($pdfDirPath, '/'), 0755, true);
            }
            $modx->invokeEvent('OnHandleRequest', array()); // call ClientConfig if installed
            $modx->resource = &$resource;
            $pdfresource->createPDF($resource, $aliasPath);
        } elseif (file_exists($pdfFilePath)){
            @unlink($pdfFilePath);
        }
    }
    break;
case 'OnWebPagePrerender':
    // Generate the PDF on the fly once if it does not exist and live_pdf template variable is checked
    // Check if the live_pdf template variable is assigned
    $assigned = checkTvAssigned($pdfresource, $modx->resource, 'pdfTvLive', 'live_pdf');

    if ($assigned) {
        $livePDF = intval($modx->resource->getTVValue($pdfresource->getOption('pdfTvLive', null, 'live_pdf')));
        if ($livePDF) {
            header('Content-Type: application/pdf');
            header('Content-Disposition:inline;filename=' . $modx->resource->get('alias') . '.pdf');
            echo $pdfresource->createPDF($modx->resource, false);
            exit;
        }
    }
    // Generate the PDF once if it does not exist, create_pdf template variable is assigned and system setting generateOnPrerender is enabled
    if ($pdfresource->getOption('generateOnPrerender')) {

        $assigned = checkTvAssigned($pdfresource, $modx->resource, 'pdfTv', 'create_pdf');
        if ($assigned) {
            $aliasPath = $modx->resource->get('parent') ? preg_replace('#(\.[^./]*)$#', '/', $modx->makeUrl($modx->resource->get('parent'))) : '';

            $createPDF = intval($modx->resource->getTVValue($pdfresource->getOption('pdfTv', null, 'create_pdf')));
            $pdfDirPath = $pdfresource->getOption('pdfPath') . $aliasPath;
            $pdfFilePath = $pdfDirPath . $modx->resource->get('alias') . '.pdf';

            if ($createPDF /*&& (!file_exists($pdfFilePath) || $pdfresource->getOption('regenerateAll'))*/) {
                if (!file_exists($pdfDirPath)){
                    mkdir(rtrim($pdfDirPath, '/'), 0755, true);
                }
                $pdfresource->createPDF($modx->resource, $aliasPath);
            }
        }
    }

}

return;`

from pdfresource.

Jako avatar Jako commented on June 14, 2024

Could not reproduce this. Feel free to reopen the issue with more specific informations.

from pdfresource.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.