处理缩略图方法,移除无用代码
This commit is contained in:
parent
34371a1996
commit
8ebf73fbd7
|
@ -4,8 +4,6 @@ class ServiceController extends Zend_Controller_Action
|
|||
private $limit=10;
|
||||
function __call($id, $arguments)
|
||||
{
|
||||
Zend_Debug::dump($arguments,'argu');
|
||||
Zend_Debug::dump($id,'id');
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
$this->_helper->layout->disableLayout();
|
||||
}
|
||||
|
@ -35,23 +33,32 @@ class ServiceController extends Zend_Controller_Action
|
|||
*/
|
||||
function thumbAction()
|
||||
{
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
$uuid = $this->_request->getParam('uuid');
|
||||
$thumb=$this->db->fetchRow("select t.data,t.filetype from thumbnail t left join metadata m on t.id=m.id where m.uuid=?",array($uuid));
|
||||
if (empty($thumb)) {
|
||||
$id = (int)$this->_request->getParam('id');
|
||||
if (empty($id)) {
|
||||
$uuid = $this->_request->getParam('uuid');
|
||||
if (empty($uuid)) $this->_redirect('/data');
|
||||
$where=$this->db->quoteInto('uuid = ?',$uuid);
|
||||
} else {
|
||||
$where=$this->db->quoteInto('id = ?',$id);
|
||||
}
|
||||
$sql="select * from thumbnail where ".$where;
|
||||
$thumb=$this->db->fetchRow($sql);
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
if (empty($thumb['data'])) {
|
||||
header("Content-Type:image/png");
|
||||
header("Content-Length: " . filesize("images/nothumb.png"));
|
||||
$file=fopen("images/nothumb.png",'r');
|
||||
fpassthru($file);
|
||||
exit;
|
||||
} else {
|
||||
header("Content-Type:image/".$thumb['filetype']);
|
||||
print base64_decode($thumb['data']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 高级搜索, no page, json output
|
||||
* 搜索, no page, json output
|
||||
*/
|
||||
function searchAction()
|
||||
{
|
||||
|
@ -86,26 +93,6 @@ class ServiceController extends Zend_Controller_Action
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据浏览
|
||||
*/
|
||||
function browseAction()
|
||||
{
|
||||
$md=new MetadataTable();
|
||||
$db=$md->getAdapter();
|
||||
$page=(int)$this->_request->getParam('page');
|
||||
if (empty($page)) $page=1;
|
||||
$limit=10;
|
||||
$offset=$limit*($page-1);
|
||||
$state=$db->query('select count(*) from metadata');
|
||||
$row=$state->fetchAll();
|
||||
$sum=$row[0]['count'];
|
||||
$select=$db->select();
|
||||
$select->from('metadata','*')->order('title')->limitPage($page,$limit);
|
||||
$this->view->metadata = $db->fetchAll($select);
|
||||
$this->view->page=new Pagination($sum,$page,$limit);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 产生geojson数据
|
||||
|
@ -136,14 +123,6 @@ class ServiceController extends Zend_Controller_Action
|
|||
}
|
||||
$this->_helper->json($geomd);
|
||||
}
|
||||
/*
|
||||
* 时空动态浏览
|
||||
*/
|
||||
function timemapAction()
|
||||
{
|
||||
$sql='select id,uuid,west,south,north,east,title,timebegin,timeend from metadata where timebegin is not null';
|
||||
$this->view->rows=$this->db->fetchAll($sql);
|
||||
}
|
||||
|
||||
function detailAction()
|
||||
{
|
||||
|
@ -243,187 +222,5 @@ class ServiceController extends Zend_Controller_Action
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* parse the wiki syntax used to render tables, code modified from mediawiki
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function parseTable ( $text ) {
|
||||
$lines = explode ( "\n" , $text );
|
||||
$td_history = array (); // Is currently a td tag open?
|
||||
$last_tag_history = array (); // Save history of last lag activated (td, th or caption)
|
||||
$tr_history = array (); // Is currently a tr tag open?
|
||||
$tr_attributes = array (); // history of tr attributes
|
||||
$has_opened_tr = array(); // Did this table open a <tr> element?
|
||||
$indent_level = 0; // indent level of the table
|
||||
foreach ( $lines as $key => $line )
|
||||
{
|
||||
$line = trim ( $line );
|
||||
|
||||
if( $line == '' ) { // empty line, go to next line
|
||||
continue;
|
||||
}
|
||||
$first_character = $line{0};
|
||||
$matches = array();
|
||||
|
||||
if ( preg_match( '/^(:*)\{\|(.*)$/' , $line , $matches ) ) {
|
||||
// First check if we are starting a new table
|
||||
$indent_level = strlen( $matches[1] );
|
||||
|
||||
$lines[$key] = str_repeat( '<dl><dd>' , $indent_level ) . "<table{$attributes}>";
|
||||
array_push ( $td_history , false );
|
||||
array_push ( $last_tag_history , '' );
|
||||
array_push ( $tr_history , false );
|
||||
array_push ( $tr_attributes , '' );
|
||||
array_push ( $has_opened_tr , false );
|
||||
} else if ( count ( $td_history ) == 0 ) {
|
||||
// Don't do any of the following
|
||||
continue;
|
||||
} else if ( substr ( $line , 0 , 2 ) == '|}' ) {
|
||||
// We are ending a table
|
||||
$line = '</table>' . substr ( $line , 2 );
|
||||
$last_tag = array_pop ( $last_tag_history );
|
||||
|
||||
if ( !array_pop ( $has_opened_tr ) ) {
|
||||
$line = "<tr><td></td></tr>{$line}";
|
||||
}
|
||||
|
||||
if ( array_pop ( $tr_history ) ) {
|
||||
$line = "</tr>{$line}";
|
||||
}
|
||||
|
||||
if ( array_pop ( $td_history ) ) {
|
||||
$line = "</{$last_tag}>{$line}";
|
||||
}
|
||||
array_pop ( $tr_attributes );
|
||||
$lines[$key] = $line . str_repeat( '</dd></dl>' , $indent_level );
|
||||
} else if ( substr ( $line , 0 , 2 ) == '|-' ) {
|
||||
// Now we have a table row
|
||||
$line = preg_replace( '#^\|-+#', '', $line );
|
||||
|
||||
$line = '';
|
||||
$last_tag = array_pop ( $last_tag_history );
|
||||
array_pop ( $has_opened_tr );
|
||||
array_push ( $has_opened_tr , true );
|
||||
|
||||
if ( array_pop ( $tr_history ) ) {
|
||||
$line = '</tr>';
|
||||
}
|
||||
|
||||
if ( array_pop ( $td_history ) ) {
|
||||
$line = "</{$last_tag}>{$line}";
|
||||
}
|
||||
|
||||
$lines[$key] = $line;
|
||||
array_push ( $tr_history , false );
|
||||
array_push ( $td_history , false );
|
||||
array_push ( $last_tag_history , '' );
|
||||
}
|
||||
else if ( $first_character == '|' || $first_character == '!' || substr ( $line , 0 , 2 ) == '|+' ) {
|
||||
// This might be cell elements, td, th or captions
|
||||
if ( substr ( $line , 0 , 2 ) == '|+' ) {
|
||||
$first_character = '+';
|
||||
$line = substr ( $line , 1 );
|
||||
}
|
||||
|
||||
$line = substr ( $line , 1 );
|
||||
|
||||
if ( $first_character == '!' ) {
|
||||
$line = str_replace ( '!!' , '||' , $line );
|
||||
}
|
||||
|
||||
// Split up multiple cells on the same line.
|
||||
// FIXME : This can result in improper nesting of tags processed
|
||||
// by earlier parser steps, but should avoid splitting up eg
|
||||
// attribute values containing literal "||".
|
||||
$cells = explode( '||' , $line );
|
||||
|
||||
$lines[$key] = '';
|
||||
|
||||
// Loop through each table cell
|
||||
foreach ( $cells as $cell )
|
||||
{
|
||||
$previous = '';
|
||||
if ( $first_character != '+' )
|
||||
{
|
||||
$tr_after = array_pop ( $tr_attributes );
|
||||
if ( !array_pop ( $tr_history ) ) {
|
||||
$previous = "<tr{$tr_after}>\n";
|
||||
}
|
||||
array_push ( $tr_history , true );
|
||||
array_push ( $tr_attributes , '' );
|
||||
array_pop ( $has_opened_tr );
|
||||
array_push ( $has_opened_tr , true );
|
||||
}
|
||||
|
||||
$last_tag = array_pop ( $last_tag_history );
|
||||
|
||||
if ( array_pop ( $td_history ) ) {
|
||||
$previous = "</{$last_tag}>{$previous}";
|
||||
}
|
||||
|
||||
if ( $first_character == '|' ) {
|
||||
$last_tag = 'td';
|
||||
} else if ( $first_character == '!' ) {
|
||||
$last_tag = 'th';
|
||||
} else if ( $first_character == '+' ) {
|
||||
$last_tag = 'caption';
|
||||
} else {
|
||||
$last_tag = '';
|
||||
}
|
||||
|
||||
array_push ( $last_tag_history , $last_tag );
|
||||
|
||||
// A cell could contain both parameters and data
|
||||
$cell_data = explode ( '|' , $cell , 2 );
|
||||
|
||||
// Bug 553: Note that a '|' inside an invalid link should not
|
||||
// be mistaken as delimiting cell parameters
|
||||
if ( strpos( $cell_data[0], '[[' ) !== false ) {
|
||||
$cell = "{$previous}<{$last_tag}>{$cell}";
|
||||
} else if ( count ( $cell_data ) == 1 )
|
||||
$cell = "{$previous}<{$last_tag}>{$cell_data[0]}";
|
||||
else {
|
||||
$cell = "{$previous}<{$last_tag}>{$cell_data[1]}";
|
||||
}
|
||||
|
||||
$lines[$key] .= $cell;
|
||||
array_push ( $td_history , true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Closing open td, tr && table
|
||||
while ( count ( $td_history ) > 0 )
|
||||
{
|
||||
if ( array_pop ( $td_history ) ) {
|
||||
$lines[] = '</td>' ;
|
||||
}
|
||||
if ( array_pop ( $tr_history ) ) {
|
||||
$lines[] = '</tr>' ;
|
||||
}
|
||||
if ( !array_pop ( $has_opened_tr ) ) {
|
||||
$lines[] = "<tr><td></td></tr>" ;
|
||||
}
|
||||
|
||||
$lines[] = '</table>' ;
|
||||
}
|
||||
|
||||
$output = implode ( "\n" , $lines ) ;
|
||||
|
||||
//@todo:移除<table></table>中所有的换行符
|
||||
//可能存在问题
|
||||
$output=preg_replace('/([a-zA-Z])>\n/m','$1>',$output);
|
||||
$output=preg_replace('/\n<\//m','</',$output);
|
||||
|
||||
// special case: don't return empty table
|
||||
if( $output == "<table>\n<tr><td></td></tr>\n</table>" ) {
|
||||
$output = '';
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue