Personal plugin showcase (yes, I'm an attention grabbing git)

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Personal plugin showcase (yes, I'm an attention grabbing git)
« on October 2nd, 2011, 06:40 PM »
Heh, well, the title might have given you a clue what's going on.

In order to more thoroughly test the plugin system, and indeed a few other things while I'm at it, I'm slowly going to be writing some plugins for Wedge. Most of them won't be huge, in fact I suspect a number of them will fall into the tweaks category, and no doubt I'm going to have to patch them as Wedge itself evolves, but it's a good indicator that I'm on the right direction if I can build these.

Two things:
1. This IS NOT a requests thread. DO NOT request plugins. I'm not taking requests, nor functionality requests for things I've already mentioned here. They will be published when I'm ready and not before.

2. I'm not sharing the plugins here. Apart from the fact that they're likely to need changes as Wedge evolves, you can't even get Wedge yourself yet. And even if you could, it's likely that something will break as things go on, so that until Wedge is at a stable position, there's no point in my handing out anything more than tiny code samples.


Anyway, the first one is a quick hack of the 'Users Online Today' functionality that's used here, though it's without configuration, options or indeed anything other than the absolute minimum functionality.

This is also interesting for me because it's the first time I've bent the rules about code placement. I think I've also found something up with the template skeleton functionality but that's another matter entirely.

Controversially, the entirety of the template and language strings are in the one file. Given that the template is 10 lines of code (and only 2 PHP statements, a global and an echo), and that I'm using 5 language strings out of nicety as 2 or 3 would probably do, with the entire plugin weighing in at 75 lines... having three files (source, language, template) seems just wasteful, and definitely inefficient.

But anyhow, here's a screenshot. It's nothing special - but it does work (after I added a hook to the board index, though I think I'm going to change that hook a bit to suit something else I have in mind). It won't look much different even if I do change that hook, though.

 users_online_today.png - 22.04 kB, 312x436, viewed 373 times.

When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

Dr. Deejay

  • Happy new year all!
  • Posts: 118

['Daniel']

  • It's about time I change this...
  • Posts: 162

spoogs

  • Posts: 417
Stick a fork in it SMF

billy2

  • Trying to earn brownie points for a lads trip to the Red Sea. Minus 1 already - just for asking!!
  • Posts: 350
<br /><br />cough, cough.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Personal plugin showcase (yes, I'm an attention grabbing git)
« Reply #5, on October 3rd, 2011, 05:44 PM »
OK, second one. I'm not quite so happy with this, though, but it works well enough, IMO.

Again, no edits. Again, a single file. I couldn't even be bothered to do language string hacking on this one :/

It has a couple of bugs, namely that it won't work when pretty URLs is enabled because it looks for index.php in the URL, and that on layouts that don't have the same header structure as the default theme/skin combo (namely Wedge->Wine->Warm), it will fail because it isn't smart enough to look for a fallback. But for a quick 45 minutes hacking together, I think it works acceptably well.


For the record: Wedge is a theme. Wine is the default skin in that theme. Warm, WorldWind and Wuthering are all skins that inherit from Wine. (Warm and Wuthering are Nao's creations, as is Wine. WorldWind is mine, but it's unfinished and needs more work, especially now the template skeleton stuff is available)

 theme_selector.png - 55.01 kB, 596x498, viewed 314 times.


Dr. Deejay

  • Happy new year all!
  • Posts: 118

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

Nao

  • Dadman with a boy
  • Posts: 15,591
Re: Personal plugin showcase (yes, I'm an attention grabbing git)
« Reply #8, on October 3rd, 2011, 10:52 PM »
LOL. Technically i had a quick skin selector in my to-do list. I guess I can drop it now ;)

Is it the same HTML as the dropdown I made on the admin area? If yes we might wanna consider putting it into a sub function...

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Personal plugin showcase (yes, I'm an attention grabbing git)
« Reply #9, on October 3rd, 2011, 11:01 PM »
It's really not that polished. I certainly wouldn't publish it, even knowing my earlier published mods weren't nearly as polished.
Quote
Is it the same HTML as the dropdown I made on the admin area? If yes we might wanna consider putting it into a sub function...
See for yourself. ThemeSelector.php - the entire plugin.

Code: [Select]
<?php

if (!defined('WEDGE'))
die('Hacking attempt...');

function 
themeSelector()
{
global $txt$user_info$language$modSettings$context$scripturl;

// Will need this whatever.
loadSource('Themes');

$temp cache_get_data('arantor_theme_listing'180);
if ($temp === null)
{
// Get all the themes...
$request wesql::query('
SELECT id_theme AS id, value AS name
FROM {db_prefix}themes
WHERE variable = {string:name}'
,
array(
'name' => 'name',
)
);
$temp = array();
while ($row wesql::fetch_assoc($request))
$temp[$row['id']] = $row;
wesql::free_result($request);

// Get theme dir for all themes
$request wesql::query('
SELECT id_theme AS id, value AS dir
FROM {db_prefix}themes
WHERE variable = {string:dir}'
,
array(
'dir' => 'theme_dir',
)
);
while ($row wesql::fetch_assoc($request))
$temp[$row['id']]['skins'] = wedge_get_skin_list($row['dir'] . '/skins');
wesql::free_result($request);

cache_put_data('arantor_theme_listing'$temp180);
}

// So, now we have a list of all the themes.
$context['themes'] = $temp;
loadBlock('header_theme_selector''header''add');
}

function 
template_header_theme_selector()
{
global $context$settings$txt;

echo '
Select a skin: <select name="boardtheme" id="boardtheme" onchange="changeTheme(this);" style="font-family: \'dejavu sans mono\',\'monaco\',\'lucida console\',\'courier new\',monospace">'
;

foreach ($context['themes'] as $theme)
{
echo '<option value="'$theme['id'], '"'$settings['theme_id'] == $theme['id'] && (empty($context['skin']) || $context['skin'] == 'skins') ? ' selected' '''>'$theme['name'], '</option>';
if (!empty($theme['skins']))
wedge_show_skins($theme$theme['skins'], 1$settings['theme_id'], $context['skin']);
}

echo '
</select>'
;

add_js('
function changeTheme (obj)
{
var sUrl = new String(window.location);
sUrl = sUrl.replace(/theme=([0-9]+\_[A-Z0-9\+\/\=]+);?/i, "");
var sAnchor = "";
var search = sUrl.search("#");

if(search != -1)
{
sAnchor = sUrl.substr(search);
sUrl = sUrl.substr(0, search);
}

var len = sUrl.length;
var lastchr = sUrl.charAt(len-1);
while ((lastchr == "?" || lastchr == ";") && len > 1)
{
len--;
lastchr = sUrl.charAt(len-1);
}
sUrl = sUrl.substr(0, len);

len = sUrl.length;

var themelink = "theme=" + obj.value + sAnchor;
var indexsearch = sUrl.search("/index.php");

if (indexsearch < len && indexsearch != -1)
window.location = sUrl + ((indexsearch == (len - 10)) ? "?" : ";") + themelink;
else
window.location = sUrl + ((sUrl.charAt(len-1) != "/") ? "/" : "") + "index.php?" + themelink;

return false;
}'
);
}

?>

So, yes, it does use your code but the amount of code that's duplicated, it's not worth making into a function. JS is not clever, not efficient, but it was hacked together quickly!

I find it hilarious that I have almost as much effort in loading the theme list than I do everything else...

billy2

  • Trying to earn brownie points for a lads trip to the Red Sea. Minus 1 already - just for asking!!
  • Posts: 350

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Personal plugin showcase (yes, I'm an attention grabbing git)
« Reply #11, on October 3rd, 2011, 11:08 PM »
Wait, what?

I haven't touched the theme in ages; so long that when I first wrote today's code, I spent 5 minutes debugging why my skin wasn't showing up, only for me to realise I never moved it into the skins/ folder, from the stylings/ folder it had. I don't recall exactly how far back it was that Nao renamed the folder but that - at least - is how long it's been since I even touched it...

billy2

  • Trying to earn brownie points for a lads trip to the Red Sea. Minus 1 already - just for asking!!
  • Posts: 350

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Personal plugin showcase (yes, I'm an attention grabbing git)
« Reply #13, on October 8th, 2011, 07:00 PM »
OK, today's little project is two-fold. Firstly, it's a plugin that provides reCAPTCHA. I'm not a huge fan of it personally, but I know some people are.

Secondly, in order to make it actually work, I had to write add some hooks. Currently it's done as four hooks injected into the control_create_verification and relevant generic control template, and I'm not sure I can make it any smaller, either, given the nature of the different operations.

Still, having implemented the hooks, I'm just working on the admin panel before tackling the proper integration (and thus testing my hooks, heh) and I thought I'd share what that looks like. It's not much in itself, but it will show a few other... hints... relating to other changes in the admin panel.[1]
 1. If you're wondering what I'm talking about, look at Admin > Configuration > Security and Moderation > Anti-Spam in 2.0 final or 2.0.1 and compare the difference. If you're still not clear what I'm getting at, post your questions/concerns here and I'll answer them. ;)

 wedge_recaptcha.png - 32.89 kB, 640x466, viewed 249 times.


Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Personal plugin showcase (yes, I'm an attention grabbing git)
« Reply #14, on October 8th, 2011, 08:22 PM »
And now I've implemented the rest, and as far as I can tell, it seems to work as expected.

Screenshot from IE8 attached. I'm not proud of this one particularly, because reCAPTCHA makes certain expectations that I had to work round, namely none of the usual JS functions could be used, the script has to be injected into the template where you want it displayed, rather than using any of the delay functions. Which sucks, especially in the quick reply since it'll actually load prior to any of the Wedge stuff, but it IS using the reCAPTCHA-own URL, so it should be cached.

It's also translatable, which is cool, and the language file is set up to allow that. Just need to throw a readme together before I commit it to the repo.
Posted: October 8th, 2011, 08:11 PM

In other news, yes, this is the quick reply dialogue. You can see one of the new CAPTCHA types in Wedge, an animated-fade-in style (designed and implemented by me), plus the ability to switch to the full editor in a snap.

I really need to make it styleable, though, I don't think I made it so either the plugin or the parent hooks actually are directly styleable (e.g. getting them centralised) but it's hardly a priority.

 wedge_recaptcha2.png - 27.92 kB, 640x454, viewed 231 times.