TheDrunkenEpic - Drunken Ramblings of a Code Monkey
Filed under

Symphony

 

Pseudo Membership Campfire Service

I went ahead and threw together a campfire service that allows you to utilize an already existing membership system from a 3rd-party application you might already be hosting on your site. Basically, if you have a supported application installed and a user, who is logged into said application, visits your Symphony site, this service will generate XML with their logon information.

What this allows you to do is create members only areas within your Symphony install. Let's say you have a Vanilla forum on your site and you only want your Vanilla users to be able to comment on your blog articles. All you have to do is attach the appropriate datasource to your page or master wrapper and then put something like the following in your XSL template:

<xsl:choose>
    <xsl:when test="external-member-check/registered = 'true'">
        SHOW COMMENT FORM
    </xsl:when>
    <xsl:otherwise>
        Sorry, only forum members can comment ...
    </xsl:otherwise>
</xsl:choose>

Now you can create members-only areas within your site. I also have the datasources returning the user's group id ( if applicable ), so you can show different types of content / functionality based on group assignments.

Here is the XML that's returned:

// When logged in:
<external-member-check software="vanilla">
    <name>Wilhelm Murdoch</name>
    <registered>true</registered>
    <id>5</id>
    <group>2</group>
</external-member-check>


// When NOT logged in:
<external-member-check software="vanilla">
    <name>Guest</name>
    <registered>false</registered>
    <id />
    <group />
</external-member-check>

So far there is support for the following forum solutions: MyTopix, PunBB, Vanilla

I need some testers to help out with... testing. Also, if you want to create more datasources for different applications, go ahead and send your finished versions to me and I'll add it to the service. Credit, of course, will be given to the code authors.

A link to the download at Overture. Scroll to the bottom of the first post.

Loading mentions Retweet
Filed under  //   Code Monkey   Free Goodies   Symphony  

Comments [0]

Symphony Search Walkthrough

It seems there are a few Symphonians out there, both new and old, that can't quite get the 'Search' campfire service working on their site. So, I've decided to go ahead and throw together a quick guide to help my comrades out.

Before We Start

This article assumes that you have, at the very least, the following:

  1. A working copy of Symphony 1.7.x
  2. The Search campfire service composed by Alistair Kearney
  3. A rudimentary understanding of HTML
  4. Some basic reading skills
  5. Some searchable content on your site

First things first:

If you're here that means you've met all the requirements, so good on ya! In order to get search functionality working, you need to download and install the latest copy of the campfire service.

Click on the link I provided in the previous section and download the package. Once finished, open the package place it's entire contents in the campfire directory of your Symphony installation. In almost all cases it will be in the %Symphony Root%/campfire/ directory.

Next, go to your Symphony administration panel and navigate to your Campfire section. You'll see a new entry entitled 'Section Search'. Click on the title of the campfire service and you will be whisked away to it's information screen. At the bottom of the screen you should see a button labeled 'Install Service'. Click this button and Section Searching should now be activated on your site.

Getting Dirty:

Now that you have the actual service installed, we're going to perform some XSL magic to get your search form up and usable. Now, there are countless ways we can do this and, due to the nature of the system, we could place this code anywhere on your site. But, for the sake of simplicity, I'll take the straight forward and common approach.

Follow these steps:
  1. Go to your page management screen in your Symphony install's administration panel.
  2. Click on the 'Create New' link.
  3. Give your page the title 'Search'.
  4. Click the 'configure' button located at the top of the new page form.
  5. Under the 'Page Environment' section you will see a list of datasources. Select the 'Section Search' datasource.
  6. Close the configuration form by clicking the 'configure' button again.
  7. I'll keep this VERY simple. Paste this code block into the 'Body' field of your new page and click the 'Save' button.

All done! Now you have a simple search form that, when submitted, will display an ordered list of entries from your 'entries' section.

Note: Now, you may not have an entries section. It could just as well be entitled articles under your install. If this is the case, you're going to have to change a very small bit of code. From the block of code above, you will notice a hidden element within the form entitled section. This variable specifies which section you want to search. The current value of this element is entries, but in your case it might be articles or blog. Just make sure you change the value of that element to what ever existing section you'd like to search or it just won't show any results.

You can even toy with the URL schema of the search page to change what section you'd like to search on the fly!

That's all folks!

Didn't seem so hard, did it? In this tutorial you learned how easy it is to set up content searching within your Symphony installation. Hopefully, this will help some of you guys and gals who've been having trouble in getting this type of functionality up and running on your sites. If you have any trouble, please just post a comment in this article and I'll be quick to respond.

Till next time!

Loading mentions Retweet
Filed under  //   Code Monkey   Symphony   Tutorials and Such  

Comments [0]

Creating datasources that pull random content

I was recently browsing around the Overture forums the other day looking for some new tips and tricks for Symphony and came to the realization that when it comes to creating new Datasources, Symphony doesn't offer an option to randomize the result set.

I realize this won't be an issue for most people, but what if you have a portfolio section to your site and you want to pull some random portfolio entries for the front page? What if you'd like to do the same with comments or articles? This tutorial aims to provide a relatively simple solution for this small issue.

Prologue

Before we start, I thought I'd let you all know that this tutorial assumes that you have a rudimentary understanding of Datasources for the Symphony publishing platform. If not, you can access the public wiki dedicated to Symphony documentation for more information. This tutorial also assumes that you're not afraid to get your hands a little dirty with the source code.

Creating the Datasource

For the sake of this tutorial, let's just say you would like to display 3 random comments on your site's main page. To accomplish this, you must first create a new Datasource. Click the image below to get the full details of this Datasource.

Datasource Preview

As you can see, this is a very basic Datasource. In this instance, we named our DS 'Random Comments', but you can call it whatever you like. The source of our data should be set to 'Comments'. Leave the filtering options alone for this tutorial; you won't really need them. In the 'format options' section, choose what fields you want included. You can choose a sorting option, but it won't really do any good as our result set will be randomized by the end of this tutorial.

Since we only want to show 3 random comments, set the Datasource limit options accordingly. Click the 'save' button and you should be good to go!.

Digging in the Source

Before We Start:

To speed up execution times, the Symphony team set up the system in such a way that it generates a new PHP source file every time you create a new Datasource. This source file's content reflects the settings you chose when creating the actual Datasource within the Symphony interface. On the system level, when a Datasource is attached to a page, Symphony will refer to the corresponding source file by including it and then executing it, generating the appropriate XML result set based on your specified criteria.

Neato!

Back to the Program:

Now, since Symphony doesn't have an option to randomize result sets, we're going to have to dive into our new Datasource's source file and change around a few things.

First, navigate to the following directory %symphony_root%/workspace/data-sources/ and open the file named data.random_comments.php in your favorite IDE. Now that you got the file open, we can handle this one of two ways. We can either randomize the returned data using PHP's built-in randomization functions or we can add a simple SQL clause into the database query strings that fetch our data. Since the latter is much simpler we'll just go with that.

In your IDE, run a quick search for ORDER BY. There should be 2 results. In both of these instances, you will need to change ORDER BY to ORDER BY RAND(),. Be sure to note the comma(,) right next to Rand().

Next, by default, Symphony likes to cache result sets pulled from Datasources. This will pretty much put a halt to all our hardwork. If our 3 random comments are cached, the system won't pull new random comments until said cache expires and updates itself. We can't have that, so do the following:

Find:

##Check the cache
$hash_id = md5(get_class($this) . serialize($env_url));

if($param['caching'] && $cache = $this->check_cache($hash_id)){
    return $cache;
    exit();
}

And either delete it or comment it out:

//  ##Check the cache
//  $hash_id = md5(get_class($this) . serialize($env_url));
//
//  if($param['caching'] && $cache = $this->check_cache($hash_id)){
//      return $cache;
//      exit();
//  }

Now, save your changes and upload it back to its home directory.

Using Your Datasource

Using this new Datasource is no different than any other. Before the system generates your XML, you will first need to attach this Datasource to a page. To display your random comments, you will need to modify the page's main template.

Find where you would like to see your comments and add something like the following:

<xsl:for-each select="random-comments/entry/comment/">
    <div>
        <xsl:value-of select="author"/> Said:<br />
        <xsl:copy-of select="message/*"/>
    </div>
</xsl:for-each>

Naturally, you'd want to spruce it up a bit, but, for the most part, that's all you need to do. Save your page's main template and view the live result. You should now see 3 random comments appear every time you refresh your page!

Please Note

Don't let all your hard work go to waste! Every time you update your Datasource's options within Symphony's interface, the system rewrites the entire source file, thus overwriting all your changes. Just remember, if you have to make a change to the Datasource, you'll need to go back and reapply these modifications.

In Closing

Well, that's pretty much all there is to it. In this tutorial you learned how to create a Datasource that randomizes result sets by modifying its source code. See what else you can do by changing a few more things around in the source. If you mess up and break something, just re-save your Datasource in the Symphony interface to overwrite your changes.

I hope you enjoyed this tutorial as much as I enjoyed writing it! Till next time ...

Loading mentions Retweet
Filed under  //   Development   Symphony   Tutorials and Such  

Comments [0]