<% // **** Your dBlog API function **** // function dBlog_build_Full_Url(strPage) 'DBLOG OK dBlog_build_Full_Url=Path_DirPublic & strPage end function function dBlog_build_Full_Url_HTTP(strPage) 'DBLOG OK dBlog_build_Full_Url_HTTP="http://" & Request.ServerVariables("HTTP_HOST") & Path_DirPublic & strPage end function function dBlog_Permalink(postID) 'DBLOG OK dBlog_Permalink="http://" & Request.ServerVariables("HTTP_HOST") & "/dblog/articolo.asp?articolo=" & strPage end function function dBlog_PostIdToFileName(postID) 'DBLOG OK NomeFile = cStr(postID) If Len(NomeFile) < 6 Then For I = 1 To 6 - Len(NomeFile) NomeFile = "0" & NomeFile Next End If dBlog_PostIdToFileName = NomeFile & ".txt" end function function dBlog_newPostToFile(strContent,idPost)'OK dBlog_getPostFromFile=FileToVar(Path_DirPublic & FNomeFileTXT, 0) end function function dBlog_getPostFromFile(FNomeFileTXT)'OK dBlog_getPostFromFile=FileToVar(Path_DirPublic & FNomeFileTXT, 0) end function function dBlog_login(FUserID, FPassword) 'DBLOG OK Dim SQLAutori, RSAutori If FUserID <> "" AND FPassword <> "" Then SQLAutori = " SELECT [Nick], [UserID], [Password], [Admin] FROM [Autori] WHERE [UserID] = '"& ControlloSQLInjection(FUserID) &"' " Set RSAutori = Server.CreateObject("ADODB.Recordset") RSAutori.Open SQLAutori, Conn, 1, 3 If NOT RSAutori.EOF Then RSAutori.MoveFirst If RSAutori("Password") = getSHAPassword(FPassword) Then Session("BLOGNick") = RSAutori("Nick") Session.TimeOut = 60 dBlog_login= true Else dBlog_login= false End If Else dBlog_login= false End If Else dBlog_login= false End If Set RSAutori = Nothing IF not dBlog_login= true THEN writeFaultXML 1, "invalid login", "dBlog_login" end if end function function dBlog_DeletePost(FID) 'OK Dim SQLArticolo, RSArticolo, SQLCommenti, RSCommenti, SQLSezioneArticoli, RSSezioneArticoli, FilSezioneArticoli, SezioneArticoli, NomeFile, FSO SQLArticolo = " DELETE * FROM Articoli WHERE ID = "& cInt(FID) &"" Set RSArticolo = Server.CreateObject("ADODB.Recordset") RSArticolo.Open SQLArticolo, Conn, 3, 3 Set RSArticolo = Nothing SQLCommenti = " DELETE * FROM Commenti WHERE IDArticolo = "& cInt(FID) &" " Set RSCommenti = Server.CreateObject("ADODB.Recordset") RSCommenti.Open SQLCommenti, Conn, 3, 3 Set RSCommenti = Nothing NomeFile = dBlog_PostIdToFileName(FID) Set FSO = CreateObject("Scripting.FileSystemObject") If FSO.FileExists(Server.MapPath(Path_DirPublic & NomeFile)) Then FSO.DeleteFile(Server.MapPath(Path_DirPublic & NomeFile)) End If Set FSO = Nothing end function Function dBlog_EditPost(postid, user, strCategory, strTitle,strText,publish) 'DBLOG OK FNomeFileTXT = dBlog_PostIdToFileName(postid) 'FTesto = SostituisciCaratteri(strText, "Si") FTesto = strText if (IsArray(strCategory)) then FSezione = DecodeEntities(SostituisciCaratteri(DoppioApice(cstr(strCategory(0))), "No")) else Fsezione=strCategory end if FAutore=user FTitolo = DecodeEntities(SostituisciCaratteri(DoppioApice(strTitle), "No")) FPodcast = "" FBozza = not publish Errore = False If FTesto = "" Then Errore = True End If If FSezione = "" Then Err.Raise -34,"dBlog_EditPost", "categoria non valida" Errore = True End If If Errore = False Then SQLModifica = " UPDATE [Articoli] SET Articoli.Sezione = '"& FSezione &"', Articoli.Autore = '"& FAutore &"', Articoli.Titolo = '"& FTitolo &"', " If FBozza = "si" Then SQLModifica = SQLModifica & "Articoli.Bozza = True " Else SQLModifica = SQLModifica & "Articoli.Bozza = False " End If SQLModifica = SQLModifica & "WHERE Articoli.ID = "& postid &" " If Session("BLOGAdmin") = False Then SQLModifica = SQLModifica & "AND Articoli.Autore = '"& Session("BLOGNick") &"' " End If Set RSModifica = Server.CreateObject("ADODB.Recordset") RSModifica.Open SQLModifica, Conn, 1, 3 Set RSModifica = Nothing Set FilContenutoArticolo = CreateObject("Scripting.FileSystemObject") Set ContenutoArticolo = FilContenutoArticolo.GetFile(Server.MapPath(Path_DirPublic & FNomeFileTXT)) Set ContenutoArticoloTemp = ContenutoArticolo.OpenAsTextStream(2, 0) ContenutoArticoloTemp.Write FTesto ContenutoArticoloTemp.Close Set ContenutoArticolo = Nothing Set ContenutoArticoloTemp = Nothing else Err.Raise -34,"dBlog_EditPost" end if dBlog_EditPost=not Errore End Function Function dBlog_AddPost(user, strCategory, strTitle,strText,publish)'DBLOG OK 'FTesto = SostituisciCaratteri(strText, "Si") FTesto = strText if IsArray(strCategory) then FSezione = DecodeEntities(SostituisciCaratteri(DoppioApice(strCategory(0)), "No")) else FSezione = DecodeEntities(SostituisciCaratteri(DoppioApice(strCategory), "No")) end if FAutore = user 'Session("BLOGNick") FTitolo = DecodeEntities(SostituisciCaratteri(DoppioApice(strTitle), "No")) FPodcast = "" 'DoppioApice(Request.Form("NomeFile")) FData = DataToStr(date) FOra = OraToStr(Time) FLetture = 0 FBozza = not publish Errore = False If FTesto = "" Then Err.Raise -34,"dBlog_AddPost", "testo non valida" Errore = True End If If FSezione = "" Then Err.Raise -34,"dBlog_AddPost", "categoria non valida" Errore = True End If If FData = "" OR Len(FData) <> 8 OR IsNumeric(FData) = False OR IsDate(StrToData(FData)) = False Then Err.Raise -34,"dBlog_AddPost", "Data non valida" Errore = True End If If FOra = "" OR Len(FOra) <> 6 OR IsNumeric(FOra) = False Then Err.Raise "Ora non valida" Errore = True End If If FLetture = "" OR IsNumeric(FLetture) = False Then Err.Raise -34,"dBlog_AddPost", "num Letture non valide" Errore = True End If If Errore = False Then SQLAggiungi = " INSERT INTO [Articoli] ([Sezione], [Autore], [Titolo], [Podcast], [Data], [Ora], [Letture], [Bozza]) VALUES ('" & FSezione & "', '" & FAutore & "', '" & FTitolo & "', '" & FPodcast & "', '" & FData & "', '" & FOra & "', '" & FLetture & "', " If FBozza = "si" or FBozza=true or lcase(FBozza)="true" Then SQLAggiungi = SQLAggiungi & vbTrue & ") " Else SQLAggiungi = SQLAggiungi & vbFalse & ") " End If Set RSAggiungi = Server.CreateObject("ADODB.Recordset") RSAggiungi.Open SQLAggiungi, Conn, 1, 3 Set RSAggiungi = Nothing SQLCercaID = " SELECT TOP 1 [ID] FROM [Articoli] ORDER BY [ID] DESC " Set RSCercaID = Server.CreateObject("ADODB.Recordset") RSCercaID.Open SQLCercaID, Conn, 1, 3 RSCercaID.MoveFirst NomeFileTXT = cStr(RSCercaID("ID")) dBlog_AddPost = NomeFileTXT NomeFileTXT=dBlog_PostIdToFileName(NomeFileTXT) SQLNomeFileTXT = " UPDATE [Articoli] SET [Testo] = '"& NomeFileTXT &"' WHERE [ID] = "& RSCercaID("ID") &" " Set RSNomeFileTXT = Server.CreateObject("ADODB.Recordset") RSNomeFileTXT.Open SQLNomeFileTXT, Conn, 1, 3 Set RSCercaID = Nothing Set RSNomeFileTXT = Nothing Set FilStuff = CreateObject("Scripting.FileSystemObject") Set Stuff = FilStuff.CreateTextFile(Server.MapPath(Path_DirPublic & NomeFileTXT), True) Stuff.Write FTesto Set Stuff = Nothing Set FilStuff = Nothing else Err.Raise -34,"dBlog_AddPost" end if End Function ' MakePath --> http://cwashington.netreach.net/depo/view.asp?Index=1027 ' Arguments: ' oFso - Instance of FileSystemObject ' sPath - Required path (must be fully qualified) ' Returns: ' True - Path now exists ' False - Path does not exist Function MakePath(oFso, sPath) ' Default result MakePath = False ' Fail if drive is not valid If Not oFso.DriveExists(oFso.GetDriveName(sPath)) Then Exit Function ' Succeed if folder exists If oFso.FolderExists(sPath) Then MakePath = True Exit Function End if ' Call self to ensure parent path exists If Not MakePath(oFso, oFso.GetParentFolderName(sPath)) Then Exit function ' Create folder On Error Resume next oFso.CreateFolder sPath MakePath = oFso.FolderExists(sPath) End function // **** MetaWeblog API **** // ' specification --> http://www.xmlrpc.com/metaWeblogApi ' *** Methods *** ' These are the available methods: ' metaWeblog.newPost (blogid, username, password, struct, publish) returns string OK 'metaWeblog.editPost (postid, username, password, struct, publish) returns true OK 'metaWeblog.getPost (postid, username, password) returns struct OK 'metaWeblog.deletePost (appkey, postid, username, password, publish) returns boolean OK 'metaWeblog.getCategories (blogid, username, password) returns struct OK 'metaWeblog.getRecentPosts (blogid, username, password, numberOfPosts) returns array of structs OK 'metaWeblog.newMediaObject (blogid, username, password, struct) returns struct OK 'metaWeblog.getTemplate (appkey, blogid, username, password, templateType) returns string -------------------------TODO 'metaWeblog.setTemplate (appkey, blogid, username, password, template, templateType) returns boolean -----------TODO function metaWeblog_newMediaObject(blogid, username, password, data) 'DBLOG OK on error resume next if dBlog_login(username, password) = true then strName=data("name") strType=data("type") Dim oFS, oFile Dim nIndex Set oFS = Server.CreateObject("Scripting.FileSystemObject") '**** MS Windows Live Writer PAtch **************** ' MS Windows Live Writer non rispetta le specifiche... infatti invece di passare SOLO il nome del file ' passa una path relativa tipo: ' \WindowsLiveWriter\testnewmedia_1039B\img.jpeg dim NewFolder NewFolder = oFS.GetParentFolderName(Server.MapPath(Path_DirPublic & strName)) If not MakePath(oFS, NewFolder) Then Err.Raise -34,"metaWeblog_newMediaObject", "Unable to create file" end if '************************************* Set oFile = oFS.CreateTextFile(Server.MapPath(Path_DirPublic & strName), True) oFile.Write data("bits") oFile.Close Set objReturn = Server.CreateObject("Scripting.Dictionary") objReturn.add "url", dBlog_build_Full_Url_HTTP(strName) catchError "metaWeblog_newMediaObject - " & NewFolder if err.number=0 then set metaWeblog_newMediaObject=objReturn end if end if end function function metaWeblog_deletePost (blogid, postid, username, password, publish) 'DBLOG OK on error resume next if dBlog_login(username, password) = true then '*** blog implementation **************************** metaWeblog_deletePost = dBlog_DeletePost(postid) '************************************************* catchError "metaWeblog_deletePost" if err.number=0 then metaWeblog_deletePost=true end if end if end function function metaWeblog_newPost (blogid, username, password, postContent ,publish) 'DBLOG OK on error resume next if dBlog_login(username, password) = true then strTitle=postContent("title") strText=postContent("description") strCategory=postContent("categories") '*** blog implementation **************************** metaWeblog_newPost = dBlog_AddPost(username, strCategory, strTitle, strText, publish) '************************************************* catchError "metaWeblog_newPost" end if end function function metaWeblog_editPost (postid, username, password, postContent ,publish) 'DBLOG TODO 'on error resume next if dBlog_login(username, password) = true then strTitle=postContent("title") strText=postContent("description") strCategory=postContent("categories") '*** blog implementation **************************** metaWeblog_editPost = dBlog_editPost(postid, username, strCategory, strTitle, strText, publish) '************************************************* catchError "metaWeblog_editPost" end if end function function metaWeblog_getRecentPosts (blogid, username, password, numberOfPosts) 'DBLOG OK 'on error resume next if dBlog_login(username, password) = true then Dim SQLArticoli, RSArticoli 'Effettuo la ricerca negli articoli per ID SQLArticoli = "SELECT TOP " & numberOfPosts & " Articoli.ID as postid, Articoli.Sezione as categories, Articoli.Titolo as title, cdate(format(Articoli.Data,""0000-00-00"") + format(Articoli.Ora,"" 00:00:00"")) as dateCreated, Articoli.Testo as description from articoli order by 4 desc" Set RSArticoli = Server.CreateObject("ADODB.Recordset") RSArticoli.Open SQLArticoli, Conn, adOpenStatic, 3 dim retArray() dim objItem If RSArticoli.Eof=True or RSArticoli.Bof=True then 'Response.Write "

Nessun risultato trovato

" Else redim retArray(RSArticoli.recordCount) 'redim retArray(numberOfPosts) For i=1 to RSArticoli.recordCount if Not RSArticoli.EOF then 'mostra record Set objItem = Server.CreateObject("Scripting.Dictionary") objItem.Add "categories", array(RSArticoli("categories").value) objItem.Add "dateCreated", RSArticoli("dateCreated").value objItem.Add "description", dBlog_getPostFromFile(RSArticoli("description").value) objItem.Add "link", dBlog_Permalink(RSArticoli("postid").value) objItem.Add "postid", RSArticoli("postid").value objItem.Add "title", RSArticoli("title").value set retArray(i)=objItem set objItem=nothing i=i+1 RSArticoli.MoveNext end if Next End if metaWeblog_getRecentPosts = retArray SET RSArticoli = Nothing end if catchError "metaWeblog_getRecentPosts" end function function metaWeblog_getPost (postid, username, password) 'DBLOG OK on error resume next if dBlog_login(username, password) = true then Dim SQLArticoli, RSArticoli Dim SQLCategorieArticoli, RSCategorieArticoli Set RSArticoli = Server.CreateObject("ADODB.Recordset") Set RSCategorieArticoli = Server.CreateObject("ADODB.Recordset") if dBlog_login(username, password) = true then '--- Effettuo la ricerca negli articoli per ID --- SQLArticoli = "SELECT Articoli.ID as postid, Articoli.Sezione as categories, Articoli.Titolo as title, cdate(format(Articoli.Data,""0000-00-00"") + format(Articoli.Ora,"" 00:00:00"")) as dateCreated, Articoli.Testo as description from articoli where Articoli.ID = " & postid RSArticoli.Open SQLArticoli, Conn, 1, 3 Set objReturn = Server.CreateObject("Scripting.Dictionary") If RSArticoli.Eof=True or RSArticoli.Bof=True then 'Response.Write "

Nessun risultato trovato

" Else '--- Effettuo la ricerca delle categorie degli articoli per ID articolo --- SQLCategorieArticoli = "SELECT distinct Articoli.Sezione as description,Articoli.Sezione as title,Articoli.Sezione as categoryid,'' as htmlUrl,'' as rssUrl from articoli where Articoli.ID = " & postid RSCategorieArticoli.Open SQLCategorieArticoli, Conn, 1, 3 'objReturn.Add "categories", RSCategorieArticoli objReturn.Add "categories", array(RSCategorieArticoli("description").value) objReturn.Add "dateCreated", RSArticoli("dateCreated").value objReturn.Add "description", dBlog_getPostFromFile(RSArticoli("description").value) objReturn.Add "link", dBlog_Permalink(RSArticoli("postid").value) objReturn.Add "postid", RSArticoli("postid").value objReturn.Add "title", RSArticoli("title").value end if SET metaWeblog_getPost = objReturn end if SET RSArticoli = Nothing Set RSCategorieArticoli = Nothing SET objReturn = Nothing end if catchError "metaWeblog_getPost" end function function metaWeblog_getCategories(blogid, username, password) 'DBLOG OK on error resume next if dBlog_login(username, password) then Dim SQLCategorieArticoli, RSCategorieArticoli Set RSCategorieArticoli = Server.CreateObject("ADODB.Recordset") 'Visualizzo le sezioni e gli articoli in esse contenuti SQLCategorieArticoli = " SELECT distinct Articoli.Sezione as description,Articoli.Sezione as title,Articoli.Sezione as categoryid,'' as htmlUrl,'' as rssUrl FROM Articoli" RSCategorieArticoli.Open SQLCategorieArticoli, Conn, 1, 3 SET metaWeblog_getCategories = RSCategorieArticoli SET RSCategorieArticoli = Nothing end if end function // **** Blogger API **** // ' *** Methods *** ' These are the available methods: ' blogger.newPost: Makes a new post to a designated blog. Optionally, will publish the blog after making the post. ' blogger.editPost: Edits a given post. Optionally, will publish the blog after making the edit. ' blogger.getUsersBlogs: Returns information on all the blogs a given user is a member of. ' blogger.getUserInfo: Authenticates a user and returns basic user info (name, email, userid, etc.). ' blogger.getTemplate: Returns the main or archive index template of a given blog. ' blogger.setTemplate: Edits the main or archive index template of a given blog. ' blogger.deletePost: Edits the main or archive index template of a given blog. ' http://xmlrpc.free-conversant.com/docs/bloggerAPI function blogger_getUsersBlogs (appkey, username, password) 'DBLOG OK on error resume next Dim SQLUsersBlogs, RSUsersBlogs if dBlog_login(username, password) = true then 'DUMMY SQL SQLUsersBlogs = "SELECT TOP 1 '" & DoppioApice(URL_Blog) & "' as url, 1 as blogid, '" & DoppioApice(Nome_Blog) & "' as blogName from articoli" 'SQLUsersBlogs = "SELECT TOP 1 'blogUrl' as url, 1 as blogid, 'blogName' as blogName from articoli" Set RSUsersBlogs = Server.CreateObject("ADODB.Recordset") RSUsersBlogs.Open SQLUsersBlogs, Conn, 1, 3 SET blogger_getUsersBlogs = RSUsersBlogs SET RSUsersBlogs = Nothing end if catchError "blogger_getUsersBlogs" end function function blogger_getUserInfo (appkey, username, password) 'TODO ERROR if dBlog_login(username, password) = true then dim objReturn 'Se è stato richiesto un autore specifico lo cerco nel database SQLAutori = " SELECT [Immagine], [Nick], [Mail], [Testo], [Sito], [ICQ], [MSN] FROM [Autori] WHERE Autori.UserID = '"& ControlloSQLInjection(username) &"' " Set RSAutori = Server.CreateObject("ADODB.Recordset") RSAutori.Open SQLAutori, Conn, 1, 3 Set objReturn = Server.CreateObject("Scripting.Dictionary") 'Debug.Print "method","blogger_getUserInfo" 'Debug.Print "SQLAutori", SQLAutori If RSAutori.Eof=True or RSAutori.Bof=True then Else objReturn.Add "nickname", RSAutori("Nick").value objReturn.Add "userid", username objReturn.Add "url", RSAutori("Sito").value objReturn.Add "email", RSAutori("Mail").value objReturn.Add "lastname", "" objReturn.Add "firstname", "" end if SET blogger_getUserInfo = objReturn SET objReturn = Nothing end if end function function blogger_newPost (appkey, blogid, username, password, content, publish)'TODO DIM lngID DIM strTitle // appkey (string): Unique identifier/passcode of the application sending the post. (See access info.) // blogid (string): Unique identifier of the blog the post will be added to. // username (string): Login for a Blogger user who has permission to post to the blog. // password (string): Password for said username. // content (string): Contents of the post. // publish (boolean): If true, the blog will be published immediately after the post is made. // Returns blog post id # lngID = 37 // Hard coded username and password look up for speed testing. // You may want to write a lookup function for this. // even if username and password is wrong I wanted this function // to exit normally thus the lngID=0 above. IF username = "username" AND password = "password" THEN strTitle = "My XMLRPC Post" ' BloggerAPI doesn't support title, metaWeblog API does lngID = AddPost(strTitle, content) ' Your own code to post to your database END IF blogger_newPost = lngID end function function blogger_editPost (appkey, blogid, username, password, content, publish) 'TODO DIM lngID DIM strTitle // appkey (string): Unique identifier/passcode of the application sending the post. (See access info.) // blogid (string): Unique identifier of the blog the post will be added to. // username (string): Login for a Blogger user who has permission to post to the blog. // password (string): Password for said username. // content (string): Contents of the post. // publish (boolean): If true, the blog will be published immediately after the post is made. // Returns true if no error otherwise err code // Hard coded username and password look up for speed testing. // You may want to write a lookup function for this. // even if username and password is wrong I wanted this function // to exit normally thus the lngID=0 above. IF username = "username" AND password = "password" THEN strTitle = "My XMLRPC Post" ' BloggerAPI doesn't support title, metaWeblog API does lngID = AddPost(strTitle, content) ' Your own code to post to your database END IF blogger_editPost = true end function function blogger_deletePost (appkey, postId,username, password,publish) 'TODO 'Parameters: ' * appkey : currently ignored ' * postId : postId is a unique identifier for the post created. It is the value returned by blogger.newPost. postId will look like..."zoneId|convId|pathToWeblog|msgNum". ' * username : the email address you use as a username for the site. This user must have privileges to post to the weblog as either the weblog owner, or a member of the owner group. ' * password : the password you use for the site ' * publish : true/false. Ignored. ' 'Returns: ' ' * true dBlog_DeletePost postId blogger_deletePost=true end function // Function Lookup Dictionary List call addServerFunction("blogger.getUsersBlogs","blogger_getUsersBlogs") 'OK call addServerFunction("blogger.getUserInfo","blogger_getUserInfo") call addServerFunction("blogger.deletePost","blogger_deletePost") call addServerFunction("metaWeblog.deletePost","metaWeblog_deletePost")'OK call addServerFunction("metaWeblog.newPost","metaWeblog_newPost") 'OK call addServerFunction("metaWeblog.editPost","metaWeblog_editPost")'TODO call addServerFunction("metaWeblog.getPost","metaWeblog_getPost")'OK call addServerFunction("metaWeblog.newMediaObject","metaWeblog_newMediaObject") 'TODO call addServerFunction("metaWeblog.getCategories","metaWeblog_getCategories")'OK call addServerFunction("metaWeblog.getRecentPosts","metaWeblog_getRecentPosts")'OK // Call the XMLRPC server (Located in xmlrpc.asp) rpcserver Conn.Close Set Conn = Nothing %>