めまぴークライアントのデモ10のソース
めまぴークライアントのデモ10の記事はこちらです。
■Application.cfm
<cfprocessingdirective pageEncoding = "UTF-8"> <cfsetting enableCFoutputOnly="yes"> <cfapplication name="#hash( getCurrentTemplatePath() )#" clientmanagement="Yes" sessionmanagement="yes" loginStorage="session" sessiontimeout=#CreateTimeSpan(1, 0, 0, 0)# > <!---=================================== 設定 ====================================---> <cfparam name="cookie.user_id" default=""> <cfparam name="cookie.key" default=""> <cfparam name="session.word" default=""> <cfparam name="session.chk1" default=""> <cfset request.user_id = cookie.user_id> <cfset request.key = cookie.key> <cfset request.word = session.word> <cfset request.chk1 = session.chk1> <cfset request.cat_id = 12> <!--- 通常 <cfset request.proxyServer = ""> <cfset request.proxyPort = "80"> ---> <!--- 会社 <cfset request.proxyServer = "xx.xx.xx.xx"> <cfset request.proxyPort = "xx"> ---> <cfset request.proxyServer = ""> <cfset request.proxyPort = "80"> <cfset request.url = "http://memapi.utalab.com/index.cfm?go="> <!---=============================== getBaseChars ================================---> <cffunction name="getBaseChars" access="public" returnType="array" output="no"> <cfset var baseList = "a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9"> <cfreturn ListToArray(baseList, " ") /> </cffunction> <!---========================================== thisURL 実行されたURL。ただしファイル名は削除。 例)http://hoge.com/ ===========================================---> <cffunction name="thisURL" access="public" returnType="string" output="no" hint="Webアプリの基本URLを取得(例)http://hoge.com/)"> <cfset var local = structNew()> <cfset local.server_name = cgi.server_name> <cfif cgi.server_port neq 80> <cfset local.server_name = local.server_name & ":" & cgi.server_port> </cfif> <cfset local.url = "#lcase(ListFirst(cgi.server_protocol,"/"))#://#local.server_name##cgi.script_name#"> <cfset local.url = ListDeleteAt(local.url, ListLen(local.url, "/"), "/") & "/"> <cfreturn local.url> </cffunction> <!---========================================== FormatBaseNData 参考:http://www.bennadel.com/index.cfm?dax=blog:1540.view ===========================================---> <cffunction name="FormatBaseNData" access="public" returntype="string" output="false"> <cfargument name="Value" type="numeric" required="true"> <cfargument name="CharacterSet" type="array" required="true"> <cfset var local = structNew()> <!--- Create the base string to be returned. ---> <cfset LOCAL.EncodedValue = "" /> <!--- Get the length of our array. This will be our radix for the conversion. NOTE: Because ColdFusion arrays start at 1, not zero, we will have to some manual offsetting when we perform the conversion. ---> <cfset LOCAL.Radix = ArrayLen( ARGUMENTS.CharacterSet ) /> <!--- Get a local copy of our value as we will be updating it as we divide into it. ---> <cfset LOCAL.Value = ARGUMENTS.Value /> <!--- When converting to a new radix, we need to keep dividing the value passed in until we hit zero (which will never have a remainder). However, because we always want to perform at least ONE division, we will break from within the loop if it hits zero rather than check for that loop conditional. ---> <cfloop condition="true"> <!--- Get the division result. ---> <cfset LOCAL.Result = Fix( LOCAL.Value / LOCAL.Radix ) /> <!--- Get the remainder of radix division. ---> <cfset LOCAL.Remainder = (LOCAL.Value MOD LOCAL.Radix) /> <!--- Take the remainder and prepend the Radix-converted string to the encoded value. Remember, since we are using arrays that start at 1, we need to add one to this value. ---> <cfset LOCAL.EncodedValue = ( ARGUMENTS.CharacterSet[ LOCAL.Remainder + 1 ] & LOCAL.EncodedValue ) /> <!--- Now that we have gotten the current, store the result value back into the value. ---> <cfset LOCAL.Value = LOCAL.Result /> <!--- Check to see if we have any more value to divide into. Once we hit zero, we are out of possible remainders. ---> <cfif NOT LOCAL.Value> <cfbreak /> </cfif> </cfloop> <!--- Return the encoded value. ---> <cfreturn LOCAL.EncodedValue /> </cffunction> <!---========================================== InputBaseNData 参考:http://www.bennadel.com/index.cfm?dax=blog:1540.view ===========================================---> <cffunction name="InputBaseNData" access="public" returntype="string" output="false"> <cfargument name="Value" type="string" required="true"> <cfargument name="CharacterSet" type="array" required="true"> <cfset var LOCAL = structNew() > <!--- Create the base number to be returned. ---> <cfset LOCAL.DecodedValue = 0 /> <!--- Get the length of our array. This will be our radix for the conversion. NOTE: Because ColdFusion arrays start at 1, not zero, we will have to some manual offsetting when we perform the conversion. ---> <cfset LOCAL.Radix = ArrayLen( ARGUMENTS.CharacterSet ) /> <!--- Convert our character set to a list so that we can easily get the numeric value of our encoded digit. ---> <cfset LOCAL.CharacterList = ArrayToList( ARGUMENTS.CharacterSet ) /> <!--- Reverse the string that was passed in. We are doing this because the right-most value is actually the smallest place and it will be easier for us to deal with in reverse. ---> <cfset LOCAL.Value = Reverse( ARGUMENTS.Value ) /> <!--- Now, break the value up into an array so that we can more easily iterate over it. ---> <cfset LOCAL.ValueArray = ListToArray( REReplace( LOCAL.Value, "(.)", "\1,", "all" ) ) /> <!--- Iterate over the array and convert each value to a power of our character set defined radix. ---> <cfloop index="LOCAL.Index" from="1" to="#ArrayLen( LOCAL.ValueArray )#" step="1"> <!--- Convert the current digit and add it to the going sum of our conversion. ---> <cfset LOCAL.DecodedValue = LOCAL.DecodedValue + ( (ListFind( LOCAL.CharacterList, LOCAL.ValueArray[ LOCAL.Index ] ) - 1) * (LOCAL.Radix ^ (LOCAL.Index - 1)) ) /> </cfloop> <!--- Return the decoded value. ---> <cfreturn LOCAL.DecodedValue /> </cffunction>
■index.cfm
<cfprocessingdirective pageEncoding = "UTF-8"> <!---///////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////---> <cfparam name="url.p" default=""> <cfparam name="url.page" default="1"> <cfparam name="form.word" default=""> <cfparam name="form.chk1" default="i1_desc"> <cfif url.p eq ""> <cfset url.p = cst_exec()> </cfif> <cfif url.p neq ""> <cfswitch expression = "#url.p#"> <!--- srch ---> <cfcase value="srch"> <cfset session.word = form.word> <cfset session.chk1 = form.chk1> <cfset request.word = form.word> <cfset request.chk1 = form.chk1> </cfcase> </cfswitch> <cfset st = cst_getData2(url.page)> <cfset cst_layout(st)> </cfif> <!---================================================================= cst_exec ==================================================================---> <cffunction name="cst_exec" access="public" returnType="string" output="no"> <cfset var local = structNew()> <cfset local.id = InputBaseNData( cgi.query_string, getBaseChars())> <cfset st = cst_getData(local.id)> <cfif st.data.recordCount neq 0> <!--- cnt+1 ---> <cfset cst_updData(local.id, st.data.i1)> <cflocation url="#st.data.m1#" addtoken="no"> <cfabort> <cfelse> <cfreturn "srch"> </cfif> <cfreturn ""> </cffunction> <!---================================================================= cst_getData ==================================================================---> <cffunction name="cst_getData" access="public" returnType="struct" output="no"> <cfargument name="id" type="string" required="yes"> <cfhttp url = "#request.url#dataGetEx" proxyServer = "#request.proxyServer#" proxyPort = "#request.proxyPort#" method="post"> <cfhttpparam type="formField" name="user_id" value="#request.user_id#"> <cfhttpparam type="formField" name="key" value="#request.key#"> <cfhttpparam type="formField" name="cat_id" value="#request.cat_id#"> <cfhttpparam type="formField" name="id" value="#arguments.id#"> <cfhttpparam type="formField" name="fld_list" value="id,cat_id,c1,m1,i1"> <cfhttpparam type="formField" name="row" value="10"> <cfhttpparam type="formField" name="page" value="1"> <cfhttpparam type="formField" name="type" value="wddx"> </cfhttp> <cfwddx action="wddx2cfml" input="#cfhttp.filecontent#" output="outData"> <cfreturn outdata> </cffunction> <!---================================================================= cst_getData2 ==================================================================---> <cffunction name="cst_getData2" access="public" returnType="struct" output="no"> <cfargument name="page" type="string" default="1"> <cfhttp url = "#request.url#dataGetEx" proxyServer = "#request.proxyServer#" proxyPort = "#request.proxyPort#" method="post"> <cfhttpparam type="formField" name="user_id" value="#request.user_id#"> <cfhttpparam type="formField" name="key" value="#request.key#"> <cfhttpparam type="formField" name="cat_id" value="#request.cat_id#"> <cfhttpparam type="formField" name="fil_id" value="#request.chk1#"> <cfhttpparam type="formField" name="fld_list" value="id,cat_id,c1,m1,i1"> <cfhttpparam type="formField" name="srch_fld" value="c1"> <cfhttpparam type="formField" name="word" value="#request.word#"> <cfhttpparam type="formField" name="row" value="10"> <cfhttpparam type="formField" name="page" value="#arguments.page#"> <cfhttpparam type="formField" name="type" value="wddx"> </cfhttp> <cfwddx action="wddx2cfml" input="#cfhttp.filecontent#" output="outData"> <cfreturn outdata> </cffunction> <!---================================================================= cst_updData ==================================================================---> <cffunction name="cst_updData" access="public" returnType="void" output="no"> <cfargument name="id" type="string" required="yes"> <cfargument name="i1" type="string" required="yes"> <cfset var cnt = arguments.i1 + 1> <cfhttp url = "#request.url#dataUpdEx" proxyServer = "#request.proxyServer#" proxyPort = "#request.proxyPort#" method="post"> <cfhttpparam type="formField" name="user_id" value="#request.user_id#"> <cfhttpparam type="formField" name="key" value="#request.key#"> <cfhttpparam type="formField" name="cat_id" value="#request.cat_id#"> <cfhttpparam type="formField" name="id" value="#arguments.id#"> <cfhttpparam type="formField" name="i1" value="#cnt#"> </cfhttp> </cffunction> <!---================================================================= cst_layout ==================================================================---> <cffunction name="cst_layout" access="public" returnType="void" output="yes"> <cfargument name="stru" type="struct" required="yes"> <cfset var st = arguments.stru> <cfoutput> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="content-style-type" content="text/css; charset=utf-8" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <title>めまぴークライアントのデモ(短縮URL)</title> <meta name="keywords" content="めまぴー,memapi" /> <meta name="description" content="めまぴークライアントのデモ(短縮URL)です。" /> <link href="common.css" rel="stylesheet" type="text/css" media="all" /> <script type="text/javascript" src="common.js"></script> <script type="text/javascript" src="index.js"></script> </head> <body> <!-- container --> <div id="container"> <!-- header --> <div id="header"> <!-- left --> <div class="left"> <h1><a href="index.cfm" accesskey="1">めまぴークライアントのデモ(短縮URL)</a></h1> <h2>by <a href="http://memapi.utalab.com/" target="_blank">めまぴー</a></h2> <!-- /.left --></div> <!-- right --> <div class="right"> <!-- /.right --></div> <!-- /##header --></div> <div class="clearblock"/> <!-- left --> <div id="left"> <!-- menu --> <div class="menu"> <p class="title">STATUS</p> <table> <tr> <th>ret</th> <td align="right" id="ret">#st.ret#</td> </tr> <tr> <th>pageCount</th> <td align="right" id="pageCount">#st.pageCount#</td> </tr> <tr> <th>recCount</th> <td align="right" id="recCount">#st.recCount#</td> </tr> </table> <!-- /.menu --></div> <!-- menu --> <div class="menu"> <p class="title">検索</p> <form name="frm_srch" action="index.cfm?p=srch" method="post"> <table> <tr> <td> <input type="text" name="word" id="word" value="#request.word#"><br> </td> </tr> <tr> <td> <select name="chk1"> <option value="c1" <cfif request.chk1 eq "c1">selected</cfif>>title(昇順)</option> <option value="c1_desc" <cfif request.chk1 eq "c1_desc">selected</cfif>>title(降順)</option> <option value="i1" <cfif request.chk1 eq "i1">selected</cfif>>cnt(昇順)</option> <option value="i1_desc" <cfif request.chk1 eq "i1_desc">selected</cfif>>cnt(降順)</option> </select> </td> </tr> <tr> <td> <input type="submit" value="検索"> </td> </tr> </table> </form> <!-- /.menu --></div> <!-- /##left --></div> <!-- center --> <div id="center"> <!-- content --> <div id="content"> <h3>短縮URL</h3> <table border="1" id="list"> <tr> <th>タイトル</th> <th width="1%">cnt</th> </tr> <cfloop query="st.data"> <tr> <td><a href="#thisURL()#?#FormatBaseNData( st.data.id, getBaseChars() )#" target="_blank">#st.data.c1#</a></td> <td align="right">#st.data.i1#</td> </tr> </cfloop> </table> page: <cfloop index="local.idx" from="1" to="#st.pageCount#"> <cfif local.idx eq url.page> <strong>#local.idx#</strong> <cfelse> <a href="index.cfm?page=#local.idx#">#local.idx#</a> </cfif> </cfloop> <!-- /##content --></div> <!-- /##center --></div> <div class="clearblock"/> <!-- footer --> <div id="footer"> <form name="frm_cookie"> <table border="0" width="100%"> <tr> <td>user_id:<input type="text" name="user_id" id="user_id" value="#request.user_id#"></td> <td>key:<input type="text" name="key" id="key" value="#request.key#"></td> <td> <input type="button" value="cookie change" onClick="js_cookie('index.cfm')"> <input type="button" value="cookie delete" onClick="js_cookie_del('index.cfm')"> </td> </tr> </table> </form> <!-- /##footer --></div> <!-- /##container --></div> </body> </html> </cfoutput> </cffunction>
■index_k.cfm
<cfprocessingdirective pageEncoding = "UTF-8"> <!---///////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////---> <cfparam name="url.p" default=""> <cfparam name="url.page" default="1"> <cfparam name="url.id" default=""> <cfparam name="form.id" default="#url.id#"> <cfparam name="form.c1" default=""> <cfparam name="form.m1" default=""> <cfswitch expression = "#url.p#"> <!--- srch ---> <cfcase value="srch"> <cfset session.word = form.word> <cfset session.chk1 = form.chk1> <cfset request.word = form.word> <cfset request.chk1 = form.chk1> </cfcase> <!--- addEnd ---> <cfcase value="addEnd"> <cfhttp url="#request.url#dataAddEx" proxyServer = "#request.proxyServer#" proxyPort = "#request.proxyPort#" method="post"> <cfhttpparam type="formField" name="user_id" value="#request.user_id#"> <cfhttpparam type="formField" name="key" value="#request.key#"> <cfhttpparam type="formField" name="cat_id" value="#request.cat_id#"> <cfhttpparam type="formField" name="c1" value="#form.c1#"> <cfhttpparam type="formField" name="m1" value="#form.m1#"> <cfhttpparam type="formField" name="i1" value="0"> </cfhttp> </cfcase> <!--- updEnd ---> <cfcase value="updEnd"> <cfhttp url="#request.url#dataUpdEx" proxyServer = "#request.proxyServer#" proxyPort = "#request.proxyPort#" method="post"> <cfhttpparam type="formField" name="user_id" value="#request.user_id#"> <cfhttpparam type="formField" name="key" value="#request.key#"> <cfhttpparam type="formField" name="cat_id" value="#request.cat_id#"> <cfhttpparam type="formField" name="id" value="#form.id#"> <cfhttpparam type="formField" name="c1" value="#form.c1#"> <cfhttpparam type="formField" name="m1" value="#form.m1#"> </cfhttp> </cfcase> <!--- delEnd ---> <cfcase value="delEnd"> <cfhttp url="#request.url#dataDelEx" proxyServer = "#request.proxyServer#" proxyPort = "#request.proxyPort#" method="post"> <cfhttpparam type="formField" name="user_id" value="#request.user_id#"> <cfhttpparam type="formField" name="key" value="#request.key#"> <cfhttpparam type="formField" name="cat_id" value="#request.cat_id#"> <cfhttpparam type="formField" name="id" value="#form.id#"> </cfhttp> </cfcase> </cfswitch> <cfif findnocase("end", url.p)> <cflocation url="index_k.cfm" addtoken="no"> </cfif> <cfset st = cst_getData("", url.page)> <cfif url.p eq "upd"> <cfset sttmp = cst_getData(form.id)> <cfset form.c1 = sttmp.data.c1> <cfset form.m1 = sttmp.data.m1> </cfif> <cfset fm = cst_fm()> <cfset cst_layout(st, fm)> <!---================================================================= cst_fm ==================================================================---> <cffunction name="cst_fm" access="public" returnType="string" output="yes"> <cfset var local = structNew()> <cfsavecontent variable = "local.tmp"> <cfoutput> <form name="frm_in" action="index_k.cfm?p=addEnd" method="post"> <input type="hidden" name="id" value="#form.id#"> <table> <tr> <th>タイトル</th> <td><input type="text" name="c1" size="70" value="#form.c1#"></td> </tr> <tr> <th>URL</th> <td> <textarea name="m1" cols="60" rows="3">#form.m1#</textarea> </td> </tr> </table> <cfif form.id eq ""> <input type="button" value="add" onClick="js_add()"> <cfelse> <input type="button" value="upd" onClick="js_upd()"> <input type="button" value="del" onClick="js_del()"> </cfif> </form> <script language="JavaScript"> <!-- function js_add(){ with(document.frm_in){ if(confirm("add OK?")){ action = "index_k.cfm?p=addEnd"; submit(); } } } function js_upd(){ with(document.frm_in){ if(confirm("upd OK?")){ action = "index_k.cfm?p=updEnd"; submit(); } } } function js_del(){ with(document.frm_in){ if(confirm("del OK?")){ action = "index_k.cfm?p=delEnd"; submit(); } } } //--> </script> </cfoutput> </cfsavecontent> <cfreturn local.tmp> </cffunction> <!---================================================================= cst_getData ==================================================================---> <cffunction name="cst_getData" access="public" returnType="struct" output="no"> <cfargument name="id" type="string" required="yes"> <cfargument name="page" type="string" default="1"> <cfhttp url = "#request.url#dataGetEx" proxyServer = "#request.proxyServer#" proxyPort = "#request.proxyPort#" method="post"> <cfhttpparam type="formField" name="user_id" value="#request.user_id#"> <cfhttpparam type="formField" name="key" value="#request.key#"> <cfhttpparam type="formField" name="cat_id" value="#request.cat_id#"> <cfhttpparam type="formField" name="id" value="#arguments.id#"> <cfhttpparam type="formField" name="fil_id" value="#request.chk1#"> <cfhttpparam type="formField" name="fld_list" value="id,cat_id,c1,m1,i1"> <cfhttpparam type="formField" name="srch_fld" value="c1"> <cfhttpparam type="formField" name="word" value="#request.word#"> <cfhttpparam type="formField" name="row" value="10"> <cfhttpparam type="formField" name="page" value="#arguments.page#"> <cfhttpparam type="formField" name="type" value="wddx"> </cfhttp> <cfwddx action="wddx2cfml" input="#cfhttp.filecontent#" output="outData"> <cfreturn outdata> </cffunction> <!---================================================================= cst_layout ==================================================================---> <cffunction name="cst_layout" access="public" returnType="void" output="yes"> <cfargument name="stru" type="struct" required="yes"> <cfargument name="fm" type="string" required="yes"> <cfset var st = arguments.stru> <cfoutput> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="content-style-type" content="text/css; charset=utf-8" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <title>めまぴークライアントのデモ(短縮URL)</title> <meta name="keywords" content="めまぴー,memapi" /> <meta name="description" content="めまぴークライアントのデモ(短縮URL)です。" /> <link href="common.css" rel="stylesheet" type="text/css" media="all" /> <script type="text/javascript" src="common.js"></script> <script type="text/javascript" src="index.js"></script> </head> <body> <!-- container --> <div id="container"> <!-- header --> <div id="header"> <!-- left --> <div class="left"> <h1><a href="index_k.cfm" accesskey="1">めまぴークライアントのデモ(短縮URL)</a></h1> <h2>by <a href="http://memapi.utalab.com/" target="_blank">めまぴー</a></h2> <!-- /.left --></div> <!-- right --> <div class="right"> <!-- /.right --></div> <!-- /##header --></div> <div class="clearblock"/> <!-- left --> <div id="left"> <!-- menu --> <div class="menu"> <p class="title">STATUS</p> <table> <tr> <th>ret</th> <td align="right" id="ret">#st.ret#</td> </tr> <tr> <th>pageCount</th> <td align="right" id="pageCount">#st.pageCount#</td> </tr> <tr> <th>recCount</th> <td align="right" id="recCount">#st.recCount#</td> </tr> </table> <!-- /.menu --></div> <!-- menu --> <div class="menu"> <p class="title">検索</p> <form name="frm_srch" action="index_k.cfm?p=srch" method="post"> <table> <tr> <td> <input type="text" name="word" id="word" value="#request.word#"><br> </td> </tr> <tr> <td> <select name="chk1"> <option value="c1" <cfif request.chk1 eq "c1">selected</cfif>>title(昇順)</option> <option value="c1_desc" <cfif request.chk1 eq "c1_desc">selected</cfif>>title(降順)</option> <option value="i1" <cfif request.chk1 eq "i1">selected</cfif>>cnt(昇順)</option> <option value="i1_desc" <cfif request.chk1 eq "i1_desc">selected</cfif>>cnt(降順)</option> </select> </td> </tr> <tr> <td> <input type="submit" value="検索"> </td> </tr> </table> </form> <!-- /.menu --></div> <!-- /##left --></div> <!-- center --> <div id="center"> <!-- content --> <div id="content"> <h3>短縮URL</h3> #arguments.fm# <br> <br> <table border="1" id="list"> <tr> <th>タイトル</th> <th>短縮URL</th> <th>cnt</th> </tr> <cfloop query="st.data"> <tr> <td><a href="index_k.cfm?p=upd&id=#st.data.id#">#st.data.c1#</a></td> <td>#thisURL()#?#FormatBaseNData( st.data.id, getBaseChars() )#</td> <td align="right">#st.data.i1#</td> </tr> </cfloop> </table> page: <cfloop index="local.idx" from="1" to="#st.pageCount#"> <cfif local.idx eq url.page> <strong>#local.idx#</strong> <cfelse> <a href="index_k.cfm?page=#local.idx#">#local.idx#</a> </cfif> </cfloop> <!-- /##content --></div> <!-- /##center --></div> <div class="clearblock"/> <!-- footer --> <div id="footer"> <form name="frm_cookie"> <table border="0" width="100%"> <tr> <td>user_id:<input type="text" name="user_id" id="user_id" value="#request.user_id#"></td> <td>key:<input type="text" name="key" id="key" value="#request.key#"></td> <td> <input type="button" value="cookie change" onClick="js_cookie('index_k.cfm')"> <input type="button" value="cookie delete" onClick="js_cookie_del('index_k.cfm')"> </td> </tr> </table> </form> <!-- /##footer --></div> <!-- /##container --></div> </body> </html> </cfoutput> </cffunction>