Lasso Soft Inc. > Home

[include_global]

Linkinclude_global
AuthorJohan Solve
CategoryFile
Version7.x
LicensePublic Domain
Posted03 Mar 2007
Updated03 Mar 2007
More by this author...

Description

1. Look for file in  web root         
2. Look for file one level above web root
3. Look for file in 0_Global_ somewhere above web root

Sample Usage

include_global: 'path/to/filename.inc'; // normal use with relative path
include_global: '/path/to/filename.inc'; // normal use with absolute path
include_global: 'path/to/filename.inc', -raw; // don´t process the included file, corresponds to include_raw

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

 get: 1),
		'process'=true;
	local: 'includepath_in'=#includepath;
	if: (params -> (find: '-raw') -> size > 0);
		local: 'process'=false;
	/if;
	
	local: 'localpath'=(response_localpath),
		'webpath'=(response_path),
		'includeContent'='';
	if: !(#includepath -> beginswith: '/');
		// not absolute path
		#includepath = #webpath + #includepath;
	/if;
	
	// inline to authenticate file tags not needed since we run as process
		
	// 1. Look for file in  web root 
	if: file_exists: #includepath;
		#includeContent = file_read: #includePath;

	else;
		// 2. Look for file one level above web root
		#localpath -> removetrailing: (#localpath -> (split: '/') -> last);
		// This ends up with ///a/very/deep/path/to/webroot/and/to/file/
		
		local: 'webroot'=#localpath;
		#webroot -> (removetrailing: #webpath);
		// #webroot += '/'; // we don´t want a trailing slash on webroot
		// This ends up with ///a/very/deep/path/to/webroot
		
		local: 'includeOutsideOfRoot'=#webroot;
		#includeOutsideOfRoot -> (removetrailing: '/' + (#includeOutsideOfRoot -> (split: '/') ->last));
		#includeOutsideOfRoot += #includepath;
		// This ends up with ///a/very/deep/path/to/includefile.inc
		
		if: file_exists: #includeOutsideOfRoot;
			#includeContent = file_read: #includeOutsideOfRoot;

		else;
			// 3. Look for file in 0_Global_ somewhere above web root
			local: 'includeGlobal'=#webroot;
			
			// look for globals level for level up from web root
			while: #includeGlobal != '//' && loop_count < 20; // for safety
				if: #includeGlobal != '//'; // make sure we are not at the top already
					#includeGlobal -> (removetrailing: '/' + (#includeGlobal -> (split: '/') ->last));
					if: file_exists: (#includeGlobal + '/0_Global_/');
						// we found the global folder - exit the loop
						loop_abort;
					/if;
				/if;
			/while;

			#includeGlobal += '/0_Global_' + #includepath;
			// This ends up with ///a/very/0_Global_/includefile.inc

			if: file_exists: #includeGlobal;
				#includeContent = file_read: #includeGlobal;

			else;
				// file not found in any location
				// throw an error
				if: (file_currenterror: -ErrorCode) != 0;
					fail: (file_currenterror: -ErrorCode), 
						file_currenterror + ' Include_global ' 
							+ #includeOutsideOfRoot;
				else: (error_currenterror: -ErrorCode) != 0;
					fail: (error_currenterror: -ErrorCode), 
						error_currenterror + ' Include_global ' 
							+ #includeOutsideOfRoot;
				else;
					fail: (error_filenotfound: -errorcode), error_filenotfound + ' Include_global ' 
							+ #includepath
							+ ', ' + #includeOutsideOfRoot
							+ ', ' + #includeGlobal;
				/if;
			/if;
		/if;
	/if;


	if: #process;
		// -raw was not specified so process the include
		if: (integer: (lasso_version: -lassoversion)) >= 7 && #includeContent->type == 'bytes';
			// make charset assumptions if we run on a Unicode aware Lasso
			// first try to detect a UTF BOM
			if (#includeContent->(get: 1) == 0xEF && #includeContent->(get: 2) == 0xBB && #includeContent->(get: 3) == 0xBF);
				// UTF with BOM
				#includeContent->(remove: 1, 3);
				#includeContent = string: #includeContent;
			else: (lasso_version: -lassoplatform) >> 'Mac OS';
				// assume file was MacRoman
				#includeContent = #includeContent->(exportstring: 'Macintosh');
			else;
				// assume file was ISO
				#includeContent = #includeContent->(exportstring: 'ISO-8859-1');
			/if;			
		/if;
		#includeContent = (process: #includeContent);
		if: #includeContent == '' && (error_currenterror: -errorcode) != 0;
			fail: (error_currenterror: -errorcode),  (error_currenterror  + ' in ' + #includepath_in);
		/if;
	/if;

	// return by reference to disable default encoding when calling the tag in LP7 
	//   (must still use -encodenone in LP6)
 	return: @#includeContent;
/define_tag;

?>

Related Tags

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft