function widget($args, $instance) { //set in kalins_pdf_create.php, in case the user just clicked a split second earlier and it's still processing global $kalinsPDFRunning; if (isset($kalinsPDFRunning)) { return ""; } if (!is_single() && !is_page()) { //if we're not on a page or post we don't show the widget return ""; } $adminOptions = kalins_pdf_get_options(KALINS_PDF_ADMIN_OPTIONS_NAME); global $post; $meta = json_decode(get_post_meta($post->ID, "kalinsPDFMeta", true)); if ($meta) { $showLink = $meta->showLink; } if (!$meta || $showLink == "default") { if (str_word_count(strip_tags($post->post_content)) > $adminOptions->wordCount) { //if this post is longer than the minimum word count $showLink = $adminOptions->showLink; } else { return ""; //if it's not long enough, just quit } } if ($showLink === "none") { //if we don't want a link or if we're not on a single page/post we don't need to do anything else return ""; } //at this point we know we're going to show a link extract($args); //change postID to identify if it's a page or post for use by our create script $postID = $post->ID; if ($post->post_type == "page") { $postID = "pg_" . $postID; } else { $postID = "po_" . $postID; } //if we have not saved an option, use the default and run it's shortcode conversion; else grab the widget setting and run its shortcode conversion if (empty($instance['beforeLink'])) { $adminOptions->beforeLink = kalins_pdf_page_shortcode_replace($adminOptions->beforeLink, $post); } else { $adminOptions->beforeLink = kalins_pdf_page_shortcode_replace($instance["beforeLink"], $post); } if (empty($instance['linkText'])) { $adminOptions->linkText = kalins_pdf_page_shortcode_replace($adminOptions->linkText, $post); } else { $adminOptions->linkText = kalins_pdf_page_shortcode_replace($instance["linkText"], $post); } if (empty($instance['afterLink'])) { $adminOptions->afterLink = kalins_pdf_page_shortcode_replace($adminOptions->afterLink, $post); } else { $adminOptions->afterLink = kalins_pdf_page_shortcode_replace($instance["afterLink"], $post); } //begin echoing content to user-facing widget echo $before_widget; //echo wordpress' standard html if (!empty($instance['title'])) { //only show the title if this widget has one echo $before_title . $instance['title'] . $after_title; } echo $adminOptions->beforeLink . '<a href="' . get_bloginfo('wpurl') . '/wp-content/plugins/kalins-pdf-creation-station/kalins_pdf_create.php?singlepost=' . $postID . '" target="_blank" >' . $adminOptions->linkText . '</a>' . $adminOptions->afterLink; echo $after_widget; }
$totalTXT = $totalTXT . $content; // output the HTML content $objTcpdf->writeHTML($strHtml, true, 0, true, 0); //$proBar->increase(); } } catch (Exception $e) { $outputVar->status = "problem creating pages and posts. Perhaps there's a problem with one of the pages you've selected or with the before or after HTML."; die(json_encode($outputVar)); } try { if ($finalPage != "") { $objTcpdf->AddPage(); //create final page in pdf $objTcpdf->SetFont(PDF_FONT_NAME_MAIN, '', $fontSize); if ($isSingle) { $finalPage = kalins_pdf_page_shortcode_replace($finalPage, $result[0]); } else { $finalPage = kalins_pdf_global_shortcode_replace($finalPage); } $strHtml = wpautop($finalPage, true); $totalHTML = $totalHTML . $strHtml; $totalTXT = $totalTXT . $finalPage; $objTcpdf->writeHTML($strHtml, true, 0, true, 0); } } catch (Exception $e) { $outputVar->status = "problem creating final page."; die(json_encode($outputVar)); } try { if ($includeTOC) { // add a new page for TOC