Skip to content

Commit

Permalink
edit/remove links, threaded mode
Browse files Browse the repository at this point in the history
  • Loading branch information
voitto committed Apr 22, 2009
1 parent 357f686 commit 1b1ef59
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 19 deletions.
7 changes: 7 additions & 0 deletions app/omb/controllers/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,16 @@ function _theme( &$vars ) {

function index( &$vars ) {
extract( $vars );

$aktwitter_tw_text_options = array(
'false'=>'false',
'true'=>'true'
);

return vars(
array(
&$collection,
&$aktwitter_tw_text_options,
&$profile
),
get_defined_vars()
Expand Down
125 changes: 106 additions & 19 deletions app/omb/plugins/wp.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,71 @@ function post_password_required() {
return false;
}

function post_reply_link($arr,$post_id) {
// peh
// array('before' => ' | ', 'reply_text' => 'Reply', 'add_below' => 'prologue')
global $the_post,$request;
if (!isset($the_post->id))
return;


echo $arr['before'].'<a href="'.$request->url_for(array(
'resource' => 'posts',
'id' => $post_id,
)).'" class="post-reply-link" rel="'. $post_id.'">Reply</a>';


}

function wp_list_comments() {
echo "";

$comments = "";

if (environment('theme') == 'p2' && environment('threaded')) {


global $db,$the_post,$prefix,$request;
$result = $db->get_result( "SELECT id FROM ".$prefix."posts WHERE parent_id = ".$the_post->id );

while ( $row = $db->fetch_array( $result ) ) {
$pp = $db->get_record('posts',$row['id']);
$cc = owner_of($pp);

$cctime = date( "g:i A" , strtotime($pp->created) );
$ccdate = date( get_settings('date_format'), strtotime($pp->created) );
$ccurl = $request->url_for(array('resource'=>'posts','id'=>$pp->id));
$comments .= ' <li class="comment byuser comment-author-'.$cc->nickname.' even thread-even depth-1" id="comment-'.$pp->id.'">';
$comments .= '<img alt=\'image\' src=\''.$cc->avatar.'\' class=\'avatar avatar-32\' height=\'32\' width=\'32\' />';
$comments .= '<h4>';
$comments .= $cc->nickname;
$comments .= ' <span class="meta">';
$comments .= $cctime.' <em>on</em> '.$ccdate;
$comments .= '<span class="actions">';



$comments .= '<a href="'.$ccurl.'">Permalink</a> | <a rel=\'nofollow\' class=\'comment-reply-link\' href=\''.$ccurl.'\'>Reply</a>';
if (get_profile_id() == $pp->profile_id) {
$comments .= ' | <a href="'.get_edit_post_link( $pp ).'" class="post-edit-link" rel="'. $pp->id.'">Edit</a>';
$comments .= ' | <a href="'.get_edit_post_link( $pp, 'remove' ).'" class="post-remove-link" rel="'. $pp->id.'">Remove</a>';
}

$comments .= '</span>';
$comments .= '<br />';
$comments .= '</span>';
$comments .= '</h4>';
$comments .= '<div class="commentcontent" id="commentcontent-'.$pp->id.'">';
$comments .= '<p>'.$pp->title.'</p>';
$comments .= '</div>';
$comments .= '</li>';

}


}


echo $comments;
}

function cancel_comment_reply_link() {
Expand All @@ -33,8 +96,8 @@ function get_the_tags( $id = 0 ) {


function get_the_id() {
global $id;
return $id;
global $the_post;
return $the_post->id;
}

function is_front_page() {
Expand Down Expand Up @@ -1598,16 +1661,27 @@ function register_sidebar() {
function add_custom_image_header( $var, $name ) {
return false;
}

function get_edit_post_link( &$post ) {
function get_edit_post_link( &$post, $action=false ) {
global $the_post,$request;
if (!$action)
$action = 'edit';
if (!isset($the_post->id))
return "";
return $request->url_for(array(
'resource' => 'posts',
'id' => $the_post->id,
'action' => 'edit'
));
if ($the_post->profile_id == get_profile_id() || get_profile_id() == 1)
return $request->url_for(array(
'resource' => 'posts',
'id' => $the_post->id,
'action' => $action
));
elseif (!empty($post->id))
if ($post->profile_id == get_profile_id() || get_profile_id() == 1)
return $request->url_for(array(
'resource' => 'posts',
'id' => $post->id,
'action' => $action
));
else
return false;
}

function edit_post_link( $post ) {
Expand Down Expand Up @@ -1679,18 +1753,27 @@ function comments_popup_link( $var1, $var2, $var3 ) {

$theme = environment('theme');

if ($theme == 'prologue-theme') {
if (in_array($theme,array('prologue-theme','p2','twitteronia'))) {

global $db,$the_post,$prefix,$request;
$result = $db->get_result( "SELECT id FROM ".$prefix."posts WHERE parent_id = ".$the_post->id );
if ($result)
$commentcount = $db->num_rows($result);
else
return;


echo "<a href=\"";
echo $request->url_for(array(
'resource' => 'posts',
'id' => $the_post->id
));
echo "\">reply</a>";
echo "\">$commentcount</a>";
if (!(environment('threaded')))
return;
}

if ($theme == 'p2')
//if (in_array($theme,array('prologue-theme','p2','twitteronia')))
return "";

echo "|&nbsp;<a href=\"JavaScript:add_comment('addcomment-$the_post->id')";
Expand Down Expand Up @@ -1799,9 +1882,9 @@ function comment_type() {
function comment_text() {

global $the_post;
global $db;
global $db,$prefix;
if ($the_post->id) {
$sql = "SELECT title from posts where parent_id = ".$the_post->id;
$sql = "SELECT title from ".$prefix."posts where parent_id = ".$the_post->id;

$result = $db->get_result($sql);

Expand Down Expand Up @@ -1845,18 +1928,22 @@ function apply_filters($tag, $string) {
return $string;
}

function current_user_can( $action ) {
global $request;
function current_user_can( $action,$post_id=false ) {
global $request,$the_author;
if ($action == 'publish_posts' && ($request->resource != 'posts' || $request->action != 'index'))
return false;
$id = get_profile_id();
elseif ($action == 'publish_posts' && get_profile_id())
return true;

$id = get_profile_id();

if (isset($request->params['byid']))
$byid = $request->params['byid'];
else
$byid = 0;
if ($byid && $id == $byid)
return true;
elseif (!$byid && $id)
elseif ($id == $the_author->id)
return true;
return false;
}
Expand Down
87 changes: 87 additions & 0 deletions app/omb/views/admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,93 @@
<li><a href="JavaScript:top.location.href('<?php base_url(); ?>');">Return To Site</a></li>
</ul>


<script src="<?php base_path(); ?>resource/jquery.ajaxfileupload.js" type="text/javascript"></script>

<script src="<?php base_path(); ?>resource/jeditable/jquery.jeditable.js" type="text/javascript"></script>
<script src="<?php base_path(); ?>resource/jeditable/jquery.highlightFade.js" type="text/javascript"></script>

<script src="<?php base_path(); ?>resource/jeditable/jquery.jeditable.ajaxupload.js" type="text/javascript"></script>

<script type="text/javascript">
// <![CDATA[

<?php

global $db;

$Setting =& $db->model('Setting');

$threadmode = $Setting->find_by(array('name'=>'config.env.threaded','profile_id'=>get_profile_id()));

if (!$threadmode) {
$threadmode = $Setting->base();
$threadmode->set_value('profile_id',get_profile_id());
$threadmode->set_value('person_id',get_person_id());
$threadmode->set_value('name','config.env.threaded');
$threadmode->set_value('value','false');
$threadmode->save_changes();
$threadmode->set_etag();
$threadmode = $Setting->find($threadmode->id);
}
$seturl = $request->url_for(array('resource'=>'settings','id'=>$threadmode->id,'action'=>'put'));

$threadentry = $threadmode->FirstChild('entries');

?>

$(document).ready(function() {

var submit_to = "<?php url_for(array(
'resource'=>'settings',
'id'=>$threadmode->id,
'action'=>'put'
)); ?>";

var submit_to = "<?php echo $seturl; ?>";

$(".editable_select_tw_text").mouseover(function() {
$(this).highlightFade({end:'#def'});
});
$(".editable_select_tw_text").mouseout(function() {
$(this).highlightFade({end:'#fff', speed:200});
});
$(".editable_select_tw_text").editable(submit_to, {
indicator : "<img src='<?php base_path(); ?>resource/jeditable/indicator.gif'>",
data : '<?php $json = new Services_JSON(); echo $json->encode( $aktwitter_tw_text_options ); ?>',
submitdata : function() {
return {"entry[etag]" : "<?php echo $threadentry->etag; ?>"};
},
name : "setting[value]",
type : "select",
placeholder : "<?php echo $threadmode->value; ?>",
noappend : "true",
submit : "OK",
tooltip : "Click to edit...",
cancel : "Cancel",
callback : function(value, settings) {
$(this).html(settings['jsonarr'][value-0]);
return(value);
}
});
});
// ]]>
</script>


<table cellpadding="10" border="0">
<tr>
<td>
<h3>Threaded:</h3>
</td>
<td>
<div class="editable_select_tw_text" id="editable_select_tw_text"></div>
</td>
</tr>
</table>



<div id="tabs-1">
<p>
OpenMicroBlogger Administration Tools
Expand Down
10 changes: 10 additions & 0 deletions wp-content/themes/p2/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,16 @@ function tags_with_count($format = 'list', $before = '', $sep = '', $after = '')
if ( !$posttags )
return;

// global $post
// $posttags
// $tag->count
// $tag->slug
// $tag->name
// $tag
// get_term_linnk
// is_tag


foreach ( $posttags as $tag ) {
if ( $tag->count > 1 && !is_tag($tag->slug) ) {
$tag_link = '<a href="' . get_term_link($tag, 'post_tag') . '" rel="tag">' . $tag->name . ' (' . $tag->count . ')</a>';
Expand Down
1 change: 1 addition & 0 deletions wp-content/themes/p2/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
echo post_reply_link(array('before' => ' | ', 'reply_text' => 'Reply', 'add_below' => 'prologue'), get_the_id()); ?>
<?php if (current_user_can('edit_post', get_the_id())) { ?>
| <a href="<?php echo (get_edit_post_link( get_the_id() ))?>" class="post-edit-link" rel="<?php the_ID(); ?>">Edit</a>
| <a href="<?php echo (get_edit_post_link( get_the_id(), 'remove' ))?>" class="post-edit-link" rel="<?php the_ID(); ?>">Remove</a>
<?php } ?>
</span>
<br />
Expand Down

0 comments on commit 1b1ef59

Please sign in to comment.