• Resolved Marcomail

    (@marcomail)


    I’ve installed a plugin to count click on link of all the submitted article, when i publish an article it change the link and other things…i don’t understand how can do this, because the plugin is a list of function and stop, it has a table to count click….how can do to parse the content of my article ? I ask this because i have an external form to submit article and the content is not filtered…so the plugin doesn’t work…it works only when i publish an article from the dashboard

    function wp_ozh_click_parse ($html="", $all=0) {
    global $wp_ozh_click, $doing_rss;

    preg_match_all ('/[^=]{1,}="[^"]+"/', $html, $wp_ozh_click['link']);
    foreach ($wp_ozh_click['link'][0] as $pair) {
    list ($tag , $value) = explode ("=", $pair , 2);
    $wp_ozh_click['link'][trim($tag)]=trim($value, '"');
    }
    unset ($wp_ozh_click['link'][0]);

    $wp_ozh_click['modify_href'] = 0;
    // do we want to display clicks ?
    if ( !isset($wp_ozh_click['link']['count']) || $wp_ozh_click['link']['count'] != "0" ) {
    if (
    ( ($all == 1) && (eregi("^[a-z]+://", $wp_ozh_click['link']['href'])) )
    ||
    ( isset($wp_ozh_click['link']['count'] ) )
    ) {
    $wp_ozh_click['modify_href'] = 1;
    }
    }

    if ($wp_ozh_click['modify_href']) {
    if ( (!isset($wp_ozh_click['link']['count']) && $wp_ozh_click['track_all_links'] && $wp_ozh_click['in_title'] ) || ( $wp_ozh_click['in_title'] && $wp_ozh_click['link']['count']=="1" ) || stristr($wp_ozh_click['link']['count'],'title') ) {
    if (isset($wp_ozh_click['link']['title'])) {
    $wp_ozh_click['link']['title']= $wp_ozh_click['link']['title'] . " (" . wp_ozh_click_getclicks($wp_ozh_click['link']['href']) . ")";
    } else {
    $wp_ozh_click['link']['title']= "(" . wp_ozh_click_getclicks($wp_ozh_click['link']['href']) . ")";
    }
    }
    if ( (!isset($wp_ozh_click['link']['count']) && $wp_ozh_click['track_all_links'] && $wp_ozh_click['in_plain'] ) || ( $wp_ozh_click['in_plain'] && $wp_ozh_click['link']['count']=="1" ) || stristr($wp_ozh_click['link']['count'],'inline') ) {
    $wp_ozh_click['after'] = ' <span class="hitcounter">(' . wp_ozh_click_getclicks($wp_ozh_click['link']['href']) . ')</span>' ;
    }

    if ($doing_rss) $wp_ozh_click['method'] = 2;

    switch ($wp_ozh_click['method']) :
    case 1 :
    $wp_ozh_click['link']['onclick'] = "window.location='". $wp_ozh_click['file'] . "?" . $wp_ozh_click['link']['href'] . "'; return false";
    break;
    case 2 :
    $wp_ozh_click['link']['href'] = $wp_ozh_click['file'] . "?" . $wp_ozh_click['link']['href'] ;
    break;
    case 3 :
    $wp_ozh_click['link']['onmouseover']="javascript:window.status='". $wp_ozh_click['link']['href'] ."'; return false;" ;
    $wp_ozh_click['link']['onmouseout']="javascript:window.status=''; return false;" ;
    $wp_ozh_click['link']['href'] = $wp_ozh_click['file'] . "?" . $wp_ozh_click['link']['href'] ;
    endswitch;

    unset ($wp_ozh_click['link']['count']);
    }

    $html='';
    foreach ($wp_ozh_click['link'] as $key => $value) {
    $html .= $key . "=\"" . $value . "\" ";
    }
    $html=trim($html);
    return '<a '. $html .'>';
    }

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Instead of modifying the links when you publish the post, why not modify them when the post is actually displayed instead?

    Try this for an example of how filters work:
    function my_filter($content)
    {
    $content = "Test function".$content;
    return $content;
    }
    add_filter('the_content','my_filter');

    This will modify the content of all your posts when they are shown to users. $content will contain the content of the posts. So you can look for your anchor tags and hrefs there, and add the code as needed, on the fly. Works no matter how you publish, because it’s not happening when you publish.

    Also, if you decide to turn it off later, all your links in posts won’t be messed up, since the actual posts themselves are unmodified.

    Another advantage to filters is that if you write them generically enough, you can apply them to more than one thing. Let’s say you wanted to now apply the same filter to comments, so you could track those as well. Just add this line:
    add_filter('comment_text','my_filter');
    And it’s done.

    Look here for more info on filters: https://codex.www.ads-software.com/Filters

    Thread Starter Marcomail

    (@marcomail)

    Thanks Otto, for now i would use this plugin, i’m not an expert of php to modify it.

    I think this is the filter at the bottom of the plugin:

    if ($wp_ozh_click[‘do_posts’])
    add_filter(‘the_content’, ‘wp_ozh_click_modifyhrefs’, 10);

    How can i integrate this filter in my script ? I’ve the_content saved in $post-content, you can see this in template-functions-post.php

    $post_content = apply_filters(‘content_save_pre’, $post_content);

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    I don’t understand why you’re changing things around if this is somebody else’s plugin. All you should have to do is to install it, activate it, and read the instructions with the plugin.

    It looks like he’s already adding a filter to the content from what you posted, so editing it and screwing around with it is probably not necessary.

    Thread Starter Marcomail

    (@marcomail)

    MMmmmmmm the problem is not the plugin…i’ve a separated page that i use to quick submit article outside the dashboard.

    i try to include the filter but it doesn’t work

    $post_content = apply_filters(‘the_content’, $post_content);

    why ? i’ve included two files at the top of this page:

    require_once(‘wp-blog-header.php’);
    require_once(‘wp-admin/admin-functions.php’);

    Thread Starter Marcomail

    (@marcomail)

    i try to use directly the function but is the same

    $post_content = wp_ozh_click_modifyhrefs ($post_content);

    Thread Starter Marcomail

    (@marcomail)

    is possible the problem is the string:

    $post_content = "<a><img src=\"" . $rel_path . $fileuploaded . "><a>" ;</a>

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Why this function don’t work with my script’ is closed to new replies.