Skip to content

Commit

Permalink
Default Picture option is added. Usage: -defaultPicture="Image URL"
Browse files Browse the repository at this point in the history
  • Loading branch information
tofighi committed Feb 22, 2018
1 parent fb3448e commit 95e84af
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 5 deletions.
3 changes: 2 additions & 1 deletion conf/default.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

$conf['toolbar_inserted_markup'] = '<nspages -h1 -subns -exclude:start>';
$conf['cache'] = 1;
$conf['default_picture'] = '';
$conf['cache'] = 1;
3 changes: 2 additions & 1 deletion conf/metadata.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

$meta['toolbar_inserted_markup'] = array('string');
$meta["cache"] = array("onoff");
$meta['default_picture'] = array('string');
$meta["cache"] = array("onoff");
1 change: 1 addition & 0 deletions lang/en/settings.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

$lang['cache'] = 'Disable the cache';
$lang['default_picture'] = 'Set your default picture';
$lang['toolbar_inserted_markup'] = 'Toolbar inserted markup';
3 changes: 3 additions & 0 deletions lang/fa/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
*
* @author Sam01 <[email protected]>
* @author Ghassem Tofighi <[email protected]>
*/
$lang['cache'] = 'غیرفعال کردن کش ';
$lang['default_picture'] = 'درج تصویر پیش‌فرض';
$lang['toolbar_inserted_markup'] = 'درج نشانه‌گذار نوار ابزار';

9 changes: 9 additions & 0 deletions optionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ static function checkTextNs(&$match, &$varAffected, $plugin){
$varAffected = null;
}
}

static function checkDefaultPicture(&$match, &$varAffected, $plugin){
if(optionParser::preg_match_wrapper("defaultPicture *= *\"([^\"]*)\"", $match, $found)) {
$varAffected = $found[1];
$match = optionParser::_removeFromMatch($found[0], $match);
} else {
$varAffected = null;
}
}

static function checkExclude(&$match, &$excludedPages, &$excludedNs){
//--Looking if the syntax -exclude[item1 item2] has been used
Expand Down
7 changes: 6 additions & 1 deletion printers/printerPictures.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class nspages_printerPictures extends nspages_printer {
function __construct($plugin, $mode, $renderer, $data){
parent::__construct($plugin, $mode, $renderer, $data);
$this->_displayModificationDate = $data['modificationDateOnPictures'];
$this->_defaultPicture = $data['defaultPicture'];
}

function _print($tab, $type) {
Expand Down Expand Up @@ -45,7 +46,11 @@ private function _getFirstImage($pageId){
if ( $picture != "" ){
return ml($picture, self::$_dims, true);
} else {
return "lib/tpl/dokuwiki/images/logo.png";
if ( $this->_defaultPicture == '' ){
return "lib/tpl/dokuwiki/images/logo.png";
} else {
return ml($this->_defaultPicture, self::$_dims, true);
}
}
}

Expand Down
14 changes: 12 additions & 2 deletions syntax.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @author Daniel Schranz <[email protected]>
* @author Ignacio Bergmann
* @author Andreas Gohr <[email protected]>
* @author Ghassem Tofighi <[email protected]>
*/
if(!defined('DOKU_INC')) die();
require_once 'printers/printerLineBreak.php';
Expand Down Expand Up @@ -78,6 +79,9 @@ function handle($match, $state, $pos, Doku_Handler $handler) {
optionParser::checkExclude($match, $return['excludedPages'], $return['excludedNS']);
optionParser::checkAnchorName($match, $return['anchorName']);
optionParser::checkActualTitle($match, $return['actualTitleLevel']);
optionParser::checkDefaultPicture($match, $return['defaultPicture'], $this);



//Now, only the wanted namespace remains in $match
$nsFinder = new namespaceFinder($match);
Expand All @@ -104,7 +108,7 @@ private function _getDefaultOptions(){
'natOrder' => false, 'sortDate' => false,
'hidenopages' => false, 'hidenosubns' => false, 'usePictures' => false,
'modificationDateOnPictures' => false,
'sortByCreationDate' => false
'sortByCreationDate' => false, 'defaultPicture' => null,
);
}

Expand All @@ -115,6 +119,7 @@ function render($mode, Doku_Renderer $renderer, $data) {
//behave well with the translation plugin (it seems like we cache strings
//even if the lang doesn't match)
$this->_denullifyLangOptions($data);
$this->_denullifyPictureOptions($data);
$printer = $this->_selectPrinter($mode, $renderer, $data);

if( ! $this->_isNamespaceUsable($data)){
Expand All @@ -132,7 +137,6 @@ function render($mode, Doku_Renderer $renderer, $data) {
$printer->printBeginning();
$this->_print($printer, $data, $subnamespaces, $pages);
$printer->printEnd();

return TRUE;
}

Expand All @@ -145,6 +149,12 @@ function _denullifyLangOptions(&$data){
$data['textPages'] = $this->getLang('pagesinthiscat');
}
}

function _denullifyPictureOptions(&$data){
if ( is_null($data['defaultPicture']) ){
$data['defaultPicture'] = $this->getConf('default_picture');
}
}

private function _shouldPrintPagesAmongNamespaces($data){
return $data['pagesinns'];
Expand Down

0 comments on commit 95e84af

Please sign in to comment.