First question clear, the second not, because my answer for what i have understand would be: why you do not add a link to the post then? So i have not understand the question i assume.
And assuming you know how to edit a php file, use ftp etc, the short answer to the first question is:
into file
/wp-content/plugins/wp-w3all-phpbb-integration/class.wp.w3all-phpbb.php
there is this function:
Code: Select all
// wp_w3all_get_phpbb_post_short Version 1.0
// This need to be rewrite/improved: all should be done following the [code][code] logic ...
public static function wp_w3all_get_phpbb_post_short( $atts ) {
global $w3all_config;
$w3db_conn = self::w3all_db_connect();
$p = shortcode_atts( array(
'id' => '0',
'plaintext' => '0',
), $atts );
$p['id'] = intval($p['id']);
if($p['id'] == 0){
return "w3all shortcode error.<br /> The shortcode need to be added like this:<br />[w3allforumpost id=\"150\"]<br />change '150' <strong>with the (existent) phpBB post ID to display here.</strong>";
}
$phpbb_post = $w3db_conn->get_results("SELECT T.*, P.* FROM ".$w3all_config["table_prefix"]."topics AS T, ".$w3all_config["table_prefix"]."posts AS P
WHERE T.topic_visibility = 1
AND T.topic_id = P.topic_id
AND P.post_visibility = 1
AND P.post_id = '".$p['id']."'
");
if( !$phpbb_post ){
$res = '<b>w3all shortcode error:<br />the provided post ID to show do not match an existent phpBB post!</b>';
return $res;
}
$p['plaintext'] = intval($p['plaintext']);
if($p['plaintext'] == 1){
return preg_replace('/[[\/\!]*?[^\[\]]*?]/', '', $phpbb_post[0]->post_text); // REVIEW // remove all bbcode tags (not html nor fake tags) //
}
// handle bbcode in the right way ...
// grab the code and replace with a placeholder '#w3#bbcode#replace#'
// so, after the others bbcode tags conversions, re-add each, properly wrapped
preg_match_all('~\<s\>\[code\]\</s\>(.*?)\<e\>\[/code\]\</e\>~si', $phpbb_post[0]->post_text, $cmatches, PREG_SET_ORDER);
if($cmatches){ // remove and add custom placeholder
$cc = 0;
$phpbb_post[0]->post_text = preg_replace('~\<s\>\[code\]\</s\>(.*?)\<e\>\[/code\]\</e\>~si', '#w3#bbcode#replace#', $phpbb_post[0]->post_text, -1 ,$cc);
// split and add 'placeholders'
$ps = preg_split('/#w3#bbcode#replace#/', $phpbb_post[0]->post_text, -1, PREG_SPLIT_DELIM_CAPTURE);
$ccc = 0;
$res = '';
foreach($ps as $p => $s){
if($ccc < $cc){
$res .= $s.'#w3#bbcode#replace#'.$ccc++; // append/assing number to placeholder for this split/string
} else { $res .= $s; } // follow add the latest text, if no more placeholders ...
}
} else { $res = $phpbb_post[0]->post_text; }
$res = self::w3all_bbcodeconvert($res); // convert all bbcode tags except [code]
if($cmatches){ // re-add grabbed bbcode blocks and wrap with proper html ...
$cccc = 0;
foreach($cmatches as $k => $v){
$res = str_ireplace('#w3#bbcode#replace#'.$cccc, '<code>'.$v[1].'</code>', $res);
$cccc++;
}
}
return $res;
}
that to achieve what you want should be substituted by this:
Code: Select all
// wp_w3all_get_phpbb_post_short Version 1.0
// This need to be rewrite/improved: all should be done following the [code][code] logic ...
public static function wp_w3all_get_phpbb_post_short( $atts ) {
global $w3all_config;
$w3db_conn = self::w3all_db_connect();
$p = shortcode_atts( array(
'id' => '0',
'plaintext' => '0',
'wordsnum' => '0'
), $atts );
$p['id'] = intval($p['id']);
if($p['id'] == 0){
return "w3all shortcode error.<br /> The shortcode need to be added like this:<br />[w3allforumpost id=\"150\"]<br />change '150' <strong>with the (existent) phpBB post ID to display here.</strong>";
}
$phpbb_post = $w3db_conn->get_results("SELECT T.*, P.* FROM ".$w3all_config["table_prefix"]."topics AS T, ".$w3all_config["table_prefix"]."posts AS P
WHERE T.topic_visibility = 1
AND T.topic_id = P.topic_id
AND P.post_visibility = 1
AND P.post_id = '".$p['id']."'
");
if( !$phpbb_post ){
$res = '<b>w3all shortcode error:<br />the provided post ID to show do not match an existent phpBB post!</b>';
return $res;
}
if(intval($p['plaintext']) == 1){
if($p['wordsnum'] > 0){
return wp_w3all_remove_bbcode_tags($phpbb_post[0]->post_text, $p['wordsnum']);
}
return preg_replace('/[[\/\!]*?[^\[\]]*?]/', '', $phpbb_post[0]->post_text); // REVIEW // remove all bbcode tags (not html nor fake tags) //
}
// handle bbcode in the right way ...
// grab the code and replace with a placeholder '#w3#bbcode#replace#'
// so, after the others bbcode tags conversions, re-add each, properly wrapped
preg_match_all('~\<s\>\[code\]\</s\>(.*?)\<e\>\[/code\]\</e\>~si', $phpbb_post[0]->post_text, $cmatches, PREG_SET_ORDER);
if($cmatches){ // remove and add custom placeholder
$cc = 0;
$phpbb_post[0]->post_text = preg_replace('~\<s\>\[code\]\</s\>(.*?)\<e\>\[/code\]\</e\>~si', '#w3#bbcode#replace#', $phpbb_post[0]->post_text, -1 ,$cc);
// split and add 'placeholders'
$ps = preg_split('/#w3#bbcode#replace#/', $phpbb_post[0]->post_text, -1, PREG_SPLIT_DELIM_CAPTURE);
$ccc = 0;
$res = '';
foreach($ps as $p0 => $s){
if($ccc < $cc){
$res .= $s.'#w3#bbcode#replace#'.$ccc++; // append/assing number to placeholder for this split/string
} else { $res .= $s; } // follow add the latest text, if no more placeholders ...
}
} else { $res = $phpbb_post[0]->post_text; }
$res = self::w3all_bbcodeconvert($res); // convert all bbcode tags except [code]
if($p['wordsnum'] > 0){
$post_s = $res;
$res0 = explode(' ',$post_s);
if( count($res0) < $p['wordsnum'] ) : return $post_s; endif;
$post_std = ''; $i = 0; $b = $p['wordsnum'];
$res1 = '';
foreach ($res0 as $post_st) {
$i++;
if( $i < $b + 1 ){ // offset of 1
$res1 .= $post_st . ' ';
}
}
$res = $res1;
}
if($cmatches){ // re-add grabbed bbcode blocks and wrap with proper html ...
$cccc = 0;
foreach($cmatches as $k => $v){
$res = str_ireplace('#w3#bbcode#replace#'.$cccc, '<code>'.$v[1].'</code>', $res);
$cccc++;
}
}
return $res;
}
now the shortcode have an attribute
wordsnum
then for example using the shortcode like this:
Code: Select all
[w3allforumpost id="4" wordsnum="150"]
or like this:
Code: Select all
[w3allforumpost id="4" plaintext="1" wordsnum="150"]
will return you number of words.
May it is not perfect, you'll have to play to adjust correct number of words in certain cases, and avoid truncation of something. By the way it works quite well on short tests i've do on fly, so may it will be added by default into next plugin version