* @copyright 2004 by http://wombat.exit0.net * @package wombatSite * @subpackage cmHtml */ /** * Dialog interface * * @todo check user before display! * * @version 1.0.0 * @package wombatSite * @subpackage cmHtml */ class wbDialog_Link extends wbDialog { /** * init language depending data * * @access private */ function _init() { $this->_options = array( 'width' => 800, 'height' => 750, 'class' => 'Link', 'title' => _( 'Hyper Linker' ), 'brief' => _( 'Create links to navigate within your own site.' ), 'name' => 'link', 'vars' => 'protocol,url,title', 'type' => 'inline', ); return true; } /** * process dialog * * @access public * @param string $html html to be displayed, or null to get it from template * @return boolean $result true */ function process() { $this->_loadTemplates( $this->_options['class'] ); // basic scripts $debug = 'false'; if( wbDebugger::isActive() ) { $debug = 'true'; } $this->_tmpl->addVar( 'onload', 'debug', $debug ); $load = $this->_tmpl->getParsedTemplate( 'onload' ); wbJSTools::includeJavascript( $load, 'onload' ); wbJSTools::includeJavascript( 'wbMisc.js' ); wbJSTools::includeJavascript( 'wbMenu.js' ); wbJSTools::includeJavascript( 'wbMenuMaker.js' ); // menu wbFactory::includeClass( 'wbMenuTools' ); $menu = wbMenuTools::getFlatMenu(); $this->_tmpl->addRows( 'menuitem_entry', $menu ); // search for wikipedia article $title = null; if( $_REQUEST['wikipedia_search_submit'] ) { $this->_selection = $_REQUEST['wikipedia_search']; $title = $_REQUEST['wikipedia_title']; } // process selection $this->_selection = strip_tags( $this->_selection ); if( empty( $this->_selection ) ) { $this->_tmpl->addGlobalVar( 'ext_title', _( 'link title' ) ); return $this->_tmpl->getParsedTemplate( 'dialog' ); } // only single line selection is valid $this->_selection = explode( "\n", trim( $this->_selection ) ); $this->_selection = $this->_selection[0]; if( empty( $title ) ) { $title = $this->_selection; } $this->_tmpl->addGlobalVar( 'ext_title', $title ); $this->_tmpl->addGlobalVar( 'wikipedia_title', $title ); $this->_tmpl->addGlobalVar( 'wikipedia_search', $this->_selection ); // seek wikipedia article $ds = wbFactory::create( 'wbDatasource' ); $lang = 'de'; $search = str_replace( ' ', '_', $this->_selection ); $clause = array(); // sub clause $c = array(); $c[] = array( 'field' => 'title', 'relation' => 'begin', 'value' => $search ); $c[] = array( 'field' => 'title_reverse', 'relation' => 'begin', 'value' => strrev( $search ) ); // add sub clause to make use of keys $clause[] = array( 'type' => 'complex', 'bond' => 'OR', 'clause' => $c ); $list = $ds->getEntries( 'wikipedia_' . $lang, null, $clause, 0 ); if( empty( $list ) ) { return $this->_tmpl->getParsedTemplate( 'dialog' ); } $this->_tmpl->addGlobalVar( 'wikipedia_count', count( $list ) ); $exactMatch = false; foreach( $list as &$l ) { if( $l['title'] == $search ) { $exactMatch = true; $l['checked'] = 'checked="checked"'; } $urlParams = array( 'title' => $l['title'], 'oldid' => $l['latest'] ); $l['link'] = $lang . '.wikipedia.org/w/index.php?' . http_build_query( $urlParams ); $l['title'] = str_replace( '_', ' ', $l['title'] ); } if( !$exactMarch ) { $list[0]['checked'] = 'checked="checked"'; } $this->_tmpl->addRows( 'wikipedia_entry', $list ); return $this->_tmpl->getParsedTemplate( 'dialog' ); } } ?>