Ejemplo n.º 1
0
/**
 * Erstellt ein PDF aus gespeicherten Anträgen
 *
 * @param int $post_id Post-ID
 * @param object $post the post
 */
function cvtx_create_pdf($post_id, $post = null, $event_id = false)
{
    global $cvtx_mime_types;
    $options = get_option('cvtx_options');
    $pdflatex = $options['cvtx_pdflatex_cmd'];
    if (isset($post) && is_object($post) && !empty($pdflatex)) {
        $out_dir = wp_upload_dir();
        $out_dir = $out_dir['path'] . '/';
        if (isset($options['cvtx_latex_tpl-plugin-dir']) && $options['cvtx_latex_tpl-plugin-dir']) {
            $tpl_dir = $options['cvtx_latex_tpl-plugin-dir'];
        } else {
            $tpl_dir = get_template_directory() . '/' . $options['cvtx_latex_tpldir'];
        }
        // prepare antrag
        if (property_exists($post, 'post_type') && $post->post_type == 'cvtx_antrag') {
            // file
            if ($post->post_status == 'publish' && ($short = cvtx_get_short($post))) {
                $file = $out_dir . cvtx_sanitize_file_name($short . '_' . $post->post_title);
            } else {
                $file = $out_dir . $post->ID;
            }
            // set file post type
            $file_post_type = 'cvtx_antrag';
        } else {
            if (property_exists($post, 'post_type') && $post->post_type == 'cvtx_aeantrag' && isset($options['cvtx_aeantrag_pdf'])) {
                // file
                if ($post->post_status == 'publish' && ($short = cvtx_get_short($post))) {
                    $file = $out_dir . cvtx_sanitize_file_name($short);
                } else {
                    $file = $out_dir . $post->ID;
                }
                // set file post type
                $file_post_type = 'cvtx_aeantrag';
            } else {
                if (property_exists($post, 'post_type') && $post->post_type == 'cvtx_application') {
                    // file
                    if ($post->post_status == 'publish' && ($short = cvtx_get_short($post))) {
                        $file = $out_dir . cvtx_sanitize_file_name($short);
                    } else {
                        $file = $out_dir . $post->ID;
                    }
                    // set file post type
                    $file_post_type = 'cvtx_application';
                } else {
                    if (property_exists($post, 'post_type') && $post->post_type == 'cvtx_reader') {
                        // file
                        if ($post->post_status == 'publish') {
                            $file = $out_dir . cvtx_sanitize_file_name($post->post_title);
                        } else {
                            $file = $out_dir . $post->ID;
                        }
                        // get reader style
                        $style = get_post_meta($post->ID, 'cvtx_reader_style', true);
                        if ($style != 'book' && $style != 'table') {
                            $style = 'book';
                        }
                        // set file post type
                        $file_post_type = 'cvtx_reader_' . $style;
                        // get reader type
                        if (function_exists('cvtx_spd_map_reader_type')) {
                            $type = get_post_meta($post->ID, 'cvtx_reader_type', true);
                            $type_short = cvtx_map_reader_type($type);
                            $file_post_type = 'cvtx_reader_' . $style . '_' . $type_short;
                        }
                    } else {
                        if (property_exists($post, 'slug')) {
                            $file = $out_dir . cvtx_sanitize_file_name($post->name);
                            $file_post_type = 'cvtx_taxonomy';
                        }
                    }
                }
            }
        }
        // get template
        if (isset($file_post_type) && !empty($file_post_type)) {
            // use special theme template for id=x if exists
            if (property_exists($post, 'post_type') && is_file($tpl_dir . '/single-' . $file_post_type . '-' . $post->ID . '.php')) {
                $tpl = $tpl_dir . '/single-' . $file_post_type . '-' . $post->ID . '.php';
            } else {
                if (function_exists('cvtx_spd_antrag_is_decided') && property_exists($post, 'post_type') && $post->post_type == 'cvtx_antrag' && cvtx_spd_antrag_is_decided($post->ID) && is_file($tpl_dir . '/single-' . $file_post_type . '-decided.php')) {
                    $tpl = $tpl_dir . '/single-' . $file_post_type . '-decided.php';
                } else {
                    if (is_file($tpl_dir . '/single-' . $file_post_type . '.php')) {
                        $tpl = $tpl_dir . '/single-' . $file_post_type . '.php';
                    } else {
                        if (is_file(CVTX_PLUGIN_DIR . '/latex/single-' . $file_post_type . '.php')) {
                            $tpl = CVTX_PLUGIN_DIR . '/latex/single-' . $file_post_type . '.php';
                        }
                    }
                }
            }
        }
        // create pdf if template found
        if (isset($tpl) && !empty($tpl) && isset($file) && !empty($file)) {
            // drop old attachments if exists
            if (property_exists($post, 'ID')) {
                foreach (array('pdf', 'log', 'tex') as $ending) {
                    if ($attachment = get_post_meta($post->ID, 'cvtx_' . $ending . '_id', true)) {
                        wp_delete_attachment($attachment, true);
                    }
                }
            }
            // start buffering
            ob_start();
            $post_bak = $post;
            // run latex template, caputure output
            require $tpl;
            $out = ob_get_contents();
            // cleanup
            $post = $post_bak;
            wp_reset_postdata();
            ob_end_clean();
            // save output to latex file. success?
            if (file_put_contents($file . '.tex', $out) !== false) {
                $cmd = $pdflatex . ' -interaction=nonstopmode ' . ' -output-format=pdf ' . ' -output-directory=' . escapeshellcmd($out_dir) . ' ' . escapeshellcmd($file) . '.tex';
                putenv('PATH=' . getenv('PATH') . ':/usr/bin/:/usr/texbin/');
                // run pdflatex
                shell_exec($cmd);
                // if reader is generated: run it twice to build toc and pagewise linenumbers.
                if (property_exists($post, 'slug') || $post->post_type == 'cvtx_reader' || $post->post_type == 'cvtx_antrag') {
                    exec($cmd);
                    exec($cmd);
                    exec($cmd);
                }
                $attach = array('pdf', 'log', 'tex');
                // remove .aux-file
                $remove = array('aux', 'toc', 'bbl', 'blg', 'out', 'synctex.gz');
                // remove .log-file
                if ($options['cvtx_drop_logfile'] == 2 && is_file($file . '.pdf') || $options['cvtx_drop_logfile'] == 1) {
                    $remove[] = 'log';
                }
                // remove .tex-file
                if ($options['cvtx_drop_texfile'] == 2 && is_file($file . '.pdf') || $options['cvtx_drop_texfile'] == 1) {
                    $remove[] = 'tex';
                }
                // remove files (if they exist)
                foreach ($remove as $ending) {
                    if (is_file($file . '.' . $ending)) {
                        unlink($file . '.' . $ending);
                    }
                }
                if (property_exists($post, 'post_type')) {
                    // register files as attachments
                    foreach ($attach as $ending) {
                        if (is_file($file . '.' . $ending) && !in_array($ending, $remove)) {
                            $attachment = array('post_mime_type' => $cvtx_mime_types[$ending], 'post_title' => $post->post_type . '_' . $post->ID, 'post_content' => '', 'post_status' => 'inherit', 'post_parent' => $post->ID);
                            $attach_id = wp_insert_attachment($attachment, $file . '.' . $ending);
                            update_post_meta($post->ID, 'cvtx_' . $ending . '_id', $attach_id);
                        }
                    }
                } else {
                    foreach ($attach as $ending) {
                        if ($ending == "pdf") {
                            // return pdf file name
                            print str_replace(get_home_path(), '', $file . '.' . $ending);
                        }
                    }
                }
            }
        }
    }
}
Ejemplo n.º 2
0
    ?>
\textbf{<?php 
    cvtx_spd_antrag_expl($post);
    ?>
}
<?php 
} elseif (cvtx_spd_has_ak_recommendation($post)) {
    ?>
\textbf{<?php 
    cvtx_spd_ak_recommendation($post);
    ?>
}\\
\newline
<?php 
}
if (!cvtx_spd_antrag_is_decided($post->ID)) {
    cvtx_spd_version_ak($post);
}
?>
\par
<?php 
if (!$col1) {
    ?>
\end{myLN}
\setcounter{cell2}{\value{numberLines}}
\ifnum\value{numberLines} > \value{maxNum}
\setcounter{maxNum}{\value{numberLines}}
\fi
\addtostream{linenumbers}{\protect\newcounter{row\the\value{rows}}\protect\setcounter{row\the\value{rows}}{\the\value{maxNum}}}
\ifcounter{row\the\value{rows}}{
\ifnum\value{cell2}<\value{row\the\value{rows}}
Ejemplo n.º 3
0
 * @package WordPress
 * @subpackage cvtx_theme_spd
 */
?>

<?php 
get_header();
?>
	<div class="inner">
	<?php 
if (have_posts()) {
    while (have_posts()) {
        the_post();
        ?>
	    <?php 
        $decided = cvtx_spd_antrag_is_decided($post->ID);
        ?>
        <?php 
        $finished = cvtx_spd_antrag_is_finished($post->ID);
        ?>
		<div <?php 
        post_class();
        ?>
 id="post-<?php 
        the_ID();
        ?>
">
			<h2><?php 
        the_title();
        ?>
</h2>