view.cfm: предпросмотр первых 15 строк документа (v1.0.69)
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<cfsetting showdebugoutput="no" enablecfoutputonly="true">
|
||||
<cfheader name="Content-Type" value="text/plain; charset=utf-8">
|
||||
|
||||
<cfparam name="url.doc_id" default="">
|
||||
|
||||
<cftry>
|
||||
<cfif NOT len(url.doc_id)>
|
||||
<cfoutput>doc_id required</cfoutput><cfabort>
|
||||
</cfif>
|
||||
|
||||
<cfquery name="doc" datasource="baza">
|
||||
SELECT filename, elements_json FROM documents WHERE id = <cfqueryparam value="#url.doc_id#" cfsqltype="cf_sql_varchar">
|
||||
</cfquery>
|
||||
|
||||
<cfif doc.recordCount EQ 0>
|
||||
<cfoutput>not found</cfoutput><cfabort>
|
||||
</cfif>
|
||||
|
||||
<cfset elements = deserializeJSON(doc.elements_json)>
|
||||
<cfset count = 0>
|
||||
<cfset outLines = []>
|
||||
<cfset arrayAppend(outLines, "=== " & doc.filename & " ===")>
|
||||
<cfset arrayAppend(outLines, "")>
|
||||
|
||||
<cfloop array="#elements#" index="el">
|
||||
<cfif count GTE 15><cfbreak></cfif>
|
||||
<cfif el.type EQ "paragraph">
|
||||
<cfset prefix = len(el.style) ? "[#el.style#] " : "">
|
||||
<cfset arrayAppend(outLines, prefix & el.text)>
|
||||
<cfset count++>
|
||||
<cfelseif el.type EQ "table">
|
||||
<cfset arrayAppend(outLines, "")>
|
||||
<cfset rows = el.rows>
|
||||
<cfset shown = 0>
|
||||
<cfloop array="#rows#" index="row">
|
||||
<cfif shown GTE 5><cfbreak></cfif>
|
||||
<cfset cells = []>
|
||||
<cfloop array="#row#" index="cell">
|
||||
<cfset arrayAppend(cells, replace(replace(toString(cell), chr(10), " ", "ALL"), "|", "\|", "ALL"))>
|
||||
</cfloop>
|
||||
<cfset arrayAppend(outLines, "| " & arrayToList(cells, " | ") & " |")>
|
||||
<cfset shown++>
|
||||
</cfloop>
|
||||
<cfif arrayLen(rows) GT 5>
|
||||
<cfset arrayAppend(outLines, "... (" & (arrayLen(rows) - 5) & " more rows)")>
|
||||
</cfif>
|
||||
<cfset arrayAppend(outLines, "")>
|
||||
<cfset count++>
|
||||
</cfif>
|
||||
</cfloop>
|
||||
|
||||
<cfif count EQ 0>
|
||||
<cfset arrayAppend(outLines, "(пустой документ)")>
|
||||
</cfif>
|
||||
|
||||
<cfoutput>#arrayToList(outLines, chr(10))#</cfoutput>
|
||||
|
||||
<cfcatch>
|
||||
<cfoutput>Error: #cfcatch.message#</cfoutput>
|
||||
</cfcatch>
|
||||
</cftry>
|
||||
Reference in New Issue
Block a user