Exemple #1
0
        $link_obj = new blcLink($url);
        //Creates or loads the link
        $instance->set_link($link_obj);
        $instances[] = $instance;
        return $instances;
    }
    /**
     * Change one URL to another (just returns the new URL). 
     *
     * @param string $content The old URL.
     * @param string $new_url The new URL.
     * @param string $old_url Ignored.
     * @param string $old_raw_url Ignored. 
     *
     * @return array|WP_Error 
     */
    function edit($content, $new_url, $old_url, $old_raw_url)
    {
        return array('content' => $new_url, 'raw_url' => $new_url);
    }
    /**
     * For URL fields, "unlinking" simply means blanking the field.
     * (However, invididual link containers may implement a different logic for those fields.)
     */
    function unlink($content, $url, $raw_url)
    {
        return '';
    }
}
blc_register_parser('url_field', 'blcUrlField');
Exemple #2
0
    /**
     * Change the URL in a metadata field to another one.
     * 
     * This is tricky because there can be multiple metadata fields with the same name
     * but different values. So we ignore $content (which might be an array of multiple
     * metadata values) and use the old raw_url that we stored when parsing the field(s)
     * instead.
     *
     * @see blcMetadataParser::parse()
     *
     * @param string $content Ignored.
     * @param string $new_url The new URL.
     * @param string $old_url Ignored.
     * @param string $old_raw_url The current meta value. 
     *
     * @return array|WP_Error 
     */
    function edit($content, $new_url, $old_url, $old_raw_url)
    {
        //For multiline fields (like 'enclosure') we only want to change the first line.
        $lines = explode("\n", $old_raw_url);
        array_shift($lines);
        //Discard the old first line
        array_unshift($lines, $new_url);
        //Insert the new URL in its place.
        $content = implode("\n", $lines);
        return array('content' => $content, 'raw_url' => $new_url);
    }
}
blc_register_parser('metadata', 'blcMetadataParser');
Exemple #3
0
    {
        $url = $matches[3];
        //Does the URL match?
        if ($url == $this->old_url) {
            return '';
            //Completely remove the IMG tag
        } else {
            return $matches[0];
            //return the image unchanged
        }
    }
    /**
     * Get the link text for printing in the "Broken Links" table.
     * Sub-classes should override this method and display the link text in a way appropriate for the link type.
     *
     * @param blcLinkInstance $instance
     * @param string $context
     * @return string HTML 
     */
    function ui_get_link_text($instance, $context = 'display')
    {
        $text = __('Image', 'broken-link-checker');
        $image = sprintf('<img src="%s/broken-link-checker/images/image.png" class="blc-small-image" alt="%2$s" title="%2$s"> ', WP_PLUGIN_URL, esc_attr($text));
        if ($context != 'email') {
            $text = $image . $text;
        }
        return $text;
    }
}
blc_register_parser('image', 'blcHTMLImage');
Exemple #4
0
     * Helper function for blcHtmlLink::multi_edit()
     * Applies the specified callback function to each link and merges 
     * the result with the current link attributes. If the callback returns
     * a replacement HTML tag instead, it will be stored in the '#new_raw'
     * key of the return array. 
     *
     * @access protected
     *
     * @param array $link
     * @param array $info The callback function and the extra argument to pass to that function (if any).
     * @return array
     */
    function execute_edit_callback($link, $info)
    {
        list($callback, $extra) = $info;
        //Prepare arguments for the callback
        $params = array($link);
        if (isset($extra)) {
            $params[] = $extra;
        }
        $new_link = call_user_func_array($callback, $params);
        if (is_array($new_link)) {
            $link = array_merge($link, $new_link);
        } elseif (is_string($new_link)) {
            $link['#new_raw'] = $new_link;
        }
        return $link;
    }
}
blc_register_parser('link', 'blcHTMLLink');