Commit 50e35599 by Cyrille37

Merge branch 'master' of framagit.org:Artefacts/CommunityVoice

parents c801678a 1558d66d
......@@ -19,6 +19,29 @@ communityvoice.eu
`[comment_nbr]` : return comments number
## Templates override
You can override default plugin templates by creating `communityVoice` folder in your theme and adding your own templates.
Templates list :
| Filename | Description | Arguments |
|--------------------------|----------------------|-------------------------------------|
| comments_count.php | Comments number | commentNbr (optional) |
| negative_vote_button.php | Negative vote button | data, name, class, value (optional) |
| negative_vote_count.php | Negative vote number | nbVote |
| positive_vote_button.php | Positive vote button | data, name, class, value (optional) |
| positive_vote_count.php | Positive vote number | nbVote |
Example :
> wp-content/themes/myAwesomeTheme/communityVoice/positive_vote_button.php
```
<input type='button' <?= $args['name'] . ' ' . $args['data'] ?> value='<?= $args['value'] ?>' class="<?= $args['class'] ?>"/>
```
To get help you can copy templates in CommunityVoice plugin.
# CommunityProject
......
......@@ -61,9 +61,14 @@ class Vote_UI
'content' => '-',
), $atts );
ob_start();
include 'templates/negative_vote_button.php';
return ob_get_clean();
$args = [
'data' => 'data-id="' . $id . '"',
'name' => 'name="vote_' . CommunityVoice_vote::MINUS . '"',
'value' => $a['content'] === null ? '-' : $a['content'],
'class' => $alreadyVote ? 'voted' : 'notvoted'
];
return $this->getTemplate( 'negative_vote_button', $args );
}
function display_positive_vote_btn( $atts = [] )
......@@ -83,9 +88,14 @@ class Vote_UI
'content' => '+',
), $atts );
ob_start();
include 'templates/positive_vote_button.php';
return ob_get_clean();
$args = [
'data' => 'data-id="' . $id . '"',
'name' => 'name="vote_' . CommunityVoice_vote::PLUS . '"',
'value' => $a['content'] === null ? '+' : $a['content'],
'class' => $alreadyVote ? 'voted' : 'notvoted'
];
return $this->getTemplate( 'positive_vote_button', $args );
}
function get_negative_vote_nbr()
......@@ -126,11 +136,10 @@ class Vote_UI
$post = get_post();
if ( ( CommunityVoice::$Settings->getSetting("CPT_only") !== false && $post->post_type === CommunityVoice::$Settings->getSetting("CPT_only") ) || CommunityVoice::$Settings->getSetting("CPT_only") === false )
{
ob_start();
include 'templates/comments_count.php';
$comments_count = ob_get_clean();
return $comments_count . $content;
$args = [
'commentNbr' => get_comments_number()
];
return $this->getTemplate( 'comments_count', $args ) . $content;
}
return $content;
}
......@@ -152,10 +161,11 @@ class Vote_UI
{
$nbvote === null ? $nbvote = 0 : null;
ob_start();
include 'templates/positive_vote_count.php';
$view = ob_get_clean();
return $view . $content;
$args = [
'nbVote' => '<span class="nb_vote_' . CommunityVoice_vote::PLUS . '_' . $post->ID . '">' . $nbvote .'</span>'
];
return $this->getTemplate( 'positive_vote_count', $args ) . $content;
}
return $content;
}
......@@ -176,11 +186,12 @@ class Vote_UI
if ( ( CommunityVoice::$Settings->getSetting('CPT_only') !== false && $post->post_type === CommunityVoice::$Settings->getSetting("CPT_only") ) || CommunityVoice::$Settings->getSetting("CPT_only") === false )
{
$nbvote === null ? $nbvote = 0 : null;
ob_start();
include 'templates/negative_vote_count.php';
$view = ob_get_clean();
return $view . $content;
$args = [
'nbVote' => '<span class="nb_vote_' . CommunityVoice_vote::MINUS . '_' . $post->ID . '">' . $nbvote . '</span>'
];
return $this->getTemplate( 'negative_vote_count') . $content;
}
return $content;
}
......@@ -200,4 +211,29 @@ class Vote_UI
}
/**
* Load templates from communityVoice folder (in theme) or from default templates
* @param String $name : template filename
* @param Array $args : template arguments
* @return String : template
*/
function getTemplate( $name, $args = null )
{
$name .= '.php';
if( file_exists( get_template_directory() . '/communityVoice/' . $name ) )
{
ob_start();
include get_template_directory() . '/communityVoice/' . $name;
return ob_get_clean();
}
else if( file_exists( plugin_dir_path( __FILE__ ) . 'templates/' . $name ) )
{
ob_start();
include plugin_dir_path( __FILE__ ) . 'templates/' . $name;
return ob_get_clean();
}
return '';
}
}
<p>Nombre de commentaires : <?= get_comments_number() ?> </p>
<p>Nombre de commentaires : <?= $args['commentNbr'] ?> </p>
<input type='button' data-id='<?= $id ?>' name='vote_<?= CommunityVoice_vote::MINUS ?>' value='<?= $a['content'] ?>' class="<?= $alreadyVote ? 'voted' : 'notvoted' ?>"/>
<input type='button' <?= $args['data'] . ' ' . $args['name'] ?> value='<?= $args['value'] ?>' class="<?= $args['class'] ?>"/>
<p>Vote négatif : <span class='nb_vote_<?= CommunityVoice_vote::MINUS . "_" . $post->ID ?>'><?= $nbvote ?></span></p>
<p>Vote négatif : <?= $args['nbvote'] ?></p>
<input type='button' data-id='<?= $id ?>' name='vote_<?= CommunityVoice_vote::PLUS ?>' value='<?= $a['content'] ?>' class="<?= $alreadyVote ? 'voted' : 'notvoted' ?>"/>
<input type='button' <?= $args['name'] . ' ' . $args['data'] ?> value='<?= $args['value'] ?>' class="<?= $args['class'] ?>"/>
<p>Vote positif : <span class='nb_vote_<?= CommunityVoice_vote::PLUS . "_" . $post->ID ?>'><?= $nbvote ?></span></p>
<p>Votes positif : <?= $args['nbVote'] ?></p>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment