· 9 years ago · Oct 04, 2016, 01:54 AM
1<?php
2
3namespace Craft;
4
5class TumblrController extends BaseController{
6
7 public function actionOffset(){
8
9 $offset = craft()->request->getRequiredParam('offset', null);
10
11 craft()->tumblr->getSubmissionData($offset);
12
13 $this->redirect($_SERVER['HTTP_REFERER']);
14 }
15}
16
17public function getSubmissionData($offset){
18
19$submission_data = array();
20
21// some variables that will be pretttty useful
22$settings = craft()->plugins->getPlugin('tumblr')->getSettings();
23$publicKey = 'example';
24$secretKey = 'example';
25$token = 'example';
26$tokenSecret = 'example';
27$callback_url = 'tumblr/callback';
28$blogName = 'example.tumblr.com';
29
30$client = new TumblrAPIClient($publicKey, $secretKey, $token, $tokenSecret);
31
32//SETTING UP OFFSET
33//$offset = (!isset($offset) || is_null($offset)) ? '0' : $offset;
34
35$submissions = $client->getSubmissionPosts($blogName, array('offset' => $offset, 'limit' => 50));
36
37$i = 0;
38
39foreach($submissions->posts as $submission) {
40 $i++;
41 foreach($submission as $key => $value){
42 if ($key == "timestamp" || $key == "publisher" || $key == "video_type" || $key == "thumbnail_url" || $key == "thumbnail_width" || $key == "thumbnail_height" || $key == "html5_capable" || $key == "id" || $key == "short_url" || $key == "video" || $key == "content_raw" || $key == "player" || $key == "highlighted" || $key == "photos" || $key == "trail" || $key == "tags" || $key == "description" || $key == "reblog" || $key == "followed" || $key == "blog_name" || $key == "reblog_key" || $key == "liked" || $key == "note_count" || $key == "link_author" || $key == "excerpt" || $key == "can_send_in_message" || $key == "can_reply" || $key == "recommended_source" || $key == "recommended_color" || $key == "font" || $key == "background" || $key == "format" || $key == "post_url" || $key == "slug" || $key == "is_submission" || $key == "is_anonymous")
43 continue;
44 $submission_data[$i][$key][] = isset($value) ? $value : "Nothing set";
45
46 }
47}
48
49
50$charset = craft()->templates->getTwig()->getCharset();
51$twig_html = new Twig_Markup(json_encode($submission_data), $charset);
52
53$tagdata = $submission_data;
54foreach($submission_data as $key => $value){
55 foreach($value as $k => $v){
56 $tagdata = str_replace("{".$key."}", $v[0], $submission_data);
57 }
58}
59
60// // // // replace the embed code with the Twig object
61$tagdata['embed_code'] = $twig_html;
62
63
64return $tagdata;
65}
66
67{% extends "_layouts/cp" %}
68{% set title = "Tumblr Submissions"|t %}
69{% includeCssResource "tumblr/css/table.css" %}
70
71{% set offset = craft.request.getParam('offset') %}
72{% set submissions = craft.tumblr.submissions(offset) %}
73
74{% block content %}
75
76<pre>{{ dump(offset) }}</pre>
77 <div id="page-wrap">
78 {% for i in range(1, 10, 1) %}
79 <a href="{{ actionUrl('tumblr/offset', {offset: i}) }}"><button type="button">{{i}}</button></a>
80 {% endfor %}
81 <table class="table">
82 {% for key,submit in submissions %}
83 {% if loop.index == 1 %}
84 <thead>
85 <tr class="row header">
86 {% for ref,items in submit %}
87 <th class="cell">{{ ref }}</th>
88 {% endfor %}
89 </tr>
90 </thead>
91 <tbody>
92 {% endif %}
93 <tr class="row">
94 {% for ref,items in submit %}
95 <td class="cell">{{ items[0]|e }}</td>
96 {% endfor %}
97 </tr>
98 {% endfor %}
99 </tbody>
100 </table>
101 </div>
102{% endblock %}