/**
  * @usage Fetch link/page template and return generated html
  * @param $template
  * @param $vars
  * @param string $type
  * @return mixed|string|void
  */
 public static function fetchTemplate($template, $vars, $type = 'link')
 {
     if (!is_array($vars) && is_int($vars) && $vars > 0) {
         $vars = array('ID' => $vars);
     }
     if (!isset($vars['ID']) || intval($vars['ID']) < 1) {
         return '';
     }
     $default['link'] = 'link-template-default.php';
     $default['page'] = 'page-template-default.php';
     if (!isset($vars['formatted'])) {
         $pack = new \WPDM\Package($vars['ID']);
         $pack->Prepare();
         $vars = $pack->PackageData;
     }
     if ($template == '') {
         if (!isset($vars['page_template'])) {
             $vars['page_template'] = 'page-template-default.php';
         }
         $template = $type == 'page' ? $vars['page_template'] : $vars['template'];
     }
     if ($template == '') {
         $template = $default[$type];
     }
     $templates = maybe_unserialize(get_option("_fm_" . $type . "_templates", true));
     if (isset($templates[$template]) && isset($templates[$template]['content'])) {
         $template = $templates[$template]['content'];
     } else {
         if (!strpos(strip_tags($template), "]")) {
             $ltpldir = get_stylesheet_directory() . '/download-manager/' . $type . '-templates/';
             if (!file_exists($ltpldir) || !file_exists($ltpldir . $template)) {
                 $ltpldir = WPDM_BASE_DIR . '/tpls/' . $type . '-templates/';
             }
             if (file_exists(TEMPLATEPATH . '/' . $template)) {
                 $template = file_get_contents(TEMPLATEPATH . '/' . $template);
             } else {
                 if (file_exists($ltpldir . $template)) {
                     $template = file_get_contents($ltpldir . $template);
                 } else {
                     if (file_exists($ltpldir . $template . '.php')) {
                         $template = file_get_contents($ltpldir . $template . '.php');
                     } else {
                         if (file_exists($ltpldir . $type . "-template-" . $template . '.php')) {
                             $template = file_get_contents($ltpldir . $type . "-template-" . $template . '.php');
                         }
                     }
                 }
             }
         }
     }
     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);
     // Parse [pdf_thumb] tag in link/page template
     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']}' />" : "";
         }
     }
     // Parse [pdf_thumb_WxH] tag in link/page template
     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']}' />" : '';
     }
     // Parse [file_type] tag in link/page template
     if (strpos($template, 'file_type')) {
         $vars['file_types'] = self::fileTypes($vars['ID'], false);
         $vars['file_type_icons'] = self::fileTypes($vars['ID']);
     }
     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'] = self::docPreview($vars);
     }
     // If need to re-process any data before fetch template
     $vars = apply_filters("wdm_before_fetch_template", $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));
 }
Ejemplo n.º 2
0
function FetchTemplate($template, $vars, $type = 'link')
{
    if ($vars['ID'] == '') {
        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');
            }
        }
    }
    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("/\[download_link ([^\]]+)\]/", $template, $cmatches);
    $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($vars['ID']), 'full');
    $vars['preview'] = $thumb['0'];
    if (isset($vars['quota']) && $vars['quota'] == 0) {
        $vars['quota'] = __('Unlimited', 'wpdm');
    }
    foreach ($matches[0] as $nd => $scode) {
        $keys[] = $scode;
        $values[] = $vars['preview'] != '' ? "<img src='" . wpdm_dynamic_thumb($vars['preview'], array($matches[1][$nd], $matches[2][$nd])) . "' 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);
    }
    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['password']=='') $template = $template."<script>jQuery('body').on('click','.wpdm-link-tpl', function(){ var durl = jQuery(this).data('durl'); location.href=durl; });</script>";
    $data = @str_replace($keys, $values, @stripcslashes($template));
    $data = str_replace(array("\r", "\n"), "", $data);
    return $data;
}
Ejemplo n.º 3
0
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));
}
Ejemplo n.º 4
0
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));
}