Skip to content

Commit

Permalink
Break out individual insight attachment data type rendering logic to …
Browse files Browse the repository at this point in the history
…included templates, expand user list presentation [ci skip]
  • Loading branch information
ginatrapani committed May 19, 2012
1 parent 53e960b commit 1eba0aa
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 141 deletions.
2 changes: 1 addition & 1 deletion webapp/_lib/model/class.InsightMySQLDAO.php
Expand Up @@ -64,7 +64,7 @@ public function insertInsight($slug, $instance_id, $date, $text, $emphasis=Insig
public function getInsights($instance_id, $page_count=10, $page_number=1) {
$start_on_record = ($page_number - 1) * $page_count;
$q = "SELECT * FROM #prefix#insights WHERE instance_id=:instance_id ";
$q .= "ORDER BY date DESC, id DESC LIMIT :start_on_record, :limit;";
$q .= "ORDER BY date DESC, emphasis DESC, id DESC LIMIT :start_on_record, :limit;";
$vars = array(
':instance_id'=>$instance_id,
":start_on_record"=>(int)$start_on_record,
Expand Down
49 changes: 49 additions & 0 deletions webapp/_lib/view/_insights.follower_count_history.tpl
@@ -0,0 +1,49 @@
<br><br>
<div id="follower_count_history_{$i->id}"></div>

<script type="text/javascript">
// Load the Visualization API and the standard charts
google.load('visualization', '1.0');
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart{$i->id});
{literal}
function drawChart{/literal}{$i->id}() {literal}{
var formatter_date = new google.visualization.DateFormat({formatType: 'medium'});
var formatter = new google.visualization.NumberFormat({fractionDigits: 0});
{/literal}
var follower_count_history_data_{$i->id} = new google.visualization.DataTable(
{$i->related_data.vis_data});
formatter.format(follower_count_history_data_{$i->id}, 1);
formatter_date.format(follower_count_history_data_{$i->id}, 0);
{literal}
var follower_count_history_chart_{/literal}{$i->id}{literal} = new google.visualization.ChartWrapper({
{/literal}
containerId: 'follower_count_history_{$i->id}',
{literal}
chartType: 'LineChart',
dataTable: follower_count_history_data_{/literal}{$i->id}{literal},
options: {
width: 625,
height: 250,
legend: "none",
interpolateNulls: true,
pointSize: 2,
hAxis: {
baselineColor: '#eee',
format: 'MMM d',
textStyle: { color: '#999' },
gridlines: { color: '#eee' }
},
vAxis: {
baselineColor: '#eee',
textStyle: { color: '#999' },
gridlines: { color: '#eee' }
},
},
});
follower_count_history_chart_{/literal}{$i->id}{literal}.draw();
}
{/literal}
</script>
<br><br>
55 changes: 55 additions & 0 deletions webapp/_lib/view/_insights.post.tpl
@@ -0,0 +1,55 @@
<br><br>
<div class="post">
{if $i->related_data->post_text}
{if $scrub_reply_username}
{if $reply_count && $reply_count > $top_20_post_min}
<div class="reply_text" id="reply_text-{$smarty.foreach.foo.iteration}">
{/if}
{$i->related_data->post_text|filter_xss|regex_replace:"/^@[a-zA-Z0-9_]+/":""|link_usernames_to_twitter}
{if $reply_count && $reply_count > $top_20_post_min}</div>{/if}
{else}
{if $i->related_data->network == 'google+'}
{$i->related_data->post_text}
{else}
{$i->related_data->post_text|filter_xss|link_usernames_to_twitter}
{/if}
{/if}
{/if}
{if $i->related_data->link->expanded_url}
{if $i->related_data->post_text != ''}<br>{/if}
{if $i->related_data->link->image_src}
<div class="pic" style="float:left;margin-right:5px;margin-top:5px;"><a href="{$i->related_data->link->expanded_url}"><img src="{$i->related_data->link->image_src}" style="margin-bottom:5px;"/></a></div>
{/if}
<span class="small"><a href="{$i->related_data->link->url}" title="{$i->related_data->link->expanded_url}">{if $i->related_data->link->title}{$i->related_data->link->title}{else}{$i->related_data->link->url}{/if}</a>
{if $i->related_data->link->description}<br><small>{$i->related_data->link->description}</small>{/if}</span>
{/if}

{if !$post && $i->related_data->in_reply_to_post_id }
<a href="{$site_root_path}post/?t={$i->related_data->in_reply_to_post_id}&n={$i->related_data->network|urlencode}"><span class="ui-icon ui-icon-arrowthick-1-w" title="reply to..."></span></a>
{/if}

<span class="small gray">
<br clear="all">
<span class="metaroll">
<a href="{$site_root_path}post/?t={$i->related_data->post_id}&n={$i->related_data->network|urlencode}">{$i->related_data->adj_pub_date|relative_datetime} ago</a>
{if $i->related_data->is_geo_encoded < 2}
{if $show_distance}
{if $unit eq 'km'}
{$i->related_data->reply_retweet_distance|number_format} kms away
{else}
{$i->related_data->reply_retweet_distance|number_format} miles away in
{/if}
{/if}
from {$i->related_data->location|truncate:60:' ...'}
{/if}
{if $i->related_data->network == 'twitter'}
<a href="http://twitter.com/intent/tweet?in_reply_to={$i->related_data->post_id}"><span class="ui-icon ui-icon-arrowreturnthick-1-w" title="reply"></a>
<a href="http://twitter.com/intent/retweet?tweet_id={$i->related_data->post_id}"><span class="ui-icon ui-icon-arrowreturnthick-1-e" title="retweet"></a>
<a href="http://twitter.com/intent/favorite?tweet_id={$i->related_data->post_id}"><span class="ui-icon ui-icon-star" title="favorite"></a>
{/if}
</span><br>&nbsp;
</span>

</div>


13 changes: 13 additions & 0 deletions webapp/_lib/view/_insights.users.tpl
@@ -0,0 +1,13 @@
{foreach from=$i->related_data key=uid item=u name=bar}
<div class="avatar-container" style="float:left;margin:7px;">
<a href="https://twitter.com/intent/user?user_id={$u->user_id}" title="{$u->username} has {$u->follower_count|number_format} followers and {$u->friend_count|number_format} friends"><img src="{$u->avatar}" class="avatar2"/><img src="{$site_root_path}plugins/{$u->network}/assets/img/favicon.png" class="service-icon2"/></a>
</div>
<div style="margin-left:60px">
<a href="https://twitter.com/intent/user?user_id={$u->user_id}">{$u->full_name}</a> <small style="color:gray">{$u->follower_count|number_format} followers</small><br>
<span style="color:gray">{$u->description|link_usernames_to_twitter}</span>
{$u->url}<br>

</div>
<div style="clear:all">&nbsp;</div>

{/foreach}
138 changes: 0 additions & 138 deletions webapp/_lib/view/dashboard.insights.tpl

This file was deleted.

27 changes: 27 additions & 0 deletions webapp/_lib/view/insights.tpl
@@ -0,0 +1,27 @@
<h1>Insights (alpha)</h1>

{assign var='cur_date' value=''}
{foreach from=$insights key=tid item=i name=foo}
{if $cur_date neq $i->date}
<h2>{$i->date|relative_day}</h2>
{assign var='cur_date' value=$i->date}
{/if}
<div class="alert {if $i->emphasis eq '2'}urgent{else}helpful{/if}">
<p>
<span class="ui-icon ui-icon-check" style="float: left; margin:.3em 0.3em 0 0;"></span>
{$i->text}

<!--begin {$i->related_data_type} attachment data-->
{if $i->related_data_type eq 'users'}
{include file="_insights.users.tpl"}
{elseif $i->related_data_type eq 'post'}
{include file="_insights.post.tpl"}
{elseif $i->related_data_type eq 'follower_count_history'}
{include file="_insights.follower_count_history.tpl"}
{/if}
<!--end {$i->related_data_type} attachment data-->

</span>
</p>
</div>
{/foreach}
2 changes: 1 addition & 1 deletion webapp/plugins/twitter/model/class.TwitterCrawler.php
Expand Up @@ -1937,7 +1937,7 @@ public function generateInsights() {
//For each of the past 7 days (remove this later & just do day by day?)
//get least likely followers for that day
$least_likely_followers = $follow_dao->getLeastLikelyFollowersByDay($this->instance->network_user_id,
'twitter', $days_ago);
'twitter', $days_ago, 3);
if (sizeof($least_likely_followers) > 0 ) { //if not null, store insight
$insight_date = new DateTime();
//Not PHP 5.2 compatible
Expand Down
2 changes: 1 addition & 1 deletion webapp/plugins/twitter/model/class.TwitterPlugin.php
Expand Up @@ -505,7 +505,7 @@ public function getDashboardMenuItems($instance) {
$ptab->addDataset($ptabds);
$menus["links-photos"] = $ptab;

$insights_menu_item = new MenuItem("Insights", "Insights", 'dashboard.insights.tpl');
$insights_menu_item = new MenuItem("Insights", "Insights", 'insights.tpl');

$insights_menu_ds_1 = new Dataset("insights", 'InsightDAO', "getInsights",
array($instance->id, 25, "#page_number#") );
Expand Down

0 comments on commit 1eba0aa

Please sign in to comment.