Extending Heise SocialSharePrivacy to pass a dynamic title to twitter

Yesterday I had a look at Heise SocialSharePrivacy and experimented around with it (probably will integrate it here via a plugin) but one think I was missing was a way to use it on a list of items, while having different titles for the twitter text, not using the current pages title. Currently it only allows for a static title or a function. But the function was worthless in this case, since I wanted to use the title each specific link.

An example based on their ones to describe it a bit more.

<div class="anriss">
    <h3><a href="http://www.heise.de">heise</a></h3>
    <p>lorem ipsum</p>
    <div class="social"></div>
</div>

<div class="anriss">
    <h3><a href="http://www.heise.de/security/">heise security</a></h3>
    <p>dolor sit amet</p>
    <div class="social"></div>
</div>

<script>
$(".social").socialSharePrivacy({
    uri : function(context) {
        return $(context).parents(".anriss").find("h3 a").attr("href");
    }
    service : {
        twitter: {
            'tweet_text': function (context) {
                return $(content).parents(".anriss").find("h3 a").text();
            }
        }
    }
});
</script>

All you need to do to get it working is changing line 196 of the jQuery Plugin from

text = text();

to

text = text(context);

Now you have access to the context inside your function.

I just mailed it to Heise, let’s see what they thing about it.

ReflectionException: Method PHPUnit_Framework_Warning::Warning() does not exist

If you ever get

ReflectionException: Method PHPUnit_Framework_Warning::Warning() does not exist

That may be because you are using @dataProvider and your dataProvider returns the data in an invalid way.

This may be caused by forgetting one dimension in the returned array when using only a single value as parameter for the test.

Wrong:

<?php

public function myDataProvider()
{
    $data = array();

    $data[] = 'some value i want to pass as param';
    $data[] = 'another value i want to pass as param';

    return $data;
}

Right:

<?php

public function myDataProvider()
{
    $data = array();

    $data[] = array('some value i want to pass as param');
    $data[] = array('another value i want to pass as param');

    return $data;
}

Switched to WordPress

I never thought I would switch to WordPress.

But there were several causes why i switched from something self-developed to WordPress:

  • Get to know WordPress better
  • Don’t waste time inventing features wp already has
  • Just have more time for other things
So from now one, this is WordPress Zone.

Identifier “request_context” is not defined with silex

If you ever receive a message like:

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Identifier "request_context" is not defined.' in phar:///.../vendor/silex/silex.phar/vendor/pimple/lib/Pimple.php on line 12

And it is not directly about the AsseticExtension in Silex-Extensions,it is probably because some of your code wants access to the url_generator – in my case it was my own Routing-Extension for twig.

First some background informations why it happens.

The problem is that some Extensions – like the url_generator – need access to the requestContext, which is defined after you have already called $app->run(); so in your bootstrap-code that probably has not happened.

The creation of the RequestContext is inside Silex\Application::onKernelRequest (Line may differ – works current master).

There are too solutions to the problem – either you lazyload the url_generator by passing in the app instead of the url_generator and access it only when you really need it or you let Silex run your code inside Silex\Application::onKernelRequest by putting it in a closure as a callback to add it to the dispatcher as a listener for the SilexEvents::BEFORE-Event – which is triggered inside Silex\Application::onKernelRequest.

Netbeans, Symfony, Xdebug and the magical file_link_format

Originally I was looking for a solution to get Chromium to open Files in Netbeans directly from symfony1 stack traces, because some time ago in a video I had see how it was done for other editors.

Here we have two screenshots for a symfony1 stack trace, which is shown in dev-mode when an error happens or an exception is thrown but not caught and a xdebug stack trace:

For symfony1 to create the links you need the following in settings.yml

all:
  .settings:
    file_link_format:       netbeans://%f?line=%l

For xdebug you need to have html_errors = On in your php.ini set xdebug.file_link_format

xdebug.file_link_format = "netbeans://%f?line=%l"

The next thing we need to do is to create a new url-handler in Gnome’s gconf.

gconftool-2 -t string --set /desktop/gnome/url-handlers/netbeans/command "/home/robo47/netbeans-7.0/bin/netbeans --open %s"
gconftool-2 -t bool --set /desktop/gnome/url-handlers/netbeans/enabled true
gconftool-2 -t bool --set /desktop/gnome/url-handlers/netbeans/needs_terminal false

Screenshot of the url-handler in Gnome’s Configuration Editor (/usr/bin/gconf-editor)

netbeansprotocol.sh will do the parsing – a snippet I found in my desktop-wiki from a search for the same problem some time ago – it probably can be done in a nicer way – but it works (for me).

#!/bin/bash

url=$2
file=${url#*\/\/}
file=${file%?line=*}
line=${url#*line=}

/home/robo47/netbeans-7.0/bin/netbeans --open $file:$line

Further Links: