5

I am attempting to gather as much interesting metadata as possible to display for readers of an expression engine site I'm developing and am looking for guidance on methods (or indeed the feasibility) of computing specific bits of this metadata in a scalable way.

Expression Engine allows for quite a few bits of data to be gathered and displayed natively, for example post totals and dates, comment totals and dates, tag totals, etc. However I'm specifically interested in finding a method to count and display totals for data like number of words, images, videos, or audio files, not only within individual posts but across a channel, as well as site-wide.

These totals would be displayed contextually depending on where they were accessed. So for example search results would display the number of words/images/etc contained in individual posts, a channel's "about" page would display totals for the entire channel, and the site's "about" page would display site-wide totals. I'm not clear on the best approach or whether this is even really feasible.

I'm not a professional web designer, so my knowledge of anything beyond html5/css3/ee is somewhat limited, but I've pondered:

  • Entering these numbers on a per-post basis, in custom fields, but am not clear on whether they can be added together for channel and site-wide totals.
  • Using PHP's "count" method, but am not very familiar with PHP so unsure of it's appropriate.
  • Using some mySql method to query the database, again unsure.
  • Utilizing the Expression Engine "Query Module." !?
  • Using some Jquery plug-in to do the counting individually and then adding after the fact.

It may be that the counting of words, images, video, and audio files and the scalability are different questions all together but the truth is I'm very confused as to what avenue to even explore. So any and all suggestions or guidance would be greatly appreciated.

Update: I'm looking into database methods to collect and add the results but am still interested in identifying the best ways to actually perform the word/image/video/audio file counts.

3
  • Each of them is rather trivial to implement on its own. To count words, you strip all HTML and count by spaces. To count images, you DOM parse the document and get all of the <img> elements, etc. Where did you get stuck? Commented Apr 28, 2012 at 17:38
  • Hey Truth, I got stuck in the planning stages! haha. Seriously, there seemed to be so many partial solutions, possibilities, and different methods that I felt like I needed to figure out a sensible path before even attempting to tackle all the separate bits and pieces. I am an ameteur coder at best, so none of it is trivial for me. Once Jquery, PHP, Database queries, etc get thrown in, in combination especially, I am thrown for a loop.
    – Jmorriso
    Commented Apr 28, 2012 at 18:57
  • I've seen that their are Jquery methods for word count, for example, but the real sticking point conceptually was how I'd scale those kinds of DOM traversing methods beyond single entries and get values for entire channels or the site as a whole.
    – Jmorriso
    Commented Apr 28, 2012 at 19:06

1 Answer 1

1

There's many solutions but I have a few in mind that may help you out. I'll just show the one I like really well that I even use for my own site.

One solution is to make a count column in tables you are interested in that is automatically updated when someone posts or does something. You can also make a new table called globalcount or whatever that counts everything site wide. This can then later just be displayed. You would need to first have a method/function of counting words and such if you want that info. And when someone makes a post, just count one up from the previous.

The above is what I use. I use a misc table (It has one row that contains all the data. You could instead make each row contain your info like 'name' 'value') that looks something like:

(`views`, `totalusers`, `totalgroups`, `totalthreads`, `totalposts`, `totalarticles`, `totalcomments`, `totalpms`, `activeusercount`)

And in something like my 'news' table I use 'totalcomments' to count the local comments posted in that article. So I have both the local and global comments.

In my case, if I wanted to update 'totalusers' in the 'misc' table after a new user registers, I'd just call my $misc array and go: $newtotalusers = intval($misc['totalusers'] + 1);

mysql_query("UPDATE `misc` SET `totalusers`='$newtotalusers'");

Or you could instead just use "totalusers+1".

Same can be done with any other thing you wish to do, such as with any file count or visa versa. Hope this helps :)

One last thing, you could also make a script that in the case the data becomes off because of an error that would update and fix any table's count values.

3
  • Thanks for the ideas Superderek! Databases / MySql / tables are without a doubt the aspect of all this I have the least experience / familiarity with as I haven't done any custom work with them in the past. So the truth is though what you've laid out here sounds sensible I'm not really able to grasp how I'd go about implementing a pure database solution like this (adding tables, tying them to counting method/function, getting the data into the tables, etc, etc). I'll certainly look into it a bit further though, so thanks for the input!
    – Jmorriso
    Commented Apr 28, 2012 at 19:29
  • No problem. If you want, I can send you some more examples that are more closer to home. I used to not know much about databases myself a year and a half ago. As with all things, practice practice practice! I created my own custom board within 3 or so months but it sure had its fair share of errors and lessons learned. So I am definitely willing to help others avoid things I did wrong and to help with good solutions. All while teaching, of course. :)
    – Scrydan
    Commented Apr 28, 2012 at 19:48
  • Feel free to send me any specific ideas/examples you'd like to share (keeping in mind, of course, it's plugging into an expressionengine instal using MySql). I'm no closer to getting a handle on this so any deeper guidance would be great. Thanks Derek.
    – Jmorriso
    Commented May 4, 2012 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.