Socialcode Activity Comment 2.2 plugin for Jomsocial – Like activity error 505 fix

I’ve got a lot of unpleasant things to say about 3rd party Joomla developers. And this is an example of why.

In Socialcode’s Activity Comment plugin for JomSocial (plg_activitycomment), when you unlike an activity, it appears to work. However, what it does is remove the likes-holder div immediately with Javascript (jQuery in fact), delete the like item from the database, then throw a 505 Internal Server Error. At this point you are supposed to get a response with the new string of likes, as other people may still like the activity, but these won’t be displayed until you refresh the page.

Most people probably don’t even realise it’s broken, as unless you have FireBugs console or net panels open, you get no notification of the error.

The problem occurs because the likeitem() function requires helper functions from a separate file, which the coders failed to include.So it’s remarkably easy to fix, once you work this out, simply add the line

to the function in /plugins/community/activitycomment.php, which will now look like this:

I discovered this problem while updating my hacks to include a dislike button at the request of a client who’s community members wanted it.If you are interested in having the hack for your own JomSocial site, leave a comment and I’ll get in touch.

10 Easy Examples for Deciphering PHP Regular Expressions

Because of the obtuse syntax, some would contend that regular expressions are unlike riding a bicycle or tying your shoes in that it’s difficult to retain a working understanding of them over the long term.

Hmm. True dat, if you don’t use them often. 

This article by W. Jason Gilmore hopes to make it a bit easier to learn, but of course can also be used as a simple reference.

http://phpbuilder.com/columns/Regular-Expressions/Jason_Gilmre072010.php3

Checking Disk Usage (*nix)

Brazenly lifted from 

http://kb.mediatemple.net/questions/916/Managing+your+disk+usage

 

View Disk Space from SSH

To check your Total Disk Usage for your entire server via SSH you can type the following:

 

 

The first column displayed is the device. The next three columns show the total size, the amount used, and the amount available

 

TIP: 

  • You can use -m for megabytes
  • You can use -k for kilobytes 

 

Another useful command is du. Running this command will list all directories with their filesize from your current directory.

 

A good example of using this command would be to view the sizes of your site’s directories:

 

NOTE: 

Remember to replace mt-example.com with your domain name.

 

 

To show the total directory size of the current directory you can run the following command:

 

To show directory sizes as a listing you can use the command:

 

Searching for Large Files

You can use the following command to search for files over 10MB in size:

 

NOTE: 

To adjust the size of your search replace +10000k with the size you desired, such as the following: 

  • 50MB: +50000k 
  • 100MB: +100000k 
  • 500MB: +500000k 

 

 

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.