ktcolumns.inc.php

来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· PHP 代码 · 共 601 行 · 第 1/2 页

PHP
601
字号
<?php
/**
 * $Id: KTColumns.inc.php 9392 2008-09-26 08:01:26Z kevin_fourie $
 *
 * KnowledgeTree Community Edition
 * Document Management Made Simple
 * Copyright (C) 2008 KnowledgeTree Inc.
 * Portions copyright The Jam Warehouse Software (Pty) Limited
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 3 as published by the
 * Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
 * California 94120-7775, or email info@knowledgetree.com.
 *
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU General Public License version 3.
 *
 * In accordance with Section 7(b) of the GNU General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * KnowledgeTree" logo and retain the original copyright notice. If the display of the
 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
 * must display the words "Powered by KnowledgeTree" and retain the original
 * copyright notice.
 * Contributor( s): ______________________________________
 */

// more advanced, intelligent columns.

require_once(KT_LIB_DIR . '/browse/advancedcolumns.inc.php');

class AdvancedTitleColumn extends AdvancedColumn {
    var $name = 'title';
    var $namespace = 'ktcore.columns.title';
    var $sortable = true;
    var $aOptions = array();
    var $aIconPaths = array();
    var $link_folders = true;
    var $link_documents = true;

    function setOptions($aOptions) {
        $this->link_folders = KTUtil::arrayGet($aOptions, 'link_folders', $this->link_folders, false);
        $this->link_documents = KTUtil::arrayGet($aOptions, 'link_documents', $this->link_documents, false);
        parent::setOptions($aOptions);
    }

    function AdvancedTitleColumn() {
        $this->label = _kt("Title");
    }

    // what is used for sorting
    // query addition is:
    //    [0] => join claus
    //    [1] => join params
    //    [2] => ORDER

    function addToFolderQuery() {
        return array(null,
            null,
            "F.name",
        );
    }
    function addToDocumentQuery() {
            return array(null,
            null,
            "DM.name"
        );
    }


    function renderFolderLink($aDataRow) {
        /* this check has to be done so that any titles longer than 40 characters is not displayed incorrectly.
         as mozilla cannot wrap text without white spaces */
        global $default;
        $charLength = (isset($default->titleCharLength)) ? $default->titleCharLength : 40;

        if (mb_strlen($aDataRow["folder"]->getName(), 'UTF-8') > $charLength) {
        	mb_internal_encoding("UTF-8");
            $outStr = htmlentities(mb_substr($aDataRow["folder"]->getName(), 0, $charLength, 'UTF-8')."...", ENT_NOQUOTES, 'UTF-8');
        }else{
            $outStr = htmlentities($aDataRow["folder"]->getName(), ENT_NOQUOTES, 'UTF-8');
        }

        if($this->link_folders) {
            $outStr = '<a href="' . $this->buildFolderLink($aDataRow) . '">' . $outStr . '</a>';
        }
        return $outStr;
    }

    function renderDocumentLink($aDataRow) {
        /* this check has to be done so that any titles longer than 40 characters is not displayed incorrectly.
         as mozilla cannot wrap text without white spaces */
        global $default;
        $charLength = (isset($default->titleCharLength)) ? $default->titleCharLength : 40;

        if (mb_strlen($aDataRow["document"]->getName(), 'UTF-8') > $charLength) {
        	mb_internal_encoding("UTF-8");
            $outStr = htmlentities(mb_substr($aDataRow["document"]->getName(), 0, $charLength, 'UTF-8')."...", ENT_NOQUOTES, 'UTF-8');
        }else{
            $outStr = htmlentities($aDataRow["document"]->getName(), ENT_NOQUOTES, 'UTF-8');
        }

        if($this->link_documents) {
            $outStr = '<a href="' . $this->buildDocumentLink($aDataRow) . '" title="' . htmlentities($aDataRow["document"]->getFilename(), ENT_QUOTES, 'UTF-8').'">' .
                $outStr . '</a>';
        }
        return $outStr;
    }

    function buildDocumentLink($aDataRow) {
    	if($aDataRow['document']->isSymbolicLink()){
    		$iDocId = $aDataRow['document']->getRealDocumentId();
    	}else{
    		$iDocId = $aDataRow["document"]->getId();
    	}

        $url = KTBrowseUtil::getUrlForDocument($iDocId);
        if($aDataRow['document']->isSymbolicLink()){
        	$aDataRow['document']->switchToRealCore();
        	$url .= "&fShortcutFolder=".$aDataRow['document']->getFolderId();
        }
        return $url;
    }


    // 'folder_link' allows you to link to a different URL when you're connecting, instead of addQueryStringSelf
    // 'direct_folder' means that you want to go to 'browse folder'
    // 'qs_params' is an array (or string!) of params to add to the link

    function buildFolderLink($aDataRow) {
        if (is_null(KTUtil::arrayGet($this->aOptions, 'direct_folder'))) {
           $dest = KTUtil::arrayGet($this->aOptions, 'folder_link');
           if($aDataRow['folder']->isSymbolicLink()){
           		$params = array('fFolderId' => $aDataRow['folder']->getLinkedFolderId(),
				     'fShortcutFolder' => $aDataRow['folder']->getParentID());
           }else{
          		$params = array('fFolderId' => $aDataRow['folder']->getId());
           }
	   		$params = kt_array_merge(KTUtil::arrayGet($this->aOptions, 'qs_params', array()),
				     $params);

            if (empty($dest)) {
                return KTUtil::addQueryStringSelf($params);
            } else {
                return KTUtil::addQueryString($dest, $params);
            }

        } else {
        	if($aDataRow['folder']->isSymbolicLink()){
        		return KTBrowseUtil::getUrlForFolder($aDataRow['folder']->getLinkedFolder())."&fShortcutFolder=".$aDataRow['folder']->getParentID();
        	}else{
            	return KTBrowseUtil::getUrlForFolder($aDataRow['folder']);
        	}
        }
    }

    // use inline, since its just too heavy to even _think_ about using smarty.
    function renderData($aDataRow) {
        if ($aDataRow["type"] == "folder") {
            $contenttype = 'folder';
            $link = $this->renderFolderLink($aDataRow);

            // If folder is a shortcut display the shortcut mime icon
            if($aDataRow['folder']->isSymbolicLink()){
                $contenttype .= '_shortcut';
            }
            // Separate the link from the mime icon to allow for right-to-left languages
            return "<div style='float: left' class='contenttype $contenttype'>&nbsp;</div>$link";
        } else {
            $type = '';
            $size = '';
            if($aDataRow['document']->isSymbolicLink()){
                // If document is a shortcut - display the shortcut mime type
                $type = 'shortcut';
            }else{
                // Display the document size if it is not a shortcut
                $size = $this->prettySize($aDataRow["document"]->getSize());
                $size = "&nbsp;($size)";
            }

            $link = $this->renderDocumentLink($aDataRow);
            $contenttype = $this->_mimeHelper($aDataRow["document"]->getMimeTypeId(), $type);

            // Separate the link from the mime icon and the size to allow for right-to-left languages
            return "<div style='float: left' class='contenttype $contenttype'>&nbsp;</div><div style='float: left'>$link</div>$size";
        }
    }

    function prettySize($size) {
        $finalSize = $size;
        $label = 'b';

        if ($finalSize > 1000) { $label='Kb'; $finalSize = floor($finalSize/1000); }
        if ($finalSize > 1000) { $label='Mb'; $finalSize = floor($finalSize/1000); }
        return $finalSize . $label;
    }

    function _mimeHelper($iMimeTypeId, $type = null) {
        require_once(KT_LIB_DIR . '/mime.inc.php');
        return KTMime::getIconPath($iMimeTypeId, $type);
    }
}

/*
 * Column to handle dates
 */

class AdvancedDateColumn extends AdvancedColumn {
    var $name = 'datecolumn';

    var $document_field_function;
    var $folder_field_function;
    var $sortable = true;
    var $document_sort_column;
    var $folder_sort_column;
    var $namespace = 'ktcore.columns.genericdate';

    function AdvancedDateColumn() {
        $this->label = _kt('Generic Date Function');
    }

    // use inline, since its just too heavy to even _think_ about using smarty.
    function renderData($aDataRow) {
        $outStr = '';
        if (($aDataRow["type"] == "folder") && (!is_null($this->folder_field_function))) {
            $res = call_user_func(array($aDataRow["folder"],  $this->folder_field_function));
            $dColumnDate = strtotime($res);

            // now reformat this into something "pretty"
            return date("Y-m-d H:i", $dColumnDate);

        } else if (($aDataRow["type"] == "document") && (!is_null($this->document_field_function))) {
            $res = call_user_func(array($aDataRow["document"],  $this->document_field_function));
            $dColumnDate = strtotime($res);

            // now reformat this into something "pretty"
            return date("Y-m-d H:i", $dColumnDate);
        } else {
            return '&mdash;';
        }
        return $outStr;
    }

    function addToFolderQuery() {
        return array(null, null, null);
    }
    function addToDocumentQuery() {
        return array(null, null, $this->document_sort_column);
    }
}

class CreationDateColumn extends AdvancedDateColumn {
    var $document_field_function = 'getCreatedDateTime';
    var $folder_field_function = null;

    var $document_sort_column = "D.created";
    var $folder_sort_column = null;
    var $namespace = 'ktcore.columns.creationdate';

    function CreationDateColumn() {
        $this->label = _kt('Created');
    }
}

class ModificationDateColumn extends AdvancedDateColumn {
    var $document_field_function = 'getLastModifiedDate';
    var $folder_field_function = null;

    var $document_sort_column = "D.modified";
    var $folder_sort_column = null;
    var $namespace = 'ktcore.columns.modificationdate';

    function ModificationDateColumn() {
        $this->label = _kt('Modified');
    }
}

class AdvancedUserColumn extends AdvancedColumn {
    var $document_field_function;
    var $folder_field_function;
    var $sortable = false; // by default
    var $document_sort_column;
    var $folder_sort_column;
    var $namespace = 'ktcore.columns.genericuser';

    function AdvancedUserColumn() {
        $this->label = null; // abstract.
    }

    // use inline, since its just too heavy to even _think_ about using smarty.
    function renderData($aDataRow) {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?