function FetchTemplate($template, $vars, $type = 'link') { if (!isset($vars['ID']) || intval($vars['ID']) < 1) { return ''; } $default['link'] = file_get_contents(dirname(__FILE__) . '/templates/link-template-default.php'); $default['popup'] = file_get_contents(dirname(__FILE__) . '/templates/page-template-default.php'); $default['page'] = file_get_contents(dirname(__FILE__) . '/templates/page-template-default.php'); $vars = wpdm_setup_package_data($vars); if ($template == '') { $template = $type == 'page' ? $vars['page_template'] : $vars['template']; } if ($template == '') { $template = $default[$type]; } if (file_exists(TEMPLATEPATH . '/' . $template)) { $template = file_get_contents(TEMPLATEPATH . '/' . $template); } else { if (file_exists(dirname(__FILE__) . '/templates/' . $template)) { $template = file_get_contents(dirname(__FILE__) . '/templates/' . $template); } else { if (file_exists(dirname(__FILE__) . '/templates/' . $template . '.php')) { $template = file_get_contents(dirname(__FILE__) . '/templates/' . $template . '.php'); } else { if (file_exists(dirname(__FILE__) . '/templates/' . $type . "-template-" . $template . '.php')) { $template = file_get_contents(dirname(__FILE__) . '/templates/' . $type . "-template-" . $template . '.php'); } } } } $templates = maybe_unserialize(get_option("_fm_link_templates", true)); if (isset($templates[$template]) && isset($templates[$template]['content'])) { $template = $templates[$template]['content']; } preg_match_all("/\\[cf ([^\\]]+)\\]/", $template, $cfmatches); preg_match_all("/\\[thumb_([0-9]+)x([0-9]+)\\]/", $template, $matches); preg_match_all("/\\[thumb_url_([0-9]+)x([0-9]+)\\]/", $template, $umatches); preg_match_all("/\\[thumb_gallery_([0-9]+)x([0-9]+)\\]/", $template, $gmatches); preg_match_all("/\\[excerpt_([0-9]+)\\]/", $template, $xmatches); preg_match_all("/\\[pdf_thumb_([0-9]+)x([0-9]+)\\]/", $template, $pmatches); //preg_match_all("/\[download_link ([^\]]+)\]/", $template, $cmatches); $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($vars['ID']), 'full'); $vars['preview'] = $thumb['0']; $pdf = isset($vars['files'][0]) ? $vars['files'][0] : ''; $ext = explode(".", $pdf); $ext = end($ext); if ($ext == 'pdf') { $vars['pdf_thumb'] = "<img src='" . wpdm_pdf_thumbnail($pdf, $vars['ID']) . "' />"; } else { $vars['pdf_thumb'] = $vars['preview'] != '' ? "<img src='{$vars['preview']}' />" : ""; } foreach ($pmatches[0] as $nd => $scode) { $keys[] = $scode; $imsrc = wpdm_dynamic_thumb(wpdm_pdf_thumbnail($pdf, $vars['ID']), array($pmatches[1][$nd], $pmatches[2][$nd])); $values[] = $imsrc != '' ? "<img src='" . $imsrc . "' alt='{$vars['title']}' />" : ''; } $vars['wpdm_custom_field_table'] = wpdm_custom_fields_table($vars); foreach ($matches[0] as $nd => $scode) { $keys[] = $scode; $imsrc = wpdm_dynamic_thumb($vars['preview'], array($matches[1][$nd], $matches[2][$nd])); $values[] = $vars['preview'] != '' ? "<img src='" . $imsrc . "' alt='{$vars['title']}' />" : ''; } foreach ($umatches[0] as $nd => $scode) { $keys[] = $scode; $values[] = $vars['preview'] != '' ? wpdm_dynamic_thumb($vars['preview'], array($umatches[1][$nd], $umatches[2][$nd])) : ''; } foreach ($gmatches[0] as $nd => $scode) { $keys[] = $scode; $values[] = wpdm_get_additional_preview_images($vars, $gmatches[1][$nd], $gmatches[2][$nd]); } /** * Depracated for premium package add-on * foreach ($cmatches[0] as $nd => $scode) { * $keys[] = $scode; * //die($vars['download_link']) ; * $tmpvar = explode(".", $cmatches[1][$nd]); * if (in_array(end($tmpvar), array('png', 'jpg', 'jpeg', 'gif'))) { * $cmatches[1][$nd] = trim($cmatches[1][$nd]); * $vars['link_label'] = "<img class='wpdm-thumb' src='{$cmatches[1][$nd]}' alt='" . __('Download', 'wpdmpro') . "' />"; * $values[] = DownloadLink($vars, 0); * } //preg_replace("/>.+?<\/a>/","/><img src='".$cmatches[1][$nd].'"/></a>', $vars['download_link']); * else * $values[] = str_replace('[btnclass]', $cmatches[1][$nd], $vars['download_link']); * } */ foreach ($xmatches[0] as $nd => $scode) { $keys[] = $scode; $ss = substr(strip_tags($vars['description']), 0, intval($xmatches[1][$nd])); $tmp = explode(" ", substr(strip_tags($vars['description']), intval($xmatches[1][$nd]))); $bw = array_shift($tmp); $ss .= $bw; $values[] = $ss . '...'; } if ($type == 'page' && (strpos($template, '[similar_downloads]') || strpos($vars['description'], '[similar_downloads]'))) { $vars['similar_downloads'] = wpdm_similar_packages($vars, 5); } $vars['doc_preview'] = wpdm_doc_preview($vars); foreach ($vars as $key => $value) { $keys[] = "[{$key}]"; $values[] = $value; } if ($vars['download_link'] == 'blocked' && $type == 'link') { return ""; } if ($vars['download_link'] == 'blocked' && $type == 'page') { return get_option('wpdm_permission_msg'); } if ($vars['download_link'] == 'loginform' && $type == 'link') { return ""; } if ($vars['download_link'] == 'loginform' && $type == 'page') { return wpdm_loginform(); } return @str_replace($keys, $values, @stripcslashes($template)); }
function FetchTemplate($template, $vars, $type = 'link') { if (!isset($vars['ID']) || intval($vars['ID']) < 1) { return ''; } $default['link'] = file_get_contents(dirname(__FILE__) . '/templates/link-template-default.php'); $default['popup'] = file_get_contents(dirname(__FILE__) . '/templates/page-template-default.php'); $default['page'] = file_get_contents(dirname(__FILE__) . '/templates/page-template-default.php'); $vars = wpdm_setup_package_data($vars); if ($template == '') { $template = $type == 'page' ? $vars['page_template'] : $vars['template']; } if ($template == '') { $template = $default[$type]; } if (file_exists(TEMPLATEPATH . '/' . $template)) { $template = file_get_contents(TEMPLATEPATH . '/' . $template); } else { if (file_exists(dirname(__FILE__) . '/templates/' . $template)) { $template = file_get_contents(dirname(__FILE__) . '/templates/' . $template); } else { if (file_exists(dirname(__FILE__) . '/templates/' . $template . '.php')) { $template = file_get_contents(dirname(__FILE__) . '/templates/' . $template . '.php'); } else { if (file_exists(dirname(__FILE__) . '/templates/' . $type . "-template-" . $template . '.php')) { $template = file_get_contents(dirname(__FILE__) . '/templates/' . $type . "-template-" . $template . '.php'); } } } } $templates = maybe_unserialize(get_option("_fm_link_templates", true)); if (isset($templates[$template]) && isset($templates[$template]['content'])) { $template = $templates[$template]['content']; } preg_match_all("/\\[cf ([^\\]]+)\\]/", $template, $cfmatches); preg_match_all("/\\[thumb_([0-9]+)x([0-9]+)\\]/", $template, $matches); preg_match_all("/\\[thumb_url_([0-9]+)x([0-9]+)\\]/", $template, $umatches); preg_match_all("/\\[thumb_gallery_([0-9]+)x([0-9]+)\\]/", $template, $gmatches); preg_match_all("/\\[excerpt_([0-9]+)\\]/", $template, $xmatches); preg_match_all("/\\[pdf_thumb_([0-9]+)x([0-9]+)\\]/", $template, $pmatches); $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($vars['ID']), 'full'); $vars['preview'] = $thumb['0']; $pdf = isset($vars['files'][0]) ? $vars['files'][0] : ''; $ext = explode(".", $pdf); $ext = end($ext); if (strpos($template, 'pdf_thumb')) { if ($ext == 'pdf') { $vars['pdf_thumb'] = "<img alt='{$vars['title']}' src='" . wpdm_pdf_thumbnail($pdf, $vars['ID']) . "' />"; } else { $vars['pdf_thumb'] = $vars['preview'] != '' ? "<img alt='{$vars['title']}' src='{$vars['preview']}' />" : ""; } } foreach ($pmatches[0] as $nd => $scode) { $keys[] = $scode; $imsrc = wpdm_dynamic_thumb(wpdm_pdf_thumbnail($pdf, $vars['ID']), array($pmatches[1][$nd], $pmatches[2][$nd])); $values[] = $imsrc != '' ? "<img src='" . $imsrc . "' alt='{$vars['title']}' />" : ''; } if (strpos($template, 'file_type')) { $vars['file_types'] = wpdm_package_filetypes($vars['ID'], false); $vars['file_type_icons'] = wpdm_package_filetypes($vars['ID']); } if (strpos($template, 'wpdm_custom_field_table')) { $vars['wpdm_custom_field_table'] = wpdm_custom_fields_table($vars); } if (strpos($template, 'file_list_extended')) { $vars['file_list_extended'] = wpdm_package_file_list_alt($vars); } foreach ($matches[0] as $nd => $scode) { $keys[] = $scode; $imsrc = wpdm_dynamic_thumb($vars['preview'], array($matches[1][$nd], $matches[2][$nd])); $values[] = $vars['preview'] != '' ? "<img src='" . $imsrc . "' alt='{$vars['title']}' />" : ''; } foreach ($umatches[0] as $nd => $scode) { $keys[] = $scode; $values[] = $vars['preview'] != '' ? wpdm_dynamic_thumb($vars['preview'], array($umatches[1][$nd], $umatches[2][$nd])) : ''; } foreach ($gmatches[0] as $nd => $scode) { $keys[] = $scode; $values[] = wpdm_get_additional_preview_images($vars, $gmatches[1][$nd], $gmatches[2][$nd]); } foreach ($xmatches[0] as $nd => $scode) { $keys[] = $scode; $ss = substr(strip_tags($vars['description']), 0, intval($xmatches[1][$nd])); $tmp = explode(" ", substr(strip_tags($vars['description']), intval($xmatches[1][$nd]))); $bw = array_shift($tmp); $ss .= $bw; $values[] = $ss . '...'; } if ($type == 'page' && (strpos($template, '[similar_downloads]') || strpos($vars['description'], '[similar_downloads]'))) { $vars['similar_downloads'] = wpdm_similar_packages($vars, 5); } if (strpos($template, 'doc_preview')) { $vars['doc_preview'] = wpdm_doc_preview($vars); } foreach ($vars as $key => $value) { if (!is_array($value)) { $keys[] = "[{$key}]"; $values[] = $value; } } $loginform = wpdm_login_form(array('redirect' => get_permalink($vars['ID']))); $hide_all_message = get_option('__wpdm_login_form', 0) == 1 ? $loginform : stripcslashes(str_replace(array("[loginform]", "[this_url]"), array($loginform, get_permalink($vars['ID'])), get_option('wpdm_login_msg'))); if ($vars['download_link'] == 'blocked' && $type == 'link') { return ""; } if ($vars['download_link'] == 'blocked' && $type == 'page') { return get_option('wpdm_permission_msg'); } if ($vars['download_link'] == 'loginform' && $type == 'link') { return ""; } if ($vars['download_link'] == 'loginform' && $type == 'page') { return $hide_all_message; } return @str_replace($keys, $values, @stripcslashes($template)); }