Hi Zans,
Cut and past into a tiddler and tag with systemConfig, reload.
Becareful with the linebreaks that are inserted by Google.
The produced tiddlers look funney because they lack the css, but it
should give you an idea how it works.
/***
|''Name:''|fileLinkerPlugin|
|''Version:''|2010-09-10 |
|''Type:''|plugin|
|''Author:''|Okido|
|''Documentation:''|Not yet, see comments in the code|
|''~SourceCode:''|All materials are presented on an "as-is" basis and
are subject to change without notice. The author of this document
makes no claims regarding the suitability or reliability of the
information presented, and assumes no liability for any damages that
may occur as a result of its use. |
|''Licence:''|Creative Commons Attribution-NonCommercial-ShareAlike
3.0 |
|''~CoreVersion:''|2.6.0|
|''Browser:''|Firefox 3.5 or better|
|''Credits:''|Kudos to Eric Shulman for the code I could use from his
showlocaldir plugin |
***/
/***
!Version History
* This is still the beta bersion
* It links files names to tiddlers and generates a tiddler with
content tags etc.
* Todo: replace the hard coded items
* Include <<autoLinker>> in the in the sidebaroptions to start the
plugin
* no release yet, becareful update important data before trying this
code
* Cut and past the code into a tiddler and tag it with systemConfig
* Press <<autoLinker>> to start the process
***/
//{{{
config.macros.autoLinker={};
config.macros.autoLinker.handler=
function(place,macroName,params,wikifier,paramString,tiddler)
{ var label = params[0]||"Update Files Linker";
var tooltip = params[1]||"You are starting a query!!!";
createTiddlyButton(place,label,tooltip,this.onclick); }
config.macros.autoLinker.onclick= function() {
var path = []; var fout = ''; var tot = 0; var user_name =
'Yourname'; var line=[]; var file_list=[]; var all=[]; var
file_paths='';
var tagslist = 'newdocs docs'; // tags that are added to tiddler
path[0] = 'backup'; path[1]= 'docs' ; path[2]= 'test'; path[3]=
'test/doccer/'; // directory names in tis example 4
window.getCurrentFolder=function() {
var h=document.location.href;
return
getLocalPath(decodeURIComponent(h.substr(0,h.lastIndexOf("/")+1)));
}
window.getParentFolder=function(cwd) {
var lastchar=cwd.substr(cwd.length-1,1);
if (lastchar=="/" || lastchar=="\\") cwd=cwd.substr(0,cwd.length-1);
var pos=cwd.lastIndexOf("/"); if (pos==-1) pos=cwd.lastIndexOf("\
\");
return pos!=-1?cwd.substr(0,pos+1):null;
}
window.getFileList=function(cwd) { // returns array of file info
(path,name,size,isFolder,url,modified)
var files=[];
if (config.browser.isIE) {
cwd=cwd.replace(/\//g,"\\");
var fso = new ActiveXObject("Scripting.FileSystemObject");
if(!fso.FolderExists(cwd)) return [];
var dir=fso.GetFolder(cwd);
for(var f=new Enumerator(dir.SubFolders); !f.atEnd(); f.moveNext())
files.push({ path:f.item().path, name:f.item().name,
size:f.item().size,
url:"file:///"+f.item().path.replace(/\\/g,"/"),
isFolder:fso.FolderExists(f.item().path),
modified:new Date(f.item().DateLastModified).formatString("YYYY.
0MM.0DD 0hh:0mm:0ss")});
for(var f=new Enumerator(dir.Files); !f.atEnd(); f.moveNext())
files.push({ path:f.item().path, name:f.item().name,
size:f.item().size,
url:"file:///"+f.item().path.replace(/\\/g,"/"),
isFolder:fso.FolderExists(f.item().path),
modified:new Date(f.item().DateLastModified).formatString("YYYY.
0MM.0DD 0hh:0mm:0ss")});
} else { // FF
if(!window.Components) return;
try
{ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); }
catch(e) { alert(e.description?e.description:e.toString()); return
null; }
var file=Components.classes["@
mozilla.org/file/local;
1"].createInstance(Components.interfaces.nsILocalFile);
try { file.initWithPath(cwd); } catch(e) { return []; }
if (!file.exists() || !file.isDirectory()) { return []; }
var folder=file.directoryEntries;
while (folder.hasMoreElements()) {
var
f=folder.getNext().QueryInterface(Components.interfaces.nsILocalFile);
if (f instanceof Components.interfaces.nsILocalFile)
files.push({path:f.path, name:f.leafName, size:f.fileSize,
isFolder:f.isDirectory(), url:"file:///"+f.path.replace(/\\/
g,"/"),
modified:new Date(f.lastModifiedTime).formatString("YYYY.0MM.0DD
0hh:0mm:0ss")});
}
}
return files;
}
listresults = function() {
fout += ('!File Linker Report') + ' ' + new
Date().formatString("YYYY.0MM.0DD 0hh:0mm:0ss") + '\n';
fout += 'Scanned paths : ' + file_paths + '\n';
fout += ('Number of files found: ' + file_list.length) + '\n';
fout += ('Tags used: ' + tagslist ) + '\n';
fout += ('Username: ' + user_name ) + '\n';
fout += ('!!Added tiddlers') + '\n';
}
date_conv = function(date) { // convert file date to TW date
format
date = date.replace(' ','.');
date = date.split('.');
return new Date(date[0],date[1]-1,date[2]); // date of creation
}
write_tiddler = function(title,date) { // write the
tiddler with the file info for each file
fout+= ('[[' + title + ']]' ) + '\n';
var newTitle = title; // tiddler title
meta = title.substr(title.lastIndexOf('/')+1);
// var newBody = 'Info: ' + meta + '\n'; // text in the
tiddler
newBody = '<<tiddler HideTiddlerSubtitle>><<tiddler
HideTiddlerToolbar>>{{stretch{<<edit tags>>}}}' + '\n' + '\n';
newBody += '{{borderless{' + '\n';
newBody += '|width:100px;Info |<<edit info>>|' + '\n';
newBody += '|Own code |<<edit own>>|' + '\n';
newBody += '|Test code |<<edit test>>|' + '\n';
newBody += '|Link |' + '[[' + title + '|./' + title +']] |'
+ '\n';
// newBody += 'Link ' + '[[' + title +'|./' + title
+']]' + ' ';
// newBody += '<<tiddler CheckboxToggleTag with:
newdocs>>Newdocs' + '\n';
newBody += '}}}' + '\n';
newBody += '{{largeblue{Comments}}}<hr>' + '\n';
// newBody += '{{hidden{ You can only edit below this
line }}}' + '\n' + '!Comments:' + '\n';
newBody += '{{stretch textarea{<<edit comments
10>>}}}'; // + '\n';
var dt = date_conv(date); // convert date toTW formaat
var newTags = tagslist; // ' newdocs docs'
store.saveTiddler(newTitle, newTitle, newBody, user_name,
dt, newTags);
store.setValue(newTitle,"meta",meta);
}
// main loop to get all file names in all paths
for( p = 0 ; p < path.length ; p++ ) {
var cwd = getCurrentFolder() + path[p] ; //sub folder were the
docs are located
file_list = file_list.concat(getFileList(cwd));
file_paths += path[p] + ' ';
}
listresults(); // print the results of loading files
// check if the tiddler exists and write if not
for (var i=0; i<file_list.length; i++) {
line=([file_list[i].path,file_list[i].name,file_list[i].url,file_list[i].size,file_list[i].modified]);
basic_line = line[0].replace(getCurrentFolder(),'');
// fout += 'basic_line ' + basic_line;
var tid = store.tiddlerExists(basic_line)?"Y":
write_tiddler(basic_line,line[4]);
}
exist_file = function(title) {
exist = false;
for( y = 0 ; y < file_list.length ; y++ ) {
if ( file_list[y].path.replace(getCurrentFolder(),'') == title )
{ exist = true;
}
}
return exist;
}
// non exsisting files
var files_missing = '';
var tids=store.getTaggedTiddlers('docs');
for( i = 0 ; i < tids.length ; i++ ) {
if ( exist_file(tids[i].title) == 0 ) {
insert = '[['+ tids[i].title + ']]' + '\n';
if (files_missing.indexOf(insert)==-1) { files_missing +=
insert; }
}
}
// linker report creation
var newTitle = 'fileLinker_report'; // tiddler report
var newBody=' ';
if (store.tiddlerExists('fileLinker_report')) {var newBody
= store.getTiddlerText('fileLinker_report');}
newBody = fout + ('!Tiddlers tagged but no file') + '\n'
+ files_missing; // alleen de laatste text in body
var dt = new Date(); // convert date toTW formaat
var newTags = '' ; // lege tags list
store.saveTiddler(newTitle, newTitle, newBody,
user_name, dt, newTags);
displayMessage('New linker report made');
saveChanges();
}
//}}}
Have a nice day, Okido