function piwiktracking_javascript_tracking()
{
    $piwik_url = esc_attr(piwiktracking_get_option('piwikurl'));
    $site_id = esc_attr(piwiktracking_get_option('siteid'));
    if (!$piwik_url && !$site_id) {
        return;
    }
    $linktracking = piwiktracking_get_option('linktracking') ? '_paq.push(["enableLinkTracking"]);' . "\n" : '';
    $subdomaintracking = piwiktracking_get_option('subdomaintracking') ? '_paq.push(["setCookieDomain", "*.' . piwiktracking_get_domain() . '"]);' . "\n" : '';
    $prependsitedomain = piwiktracking_get_option('prependsitedomain') ? '_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);' . "\n" : '';
    $hidealiasclicks = piwiktracking_get_option('hidealiasclicks') ? '_paq.push(["setDomains", ["*.' . piwiktracking_get_domain() . '"]]);' . "\n" : '';
    $cliensidednt = piwiktracking_get_option('clientsidednt') ? '_paq.push(["setDoNotTrack", true]);' . "\n" : '';
    ?>
	<!-- Piwik -->
	<script type="text/javascript">
		var _paq = _paq || [];
		<?php 
    echo $prependsitedomain;
    ?>
		<?php 
    echo $subdomaintracking;
    ?>
		<?php 
    echo $hidealiasclicks;
    ?>
		<?php 
    echo $cliensidednt;
    ?>
		_paq.push(["trackPageView"]);
		<?php 
    echo $linktracking;
    ?>
		(function() {
			var u = (("https:" == document.location.protocol) ? "https" : "http") + "://" + "<?php 
    echo $piwik_url;
    ?>
";
			_paq.push(["setTrackerUrl", u + "piwik.php"]);
			_paq.push(["setSiteId", "<?php 
    echo $site_id;
    ?>
"]);
			var d = document, g = d.createElement("script"), s = d.getElementsByTagName("script")[0];
			g.type = "text/javascript";
			g.defer = true;
			g.async = true;
			g.src = u + "piwik.js";
			s.parentNode.insertBefore(g, s);
		})();
	</script>
	<!-- End Piwik Code -->
	<?php 
}
function piwiktracking_create_setting($args = array(), $before = '<div class="settings-row">', $after = '</div>')
{
    extract($args);
    $settings_field = isset($groupid) ? piwiktracking_get_option($groupid) : piwiktracking_get_option($id);
    $field_value = isset($groupid) ? $settings_field[$id] : $settings_field;
    $prefix = 'piwiktracking_settings';
    $setting_id = isset($groupid) ? $prefix . '[' . $groupid . '][' . $id . ']' : $prefix . '[' . $id . ']';
    $html = $before . "\n";
    switch ($type) {
        case 'text':
            if (isset($label)) {
                $html .= "\t" . '<label for="' . $id . '">' . $label . '</label>' . "\n";
            }
            $html .= "\t" . '<input type="text" id="' . $id . '" name="' . $setting_id . '" class="' . $class . '" value="' . esc_attr($field_value) . '" >' . "\n";
            if (isset($desc)) {
                $html .= '<span class="description">' . esc_attr($desc) . '</span>' . "\n";
            }
            break;
        case 'checkbox':
            if (isset($label)) {
                $html .= "\t" . '<label for="' . $id . '">' . $label . '</label>' . "\n";
            }
            $html .= "\t" . '<input type="checkbox" id="' . $id . '" name="' . $setting_id . '" value="' . $value . '"' . checked($value, $field_value, false) . ' >' . "\n";
            if (isset($desc)) {
                $html .= '<span class="description">' . esc_attr($desc) . '</span>' . "\n";
            }
            break;
        case 'select':
            if (isset($label)) {
                $html .= "\t" . '<label for="' . $id . '">' . $label . '</label>' . "\n";
            }
            $html .= "\t" . '<select id="' . $id . '" name="' . $setting_id . '">';
            foreach ($options as $value => $name) {
                $html .= "\t\t" . '<option value="' . esc_attr($value) . '"' . selected($value, $field_value, false) . '>' . esc_attr($name) . '</option>' . "\n";
            }
            $html .= "\t" . '</select>' . "\n";
            if (isset($desc)) {
                $html .= '<span class="description">' . esc_attr($desc) . '</span>' . "\n";
            }
            break;
        default:
            break;
    }
    $html .= $after . "\n";
    return $html;
}
 function piwiktracking_admin_notices()
 {
     $piwik_url = piwiktracking_get_option('piwikurl');
     $site_id = piwiktracking_get_option('siteid');
     if (!$piwik_url || !$site_id) {
         if (!$piwik_url && !$site_id) {
             $text = __('Please set your <strong>Piwik URL</strong> and your <strong>Piwik SiteID</strong> on the <a href="options-general.php?page=piwiktracking-settings-page"><strong>Piwiktracking Settings Page</strong></a>.', 'piwiktracking');
         }
         if ($piwik_url && !$site_id) {
             $text = __('Please set your <a href="options-general.php?page=piwiktracking-settings-page"><strong>Piwik SiteID</strong></a>.', 'piwiktracking');
         }
         if (!$piwik_url && $site_id) {
             $text = __('Please set your <a href="options-general.php?page=piwiktracking-settings-page"><strong>Piwik URL</strong></a>.', 'piwiktracking');
         }
         $out = '<div class="updated fade">';
         $out .= '<p>' . $text . '</p>';
         $out .= '</div>';
         echo $out;
     }
 }