Jom Soc error report CC ACTIVITIES WALL POST EVENT

‘CC ACTIVITIES WALL POST’ appears in activity stream when someone posts to the wall of an event in JomSocial 1.8.3 

 

[url=http://www.jomsocial.com/forum/index.php?f=3&t=19059&p=104230&hilit=CC%20ACTIVITIES%20WALL%20POST%20EVENT&rb_v=viewtopic#p104230]This forum also mentions it.[/url]

I have added

CC ACTIVITIES WALL POST EVENT={actor} added a new wall post in the event, %2$s

to /language/en-GB/en-GB.com_community.ini

 

/components/com_community/controllers/events.php l.1934 already reads:

$act->title<span style="white-space: pre;"> </span>= JText::sprintf('CC ACTIVITIES WALL POST EVENT' , $url , $event->title );

[url=http://pastebin.com/rWAHNLHj]Full events.php code on pastebin[/url]

 

Product version: JomSocial 1.8.3

Joomla! version: 1.5.14

PHP version: 5.2.10

MySQL version: 5.0.77: 

PHP: Sort an array of objects by an object property

I was asked if it was possible to re-order the list of friends when inviting people to events in the JomSocial v.1.8.3 community component of Joomla! 1.5

The problem here was that the array of friends is an array of objects, ordered by their database id as they were pulled from the database.I don’t want to be hacking the core functions that pulled the data from the database and re-ordering it there – I want to keep as close to the top layer as possible with simple bits of code, as I don’t want to waste time decoding other peoples work.

This all occurs in /components/com_community/views/events/view.html.php

If you know JomSocial, you might be aware that the friends model function ‘getFriends’ call looks like this:/components/com_community/models/friends.php

L.855

Well, that might suggest that we can order it by changing the call in view.html.php which currently is:

L.247

However swapping out ‘name’ for ‘username’ doesn’t work as rather than simply using this flag as the ORDER BY clause in the MySQL, the getFriends function uses a switch case to determine what action to take.models/friends.php

L.1030

Now I could just add a case for ‘username’ here. This would be the logical long term solution to any system over which I had real control. However, JomSocial is frequently updated, meaning any hacks I make must be reapplied, with no guarantee that they won’t have to be completely re-written. So this solution would mean changing two files, and getting deeper into the system. I want to keep my changes as few and as contiguous as possible.

Which brings me back to the original problem, and the ostensible perverse way of going about solving it.

So, I have an array of objects in the wrong order.What I’m going to do is loop through that single-dimension array, turning it into a two-dimensional array – one key the object (itself multi-dimensional), and the other key the username that we will sort on, obtained with the getDisplayName() method of the object.This new array will then be sorted with uname() and a simple custom function compare_uname($a, $b), and the sorted array looped to recreate the original single-dimensional array in the desired order.For JomSocial, this has been inserted in views/events/view.html.php at line 265

Rotating background image (or other PHP function) in CubeCart templates

I have a site where the main site picks an image from a particular folder for the background every time you hit a page, rotating through the available images in a loop. We also have a CubeCart store, which has had the template skinned to fit the main site, so obviously enough, I wanted to have the same background image feature for the shop.

The thing with CubeCart templates is that you can’t just add php to the .tpl files – you have to do all your PHP jiggery pokery in include files, and assign values to object properties, and include a placeholder in the tpl.

There are two key CubeCart files to make this change over the whole shop:

{www,yourdomain.com}/{shop_location}/includes/global/index.inc.php{www,yourdomain.com}/{shop_location}/skins/{your_skin}/styleTemplates/global/index.tpl

First off you want to get your functions together from the main site. Mine all live in a lib.php file, but as I don’t need to load all of them into CubeCart, I pulled the relevant ones into a new file, /lib/php/rotatebg_lib.php. Now I can include this file in my original lib.php as well as in CubeCart, and reduce unnecessary memory overheads.

The system relies on three functions:

files_in_dir($start_dir) creates an array of the files in a directory. This is one of my standard ‘off the shelf’ functions

index_background_images() checks for files with a .jpg extentsion, creates an array of them and stores it in a $_SESSION variable, called only when a session is started. There are other ways of checking for file types – the most reliable is to mime_content_type() function, but if you trust the files on your server, my method is fine. If you are dealing with user uploaded files, remember you should NEVER trust the file to be what it says it is!

rotate_background() checks for a session, calls the indexing function if necessary and otherwise increments the index counter.

rotatebg_lib.php

Now we need to include and run these functions in the CubeCart global index include.Line numbers may vary dependant on your template, but essentially you want to add this just after the $body template has been defined

{your_skin}/includes/global/index.inc.php

Replace:

With:

And finally, insert VAL_CUSTOM_BACKGROUND into the index.tpl file. This needs to be added in the head section, I prefer the end of the head section as CSS latency will ensure that the rule is obeyed. Again, line numbers may vary.

{your_skin}/styleTemplates/global/index.tpl

Replace:

With

Shazzamwhazzam. We are done.

Multiple FTP users in Plesk 9

By now, Plesk is supposed to have built in support for creating multiple FTP users through the web interface, but it doesn’t seem to have materialised. So for the mean time, SSH is still the way forward:

Create ftp user with their own home directory:

Set the ftp user’s password:

Add user to group psacln:

Change folder permissions for home directory:

Change ownership to user and group:

Set execute permission on the httpdocs folder for the domain:

At this point you have a valid FTP user who can connect. But only to their own folder. Now I want users with FTP write access to httpdocs so I can give 3rd party support access on occasion and later revoke it without having to change my master password. Also, all their actions will be logged as their user, so we have a data trail in case of things going pear shaped.This is as far as Parallels’ guide goes, so we have to do a couple more steps:

Set the user’s home directory to the webroot:

Grant write permissions to the group on the webroot:

And we are done!

Where $HTTPD_VHOSTS_D is your vhosts path (typically /var/www/vhosts on the CentOS 5 boxes I’ve used) and USER_NAME is your chosen… errr, wossitcalled…

‘/some/location’ should be a non public access directory, e.g. /var/www/vhosts/your_domain/web_users/USER_NAME

These intstructions are tested on CentOS 5 / Plesk 9. They should work for other *nix flavours, but as with everything on t’net, excercise caution, and on your own head be it.

http://kb.parallels.com/en/415

Checking multiple XML files for errors with Shell script and PHP

A joomla site I work on is throwing an XML error, with, of course, no information on what file is throwing the error.There are 1260 XML files on the server, so I’m not about to check them all by hand.

The first task is to locate and list all the XML files in the site in a text file:

I then tried to write a script to process each line of that file (based on http://bash.cyberciti.biz/file-management/read-a-file-line-by-line/ ) and use xmllint to check the file, and again output the results to a file. Unfortunately, xmllint doesn’t seem to like appending with >> and while you can specify an output file, I don’t want 1260 results files either! So I wrote a php script to do the job instead.

Note that in all these snippets, you will need to replace the paths and domains with yours, of course. So, this worked nicely. Except that most of the XML files don’t have a DTD, and those that do seem to completely ignore it, so everything comes out as invalid. Just… great. I love working with Joomla.

Bi-directional AJAX Loading Icon

Just got this idea in my head for a loading icon that spins in two directions at once, based on an exclamation mark, so I thought I’d try it:

The idea seems to work, but it could do with some tweaking. But enough dicking around, I have more important things to do.
I tried to post the file for people to play around with, but Posterous doesn’t accept ZIP files (security risk) and cleverly converts PSDs to images (cunning indeed). So you will just have to live without. Make your own damn annoying spinning thing why don’t you?

Oh go on, here it is:

reversing-flowers.zip

Tweet and Like This for your site

Just as Posterous has Tweet and Like buttons on each post, a client asked me to do the same for his site yesterday.

 

Getting all twittered up wasn’t too hard – I started with John Resig’s Easy ‘Retweet’ Button

http://ejohn.org/blog/retweet/

Nomenclature not withstanding (it’s not exactly ‘retweeting’, more ‘tweet this’) I found it to be a pretty good guide, highly customisable, and it was up and running before I left the Brixton office.

 

Facebook Like buttons are a bit more work, and I haven’t finished them yet, as they require ‘setting up your page as a Facebook Application’ – I’ve done everything on the client site end, which required a lot of reconfiguring of the way the site was moddled, which is OK as its now much closer to the MVC model, and now just need to deal with the Facebook end. Arse about tit perhaps, but the Facebook instructions neglected to mention the minor of matter of making your site an FB app – or how to do it as far as I have found yet. Well that’s one of the next things on the list.

I am going for the more complex <fb:like> XFBML tag/Javascrip route over the iFrame method for two reasons:

1)      Javascript is more powerful, flexible and tidier.

2)      iFrames just SUCK. Once upon a time they were a clever and necessary if messy way of achieving some nice tricks. Today they are like the appendix, the coccyx and nipples on men.

 

Here are some links that have gotten me this far:

http://developers.facebook.com/docs/opengraph
http://developers.facebook.com/docs/reference/plugins/like
http://developers.facebook.com/docs/reference/javascript/

http://hillarsaare.com/multiple-facebook-like-buttons-on-one-page/

http://www.hyperarts.com/blog/how-to-add-facebook-like-button-social-plugins-to-wordpress-posts/

Note, I’m not working on a wordpress site, but this was the first page I saw that pointed out that <fb:like> XFBML  “requires that your page/post make a call to the JavaScript SDK and that your page be set up as a Facebook application (quite easy)” and then goes on to show you EXACTLY HOW TO DO IT! Yeah, that’s the way we like it, uh huh, uh huh…

[UPDATE 1800 4-6-2010]
Well, the application setup was incredibly  simple, and just dropping in the FB App ID (and adding a <div id=”fb-root”></div> tag to the end of the page, which FB didn’t  think important enough to mention!) it works. Now I need to hack it to display the way I want it to! 

[/UPDATE] 

[UPDATE 2000 4-6-2010]
Ah. No, it doesn’t work – it just throws an error with no debug info. That sucks.
And you don’t stand a chance in hell of restyling it – even the Javascript method calls up an iFrame, meaning you are unable to affect it’s appearence with either JS or CSS. That also sucks.

[/UPDATE] 

[UPDATE 1650 21-6-2010]
First time back on this particular client’s site since, and it appears things are actually working well. It does occasionally throw an unspecified error, as I first saw, making me think it was crocked on my first test, but you will get AJAX communication errors from time to time whatever you are doing.
Now I just had to make it usable – we don’t have room in the site design to have this massive Facebook like widget eating virtual real estate, and as noted before, we can’t control the iFrame contents using CSS or Js.

BUT we can control the iFrame container. By placing the Facebook widget in a div, we can shrink that div to just the size of the button, and then using the :hover pseudoclass increase it’s size on mouseover.

[/UPDATE] 

What is it with documentation? I’m a clever guy, I write tech docs myself, and while I’m not a university trained programmer I’m not a bad one. But SO many tech docs sketch barest bones on very specific tasks, miss vital instructions that could often be provided with a simple link where they are more complex than space permits, and don’t provide examples!

Speaking of which, I hope to add some code examples of both these methods later, as well as my Like and Tweet PSD files, free to use, modify and redistribute.

Cutting the Stream: Counting and stripping tags cont.

As I continue to work on truncating long activity stream posts, there aremore and more steps that need to be taken to clean up the code.

I don’t have time to fully explain everything I have done lately, so this iscurrently more a bunch of useful links and the current function and classesto point in the right direction.

First off, with some activities coming from the forum, they have BBCode inthem which is not parsed by the activity stream. Updating thestrip_html_tags() function to remove BBCode tags too is easy:

Argh! Knackernuts! While I get on to Posterous about the continued issue with object and embed in markdown, get the code from http://pastebin.com/kYRPPYrp

The function now also replaces inserts html line breaks before newline characters with the php nl2br() function after all tags have been stripped. The function name is perhaps becoming inaccurate, but the function is doing what I demand of it!

I also had some issues getting html_count class working in production, where it had been fine in testing.http://www.phpclasses.org/package/2653-PHP-Count-the-occurrences-of-a-given-H…

The issues here was that html_count is designed to parse the contents of an external file, not a string. Now, I can call an individual activity as an external file, but this requires post data to be sent.Wez Furlong’s do_post_request function set me on the track to solving that one:http://wezfurlong.org/blog/2006/nov/http-post-from-php-without-curl

However, it seemed a little (understatement of the year) inefficient to be generating an external file and parsing that for each activity in a stream (which can get very long when you ‘show older posts’ a few times), particularly when all that data being parsed is already in my hands at that point, so html_count needed tweaking to be able to handle strings and files – there are now two classes: string_html_tag_count and file_html_tag_count. These could easily be wrapped into one class with a switch to select which variant you wished to use. I just haven’t spent the extra few minutes doing that, as this is all taking far too long as is!

Define your own colour names in CSS

Looking at my Posterous template, I notice the following:

h2 a:hover { color: {color:Accent}; }

WTF? Accent isn’t a standard CSS colour name.
Searching for Accent I find the following inside the head tag:

<meta name=”color:Accent” content=”#a98e2e”/>
<meta name=”color:Darker Accent” content=”#776421″/> 

Genius! I didn’t know you could do that. Now with this you can define a set of colours in an external file (possibly in a database for a CMS) and include that in your templates, and easily control and change all colour references in a site by only changing that file. What a fantastic time saver – no complex find and replace in multiple CSS files to update a colour scheme for a special occasion. BUT: Does this only work with Posterous’ template system? If so, it would be easy to write into your own systems but could be more of a pain to implement for say Joomla. I shall have to do some tests….

[UPDATE: 1436-08062010]
Haven’t gotten round to doing any testing, but my associate Bishop Dante tells me:

“the meta trick is pure HTML, it’s not specific to your blog platform.
It can be done to assign classic global control over most anything of value,
including the source of the HTML file itself.”

Well blow me! I’ve been doing HTML for over 10 years, and I have NEVER come across this before. Never seen it on a site, never found a reference in a manual or a guide online. Me still likey. Next question: Can you use this trick with external CSS or does it have to be inline?
[/UPDATE]

[UPDATE: 1641-12112010]
Well, I’ve finally tried it out, and it doesn’t seem to work either inline or external. Can’t find much of anything on Google relating to it, apart from mention of Tumblr profiles. It may be accomplished with Javascript perhaps, which is a real shame. I’d love to know more about it…
[/UPDATE]