Wordpress Steemit Theme Hack

in #steemit6 years ago (edited)

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, $cachefolder) {

$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() - $cachetime < filemtime($cachefile)) {
$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, 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 = curl_exec($ch);

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

$fp = fopen($cachefile, 'w');
fwrite($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 = $post_slug=$post->post_name;
$steemuser = "wolfeblog" ;
$cachefolder = "/home/myuseracct/cache/" ;

SteemExtra($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, $steemuser, $cachefolder) {

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

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

$steemdata = json_decode($json,true) ;

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

if($status == 200) {

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

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

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

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

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

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

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

$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($total_payout_value, $total_pending_payout_value, $created, $url, $curator_payout_value)."<br>" ;

$display .= "Supporters: " ;
foreach($supporters as $voter) {
$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
Sort:  

To see a live version of this, on this actual post go here:

http://danwolfe.me/wordpress-steemit-theme-hack.html

I was checking to see who was voting for my zombie game and found this page. The link above goes to a "page not found" error.
I sure envy people like you who know all this programming stuff. I love that quote on your blog about specialization being for insects, but with limited time on Earth, it is impossible to learn everything. I'm trying but things in the computer field change so rapidly its a full-time job just trying to keep up with the changes. I'm falling behind in Search Engine Optimization and still haven't really done anything with HTML5... too many distractions! So much to learn and do!

Yup! It would be great if someone made a theme for us using your hack.

I need to rewrite the hack, I might be able to get to it next week, but work has taken over my life right now. Steem Press plugin for wordpress is current the best post to steemit, (currently working on @prepperbot ) As for the reverse, getting info from the API as this hack was set up, the API changed, so I need to redo it.

Ah... the way of the Internet... everything is changing so rapidly! It is difficult to keep up. I'm way behind on my gardening and have taken on a new project to help a friend with art assets for a video game (and I'm no artist, so I'm very slow).

thank for your respon

Impressive! Thanks for sharing

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.032
BTC 59110.01
ETH 2990.61
USDT 1.00
SBD 3.72