Beispiel #1
0
 function display($tpl = null)
 {
     // Frontpage hack
     $this->addTemplatePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'views' . DS . 'link' . DS . 'tmpl');
     // Only allow "component" template
     JRequest::setVar('tmpl', 'component');
     // JFactory
     $user =& JFactory::getUser();
     $config =& JFactory::getConfig();
     $doc =& JFactory::getDocument();
     $lingo =& JFactory::getLanguage();
     // Include styles
     $doc->addStyleSheet(LINKR_ASSETS . 'css/modal.css?' . LINKR_VERSION_INC);
     // Template override
     global $mainframe;
     $tmpl = $mainframe->getTemplate();
     if (file_exists(JPATH_BASE . DS . 'templates' . DS . $tmpl . DS . 'linkr.css')) {
         $doc->addStyleSheet(JURI::base() . 'templates/' . $tmpl . '/linkr.css');
     } elseif (file_exists(JPATH_BASE . DS . 'templates' . DS . $tmpl . DS . 'css' . DS . 'linkr.css')) {
         $doc->addStyleSheet(JURI::base() . 'templates/' . $tmpl . '/css/linkr.css');
     }
     // Editor name, request endpoint, document base
     $editor = JRequest::getString('e_name', 'text');
     $rUrl = JURI::base() . 'index.php?option=com_linkr&view=request&' . JUtility::getToken() . '=1';
     // Include scripts
     JHTML::_('behavior.mootools');
     $unc = LinkrHelper::getParam('compress', 1) ? '.js' : '-UCP.js';
     $doc->addScript(LINKR_ASSETS . 'js/helper' . $unc . '?' . LINKR_VERSION_INC);
     $doc->addScriptDeclaration('var Linkr=new LinkrAPI(' . '[' . implode(',', explode('.', LINKR_VERSION_READ)) . '],' . '"' . $rUrl . '",' . '"' . $editor . '",' . '"' . JURI::root() . '",' . '[' . '"' . JRequest::getWord('mode', 'squeezebox') . '",' . '"' . $lingo->getTag() . '",' . '"' . LinkrHelper::UTF8Encode(JText::_('MISSING_TEXT', true)) . '",' . '"' . LinkrHelper::UTF8Encode(JText::_('IMG_ANCHOR', true)) . '",' . '"' . LINKR_ASSETS . 'img/",' . $user->get('aid') . ']' . ');' . 'var LinkrHelper=Linkr;');
     // Frontend fix
     if (LinkrHelper::isSite()) {
         //$doc->setBase(LinkrHelper::getLinkrUrl($editor));
     }
     // References
     $this->assign('links', $this->get('Links'));
     $this->assign('tools', $this->get('ToolLinks'));
     // Localize text
     if ($text = $this->get('L18N')) {
         $l18n = array();
         foreach ($text as $k => $v) {
             $l18n[] = '["' . $k . '","' . $v . '"]';
         }
         $doc->addScriptDeclaration('Linkr.setL18N([' . implode(',', $l18n) . ']);');
     }
     // 3rd party javascript
     if ($js = $this->get('Scripts')) {
         $doc->addScriptDeclaration($js);
     }
     // Load single link
     $load = '';
     $inc = $this->get('IncludedLinks');
     if (!$this->tools['count'] && $this->links['count'] == 1) {
         $load = 'Linkr.__fr=function(){' . $inc[$this->links['name'][0]] . '};';
     } elseif (!$this->links['count'] && $this->tools['count'] == 1) {
         $load = 'Linkr.__fr=function(){' . $inc[$this->tools['name'][0]] . '};';
     }
     // Fire "onLoad" event
     $doc->addScriptDeclaration('window.addEvent("domready",function(){' . $load . 'Linkr.fireEvent("onLoad");' . '});');
     parent::display($tpl);
 }
Beispiel #2
0
 function onLinkrLoadJS($version, $inc = array())
 {
     // File append
     $append = $this->cp('compress', 1) ? '.js' : '-UCP.js';
     $append .= '?' . LINKR_VERSION_INC;
     // Initialize variables
     $js = '';
     $d =& JFactory::getDocument();
     $r = JURI::root() . 'components/com_linkr/assets/js/';
     // Base files
     $d->addScript($r . 'tree' . $append);
     $d->addScript($r . 'object' . $append);
     $js .= 'LinkrObject.options.defaultItemid=' . LinkrHelper::getParam('itemid', 0) . ';';
     // Plugin check
     // ToDo: use some other check
     $p = LinkrHelper::getPluginParam() ? 'true' : 'false';
     // Bookmarks
     if ($inc['bookmarks']) {
         $d->addScript($r . 'bookmarks' . $append);
         $bm = $this->cp('def_bm', 0) ? 'true' : 'false';
         $js .= 'LinkrBookmarks.loadedByDefault=' . $bm . ';' . 'LinkrBookmarks.isPluginInstalled=' . $p . ';';
     }
     // Related articles
     if ($inc['related']) {
         $d->addScript($r . 'related' . $append);
         $rl = $this->cp('def_rel', 0) ? 'true' : 'false';
         $js .= 'LinkrRelated.loadedByDefault=' . $rl . ';' . 'LinkrRelated.isPluginInstalled=' . $p . ';';
     }
     // Files
     if ($this->cp('link_file', 1) && $inc['file']) {
         $d->addScript($r . 'file' . $append);
         $u = (bool) $this->cp('frontend_upload', 0);
         $u = $u ? true : !LinkrHelper::isSite();
         $u = $u ? JURI::base() . 'index.php?option=com_linkr&controller=file&task=upload&e_name=' . JRequest::getString('e_name', 'text') . '&' . JUtility::getToken() . '=1' : false;
         // Upload
         $js .= 'LinkrFile.uploadURL=' . ($u ? '"' . $u . '"' : 'false') . ';';
         // Message
         if ($msg = JRequest::getString('msg', null)) {
             $js .= 'LinkrFile.msg="' . LinkrHelper::UTF8Encode($msg) . '";';
         }
         // Paths
         global $mainframe;
         $path = JRequest::getString('path', '', 'REQUEST');
         if (strlen($path)) {
             $mainframe->setUserState('linkr.path', $path);
         } else {
             $mainframe->setUserState('linkr.path', null);
         }
         // Simple list
         $simple = JRequest::getInt('simplelist', -1, 'REQUEST');
         if ($simple != -1) {
             $mainframe->setUserState('linkr.simplelist', $simple);
         } else {
             $mainframe->setUserState('linkr.simplelist', null);
         }
     }
     // Articles
     if ($this->cp('link_article', 1) && $inc['article']) {
         $d->addScript($r . 'article' . $append);
         $s = (bool) $this->cp('use_slug', 1);
         $js .= 'ArtOpts.slug=' . ($s ? 'true' : 'false') . ';' . 'var LinkrArticle=LinkrObject.getInstance(ArtOpts, ArtSrch, ArtLay, ArtTmpl);';
     }
     // Menu links
     if ($this->cp('link_menu', 1) && $inc['menu']) {
         $d->addScript($r . 'menu' . $append);
         // Get menus
         $db =& JFactory::getDBO();
         $db->setQuery('SELECT * FROM #__menu_types');
         $ml = (array) $db->loadObjectList();
         foreach ($ml as $m) {
             $ti = LinkrHelper::UTF8Encode($m->title);
             $de = LinkrHelper::UTF8Encode($m->description);
             $js .= 'MITree.include({' . 'id:"' . $m->menutype . '",' . 'name:"' . urlencode($ti) . '",' . 'description:"' . urlencode($de) . '"' . '});';
         }
         $js .= 'var LinkrMenu=LinkrTree.getInstance(MIOpts,MITree,MISrch,MITmpl);';
     }
     // Contacts
     if ($this->cp('link_contact', 1) && $inc['contact']) {
         $d->addScript($r . 'contact' . $append);
         $js .= 'var LinkrContact = LinkrObject.getInstance(ConOpts,ConSrch,ConLay,ConTmpl);';
     }
     // Automatic links
     /*if ($inc['auto'])
     		{
     			$d->addScript($r .'auto'. $append);
     			
     			// Get extensions
     			$db	= & JFactory::getDBO();
     			$db->setQuery(
     				'SELECT c.id, c.name, c.option '.
     				'FROM #__components AS c '.
     				'WHERE c.link <> "" AND c.parent = 0 '.
     				'AND c.enabled = 1');
     			$ex	= (array) $db->loadObjectList();
     			foreach ($ex as $e)
     			{
     				$js	.=
     				'_xr.include({'.
     					'id:'. $e->id .','.
     					'option:"'. $e->option .'",'.
     					'name:"'. urlencode(LinkrHelper::UTF8Encode($e->name)) .'"'.
     				'});';
     			}
     			
     			$js	.= 'var LinkrX=LinkrTree.getInstance(_xo,_xr,_xs,_xt);';
     		}*/
     // Debug
     $user =& JFactory::getUser();
     if ($this->cp('debug', 0) && $user->gid >= 23) {
         $d->addScript($r . 'debug.js?' . LINKR_VERSION_INC);
     }
     return $js;
 }
Beispiel #3
0
 function UTF8Encode($str)
 {
     if (is_array($str) || is_object($str)) {
         settype($str, 'array');
         foreach ($str as $k => $v) {
             $str[$k] = LinkrHelper::UTF8Encode($v);
         }
         return $str;
     } elseif (is_string($str)) {
         return LinkrHelper::isUTF8Encoded($str) ? $str : utf8_encode($str);
     } else {
         return $str;
     }
 }
Beispiel #4
0
 function dbobject()
 {
     // Get query
     $q = $this->getQuery('q');
     if (is_array($q)) {
         return $q;
     }
     // Query database
     $r = $this->_getObj($q);
     if ($this->_db->getErrorNum()) {
         return $this->badRequest($this->_db->getErrorMsg());
     } elseif (is_string($r)) {
         return $this->badRequest($r);
     }
     // UTF8 encode values
     $r = LinkrHelper::UTF8Encode($r);
     // Return results
     return array('status' => 'ok', 'result' => $r);
 }
Beispiel #5
0
 function getL18N()
 {
     // Trigger "onLinkrLoadL18N"
     JPluginHelper::importPlugin('content');
     $dispatcher =& JDispatcher::getInstance();
     $results = $dispatcher->trigger('onLinkrLoadL18N', array(LINKR_VERSION, $this->links));
     if (empty($results) || !is_array($results)) {
         return false;
     }
     // Get localized text
     $l18n = array();
     foreach ($results as $strings) {
         // Performance check
         if (empty($strings)) {
             continue;
         }
         // Include localized text (once)
         foreach ($strings as $s) {
             if (!isset($l18n[$s])) {
                 $l18n[$s] = LinkrHelper::UTF8Encode(JText::_($s, true));
             }
         }
     }
     // Return localized text
     return empty($l18n) ? false : $l18n;
 }