function wpdm_init_tree() { if (!isset($_GET['task']) || $_GET['task'] != 'wpdm_init_tree') { return; } global $wpdb; echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">"; // All Cats $_POST['dir'] = !isset($_POST['dir']) || $_POST['dir'] == '/' ? null : $_POST['dir']; $cats = get_terms('wpdmcategory', array('hide_empty' => false, 'parent' => $_POST['dir'])); foreach ($cats as $cat) { echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"" . $cat->term_id . "\">" . $cat->name . "</a></li>"; } // All files $qparams = array('post_type' => 'wpdmpro', 'posts_per_page' => 9999); if ($_POST['dir']) { $qparams['tax_query'] = array(array('taxonomy' => 'wpdmcategory', 'terms' => array($_POST['dir']), 'include_children' => false)); } $ndata = get_posts($qparams); $sap = '?'; //count($_GET)>0?'&':'?'; foreach ($ndata as $data) { $html = ''; //$link = "<a href='" . get_permalink($data->ID) . "' >".$data->post_title."</a>"; $exts = function_exists('wpdm_package_filetypes') ? wpdm_package_filetypes($data->ID, false) : array(); $ext = count($exts) > 1 ? 'zip' : (count($exts) == 0 ? "" : $exts[0]); $template = "<li class=\"wpdm_clink file ext_{$ext}\"><a href='#' rel='" . $data->ID . "' >" . $data->post_title . "</a></li>"; $html .= $template; echo $html; } echo "</ul>"; die; }
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)); }