Monday, November 08, 2010 at 12:00 AM.

scripting2Suite.editor.checkWatchedFolder

on checkWatchedFolder () {
	<<Changes
		<<7/4/10; 4:30:12 PM by DW
			<<Added sounds before and after the image is uploaded.
		<<7/4/10; 7:46:11 AM by DW
			<<Bring the OPML Editor to the front after the picture is uploaded.
		<<7/1/10; 6:07:19 AM by DW
			<<Cribbed from wordPress.root.
	local (adrdata = scripting2suite.init (), f);
	if adrdata^.editor.prefs.watchedfolder.enabled {
		adrdata^.editor.prefs.watchedfolder.ctChecks++;
		adrdata^.editor.prefs.watchedfolder.whenLastCheck = clock.now ();
		fileloop (f in adrdata^.editor.prefs.watchedfolder.folder) {
			local (lowerf = string.lower (f));
			if (lowerf endswith "gif") or (lowerf endswith "jpg") or (lowerf endswith "jpeg") {
				local (url);
				speaker.sound (1, 100, 1000);
				url = scripting2Suite.editor.uploadImageFile (f);
				bundle { //backup the image
					local (pc = file.getpathchar ());
					local (folder = adrdata^.editor.prefs.backupFolder + "images" + pc + adrdata^.editor.prefs.username + pc);
					local (fbackup = folder + file.getdatepath () + file.filefrompath (f));
					file.surefilepath (fbackup);
					file.writewholefile (fbackup, file.readwholefile (f))};
				bundle { //show clipboard text
					local (img = scripting2Suite.editor.getImageClipboardText (f, url));
					<<bundle //old code
						<<local (t, height, width)
						<<new (tabletype, @t)
						<<bundle //set height, width
							<<if lowerf endswith ".gif"
								<<local (hw = html.getgifheightwidth (f))
								<<height = hw [1]
								<<width = hw [2]
							<<else
								<<hw = html.getjpegheightwidth (f)
								<<height = hw [1]
								<<width = hw [2]
						<<t.url = url
						<<t.height = height
						<<t.width = width
						<<t.filename = file.filefrompath (f)
						<<wp.newtextobject (string.multipleReplaceAll (string (user.wordpress.prefs.watchedFolder.clipboardTemplate), @t, false, "<%", "%>"), @system.temp.clipboard); edit (@system.temp.clipboard)
					frontier.bringtofront (); //7/4/10 by DW
					wp.newtextobject (img, @system.temp.clipboard); edit (@system.temp.clipboard)};
				speaker.sound (1, 125, 2000)};
			file.delete (f);
			return}}}; //only do one file each loop
bundle { //test code
	checkWatchedFolder ()}



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.