4th Street Bar Hive-Bar

Hive-Bar Powered by Hive beta-fdb5b5b

Community post

Wordpress Steemit Theme Hack

wordpress_1511398505-768x508.jpgSo I have to admit, waiting for the Steem token system to come out sometime in the next year, has been just to much to bare. So I wrote a set of functions to add to my word-press theme to add a bit of an information block to posts that I push to Steem, mostly for my fiction writings. (I am still messing around with the code for the Steem based banner advertisement system as well.)

The first function is just a curl cache implication, I do this to reduce the amount of loads that steemit.com ends up getting. (I'm a nice guy after all) make sure you set the correct full path to the cache folder, mine is above the public folder.

<?php

function CurlByCache(url,url,cachefolder) {

cachefile=cachefile =cachefolder.md5($url).".curl.cache.txt" ;

// define how long we want to keep the file in seconds. I set mine to 5 hours.
$cachetime = 18000;
// Check if the cached file is still fresh. If it is, serve it up and exit.
if (file_exists(cachefile)&&time()-cachefile) && time() -cachetime < filemtime($cachefile)) {
cache=filegetcontents(cache = file_get_contents(cachefile);
}
// if there is either no file OR the file to too old, render the page and capture the HTML.
ob_start();

$ch = curl_init();

// set url
curl_setopt(ch,CURLOPTURL,ch, CURLOPT_URL,url);

//return the transfer as ain plain txt encoding
curl_setopt($ch, CURLOPT_ENCODING, "text/plain");

//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// $output contains the output string
cache=curlexec(cache = curl_exec(ch);

// close curl resource to free up system resources
curl_close($ch);

fp=fopen(fp = fopen(cachefile, 'w');
fwrite(fp,fp,cache);
fclose($fp);
// finally send browser output
ob_end_flush();

return $cache ;
}

?>

The second function grabs the json encoding of the post on steemit itself. You need to set the username, (without the @) and the steemit permalink (slug) for this to work, but if you are publishing to steemit via the wordpress plugin written by @recrypto then just make sure you use the wordpress $post->post_name in your themes single.php file like so:

global $post;
steemslug=steemslug =post_slug=$post->post_name;
$steemuser = "wolfeblog" ;
$cachefolder = "/home/myuseracct/cache/" ;

SteemExtra(steemslug,steemslug,steemuser, $cachefolder) ;

Within the function below I set the class id for the division to author2 you might need to change this to fit your style.css file, mine already had an author id so I just added the author2 to it. Remember that these functions should be added to a child theme instead of the original since any updates might delete your hack.

function SteemExtra(steemslug,steemslug,steemuser, $cachefolder) {

datalink="https://steemit.com/curation/@".datalink = "https://steemit.com/curation/@".steemuser."/".$steemslug.".json";

json=CurlByCache(json = CurlByCache(datalink, $cachefolder) ;

steemdata=jsondecode(steemdata = json_decode(json,true) ;

// check status first
status=status =steemdata['status'] ;

if($status == 200) {

$display = "<div id='authorbox2'>" ;
// created
created=created =steemdata['post']['created'] ;
timestamp=strtotime(timestamp = strtotime(created) ;
created=date("Fj,Y,g:ia",strtotime(created = date("F j, Y, g:i a", strtotime(created));

// tags ... [tags]
tags=tags =steemdata['post']['json_metadata']['tags'] ;
if(!is_array($tags)) {
tags=explode("",tags = explode(" ",tags);
}
display.="<p>ThispostwasonpublishedonSteemit.com<b>(".display .= "<p>This post was on published on Steemit.com <b>(".created.")</b> under:</p><p>" ;
foreach(tagsastags astag) {

display.="<ahref='https://steemit.com/trending/".display .= " <a href='https://steemit.com/trending/".tag."' target='_blank'>#".$tag."</a>" ;
}
$display .= "</p><p>";
// steemit.com/[url]
url=url =steemdata['post']['url'] ;

// [pending_payout_value]
totalpayoutvalue=total_payout_value =steemdata['post']['total_payout_value'] ;

// total_pending_payout_value
totalpendingpayoutvalue=total_pending_payout_value =steemdata['post']['total_pending_payout_value'] ;

// supporters [active_votes][$n][voter]

curatorpayoutvalue=curator_payout_value =steemdata['post']['curator_payout_value'] ;

supporters=supporters =steemdata['post']['active_votes'] ;
// sort by highest payout? done by the json already?

$display .= "Posts on steemit earn the author Steem coin, a crypto-currency. ".
SteemPayout(totalpayoutvalue,total_payout_value,total_pending_payout_value, created,created,url, $curator_payout_value)."<br>" ;

$display .= "Supporters: " ;
foreach(supportersassupporters asvoter) {
display.="<ahref='http://steemit.com/@".display .= " <a href='http://steemit.com/@".voter['voter']."' target='_blank'>@".$voter['voter'].'</a>' ;
}

$display .= " </p></div>";

echo $display ;
}
}

As an added bonus you can add a do_shortcode('') within the last $display above (google the do_shortcode('') instructions, and see the bottom of this post for a link to the steem to US dollar convertor)

Hopefully, @recrypto will steal this code and turn it into a plugin for the non geeks. ;)

  • wolfe
23 upvotes $0.18

Replies (6)

Review before signing

Posting as . Signing with . Keychain permission: Posting. Hive Keychain will ask you to approve this action next.


  
Technical details

Operation fingerprint: