Joomla组件学习之后台com_admin组件-帮助信息

com_admin组件-系统帮助功能

效果

 

 

 

 

关键代码

(HTML_admin_misc代码) function help() { global $mainframe; jimport( 'joomla.filesystem.folder' ); jimport( 'joomla.language.help' ); // Get Help URL - an empty helpurl is interpreted as local help files! // 获得帮助URL,如果没有设置则使用本地帮助文件 $helpurl = $mainframe->getCfg('helpurl'); if ( $helpurl == 'http://help.mamboserver.com' ) { $helpurl = 'http://help.joomla.org'; } // 如果没有指定帮助文档路径,则使用本地帮助文档 $fullhelpurl = $helpurl . '/index2.php?option=com_content&task=findkey&pop=1&keyref='; $helpsearch = JRequest::getString('helpsearch'); $page = JRequest::getCmd('page', 'joomla.whatsnew15.html'); $toc = getHelpToc( $helpsearch );

 

 


 

 getHelpToc函数

$toc = getHelpToc( $helpsearch );

 

 

关键代码

(HTML_admin_misc代码) function getHelpTOC( $helpsearch ) { global $mainframe; $lang =& JFactory::getLanguage(); jimport( 'joomla.filesystem.folder' ); $helpurl = $mainframe->getCfg('helpurl'); // Check for files in the actual language // 检查当前语言文件 $langTag = $lang->getTag(); if( !JFolder::exists( JPATH_BASE.DS.'help'.DS.$langTag ) ) { $langTag = 'en-GB'; // use english as fallback } // 通过指定格式,返回目录下文件名集合 $files = JFolder::files( JPATH_BASE.DS.'help'.DS.$langTag, '/.xml$|/.html$' ); $toc = array(); foreach ($files as $file) { $buffer = file_get_contents( JPATH_BASE.DS.'help'.DS.$langTag.DS.$file ); if (preg_match( '#(.*?)#', $buffer, $m )) { $title = trim( $m[1] ); if ($title) { if ($helpurl) { // strip the extension $file = preg_replace( '#/.xml$|/.html$#', '', $file ); } if ($helpsearch) { //判断当前文件文本中,是否具有用户搜索关键字,有则保存 if (JString::strpos( strip_tags( $buffer ), $helpsearch ) !== false) { $toc[$file] = $title; } elseif(JString::strpos( $file, $helpsearch) !== false) { $toc[$file] = $title; } } else { $toc[$file] = $title; } } } } asort( $toc ); //返回的是符合搜索条件数组(key=>文件名,value=>标题),显示用户看格式 标题 return $toc; }

 

 

 

 

JFolder::files();函数 

//根据一定的模式,返回指定目录下文件名 $files = JFolder::files( JPATH_BASE.DS.'help'.DS.$langTag, '/.xml$|/.html$' );

 

 

 

 

关键代码

(JFolder代码) function files($path, $filter = '.', $recurse = false, $fullpath = false, $exclude = array('.svn', 'CVS')) { // Initialize variables // 初始化参数 $arr = array(); // Check to make sure the path valid and clean // 检查判断路径是有效合理的 $path = JPath::clean($path); // Is the path a folder? // 判断是否是文件夹 if (!is_dir($path)) { JError::raiseWarning(21, 'JFolder::files: ' . JText::_('Path is not a folder'), 'Path: ' . $path); return false; } // read the source directory // 读取源目录 // 获得目录句柄, readdir 从句柄中获得条目 $handle = opendir($path); while (($file = readdir($handle)) !== false) { // $file不在array('.svn', 'cvs')数组中 if (($file != '.') && ($file != '..') && (!in_array($file, $exclude))) { $dir = $path . DS . $file; // 如果还是目录,递归 $isDir = is_dir($dir); if ($isDir) { if ($recurse) { // 则迭代子目录 if (is_integer($recurse)) { // 数字则迭代数字深度目录, $arr2 = JFolder::files($dir, $filter, $recurse - 1, $fullpath); } else { $arr2 = JFolder::files($dir, $filter, $recurse, $fullpath); } $arr = array_merge($arr, $arr2); } } else { // 匹配出路径 if (preg_match("/$filter/", $file)) { if ($fullpath) { $arr[] = $path . DS . $file; } else { $arr[] = $file; } } } } } // 关闭目录句柄 closedir($handle); // 对数组进行排序并保持索引关系(注:应该是按照value来排序的) asort($arr); return $arr; }


(HTML_admin_misc代码) ...... $v) { if ($helpurl) { echo '

  • '; echo JHTML::_('link', JHelp::createUrl( $k ), $v, array('target' => 'helpFrame')); echo '
  • '; } else { echo '
  • '; echo JHTML::_('link', JURI::base() .'help/'.$langTag.'/'.$k, $v, array('target' => 'helpFrame')); echo '
  • '; } } ?> ......


     

     

     

     

    JHelp::createUrl()函数

    JHTML::_('link', JHelp::createUrl( $k ), $v, array('target' => 'helpFrame'))

     

     

     

    关键代码

    (JHelp代码) function createURL($ref, $useComponent = false) { global $mainframe, $option; $user =& JFactory::getUser(); $userHelpUrl = $user->getParam( 'helpsite' ); $globalHelpUrl = $mainframe->getCfg('helpurl'); $lang =& JFactory::getLanguage(); // 返回组件的帮助路径 if ($useComponent) { if (!preg_match( '#/.html$#i', $ref )) { $ref = $ref . '.html'; } $url = 'components/' . $option. '/help'; $tag = $lang->getTag(); // Check if the file exists within a different language! if( $lang->getTag() != 'en-GB' ) { $localeURL = JPATH_BASE.DS.$url.DS.$tag.DS.$ref; jimport( 'joomla.filesystem.file' ); if( !JFile::exists( $localeURL ) ) { $tag = 'en-GB'; } } return $url.'/'.$tag.'/'.$ref; } // 返回用户特殊的帮助路径 if ( $userHelpUrl ) { // Online help site as defined in GC $version = new JVersion(); $ref .= $version->getHelpVersion(); $url = $userHelpUrl . '/index2.php?option=com_content&task=findkey &tmpl=component&keyref=' . urlencode( $ref ); } else if ( $globalHelpUrl ) //用户指定网站网络帮助目录 { // Online help site as defined in GC $version = new JVersion(); $ref .= $version->getHelpVersion(); $url = $globalHelpUrl . '/index2.php?option=com_content&task=findkey &tmpl=component;1&keyref=' . urlencode( $ref ); } else //没有指定网络相关帮助 { // Included html help files // 本地帮助文件 $helpURL = 'help/' .$lang->getTag() .'/'; if (!preg_match( '#/.html$#i', $ref )) { $ref = $ref . '.html'; } // Check if the file exists within a different language! if( $lang->getTag() != 'en-GB' ) { $localeURL = JPATH_BASE . $helpURL .$ref; jimport( 'joomla.filesystem.file' ); if( !JFile::exists( $localeURL ) ) { $helpURL = 'help/en-GB/'; } } $url = $helpURL . $ref; } return $url; }

    你可能感兴趣的:(Joomla源码解剖,file,path,function,filter,url,buffer)