| 1 |
<?php
|
| 2 |
|
| 3 |
/*
|
| 4 |
* Copyright (C) May 2007 Jonathan Hendler
|
| 5 |
*
|
| 6 |
* This program is free software; you can redistribute it and/or
|
| 7 |
* modify it under the terms of the GNU General Public License
|
| 8 |
* as published by the Free Software Foundation; either version 2
|
| 9 |
* of the License, or (at your option) any later version.
|
| 10 |
*
|
| 11 |
* This program is distributed in the hope that it will be useful,
|
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
* GNU General Public License for more details.
|
| 15 |
*
|
| 16 |
* You should have received a copy of the GNU General Public License
|
| 17 |
* along with this program; if not, write to the Free Software
|
| 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
| 19 |
*
|
| 20 |
* The authors can be contacted at:
|
| 21 |
* - jonathan [at] civicactions (dot) com
|
| 22 |
*
|
| 23 |
* @license http://www.affero.org/oagpl.html
|
| 24 |
* @link http://drupal.org/project/semantic_search
|
| 25 |
*/
|
| 26 |
|
| 27 |
/**
|
| 28 |
* This file is the set of functions needed for making javascript and XMLRPC calls
|
| 29 |
* to SEMANTIC_SEARCH
|
| 30 |
* */
|
| 31 |
define('SEMANTIC_SEARCH_BROWSE_PATH','semb');
|
| 32 |
define('SEMANTIC_SEARCH_BROWSE_RPC_PATH','semb/rpc');
|
| 33 |
/**
|
| 34 |
* Implementation of hook_help().
|
| 35 |
*/
|
| 36 |
function semantic_search_browser_help($section) {
|
| 37 |
switch ($section) {
|
| 38 |
case 'admin/modules#description' :
|
| 39 |
return ('<strong>SEMANTIC SEARCH BROWSER:</strong> enables the default data browser');
|
| 40 |
}
|
| 41 |
}
|
| 42 |
|
| 43 |
/**
|
| 44 |
* Implementation of hook_menu
|
| 45 |
*/
|
| 46 |
function semantic_search_browser_menu($may_cache) {
|
| 47 |
|
| 48 |
$items = array ();
|
| 49 |
|
| 50 |
if (!$may_cache) {
|
| 51 |
//rpc access
|
| 52 |
$items[] = array (
|
| 53 |
'path' => SEMANTIC_SEARCH_BROWSE_RPC_PATH,
|
| 54 |
'title' => t('dynamic update of search'
|
| 55 |
), 'access' => user_access('search semantic_search'),
|
| 56 |
'type' => MENU_CALLBACK,
|
| 57 |
'callback' => '_semantic_search_browser_search');
|
| 58 |
|
| 59 |
$items[] = array (
|
| 60 |
'path' => SEMANTIC_SEARCH_BROWSE_PATH,
|
| 61 |
'title' => t('Semantic Search Browser'),
|
| 62 |
'callback' => '_semantic_search_browser_widget',
|
| 63 |
'access' => user_access('search semantic_search'),
|
| 64 |
'type' => MENU_NORMAL_ITEM,
|
| 65 |
);
|
| 66 |
}
|
| 67 |
return $items;
|
| 68 |
}
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
/**
|
| 74 |
*
|
| 75 |
* */
|
| 76 |
function _semantic_search_browser_search(){
|
| 77 |
global $_semantic_search_search;
|
| 78 |
if (empty ($_semantic_search_search))
|
| 79 |
_SEMANTIC_SEARCH_INIT();
|
| 80 |
|
| 81 |
/**
|
| 82 |
* base URL for semantic_search in drupal.
|
| 83 |
* */
|
| 84 |
define('SEMANTIC_SEARCH_BASE_URL', SEMANTIC_SEARCH_BROWSE_PATH);
|
| 85 |
|
| 86 |
_semantic_search_set_constants();
|
| 87 |
|
| 88 |
|
| 89 |
$_semantic_search_search_hash = 'rpcb' . $_semantic_search_search->search_hash;
|
| 90 |
|
| 91 |
$result = (SONIA_USE_CACHE) ? $_semantic_search_search->sonia->io->getCache($_semantic_search_search_hash) : null;
|
| 92 |
|
| 93 |
if (SONIA_USE_CACHE && $result !== null) {
|
| 94 |
// print $result;
|
| 95 |
// exit ();
|
| 96 |
} else {
|
| 97 |
$_semantic_search_search_results = theme("semantic_search_search_results", $_semantic_search_search->searchResults(false),false,false,true);
|
| 98 |
$pagination = theme("semantic_search_search_results_pagination", $_semantic_search_search->searchPaginaton());
|
| 99 |
// if (SONIA_USE_CACHE)
|
| 100 |
// $_semantic_search_search->sonia->io->putCache($_semantic_search_search_hash, $result);
|
| 101 |
//
|
| 102 |
}
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
$all_base_elements = $_semantic_search_search->sonia->getAllBaseElementsAndCounts();
|
| 107 |
$return_array = array();
|
| 108 |
$uris = array();
|
| 109 |
$type_name = (isset($_GET['dt'])) ?$_GET['dt'] : 'CLASS' ;
|
| 110 |
|
| 111 |
foreach($all_base_elements as $type => $data){
|
| 112 |
$type = strtoupper($type);
|
| 113 |
$counts_per_category[$type]['list_total'] = count($data);
|
| 114 |
$counts_per_category[$type]['data_total'] = 0;
|
| 115 |
$counts_per_category[$type]['in_search_total'] = 0;
|
| 116 |
|
| 117 |
|
| 118 |
foreach($data as $uri =>$values) {
|
| 119 |
$uri = SONIA_H :: encodeURI($uri);
|
| 120 |
if ($values['count']>0){
|
| 121 |
$counts_per_category[$type]['data_total'] += $values['count'];
|
| 122 |
//get count in search
|
| 123 |
$counts_per_category[$type]['in_search_total'] += $values['count'];
|
| 124 |
if ($type_name == $type){
|
| 125 |
$prop = (isset($values['property'])) ? SONIA_H :: encodeURI($values['property']):'';
|
| 126 |
$title = (isset($values['property_label'])) ? $values['label'].'<br /> <em>('.$values['property_label'].')</em>':$values['label'];
|
| 127 |
$uris[] = (object) array('title'=>$title . '('.$values['count'].')','uri'=>$uri,'type'=>$type,'value'=>$prop);
|
| 128 |
}
|
| 129 |
}
|
| 130 |
}
|
| 131 |
}
|
| 132 |
|
| 133 |
$return_array[] = $counts_per_category;
|
| 134 |
$return_array[] = $uris;
|
| 135 |
$return_array[] = $_semantic_search_search_results;
|
| 136 |
$return_array[] = $pagination;
|
| 137 |
|
| 138 |
|
| 139 |
//get search result data
|
| 140 |
print drupal_to_js($return_array);
|
| 141 |
die();
|
| 142 |
}
|
| 143 |
|
| 144 |
/**
|
| 145 |
* @todo drupal specific configurations
|
| 146 |
* */
|
| 147 |
function semantic_search_browser_configure() {
|
| 148 |
if (!user_access("configure semantic_search_browser")) {
|
| 149 |
return message_admin_access();
|
| 150 |
}
|
| 151 |
|
| 152 |
return system_settings_form('menu_configure', $form);
|
| 153 |
}
|
| 154 |
|
| 155 |
function semantic_search_browser_perm() {
|
| 156 |
return array();
|
| 157 |
}
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
///**
|
| 162 |
// * implementation of hook block
|
| 163 |
// * most content is rendered via javascript
|
| 164 |
// * */
|
| 165 |
//function semantic_search_browser_block($op = 'list', $delta = 0, $edit = array()){
|
| 166 |
// // The $op parameter determines what piece of information is being requested.
|
| 167 |
// switch ($op) {
|
| 168 |
// case 'list':
|
| 169 |
// // If $op is "list", we just need to return a list of block descriptions.
|
| 170 |
// // This is used to provide a list of possible blocks to the administrator,
|
| 171 |
// // end users will not see these descriptions.
|
| 172 |
// $blocks[0]['info'] = t('Semantic Search Browser: a graphical javascript based RDF data browser');
|
| 173 |
// return $blocks;
|
| 174 |
// case 'configure':
|
| 175 |
// // If $op is "configure", we need to provide the administrator with a
|
| 176 |
// // configuration form. The $delta parameter tells us which block is being
|
| 177 |
// // configured. In this example, we'll allow the administrator to customize
|
| 178 |
// // the text of the first block.
|
| 179 |
// $form = array();
|
| 180 |
// if ($delta == 0) {
|
| 181 |
// // All we need to provide is a text field, Drupal will take care of
|
| 182 |
// // the other block configuration options and the save button.
|
| 183 |
// $form['semantic_search_browser_title'] = array(
|
| 184 |
// '#type' => 'textfield',
|
| 185 |
// '#title' => t('Title'),
|
| 186 |
// '#size' => 60,
|
| 187 |
// '#description' => t('Title of the browser block'),
|
| 188 |
// '#default_value' =>
|
| 189 |
// variable_get('semantic_search_browser_title', t(' ')),
|
| 190 |
// );
|
| 191 |
// $form['semantic_search_browser_description'] = array(
|
| 192 |
// '#type' => 'textarea',
|
| 193 |
// '#title' => t('Description'),
|
| 194 |
// '#description' => t('Description of the browser block.'),
|
| 195 |
// '#default_value' =>
|
| 196 |
// variable_get('semantic_search_browser_description', ''),
|
| 197 |
// );
|
| 198 |
//
|
| 199 |
// $form['semantic_search_default_path'] = array(
|
| 200 |
// '#type' => 'textfield',
|
| 201 |
// '#title' => t('Default path'),
|
| 202 |
// '#description' => t('Description of the browser block.'),
|
| 203 |
// '#default_value' =>
|
| 204 |
// variable_get('semantic_search_default_path', 'sb'),
|
| 205 |
// );
|
| 206 |
//
|
| 207 |
// }
|
| 208 |
// return $form;
|
| 209 |
// case 'save':
|
| 210 |
// // If $op is "save", we need to save settings from the configuration form.
|
| 211 |
// // Since the first block is the only one that allows configuration, we
|
| 212 |
// // need to check $delta to make sure we only save it.
|
| 213 |
// if ($delta == 0) {
|
| 214 |
// // Have Drupal save the string to the database.
|
| 215 |
// variable_set('semantic_search_browser_title', $edit['semantic_search_browser_title']);
|
| 216 |
// variable_set('semantic_search_browser_description', $edit['semantic_search_browser_description']);
|
| 217 |
// variable_set('semantic_search_default_path', $edit['semantic_search_default_path']);
|
| 218 |
// }
|
| 219 |
// return;
|
| 220 |
// case 'view': default:
|
| 221 |
// print 'hello VIEW';
|
| 222 |
// // If $op is "view", then we need to generate the block for display
|
| 223 |
// // purposes. The $delta parameter tells us which block is being requested.
|
| 224 |
// switch ($delta) {
|
| 225 |
// case 0:
|
| 226 |
// // The subject is displayed at the top of the block. Note that it
|
| 227 |
// // should be passed through t() for translation.
|
| 228 |
// $block['subject'] = t(variable_get('semantic_search_browser_title',''));
|
| 229 |
// // The content of the block is typically generated by calling a custom
|
| 230 |
// // function.
|
| 231 |
// $block['content'] = theme('semantic_search_browser_widget',_semantic_search_browser_search());
|
| 232 |
// break;
|
| 233 |
//
|
| 234 |
// }
|
| 235 |
// return $block;
|
| 236 |
// }
|
| 237 |
//}
|
| 238 |
|
| 239 |
function _semantic_search_browser_widget(){
|
| 240 |
$path = drupal_get_path('module', 'semantic_search');
|
| 241 |
$js_path = $path . '/js';
|
| 242 |
$css_path = $path . '/css';
|
| 243 |
drupal_add_js($js_path . '/jquery.history.js');
|
| 244 |
drupal_add_js($js_path . '/semantic_search_browser.js','module','header',false,false);
|
| 245 |
drupal_add_css($css_path . '/semantic_search_browser.css');
|
| 246 |
drupal_add_js("
|
| 247 |
var SemanticSearchBrowseBaseURL = '".url(SEMANTIC_SEARCH_BROWSE_PATH,null,null,true)."';
|
| 248 |
",'inline');
|
| 249 |
|
| 250 |
$constants = ' var SEMANTIC_SEARCH_BROWSE_RPC_PATH = "' . url(SEMANTIC_SEARCH_BROWSE_RPC_PATH,null,null,true) . '"; ';
|
| 251 |
drupal_add_js($constants,'inline');
|
| 252 |
|
| 253 |
|
| 254 |
$data['container'] = '<div id="semantic-search-browser-container"> %s</div>';
|
| 255 |
$data['jellybean'] = '<div id="semantic-search-browser-jellybean"><div class="semantic-search-browser-jellybean-title" >'.t('JellyBeans').'</div><ul></ul></div>';
|
| 256 |
//<div class="semantic-search-browser-block-wrapper" >
|
| 257 |
$data['classes'] = '<div id="semantic-search-browser-classes"><div class="semantic-search-browser-nav-title" title="'.t('Focus on (RDF:Classes)').'">'.t('Categories').'<div class="semantic-search-title-count" id="semantic-search-title-count-classes" > </div></div><span><ul></ul></span></div>';
|
| 258 |
$data['properties'] = '<div id="semantic-search-browser-properties"><div class="semantic-search-browser-nav-title" title="'.t('Focus on (RDF: Properties)').'">'.t('Field Titles').'<div class="semantic-search-title-count" id="semantic-search-title-count-properties" > </div></div><span><ul></ul></span></div>';
|
| 259 |
$data['values'] = '<div id="semantic-search-browser-values"><div class="semantic-search-browser-nav-title" title="'.t('Focus on (RDF: Literals)').'">'.t('Field Values').'<div class="semantic-search-title-count" id="semantic-search-title-count-values" > </div></div><span><ul></ul></span></div>';
|
| 260 |
$data['triangle'] = '<div id="semantic-search-browser-triangle"></div>';
|
| 261 |
$data['objects'] = '<div id="semantic-search-browser-objects"><div class="semantic-search-browser-objects-title" title="'.t('Focus').'">'.t('Data Results (Objects)').'</div><span><ul></ul></span></div>';
|
| 262 |
$data['restart_search_link'] = l(t('Restart'),url(SEMANTIC_SEARCH_BROWSE_PATH,null,null,true));
|
| 263 |
$data['indicator'] = '<div id="semantic-search-browser-indicator"></div>';
|
| 264 |
|
| 265 |
return theme('semantic_search_browser_widget',$data);
|
| 266 |
}
|
| 267 |
/**
|
| 268 |
* implementation of hook theme
|
| 269 |
* */
|
| 270 |
function theme_semantic_search_browser_widget($data){
|
| 271 |
$html = $data['restart_search_link'].'<br />';
|
| 272 |
$html .= sprintf($data['container'],$data['indicator'].$data['jellybean'].$data['classes'].$data['properties'].$data['values'].$data['triangle']);
|
| 273 |
$html .= $data['objects'];
|
| 274 |
|
| 275 |
return '<div id="semantic-search-browser">'.$html.'</div>';
|
| 276 |
}
|
| 277 |
|
| 278 |
//TODO ?
|
| 279 |
//http://bryght.com/xml-rpc-hacks
|
| 280 |
//drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
|