⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 odtindexer.class.php

📁 joomla的图片功能插件,能够有很多图片特效功能
💻 PHP
字号:
<?php/*** @package ODT_Indexer* @copyright (C) 2006 Websmurf* @author Websmurf** --------------------------------------------------------------------------------* All rights reserved.  ODT Indexer is a component for Joomla and Mambo.* You can use it to search through ODT files** This program is free software; you can redistribute it and/or* modify it under the terms of the Creative Commons - Attribution-NoDerivs 2.5* license as published by the Creative Commons Organisation* http://creativecommons.org/licenses/by-nd/2.5/.** This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.* --------------------------------------------------------------------------------**/// ensure this file is being included by a parent filedefined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );class indexer{  function showIndex(){    global $database, $mainframe, $option;    $limit = $mainframe->getUserStateFromRequest("limit.$option", "limit", $mainframe->getCfg('list_limit'));    $limitstart = $mainframe->getUserStateFromRequest("limitstart.$option", "limitstart", 0);    $basequery = "SELECT * FROM #__odtindex ORDER BY path";    $query = str_replace("*", "COUNT(1)", $basequery);    $database->setQuery($query);    $total = $database->loadResult();    echo $database->getErrorMsg();    require_once( $mainframe->getCfg('absolute_path') . '/administrator/includes/pageNavigation.php' );    $pageNav = new mosPageNav($total, $limitstart, $limit);    $query = $basequery . " LIMIT $limitstart, $limit";    $database->setQuery($query);    $rows = $database->loadObjectList();    echo $database->getErrorMsg();    HTML_indexer::showIndex($rows, $pageNav);  }  function editIndex($id){    global $database, $mainframe, $option;    if(!is_writable($mainframe->getCfg('absolute_path') . '/cache')){      mosRedirect('index2.php?option=' . $option, "Please make sure the /cache directory is writable");      return;    }    $row = new dbODTIndex($database);    $row->load($id);    HTML_indexer::editIndex($row);  }  function saveIndex(){    global $database, $mainframe, $option, $task;    $row = new dbODTIndex($database);    $row->bind($_POST);    //do indexing    $row->content = indexer::getContent($row->path);		$row->indexed = date('Y-m-d H:i:s');    //save    if (!$row->store()) {  		echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";  		exit();  	}//  	return;  	switch ($task){  	  case 'apply':        mosRedirect('index2.php?option=' . $option . '&task=edit&cid=' . $row->id, 'Document saved');  	    break;  	  case 'save':  	    mosRedirect('index2.php?option=' . $option, 'Document saved');  	    break;  	}  }    function getContent($path){    global $mainframe;        $iswin = (substr(PHP_OS, 0, 3) == 'WIN');    require_once( $mainframe->getCfg('absolute_path') . '/administrator/includes/pcl/pclzip.lib.php' );		require_once( $mainframe->getCfg('absolute_path') . '/administrator/includes/pcl/pclerror.lib.php' );    		if(!file_exists($mainframe->getCfg('absolute_path') . '/' . $path)){		  echo "<script> alert('File $row->path does not exist'); window.history.go(-1); </script>\n";    	exit();		}		$zipfile = new PclZip( $mainframe->getCfg('absolute_path') . '/' . $path );		if($iswin) {			define('OS_WINDOWS',1);		} else {			define('OS_WINDOWS',0);		}				$extension = explode(".", $path);		$ext = $extension[sizeof($extension) - 1];				$files = $zipfile->listContent();		if(!file_exists($mainframe->getCfg('absolute_path') . '/cache/' . md5($path))){  		if(!mkdir($mainframe->getCfg('absolute_path') . '/cache/' . md5($path))){  		  echo "<script> alert('Failed to create temporary directory'); window.history.go(-1); </script>\n";    		exit();  		}		}		require_once( $mainframe->getCfg('absolute_path') . '/includes/domit/xml_domit_lite_include.php' );//		$ret = $zipfile->extract( PCLZIP_OPT_PATH, $mainframe->getCfg('absolute_path') . '/cache/' . md5($row->path) . '/' );		$xmlDoc = new DOMIT_Lite_Document();		$xmlDoc->resolveErrors( true );//		print_r ($zipfile->listContent());				if($ext == 'odt'){		  //file to look for: content.xml		  $index = -1;		  for($i=0,$n=count($files);$i<$n;$i++){		    if($files[$i]['filename'] == "content.xml"){		      $index = $files[$i]['index'];		      break;		    }		  }		  		  $ret = $zipfile->extractByIndex($index, PCLZIP_OPT_PATH, $mainframe->getCfg('absolute_path') . '/cache/' . md5($path) . '/');		    		if (!$xmlDoc->loadXML( $mainframe->getCfg('absolute_path') . '/cache/' . md5($path) . '/content.xml', false, true )) {  			echo "<script> alert('Failed to read document content'); window.history.go(-1); </script>\n";    		exit();  		}		} else if($ext == 'docx'){		  //file to look for: word/document.xml		  $index = -1;		  for($i=0,$n=count($files);$i<$n;$i++){		    if($files[$i]['filename'] == "word/document.xml"){		      $index = $files[$i]['index'];		      break;		    }		  }//		  echo "|" . intval($index) ."|";		  $ret = $zipfile->extractByIndex($index, PCLZIP_OPT_PATH, $mainframe->getCfg('absolute_path') . '/cache/' . md5($path) . '/');		  //		  die;  		if (!$xmlDoc->loadXML( $mainframe->getCfg('absolute_path') . '/cache/' . md5($path) . '/word/document.xml', false, true )) {  			echo "<script> alert('Failed to read document content'); window.history.go(-1); </script>\n";    		exit();  		}		}		$root = &$xmlDoc->documentElement;		$files = mosReadDirectory($mainframe->getCfg('absolute_path') . '/cache/' . md5($path), '.', true, true);		$dirs = array();		$dirs[] = $mainframe->getCfg('absolute_path') . '/cache/' . md5($path);		for($i=0,$n=count($files);$i<$n;$i++){//		  echo 'delete: ' . $files[$i] . '<br />';		  if(!unlink($files[$i])){		    $dirs[] = $files[$i];		  }		}		rsort($dirs);		for($i=0,$n=count($dirs);$i<$n;$i++){//		  echo 'delete: ' . $dirs[$i] . '<br />';		  rmdir($dirs[$i]);		}				return $root->getText();  }  /**   * Remove file(s) from the indexed files   *   * @param array $ids   */  function removeIndex($ids){    global $database, $mainframe, $option;    $row = new dbODTIndex($database);    for($i=0,$n=count($ids);$i<$n;$i++){      $row->delete($ids[$i]);    }    mosRedirect('index2.php?option=' . $option, 'Document(s) removed');  }    /**   * Update index of indexed files   *   * @param array $ids   */  function updateIndex($ids){    global $database, $mainframe, $option;    $row = new dbODTIndex($database);    for($i=0,$n=count($ids);$i<$n;$i++){      $row->load($ids[$i]);            $row->content = indexer::getContent($row->path);  		$row->indexed = date('Y-m-d H:i:s');        //save      if (!$row->store()) {    		echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";    		exit();    	}    }    mosRedirect('index2.php?option=' . $option, 'Document(s) updated');  }}class dbODTIndex extends mosDBTable {  /** @var int ID **/  var $id = null;  /** @var string name **/  var $name = null;  /** @var string path **/  var $path = null;  /** @var text content **/  var $content = null;  /** @var datetime indexed **/  var $indexed = null;  function dbODTIndex(&$db){    $this->mosDBTable('#__odtindex', 'id', $db);  }}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -