[xdownload=IDs||t:ags||f:older-IDs/]

Download rt for files from file center.

File download selected by tags or image ids or folder ids.

The entries description, file name, copyright, …., come directly from file center.

Output is generated by the basic function from the CP filelist.

E.g. v1.1: [xdownload= t: a string tag, tag05, tag06/]

E.g. v1.2: [xdownload= t: a string tag, tag05, tag06 : template, greedy, max_count, sort_by /]

E.g. v1.3: [xdownload= t: a string tag, tag05, tag06 : template, operator, greedy, max_count, sort_by /]


Backend e.g. CP plain text:

V1.2: [xdownload= t: a string tag, tag05, tag06 : x_download_01, 1, 5, ext_asc /]

V1.3: [xdownload= t: a string tag, tag05, tag06 : x_download_01, OR, 1, 5, ext_asc /]


File center:


Overview file infos (a very special filebrowser: FilebrowserX):


Frontend output using a template from cp filelist:


Short Description:

possible opportunities:

  • Output: template based like filelist
  • tag search is “word sensitive” or ”*all character strings*” [ungreedy=0|greedy=1]
  • logical operators [AND|OR|NOT] if tag is selected (V1.3) (only important in tag mode)
  • max count files are displayed [int]
  • minimal key lenght [int] (only important in tag mode)
  • -
  • Optional parameter input: ”:template name, AND|OR|NOT, ungreedy|greedy, max count, sort by” (V1.2/3)
  • -
  • sort order [string]
  • - sort_asc / sort_desc
  • - tstamp_asc / tstamp_desc
  • - name_asc / name_desc
  • - ext_asc / ext_desc
  • - type_asc / type_desc
  • - shortinfo_asc / shortinfo_desc
  • - longinfo_asc / longinfo_desc
  • - copyright_asc / copyright_desc
  • -
  • file description line: info from filecenter
  • FILE_DESCRIPTION|FILE_NAME|FILE_TITLE|_target|WxHxC|Copyright
  • - FILE_DESCRIPTION = long info
  • - FILE_NAME = filename
  • - FILE_TITLE = short info
  • - _target = set up in RT (see in CUSTOM VAR or template)
  • - WxHxC = set up in RT (see in CUSTOM VAR or template)
  • - Copyright = copyright
  • -
  • V1.1: BB code and lang replace like [en]…[/en] [de]…[/de] available





rt_xdownload V1.0 14.05.10

Docu: –
Forum: http://forum.phpwcms.org/viewtopic.php?p=124320

Autor: K.Heermann (flip-flop) http://planmatrix.de
CMS Version: >= 1.46 r402
Version: V1.0
Update: V 1.1 18.05.2010 KH: Parsing bbcode and call lang_replace if available
Update: template 19.05.2010 KH: Optional lightBox feature inserted and small bugs removed
Update: V 1.2 20.05.2010 KH: optional parameter input by tag Update: V 1.3 21.05.2010 KH: enhanced with logical operators [AND|OR|NOT] if tag selected

Tag v1.1:

  • [xdownload= t: tag1, tag2, tag3/] → selected by tags
  • [xdownload= f: id1, d2, d3/] → selected by folder ids
  • [xdownload= id1, id2, id3/] → image ids


Tag v1.2:

  • [xdownload= t: tag1, tag2, tag3 : template, greedy, max_count, sort_by /] → selected by tags
  • [xdownload= f: id1, d2, d3 : template, , max_count, sort_by /] → selected by folder ids
  • [xdownload= id1, id2, id3 : template, , max_count, sort_by /] → image ids
  • - or e.g.
  • [xdownload= XX, XX, XX : template,,, sort_by /] → image ids (The “template” is located in template/inc_cntpart/filelist/* with the name e.g. “template.html”)
  • or like v1.1


Tag v1.3:

  • [xdownload= t: tag1, tag2, tag3 : template, operator, greedy, max_count, sort_by /] → selected by tags
  • [xdownload= f: id1, d2, d3 : template, operator, , max_count, sort_by /] → selected by folder ids
  • [xdownload= id1, id2, id3 : template, operator, , max_count, sort_by /] → image ids


Filename: rt_xdownload.php

Folder: template/inc_script/frontend_render/

Condition:/config/phpwcms/conf.inc.php

  • $phpwcms['allow_ext_render'] = 1;


PHP v1.1:

File: template/inc_script/frontend_render/rt_xdownload.php

rt_xdownload

<?php
/**
 * *****************************************************************************
 * 14.05.2010 V1.1 K.Heermann http://planmatrix.de
 * Update 18.05.2010 V1.1: Update parsing bbcode and call lang_replace if available
 *
 * File download selected by Tags or image ids or filecenter folder id
 *
 * Tags:
 * - [xdownload= t: tag1, tag2, tag3/]  // tags
 * - [xdownload= f: id1, id2, id3/]     // folder ids
 * - [xdownload= id1, id2, id3/]        // image ids
 *
 * possible opportunities:
 * - Output: template based like filelist
 * - tag search is "word sensitive" or "all character strings" [ungreedy|greedy]
 *
 * - sort order
 *   - sort_asc   / sort_desc
 *   - tstamp_asc / tstamp_desc
 *   - name_asc   / name_desc
 *   - ext_asc    / ext_desc
 *   - type_asc   / type_desc
 *   - shortinfo_asc / shortinfo_desc
 *   - longinfo_asc  / longinfo_desc
 *   - copyright_asc / copyright_desc
 *
 * - file description line: info from filecenter
 *   FILE_DESCRIPTION|FILE_NAME|FILE_TITLE|_target|WxHxC|Copyright
 *   - FILE_DESCRIPTION     = long info
 *   - FILE_NAME            = filename
 *   - FILE_TITLE           = short info
 *   - _target              = set up in RT  (see in CUSTOM VAR or template)
 *   - WxHxC                = set up in RT  (see in CUSTOM VAR or template)
 *   - Copyright            = copyright
 *
 * http://www.phpwcms-howto.de/wiki/doku.php/english/phpwcms_replacer_rts/frontend_render/xdownload
 * *****************************************************************************
*/
// -----------------------------------------------------------------------------
// obligate check for phpwcms constants
    if (!defined('PHPWCMS_ROOT')) {
        die("You Cannot Access This Script Directly, Have a Nice Day."); }
// -----------------------------------------------------------------------------
 
 
 
function parse_xdownloads($match) {
 
    if(isset($match[1])) {
 
 
 
 
// =============== CUSTOM VAR ==================================================
 
        $download_template = 'x_download.html';  // template in "template/inc_cntpart/filelist/*"
 
        $key_lenght        = 1;                  //Min lenght of entry
 
        $max_count         = '';                 // Max count of files
 
        $sort_by           = 'sort_asc';         // Sort order
 
        // sort_asc   / sort_desc:          f_sort      -> sort field
        // tstamp_asc / tstamp_desc:        f_tstamp    -> Timestamp
        // name_asc   / name_desc:          f_name      -> Filename
        // ext_asc    / ext_desc:           f_ext       -> File extension
        // type_asc   / type_desc:          f_type      -> File type
        // shortinfo_asc / shortinfo_desc:  f_shortinfo    -> Short info
        // longinfo_asc  / longinfo_desc:   f_longinfo     -> Long info
        // copyright_asc / copyright_desc:  f_copyright -> Copyright
 
 
        $greedy   = 1;        // [0|1]  [ungreedy|greedy] = [word sensitive | all character strings]
 
        $WxHxC    = '';       // e.g. 100x100x1  [Width x Height x Crop] if there is an image
        $_target  = '_self';
 
// =============== END CUSTOM VAR ==============================================
 
 
 
        $flag         = 'id';  // default = id
 
        // using folders?
        if (stripos($match[1], 'f:') !== false) {
 
            $match[1] = preg_replace('/^\s*f:\s*(.*?)/i','$1',$match[1]);
            $flag = 'folder';
        }
        // using tags?
        elseif (stripos($match[1], 't:') !== false) {
 
            $match[1] = preg_replace('/^\s*t:\s*(.*?)/i','$1',$match[1]);
            $flag = 'tag';
            $key_lenght = 3;  // Min lenght of tag word
 
            if ($greedy) {
                // $where .= "f_tags LIKE '%".aporeplace($val)."%'";  // greedy
                $f_tags['1'] = "LIKE '%";
                $f_tags['2'] = "%'";
            } else {
                // $where .= "f_tags REGEXP '[[:<:]]".aporeplace($val)."[[:>:]]'";  // ungreedy
                $f_tags['1'] = "REGEXP '[[:<:]]";
                $f_tags['2'] = "[[:>:]]'";
            }
        }
 
 
 
 
// ============ front.func.inc.php: function get_related_articles
 
        // keywords: string with separated tags
 
        $keywords = $match[1];
 
        // replace unwanted chars and convert to wanted
        $keywords = str_replace(";", ",", $keywords);
        $keywords = str_replace("'", "", $keywords);
        if (!$greedy) $keywords = str_replace(" ", ",", $keywords);
        $keywords = str_replace(",,", ",", $keywords);
 
        // choose comma separated keywords
        $keywordarray = explode (",", $keywords);
        $keywordarray = array_map('trim', $keywordarray);
        $keywordarray = array_diff($keywordarray, array(''));
        $keywordarray = array_unique($keywordarray);
        $keywordarray = array_map('strtoupper', $keywordarray);
 
        // check for empty keywords or keywords smaller than 3 chars
        if(is_array($keywordarray) && count($keywordarray)) {
            foreach($keywordarray as $key => $val) {
 
                if(substr($keywordarray[$key], 0, 1) == '-') {
                    $doNotUse = substr($keywordarray[$key], 1);
                    foreach($keywordarray as $key2 => $val2) {
                        if($doNotUse == $val2) {
                            unset($keywordarray[$key2]);
                            unset($keywordarray[$key]);
                        }
                    }
                }
 
                if ( isset($keywordarray[$key]) &&
                        ( strlen($keywordarray[$key]) < $key_lenght ||
                          empty($keywordarray[$key]) )
                    ) {
 
                    unset($keywordarray[$key]);
                }
                // val into integer if no tag
                if ($flag != 'tag') $keywordarray[$key] = intval($keywordarray[$key]);
            }
        }
    // ============
 
 
        if(is_array($keywordarray) && count($keywordarray)) {
 
            $where = '';
 
        if ($flag =='tag') {
            foreach($keywordarray as $val) {
                //build where keyword = blabla
                $where .= ($where) ? " OR " : "";
 
                //replace every "'" to "''" for security reasons with aporeplace()
                $where .= " f_tags ".$f_tags['1'].aporeplace($val).$f_tags['2'];  // [greedy|ungreedy]
            }
        }
 
        if ($flag =='folder') {
 
            $val = implode('","', $keywordarray);
 
            $where .= 'f_pid IN ("'.$val.'")';  //
        }
 
        if ($flag =='id') {
 
            $val = implode('","', $keywordarray);
 
            $where .= 'f_id IN ("'.$val.'")';  //
        }
 
 
 
        $limit = ($max_count) ? " LIMIT ".$max_count : "";
        $sql  =    "SELECT f_id, f_pid, f_tags, f_name, f_shortinfo, f_longinfo, f_copyright ";
        $sql .=    "FROM ".DB_PREPEND."phpwcms_file ";
        $sql .= "WHERE f_aktiv=1 AND f_public=1 AND f_trash=0 AND f_kid=1 AND ";
        $sql .=    "(".$where.") ";
 
        if(empty($sort_by)) $sort_by = '';
 
        switch($sort_by) {
 
            case 'sort_asc':         $sql .=    "ORDER BY f_sort";             break;
            case 'sort_desc':         $sql .=    "ORDER BY f_sort DESC";        break;
 
            case 'tstamp_asc':         $sql .=    "ORDER BY f_tstamp";        break;
            case 'tstamp_desc':     $sql .=    "ORDER BY f_tstamp DESC";    break;
 
            case 'name_asc':         $sql .=    "ORDER BY f_name";            break;
            case 'name_desc':         $sql .=    "ORDER BY f_name DESC";        break;
 
            case 'ext_asc':         $sql .=    "ORDER BY f_ext";            break;
            case 'ext_desc':         $sql .=    "ORDER BY f_ext DESC";        break;
 
            case 'type_asc':         $sql .=    "ORDER BY f_type";            break;
            case 'type_desc':         $sql .=    "ORDER BY f_type DESC";        break;
 
            case 'shortinfo_asc':     $sql .=    "ORDER BY f_shortinfo";            break;
            case 'shortinfo_desc':     $sql .=    "ORDER BY f_shortinfo DESC";    break;
 
            case 'longinfo_asc':     $sql .=    "ORDER BY f_longinfo";            break;
            case 'longinfo_desc':     $sql .=    "ORDER BY f_longinfo DESC";        break;
 
            case 'copyright_asc':     $sql .=    "ORDER BY f_copyright";            break;
            case 'copyright_desc':     $sql .=    "ORDER BY f_copyright DESC";    break;
 
            default:            $sql .=    "ORDER BY f_pid DESC";
        }
 
        $sql .= $limit.';';
 
        // Read database
        $result = _dbQuery($sql);
 
        $id ='';            // using for transfer into filelist cp
        // ------------------------------------------------
        $caption = '';         // FILE_DESCRIPTION|FILE_NAME|FILE_TITLE|_target|WxHxC|Copyright
        // check if info for the file is available
        // [0] = normal file description like before
        // [1] = name the file (it's not the file name)
        // [2] = title
        // [3] = target (where to open a new file -> default is _blank even if empty
        // [4] = if it is an image try to show a thumbnail instead of the file icon -> here thumbnail WIDTHxHEIGHT
        // [5] = copyright information
        // ------------------------------------------------
 
        if(isset($result[0])) {
 
            foreach($result as $row) {
 
                $id .= ','.$row['f_id'];
 
                // catch all informations for caption
                $caption .= str_replace(LF,'',$row['f_longinfo']).'|'.
                            $row['f_name'].'|'.
                            $row['f_shortinfo'].'|'.
                            $_target.'|'.
                            $WxHxC.'|'.
                            $row['f_copyright'].LF;
            }
        }
        if ($id) $id = substr($id, 1);  // Kill first comma
 
        $caption = @html_entity_decode(trim($caption), ENT_QUOTES, PHPWCMS_CHARSET);
    }
 
 
 
// ============ END front.func.inc.php: function get_related_articles
 
 
 
        $value    = array();
 
        // IDs for transfer to file list basic function
        $value['cnt_object']['cnt_files']['id']            = convertStringToArray($id);
 
        if(isset($value['cnt_object']['cnt_files']['id']) && is_array($value['cnt_object']['cnt_files']['id']) && count($value['cnt_object']['cnt_files']['id'])) {
 
            global $phpwcms;
 
            $IS_NEWS_CP                                        = true;
 
            $news                                            = array();
            $news['files_result']                            = '';
 
            $crow                                            = array();
 
            //$caption      = 'FILE_DESCRIPTION|FILE_NAME|FILE_TITLE|_target|100x100x1|Copyright Text'.LF;
            $value['cnt_object']['cnt_files']['caption']    = isset($caption) ? @html_entity_decode(trim($caption), ENT_QUOTES, PHPWCMS_CHARSET) : '';
            $value['files_direct_download']                    = 0;
            $value['files_template']                        = $download_template;
 
            // include content part files renderer
            include(PHPWCMS_ROOT.'/include/inc_front/content/cnt7.article.inc.php');
 
 
            return render_bbcode_basics($news['files_result']);    // parse the bbcode and return
 
        }
 
    }
 
    return '';
 
}
 
 
$content["all"] = preg_replace_callback('/\[xdownload=(.*?)\/\]/i', 'parse_xdownloads', $content["all"]);
//$content["all"] = preg_replace_callback('/\[xdownload=(.*?)\](.*?)\[\/xdownload\]/is', 'parse_xdownloads', $content["all"]);
 
 
// if ../frontend_render/lang_replace.php is available, then call it a second time on the safe side
if (is_file(PHPWCMS_TEMPLATE.'inc_script/frontend_render/lang_replace.php'))
    include(PHPWCMS_TEMPLATE.'inc_script/frontend_render/lang_replace.php');
 
?>


PHP v1.2:

Update 20.05.2010 V1.2: optional parameter input by tag

  • [xdownload= t: tag1, tag2, tag3 : template, greedy, max_count, sort_by /]
  • e.g.
  • [xdownload= t: tag1, tag2, tag3 : x_download_01, 1, 5, ext_asc /]
  • tag1, tag2, tag3 : search by tag : using the template x_download_01.html, all character strings from tag, sort by file extension
    • (In this case “x_download_01” is the name of file in template/inc_cntpart/filelist/ without an extend).


File: template/inc_script/frontend_render/rt_xdownload.php

rt_xdownload

<?php
/**
 * *****************************************************************************
 * 14.05.2010 V1.2 K.Heermann http://planmatrix.de
 * Update 18.05.2010 V1.1: Update parsing bbcode and call lang_replace if available
 * Update 20.05.2010 V1.2: Update optional parameter input by tag
 *  + template name, greedy|ungreedy, max count, sort by
 *  + e.g.:
 *  + [xdownload= t: tag1, tag2, tag3 : template, greedy, max_count, sort_by /]  // tags
 *  + If there is no parameter, the default values from script are catched
 *
 * File download selected by Tags or image ids or filecenter folder id
 *
 * Tags v1.1:
 * - [xdownload= t: tag1, tag2, tag3/]  // tags
 * - [xdownload= f: id1, id2, id3/]     // folder ids
 * - [xdownload= id1, id2, id3/]        // image ids
 *
 * Tags v1.2:
 * - [xdownload= t: tag1, tag2, tag3 : template, greedy, max_count, sort_by/]  // tags
 * - [xdownload= f: id1, id2, id3 : template, greedy, max_count, sort_by/]     // folder ids
 * - [xdownload= id1, id2, id3 : template, greedy, max_count, sort_by/]        // image ids
 *
 * possible opportunities:
 * - Output: template based like filelist
 * - tag search is "word sensitive" or "all character strings" [ungreedy|greedy]
 *
 * - sort order
 *   - sort_asc   / sort_desc
 *   - tstamp_asc / tstamp_desc
 *   - name_asc   / name_desc
 *   - ext_asc    / ext_desc
 *   - type_asc   / type_desc
 *   - shortinfo_asc / shortinfo_desc
 *   - longinfo_asc  / longinfo_desc
 *   - copyright_asc / copyright_desc
 *
 * - file description line: info from filecenter
 *   FILE_DESCRIPTION|FILE_NAME|FILE_TITLE|_target|WxHxC|Copyright
 *   - FILE_DESCRIPTION     = long info
 *   - FILE_NAME            = filename
 *   - FILE_TITLE           = short info
 *   - _target              = set up in RT  (see in CUSTOM VAR or template)
 *   - WxHxC                = set up in RT  (see in CUSTOM VAR or template)
 *   - Copyright            = copyright
 *
 * http://www.phpwcms-howto.de/wiki/doku.php/english/phpwcms_replacer_rts/frontend_render/xdownload
 * *****************************************************************************
*/
// -----------------------------------------------------------------------------
// obligate check for phpwcms constants
    if (!defined('PHPWCMS_ROOT')) {
        die("You Cannot Access This Script Directly, Have a Nice Day."); }
// -----------------------------------------------------------------------------
 
 
 
function parse_xdownloads($match) {
 
    if(isset($match[1])) {
 
        $param         = explode(':', $match[1]);
 
        foreach ($param as $key => $val) // kill all begin/end spaces
            $param[$key] = trim($val);
 
        if ( strtolower($param[0]) !== 't' AND strtolower($param[0]) !== 'f' ) {
            array_unshift($param, "i");  // fill up the first place in array
        }
 
// =============== CUSTOM VAR ==================================================
// Tag: [xdownload= t: tag1, tag2, tag3 : template, greedy, max_count, sort_by /]
 
 
        $download_template = 'x_download.html';  // template in "template/inc_cntpart/filelist/*"
 
        $key_lenght        = 1;                  //Min lenght of entry
 
        $max_count         = '';                 // Max count of files
 
        $sort_by           = 'sort_asc';         // Sort order
 
        // sort_asc   / sort_desc:          f_sort      -> sort field
        // tstamp_asc / tstamp_desc:        f_tstamp    -> Timestamp
        // name_asc   / name_desc:          f_name      -> Filename
        // ext_asc    / ext_desc:           f_ext       -> File extension
        // type_asc   / type_desc:          f_type      -> File type
        // shortinfo_asc / shortinfo_desc:  f_shortinfo    -> Short info
        // longinfo_asc  / longinfo_desc:   f_longinfo     -> Long info
        // copyright_asc / copyright_desc:  f_copyright -> Copyright
 
 
        $greedy   = 1;        // [0|1]  [ungreedy|greedy] = [word sensitive | all character strings]
 
        $WxHxC    = '';       // e.g. 100x100x1  [Width x Height x Crop] if there is an image
        $_target  = '_self';
 
// =============== END CUSTOM VAR ==============================================
 
        if (count($param) >= 2)    $keywords = $param[1];
 
        if (count($param) === 3) {  // parameter available
 
            $cparam = explode(',',$param[2]);
 
            foreach ($cparam as $key => $val) // kill all begin/end spaces
                $cparam[$key] = trim($val);
 
            $download_template    = (empty($cparam[0])) ? $download_template     : strip_tags($cparam[0]).'.html';
            $greedy                = (empty($cparam[1])) ? $greedy                : intval($cparam[1]);
            $max_count            = (empty($cparam[2])) ? $max_count            : intval($cparam[2]);
            $sort_by            = (empty($cparam[3])) ? $sort_by            : strtolower(strip_tags($cparam[3]));
        }
 
        switch ($param[0]) {
 
            case 'f':     $flag = 'folder';    break;
 
            case 't':    $flag = 'tag';
                $key_lenght = 3;  // Min lenght of tag word
                if ($greedy) {
                    // $where .= "f_tags LIKE '%".aporeplace($val)."%'";  // greedy
                    $f_tags['1'] = "LIKE '%";
                    $f_tags['2'] = "%'";
                } else {
                    // $where .= "f_tags REGEXP '[[:<:]]".aporeplace($val)."[[:>:]]'";  // ungreedy
                    $f_tags['1'] = "REGEXP '[[:<:]]";
                    $f_tags['2'] = "[[:>:]]'";
                }
 
            break;
 
            default:    $flag = 'id';        break;  // default = id
        }
 
// ============ front.func.inc.php: function get_related_articles
 
        // keywords: string with separated tags
 
        // replace unwanted chars and convert to wanted
        $keywords = str_replace(";", ",", $keywords);
        $keywords = str_replace("'", "", $keywords);
        if (!$greedy) $keywords = str_replace(" ", ",", $keywords);
        $keywords = str_replace(",,", ",", $keywords);
 
        // choose comma separated keywords
        $keywordarray = explode (",", $keywords);
        $keywordarray = array_map('trim', $keywordarray);
        $keywordarray = array_diff($keywordarray, array(''));
        $keywordarray = array_unique($keywordarray);
        $keywordarray = array_map('strtoupper', $keywordarray);
        // check for empty keywords or keywords smaller than 3 chars
        if(is_array($keywordarray) && count($keywordarray)) {
            foreach($keywordarray as $key => $val) {
 
                if(substr($keywordarray[$key], 0, 1) == '-') {
                    $doNotUse = substr($keywordarray[$key], 1);
                    foreach($keywordarray as $key2 => $val2) {
                        if($doNotUse == $val2) {
                            unset($keywordarray[$key2]);
                            unset($keywordarray[$key]);
                        }
                    }
                }
 
                if ( isset($keywordarray[$key]) &&
                        ( strlen($keywordarray[$key]) < $key_lenght ||
                          empty($keywordarray[$key]) )
                    ) {
 
                    unset($keywordarray[$key]);
                }
                // val into integer if no tag
                if ($flag != 'tag') $keywordarray[$key] = intval($keywordarray[$key]);
            }
        }
    // ============
 
 
 
        if(is_array($keywordarray) && count($keywordarray)) {
 
            $where = '';
 
        if ($flag =='tag') {
            foreach($keywordarray as $val) {
                //build where keyword = blabla
                $where .= ($where) ? " OR " : "";
 
                //replace every "'" to "''" for security reasons with aporeplace()
                // $where .= "f_tags LIKE '%".aporeplace($val)."%'";
                $where .= " f_tags ".$f_tags['1'].aporeplace($val).$f_tags['2'];  // [greedy|ungreedy]
            }
        }
 
        if ($flag =='folder') {
 
            $val = implode('","', $keywordarray);
 
            $where .= 'f_pid IN ("'.$val.'")';  //
        }
 
        if ($flag =='id') {
 
            $val = implode('","', $keywordarray);
 
            $where .= 'f_id IN ("'.$val.'")';  //
        }
 
 
 
        $limit = ($max_count) ? " LIMIT ".$max_count : "";
        $sql  =    "SELECT f_id, f_pid, f_tags, f_name, f_shortinfo, f_longinfo, f_copyright ";
        $sql .=    "FROM ".DB_PREPEND."phpwcms_file ";
        $sql .= "WHERE f_aktiv=1 AND f_public=1 AND f_trash=0 AND f_kid=1 AND ";
        $sql .=    "(".$where.") ";
 
        if(empty($sort_by)) $sort_by = '';
 
        switch($sort_by) {
 
            case 'sort_asc':         $sql .=    "ORDER BY f_sort";             break;
            case 'sort_desc':         $sql .=    "ORDER BY f_sort DESC";        break;
 
            case 'tstamp_asc':         $sql .=    "ORDER BY f_tstamp";        break;
            case 'tstamp_desc':     $sql .=    "ORDER BY f_tstamp DESC";    break;
 
            case 'name_asc':         $sql .=    "ORDER BY f_name";            break;
            case 'name_desc':         $sql .=    "ORDER BY f_name DESC";        break;
 
            case 'ext_asc':         $sql .=    "ORDER BY f_ext";            break;
            case 'ext_desc':         $sql .=    "ORDER BY f_ext DESC";        break;
 
            case 'type_asc':         $sql .=    "ORDER BY f_type";            break;
            case 'type_desc':         $sql .=    "ORDER BY f_type DESC";        break;
 
            case 'shortinfo_asc':     $sql .=    "ORDER BY f_shortinfo";            break;
            case 'shortinfo_desc':     $sql .=    "ORDER BY f_shortinfo DESC";    break;
 
            case 'longinfo_asc':     $sql .=    "ORDER BY f_longinfo";            break;
            case 'longinfo_desc':     $sql .=    "ORDER BY f_longinfo DESC";        break;
 
            case 'copyright_asc':     $sql .=    "ORDER BY f_copyright";            break;
            case 'copyright_desc':     $sql .=    "ORDER BY f_copyright DESC";    break;
 
            default:            $sql .=    "ORDER BY f_pid DESC";
        }
 
        $sql .= $limit.';';
 
        // Read database
        $result = _dbQuery($sql);
 
        $id ='';            // using for transfer into filelist cp
        // ------------------------------------------------
        $caption = '';         // FILE_DESCRIPTION|FILE_NAME|FILE_TITLE|_target|WxHxC|Copyright
        // check if info for the file is available
        // [0] = normal file description like before
        // [1] = name the file (it's not the file name)
        // [2] = title
        // [3] = target (where to open a new file -> default is _blank even if empty
        // [4] = if it is an image try to show a thumbnail instead of the file icon -> here thumbnail WIDTHxHEIGHT
        // [5] = copyright information
        // ------------------------------------------------
 
        if(isset($result[0])) {
 
            foreach($result as $row) {
 
                $id .= ','.$row['f_id'];
 
                // catch all informations for caption
                $caption .= str_replace(LF,'',$row['f_longinfo']).'|'.
                            $row['f_name'].'|'.
                            $row['f_shortinfo'].'|'.
                            $_target.'|'.
                            $WxHxC.'|'.
                            $row['f_copyright'].LF;
            }
        }
        if ($id) $id = substr($id, 1);  // Kill first comma
 
    }
 
 
 
// ============ END front.func.inc.php: function get_related_articles
 
 
 
        $value    = array();
 
        // IDs for transfer to file list basic function
        $value['cnt_object']['cnt_files']['id']            = convertStringToArray($id);
 
        if(isset($value['cnt_object']['cnt_files']['id']) && is_array($value['cnt_object']['cnt_files']['id']) && count($value['cnt_object']['cnt_files']['id']))
        {
            global $phpwcms;
 
            $IS_NEWS_CP                                        = true;
 
            $news                                            = array();
            $news['files_result']                            = '';
 
            $crow                                            = array();
 
            //$caption      = 'FILE_DESCRIPTION|FILE_NAME|FILE_TITLE|_target|100x100x1|Copyright Text'.LF;
            $value['cnt_object']['cnt_files']['caption']    = isset($caption) ? @html_entity_decode(trim($caption), ENT_QUOTES, PHPWCMS_CHARSET) : '';
            $value['files_direct_download']                    = 0;
            $value['files_template']                        = $download_template;
 
            // include content part files renderer
            include(PHPWCMS_ROOT.'/include/inc_front/content/cnt7.article.inc.php');
 
            return render_bbcode_basics($news['files_result']);    // parse the bbcode and return
 
        }
    }
 
    return '';
 
}
 
 
// [xdownload= t: tag1, tag2, tag3:template,greedy,max_count,sort_by/]
 
$content["all"] = preg_replace_callback('/\[xdownload=(.*?)\/\]/i', 'parse_xdownloads', $content["all"]);
//$content["all"] = preg_replace_callback('/\[xdownload=(.*?)\](.*?)\[\/xdownload\]/is', 'parse_xdownloads', $content["all"]);
 
 
// if ../frontend_render/lang_replace.php is available, then call it a second time on the safe side
if (is_file(PHPWCMS_TEMPLATE.'inc_script/frontend_render/lang_replace.php'))
    include(PHPWCMS_TEMPLATE.'inc_script/frontend_render/lang_replace.php');
 
?>


PHP v1.3:

Update 21.05.2010 V1.3: enhanced with logical operators [AND|OR|NOT] if tag selected

  • [xdownload= t: tag1, tag2, tag3 : template, operator, greedy, max_count, sort_by /]
  • e.g.
  • [xdownload= t: tag1, tag2, tag3 : x_download_01, AND, 1, 5, ext_asc /]
  • tag1, tag2, tag3 : search by tag : using the template x_download_01.html, AND logical linked, all character strings from tag, sort by file extension
    • (In this case “x_download_01” is the name of file in template/inc_cntpart/filelist/ without an extend).


File: template/inc_script/frontend_render/rt_xdownload.php

rt_xdownload

<?php
/**
 * *****************************************************************************
 * 14.05.2010 V1.0 K.Heermann http://planmatrix.de
 * Update 18.05.2010 V1.1: parsing bbcode and call lang_replace if available
 * Update 20.05.2010 V1.2: optional parameter input by tag
 *  + template name, greedy|ungreedy, max count, sort by
 *  + e.g.:
 *  + [xdownload= t: tag1, tag2, tag3 : template, greedy, max_count, sort_by /]  // tags
 *  + If there is no parameter, the default values from script are catched
 *
 * Update 21.05.2010 V1.3: enhanced with logical operators [AND|OR|NOT] if tag selected
 *  + e.g.:
 *  + [xdownload= t: tag1, tag2, tag3 : template, operator, greedy, max_count, sort_by /]  // tags
 *
 *
 * File download selected by Tags or image ids or filecenter folder id
 *
 * Tags v1.1:
 * - [xdownload= t: tag1, tag2, tag3/]  // tags
 * - [xdownload= f: id1, id2, id3/]     // folder ids
 * - [xdownload= id1, id2, id3/]        // image ids
 *
 * Tags v1.2:
 * - [xdownload= t: tag1, tag2, tag3 : template, greedy, max_count, sort_by/]  // tags
 * - [xdownload= f: id1, id2, id3    : template,       , max_count, sort_by/]     // folder ids
 * - [xdownload= id1, id2, id3       : template,       , max_count, sort_by/]        // image ids
 *
 * Tags v1.3:
 * - [xdownload= t: tag1, tag2, tag3 : template, operator, greedy, max_count, sort_by/]  // tags
 * - [xdownload= f: id1, id2, id3    : template,         ,       , max_count, sort_by/]  // folder ids
 * - [xdownload= id1, id2, id3       : template,         ,       , max_count, sort_by/]  // image ids
 *
 * possible opportunities:
 * - Output: template based like filelist
 * - tag search is "word sensitive" or "all character strings" [ungreedy|greedy]
 * - tags search in dependence from operator [AND|OR|NOT]   // OR = default
 * - max_count = maximum number of output
 *
 * - sort order
 *   - sort_asc   / sort_desc
 *   - tstamp_asc / tstamp_desc
 *   - name_asc   / name_desc
 *   - ext_asc    / ext_desc
 *   - type_asc   / type_desc
 *   - shortinfo_asc / shortinfo_desc
 *   - longinfo_asc  / longinfo_desc
 *   - copyright_asc / copyright_desc
 *
 * - file description line: info from filecenter
 *   FILE_DESCRIPTION|FILE_NAME|FILE_TITLE|_target|WxHxC|Copyright
 *   - FILE_DESCRIPTION     = long info
 *   - FILE_NAME            = filename
 *   - FILE_TITLE           = short info
 *   - _target              = set up in RT  (see in CUSTOM VAR or template)
 *   - WxHxC                = set up in RT  (see in CUSTOM VAR or template)
 *   - Copyright            = copyright
 *
 * http://www.phpwcms-howto.de/wiki/doku.php/english/phpwcms_replacer_rts/frontend_render/xdownload
 * *****************************************************************************
*/
// -----------------------------------------------------------------------------
// obligate check for phpwcms constants
    if (!defined('PHPWCMS_ROOT')) {
        die("You Cannot Access This Script Directly, Have a Nice Day."); }
// -----------------------------------------------------------------------------
 
 
 
function parse_xdownloads($match) {
 
    if(isset($match[1])) {
 
        $param         = explode(':', $match[1]);
 
        foreach ($param as $key => $val) // kill all begin/end spaces
            $param[$key] = trim($val);
 
        if ( strtolower($param[0]) !== 't' AND strtolower($param[0]) !== 'f' ) {
            array_unshift($param, "i");  // fill up the first place in array
        }
 
// =============== CUSTOM VAR ==================================================
// Tag: [xdownload= t: tag1, tag2, tag3 : template, operator, greedy, max_count, sort_by /]
 
 
        $download_template = 'x_download.html';  // template in "template/inc_cntpart/filelist/*"
 
        $key_lenght        = 1;                  //Min lenght of entry
 
        $max_count         = '';                 // Max count of files
 
        $sort_by           = 'sort_asc';         // Sort order
 
        // sort_asc   / sort_desc:          f_sort      -> sort field
        // tstamp_asc / tstamp_desc:        f_tstamp    -> Timestamp
        // name_asc   / name_desc:          f_name      -> Filename
        // ext_asc    / ext_desc:           f_ext       -> File extension
        // type_asc   / type_desc:          f_type      -> File type
        // shortinfo_asc / shortinfo_desc:  f_shortinfo    -> Short info
        // longinfo_asc  / longinfo_desc:   f_longinfo     -> Long info
        // copyright_asc / copyright_desc:  f_copyright -> Copyright
 
        $operator = 'OR';     // if tag is selected [AND|OR|NOT]  (Uppercase letter!!)
 
        $greedy   = 1;        // [0|1]  [ungreedy|greedy] = [word sensitive | all character strings]
 
        $WxHxC    = '';       // e.g. 100x100x1  [Width x Height x Crop] if there is an image
        $_target  = '_self';
 
// =============== END CUSTOM VAR ==============================================
 
        if (count($param) >= 2)    $keywords = $param[1];
 
        if (count($param) === 3) {  // parameter available
 
            $cparam = explode(',',$param[2]);
 
            foreach ($cparam as $key => $val) // kill all begin/end spaces
                $cparam[$key] = trim($val);
 
            $download_template    = (empty($cparam[0])) ? $download_template     : strip_tags($cparam[0]).'.html';
            $operator            = (empty($cparam[1])) ? $operator            : strtoupper(strip_tags($cparam[1]));
            $greedy                = (empty($cparam[2]) AND ($cparam[1] != '0')) ? $greedy    : intval($cparam[2]);    // Update 21.05.10
            $max_count            = (empty($cparam[3])) ? $max_count            : intval($cparam[3]);                // Update 21.05.10
            $sort_by            = (empty($cparam[4])) ? $sort_by            : strtolower(strip_tags($cparam[4]));
        }
 
        switch ($param[0]) {
 
            case 'f':     $flag = 'folder';    break;
 
            case 't':    $flag = 'tag';
                // $key_lenght = 3;  // Min lenght of tag word
                if ($greedy) {
                    // $where .= "f_tags LIKE '%".aporeplace($val)."%'";  // greedy
                    $f_tags['1'] = "LIKE '%";
                    $f_tags['2'] = "%'";
                } else {
                    // $where .= "f_tags REGEXP '[[:<:]]".aporeplace($val)."[[:>:]]'";  // ungreedy
                    $f_tags['1'] = "REGEXP '[[:<:]]";
                    $f_tags['2'] = "[[:>:]]'";
                }
 
            break;
 
            default:    $flag = 'id';        break;  // default = id
        }
 
// ============ front.func.inc.php: function get_related_articles
 
        // keywords: string with separated tags
 
        // replace unwanted chars and convert to wanted
        $keywords = str_replace(";", ",", $keywords);
        $keywords = str_replace("'", "", $keywords);
        // if (!$greedy) $keywords = str_replace(" ", ",", $keywords);  // disabled 21.05.10
        $keywords = str_replace(",,", ",", $keywords);
 
        // choose comma separated keywords
        $keywordarray = explode (",", $keywords);
        $keywordarray = array_map('trim', $keywordarray);
        $keywordarray = array_diff($keywordarray, array(''));
        $keywordarray = array_unique($keywordarray);
        $keywordarray = array_map('strtoupper', $keywordarray);
        // check for empty keywords or keywords smaller than 3 chars
        if(is_array($keywordarray) && count($keywordarray)) {
            foreach($keywordarray as $key => $val) {
 
                if(substr($keywordarray[$key], 0, 1) == '-') {
                    $doNotUse = substr($keywordarray[$key], 1);
                    foreach($keywordarray as $key2 => $val2) {
                        if($doNotUse == $val2) {
                            unset($keywordarray[$key2]);
                            unset($keywordarray[$key]);
                        }
                    }
                }
 
                if ( isset($keywordarray[$key]) &&
                        ( strlen($keywordarray[$key]) < $key_lenght ||
                          empty($keywordarray[$key]) )
                    ) {
 
                    unset($keywordarray[$key]);
                }
                // val into integer if no tag
                if ($flag != 'tag') $keywordarray[$key] = intval($keywordarray[$key]);
            }
        }
    // ============
 
 
 
        if(is_array($keywordarray) && count($keywordarray)) {
 
            $where = '';
 
            if ($flag =='tag') {
 
                $first_op = '';
 
                if (in_array($operator, array('AND','OR','NOT'))) {  // Update 21.05.10
 
                    if ($operator == 'NOT') {
                        $operator = 'AND NOT';
                        $first_op = 'NOT ';
                    }
                }
 
            foreach($keywordarray as $val) {
                //build where keyword = blabla
                $where .= ($where) ? " $operator " : "$first_op";
 
                //replace every "'" to "''" for security reasons with aporeplace()
                // $where .= "f_tags LIKE '%".aporeplace($val)."%'";
                $where .= " f_tags ".$f_tags['1'].aporeplace($val).$f_tags['2'];  // [greedy|ungreedy]
            }
        }
 
        if ($flag =='folder') {
 
            $val = implode('","', $keywordarray);
 
            $where .= 'f_pid IN ("'.$val.'")';  //
        }
 
        if ($flag =='id') {
 
            $val = implode('","', $keywordarray);
 
            $where .= 'f_id IN ("'.$val.'")';  //
        }
 
 
 
        $limit = ($max_count) ? " LIMIT ".$max_count : "";
        $sql  =    "SELECT f_id, f_pid, f_tags, f_name, f_shortinfo, f_longinfo, f_copyright ";
        $sql .=    "FROM ".DB_PREPEND."phpwcms_file ";
        $sql .= "WHERE f_aktiv=1 AND f_public=1 AND f_trash=0 AND f_kid=1 AND ";
        $sql .=    "(".$where.") ";
 
        if(empty($sort_by)) $sort_by = '';
 
        switch($sort_by) {
 
            case 'sort_asc':         $sql .=    "ORDER BY f_sort";             break;
            case 'sort_desc':         $sql .=    "ORDER BY f_sort DESC";        break;
 
            case 'tstamp_asc':         $sql .=    "ORDER BY f_tstamp";        break;
            case 'tstamp_desc':     $sql .=    "ORDER BY f_tstamp DESC";    break;
 
            case 'name_asc':         $sql .=    "ORDER BY f_name";            break;
            case 'name_desc':         $sql .=    "ORDER BY f_name DESC";        break;
 
            case 'ext_asc':         $sql .=    "ORDER BY f_ext";            break;
            case 'ext_desc':         $sql .=    "ORDER BY f_ext DESC";        break;
 
            case 'type_asc':         $sql .=    "ORDER BY f_type";            break;
            case 'type_desc':         $sql .=    "ORDER BY f_type DESC";        break;
 
            case 'shortinfo_asc':     $sql .=    "ORDER BY f_shortinfo";            break;
            case 'shortinfo_desc':     $sql .=    "ORDER BY f_shortinfo DESC";    break;
 
            case 'longinfo_asc':     $sql .=    "ORDER BY f_longinfo";            break;
            case 'longinfo_desc':     $sql .=    "ORDER BY f_longinfo DESC";        break;
 
            case 'copyright_asc':     $sql .=    "ORDER BY f_copyright";            break;
            case 'copyright_desc':     $sql .=    "ORDER BY f_copyright DESC";    break;
 
            default:            $sql .=    "ORDER BY f_pid DESC";
        }
 
        $sql .= $limit.';';
 
        // Read database
        $result = _dbQuery($sql);
 
        $id ='';            // using for transfer into filelist cp
        // ------------------------------------------------
        $caption = '';         // FILE_DESCRIPTION|FILE_NAME|FILE_TITLE|_target|WxHxC|Copyright
        // check if info for the file is available
        // [0] = normal file description like before
        // [1] = name the file (it's not the file name)
        // [2] = title
        // [3] = target (where to open a new file -> default is _blank even if empty
        // [4] = if it is an image try to show a thumbnail instead of the file icon -> here thumbnail WIDTHxHEIGHT
        // [5] = copyright information
        // ------------------------------------------------
 
        if(isset($result[0])) {
 
            foreach($result as $row) {
 
                $id .= ','.$row['f_id'];
 
                // catch all informations for caption
                $caption .= str_replace(LF,'',$row['f_longinfo']).'|'.
                            $row['f_name'].'|'.
                            $row['f_shortinfo'].'|'.
                            $_target.'|'.
                            $WxHxC.'|'.
                            $row['f_copyright'].LF;
            }
        }
        if ($id) $id = substr($id, 1);  // Kill first comma
 
    }
 
 
 
// ============ END front.func.inc.php: function get_related_articles
 
 
 
        $value    = array();
 
        // IDs for transfer to file list basic function
        $value['cnt_object']['cnt_files']['id']            = convertStringToArray($id);
 
        if(isset($value['cnt_object']['cnt_files']['id']) && is_array($value['cnt_object']['cnt_files']['id']) && count($value['cnt_object']['cnt_files']['id']))
        {
            global $phpwcms;
 
            $IS_NEWS_CP                                        = true;
 
            $news                                            = array();
            $news['files_result']                            = '';
 
            $crow                                            = array();
 
            //$caption      = 'FILE_DESCRIPTION|FILE_NAME|FILE_TITLE|_target|100x100x1|Copyright Text'.LF;
            $value['cnt_object']['cnt_files']['caption']    = isset($caption) ? @html_entity_decode(trim($caption), ENT_QUOTES, PHPWCMS_CHARSET) : '';
            $value['files_direct_download']                    = 0;
            $value['files_template']                        = $download_template;
 
            // include content part files renderer
            include(PHPWCMS_ROOT.'/include/inc_front/content/cnt7.article.inc.php');
 
            return render_bbcode_basics($news['files_result']);    // parse the bbcode and return
 
        }
    }
 
    return '';
 
}
 
 
// [xdownload= t: tag1, tag2, tag3:template,operator,greedy,max_count,sort_by/]
 
$content["all"] = preg_replace_callback('/\[xdownload=(.*?)\/\]/i', 'parse_xdownloads', $content["all"]);
//$content["all"] = preg_replace_callback('/\[xdownload=(.*?)\](.*?)\[\/xdownload\]/is', 'parse_xdownloads', $content["all"]);
 
 
// if ../frontend_render/lang_replace.php is available, then call it a second time on the safe side
if (is_file(PHPWCMS_TEMPLATE.'inc_script/frontend_render/lang_replace.php'))
    include(PHPWCMS_TEMPLATE.'inc_script/frontend_render/lang_replace.php');
 
?>


Template:

Update: 19.05.2010 KH: optional lightBox feature inserted and small bugs removed

File: template/inc_cntpart/filelist/x_download.html

xdownload

<!--FILE_SETTINGS_START//-->
; this is formatted like WIN.INI
; please: do not use comments for value lines
icon_path             = "img/icons/"
icon_name             = "small_icon_{FILE_EXT}.gif"
thumbnail            = 1
thumbnail_width        = 50
thumbnail_height    = 50
thumbnail_crop        = 1
lightbox_init        = 0
file_size_round        = 1
file_size_space        = " "
date_format            = "%d.%m.%y"
set_locale            = "de_DE@Euro"
<!--FILE_SETTINGS_END//-->
 
<div style="margin-top: 15px; padding-top: 10px; border-top: 1px dotted #CCCCCC;">
<!--FILE_ENTRY_START//-->
 
 
    <div class="fileEntry" style="margin-bottom:10px; padding-bottom: 10px; border-bottom: 1px dotted #CCCCCC;" id="file-{FILE_ID}">
        <h2>
            [FILE_IMAGE_ELSE]<img src="{FILE_ICON}" alt="" border="0" />[/FILE_IMAGE_ELSE]
            [FILE_IMAGE]
            <img src="{FILE_IMAGE}" alt="" border="" />
            <!--  If you want an lighBox output, please enable this two lines and disable the line above.
            <a href="img/cmsimage.php/800x600/{FILE_ID}.{FILE_EXT}" rel="lightbox[XYZ{FILE_ID}]" title="{FILE_DESCRIPTION}" target="_blank">
            <img src="{FILE_IMAGE}" alt="" border="" /></a>
            //-->
            [/FILE_IMAGE]
            <a href="{FILE_LINK}&amp;target=0"{FILE_TARGET} alt="{FILE_NAME}">[FILE_TITLE]{FILE_TITLE}[/FILE_TITLE][FILE_TITLE_ELSE]{FILE_NAME}[/FILE_TITLE_ELSE]</a>
        </h2>
        <div style="font-size:10px;width:300px;background:#eaeaea;border:1px solid#ccc;">
        <p style="padding:2px;border-bottom:1px solid#ccc;">[FILE_DESCRIPTION]
        {FILE_DESCRIPTION}<br />[/FILE_DESCRIPTION][FILE_COPYRIGHT]
        </p>
 
        <p style="padding:2px;border-bottom:1px solid#ccc;">
        Copyright: {FILE_COPYRIGHT}<br />[/FILE_COPYRIGHT]
        </p>
 
        <p style="padding:2px;">
        {FILE_EXT}, {FILE_SIZE}, {FILE_DATE}, {FILE_DOWNLOADS} downloads (XDownload)
        [FILE_IMAGE][FILE_IMAGE_WIDTH]
 
        width: {FILE_IMAGE_WIDTH}px, height: {FILE_IMAGE_HEIGHT}px<br />
        mode: {FILE_IMAGE_CHANNEL}, MIME type: {FILE_IMAGE_MIME}<br />
        format: [FILE_IMAGE_LANDSCAPE]landscape[/FILE_IMAGE_LANDSCAPE][FILE_IMAGE_PORTRAIT]portrait[/FILE_IMAGE_PORTRAIT]
 
        [/FILE_IMAGE_WIDTH][/FILE_IMAGE]
        </p>
        </div>
    </div>
 
<!--FILE_ENTRY_END//-->
</div>
english/phpwcms_replacer_rts/frontend_render/xdownload.txt · Last modified: 2011/03/29 08:59 by Knut Heermann (flip-flop)
www.planmatrix.de www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0