formmailer Posted November 18, 2011 Share Posted November 18, 2011 Hi, I am planning to build a module to get the Top Keywords for a page from Piwik (open source alternative for Google Analytics, http://piwik.org) When finished the module should provide the same as the code below + css class references in order to make a tag cloud possible. <?php // This function will call the API to get best keyword for current URL. // Then it writes the list of best keywords in a HTML list function DisplayTopKeywords($url = "") { // Do not spend more than 1 second fetching the data @ini_set("default_socket_timeout", $timeout = 1); // Get the Keywords data $url = empty($url) ? "http://". $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] : $url; $api = "http://www.my-statistics-domain.com/piwik/?module=API&method=Referers.getKeywordsForPageUrl&format=php&filter_limit=10&token_auth=f0b2a0sfhgsfga4523675ab4c01aff6d4a&date=previous1&period=week&idSite=3&url=" . urlencode($url); $keywords = @unserialize(file_get_contents($api)); if($keywords === false || isset($keywords["result"])) { // DEBUG ONLY: uncomment for troubleshooting an empty output (the URL output reveals the token_auth) // echo "Error while fetching the <a href='$api'>Top Keywords from Piwik</a>"; return; } // Display the list in HTML $output = "<h2>Top Keywords for <a href='$url'>$url</a></h2><ul>"; foreach($keywords as $keyword) { $output .= "<li>". $keyword[0]. "</li>"; } if(empty($keywords)) { $output .= "Nothing yet..."; } $output .= "</ul>"; echo $output; } DisplayTopKeywords(); Since I am new to making moldules I figured that using an existing module as an example would be a good idea. I looked at some modules and found that Ryan's MarkupRSS module might be a good example to start with (since it contains a way to configure some settings from the adminarea, in my example would the Piwik URL be something that should be configured from the admin). But before I start I would like to ask if there are special things to keep in mind and check if you agree that the MarkupRSS module would be a good example for my module. Thanks in advance! /Jasper Updated "goal of the module" Link to comment Share on other sites More sharing options...
ryan Posted November 18, 2011 Share Posted November 18, 2011 Jasper, is this something where the output would ultimately be used for the front end of the site or the admin? I usually take the Helloworld.module as my starting point. But assuming it's not ultimately intended to be an admin Process module, then I think the MarkupRSS is a fine starting point, especially given that you want to make a Configurable Module. If you use MarkupRSS, you'll want to delete everything after the init() function, up until the getModuleConfigInputfields() function, and that will give you a better skeleton to start from. Link to comment Share on other sites More sharing options...
formmailer Posted November 18, 2011 Author Share Posted November 18, 2011 You are right Ryan, it will be a front end module. Hopefully the result will be a tag (or keyword) cloud with popular searches that users used in search engines to find the site. I'll start working from the MarkupRSS module and will see where it brings me. /Jasper Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now