Tuesday, July 23, 2013

Plugin Admin Page

In some logical order of things (at least in my head) the next step after making the Plugins index page was making the Plugins admin page. Before I got on to that I had to change bit's and pieces all over the code. First of all I realized why the $_TABLES['table_name'] trick did not work, mainly because I did not add my tables to the list. /*feels ashamed*/. After fixing this I had to go on and find ALL the sqls used int the code and fix this. Additionally +Dirk Haun reminded me that I am missing some basic security for my lib-translator.php. As indicated before lib-translator.php will at the end be the collection of all the functions the plugin uses. So the security , the first defense line is this piece of code:



If you are interested in what the $function part is just go here.

Admin Page is not Index Page

Why I have to specify that the pages are not the same? Well because for a good part they do look alike.
Here is how the admin page could look like.

Lets break this page down to pieces to show what the differences are.

Quick Stats

On the Index page the user had preview of his own stats (and some for the plugin). Here it is all about general Plugin stats, on this particular screen shot the data is such:

Quick Stats

Translations submitted:150
Total votes:150
Most up votes:100
Users translating:2
Languages being translated:2
Translations with negative vote count:0
Basically it is self explanatory the nice part is the last row, the number of translations with negative vote count (approval count). At this point let me explain how approval count is generated. Every translation starts with a approval count of 1 (ap=1), the assumption is that the translation submitter would vote for his own translation. Every time a user hits the   the ap is increased by one, every time a user hits the ap is decreased by one. (In the case a user changes his vote from +1 to -1 ap=ap-2  or the other way around)
After the little detour, the last row in the quick stats indicates the number of negative votes, now the plugin will (said it here) delete translations automatically once they reach a certain negative approval count (e.g. -5), but here the admin gets a heads up so he can do something about the translation submitter. More about this later on.

The next part is the status and list of languages being translated. One thing missing here is the "Pack Language" button, this will be added later on and basically will pack the translation to a format Geeklog can use. 

Badges

The Index page displayed the current user's badges, the Admin page gives a view of all available badges. I put this here because the plan is to allow the page admin to change the badge image. The badges will be displayed on the user's profile(as for so many things in the known universe Geeklog has an API for that), and I wanted to give them a possibility to adjust the look of the bade to the look of the page. On some page, someone who submitted a lot of good translations could get the badge:

The table

About this part I am proud. I wanted the table not only to be a place where translations could be viewed I wanted it to actually be useful. So here the table is 
User (ASC)Language(ASC)TranslationUpvotes (ASC)Posted (ASC)
test_user1(block)Fake InputDaqmeynzhG932 hours agodelete
test_user1(block)Fake InputtkrLqNmeiL962 hours agodelete
test_user1(block)Fake InputwoXsaXTNtS602 hours agodelete
test_user1(block)Fake InputQfehQpttam542 hours agodelete
test_user1(block)Fake InputeyOCMyQJnI112 hours agodelete
<- Show previousShow next ->
The table will display a bunch of data. Which is nice but additionally I added sorting, changing the number of translations per page and blocking users. The sorting can be done by user, language, upvotes, post time and in ascending and descending order.


The code will basically just create the query for different parameters. I am a firm believer of avoiding code repetition, not because of the whole if it is in one place it is easier to update philosophy (I am not saying this is not a big benefit) but more because I want to believe that the code can indeed be 'smart'.

Why the blocked users?

I had a dream about a world where people would not spam, troll and inject - I am sure someone said it, but if not I just did.
The point is that although we would like to think that the plugin users will submit only what is expected that is not the case, that is why we (in general) do input validation, security checks and ... blocking users. The blocked user will be prevented from submitting translations, voting, all of his translations (and their votes) will be deleted and he will be stripped from his badges. If you get blocked this is how the plugin looks like:


The last part of the admin interface allows to show mercy upon the poor soul:

while (problem) { me.ask_for_help(); }

The My Badges section displays all the badges the user has acquired over time. We wont to use
Gamification here to encourage users to submit translations and vote translations.

The preliminary list of 'badges' a user can get is:
  • First translation
  • 10th, 50th, 100th... translation
  • First vote
  • Casting a vote which removes a translation
  • Getting more than 100 upvotes
  • Submitting more than 10 translations in a day
  • Submitting more than 20 translations in a day
  • Submitting translations 1, 7, 20 days in a row
  • Working on a language which is fully translated
This list will be a bit longer, If you have an idea for awards and designs please do send me an email or leave a comment.

Non related stuff

Sarajevo had it's second startup weekend this weekend. As this is a great opportunity to meet people with the same interests I was in line for it. Now someone might (and did say) : "You are crazy, you spend your weekend working and pay for it" - +Lasse Chor . Thinking about it , does seem a bit crazy. But even whit the back-pain (bending over a laptop for 2 days and I do mean bending), after having a couple of  0-100

 range bursts it was great and I can't wait to do it again. Not only did I get to meet some great people, even a real 'Googler' +Martin Omander , he was the man that made my team work together.
And I got to discover that I am not even that bad at presenting. Well I was but with quite a bit of a kick-start from +Nejra Plasto I got it somewhat down.
All in all a great weekend, and for the second time in my life I got to be called a marketing genius, and taking from whom I got this compliment I am proud.


But, I was and will be a programmer/developer first and then we can talk about all the other stuff.