コード例 #1
0
ファイル: index.php プロジェクト: bitweaver/meta
// $Header$
// Copyright (c) 2004 bitweaver Sample
// All Rights Reserved. See below for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.
// Initialization
require_once '../kernel/setup_inc.php';
require_once 'meta_lib.php';
// Is package installed and enabled
$gBitSystem->verifyPackage('meta');
// Now check permissions to access this page
$gBitSystem->verifyPermission('p_browse_meta');
$gBitSmarty->assign('metaAttributes', meta_get_possible_values(null, false));
if (isset($_REQUEST['metatt'])) {
    foreach ($_REQUEST['metatt'] as $key => $value) {
        if (!empty($value)) {
            $listHash['search'][$key] = $value;
        }
    }
    $searchResults = meta_search($listHash);
    foreach (array_keys($searchResults) as $key) {
        $groupKey = implode($searchResults[$key]['meta'], ',');
        $groupedResults[$groupKey][$key] = $searchResults[$key];
    }
    ksort($groupedResults);
    $gBitSmarty->assign_by_ref('searchData', $groupedResults);
    $gBitSmarty->assign('tab', 2);
} else {
    $gBitSmarty->assign('tab', 0);
}
// Display the template
$gBitSystem->display('bitpackage:meta/display_search.tpl', tra('Meta Search'), array('display_mode' => 'display'));
コード例 #2
0
ファイル: meta_lib.php プロジェクト: bitweaver/meta
function data_metatable($data, $params, $pFormat = 'html')
{
    // {{{
    global $gBitDb;
    $whereSql = '';
    if (!isset($params['param'])) {
        return tra('Missing parameter "param".');
    }
    $listHash['search'] = meta_parse_plugin_params($params['param']);
    $data = array();
    if ($rows = meta_search($listHash)) {
        switch ($pFormat) {
            case 'csv':
                $columns = array('-1' => tra('Name'));
                break;
            default:
                $columns = array('-1' => '<a href="' . META_PKG_URL . 'export.php?' . http_build_query($params) . '"><i class="icon-table"></i></a> ' . tra('Name'));
                break;
        }
        $groupSql = '';
        if (!empty($params['columns'])) {
            $colVars = array();
            $p = explode(',', $params['columns']);
            $p = array_map('trim', $p);
            foreach ($p as $value) {
                if ($valueId = meta_get_attribute_id($value)) {
                    $columns[$valueId] = ucwords($value);
                    if (!empty($groupSql)) {
                        $groupSql .= ' OR ';
                    }
                    $groupSql .= ' meta_attribute_id=? ';
                    $colVars[] = $valueId;
                } else {
                    $columns[strtolower($value)] = $value;
                }
            }
        }
        $rowCount = 1;
        foreach ($rows as $row) {
            $bindVars = array($row['content_id']);
            $rowData = array();
            $dataString = '';
            $whereSql = '';
            $rowClass = $rowCount++ % 2 ? 'odd' : 'even';
            switch ($pFormat) {
                case 'csv':
                    $rowData[-1] = $row['title'];
                    break;
                default:
                    $rowData[-1] = '<a href="' . BIT_ROOT_URL . 'index.php?content_id=' . $row['content_id'] . '">' . $row['title'] . '</a>';
                    break;
            }
            if ($groupSql) {
                $bindVars = array_merge($bindVars, $colVars);
                $whereSql .= " AND ( {$groupSql} ) ";
            }
            $sql = "SELECT * \n\t\t\t\t\tFROM `" . BIT_DB_PREFIX . "meta_associations` metaa\n\t\t\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "meta_values` metav ON( metaa.`meta_value_id`=metav.`meta_value_id`)\n\t\t\t\t\tWHERE metaa.`content_id`=? AND `metaa`.`end` IS NULL {$whereSql} ";
            if ($vals = $gBitDb->getAll($sql, $bindVars)) {
                foreach ($vals as $v) {
                    $rowData[$v['meta_attribute_id']] = $v['value'];
                }
            }
            $sql = "SELECT lc.*, lcds.`data` AS `summary` \n\t\t\t\t\tFROM `" . BIT_DB_PREFIX . "liberty_content` lc \n\t\t\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_content_data` lcds ON( lc.`content_id` = lcds.`content_id` AND lcds.`data_type` = ? )\n\t\t\t\t\tWHERE lc.`content_id`=?";
            $contentData = current($gBitDb->getAssoc($sql, array('summary', $row['content_id'])));
            foreach ($columns as $valueId => $value) {
                switch ($pFormat) {
                    case 'csv':
                        $dataString[] .= !empty($rowData[$valueId]) ? $rowData[$valueId] : (!empty($contentData[$valueId]) ? $contentData[$valueId] : '');
                        break;
                    default:
                        $dataString .= '<td class="' . $rowClass . '">' . (!empty($rowData[$valueId]) ? $rowData[$valueId] : (!empty($contentData[$valueId]) ? $contentData[$valueId] : '&nbsp;')) . '</td>';
                        break;
                }
            }
            $data[] = $dataString;
        }
    }
    if (count($data) > 0) {
        switch ($pFormat) {
            case 'csv':
                $ret = array_merge(array($columns), $data);
                break;
            default:
                $ret = '<table class="table"><tr><th>' . implode('</th><th class="bitbar">', $columns) . '</th></tr><tr>' . implode("</tr><tr>", $data) . '</tr></table>';
                break;
        }
    } else {
        $ret = tra('No results found.');
    }
    return $ret;
}