From debfd86a27b5fcc6c460202f324269140e09affd Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 15 Sep 2014 22:25:44 +0200 Subject: [PATCH 1/7] hide the edit button in settings --- action.php | 2 +- conf/default.php | 1 + conf/metadata.php | 1 + lang/en/settings.php | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/action.php b/action.php index 4d603bf..9b9a9f6 100644 --- a/action.php +++ b/action.php @@ -58,7 +58,7 @@ function _handle(&$event, $param){ } function _editbutton(&$event, $param) { - if ($event->data['target'] !== 'plugin_data') { + if ($event->data['target'] !== 'plugin_data' OR $this->getConf('hide_edit_button')) { return; } diff --git a/conf/default.php b/conf/default.php index c09c56f..67133f1 100644 --- a/conf/default.php +++ b/conf/default.php @@ -3,3 +3,4 @@ $conf['edit_content_only'] = 0; $conf['use_dataresolve'] = 1; $conf['rownumbers'] = 0; +$conf['hide_edit_button'] = 0; diff --git a/conf/metadata.php b/conf/metadata.php index 9f3992e..224434f 100644 --- a/conf/metadata.php +++ b/conf/metadata.php @@ -3,3 +3,4 @@ $meta['edit_content_only'] = array('onoff'); $meta['use_dataresolve'] = array('onoff');; $meta['rownumbers'] = array('onoff'); +$meta['hide_edit_button'] = array('onoff'); diff --git a/lang/en/settings.php b/lang/en/settings.php index 427f22a..82b7775 100644 --- a/lang/en/settings.php +++ b/lang/en/settings.php @@ -5,3 +5,4 @@ // https://github.com/splitbrain/dokuwiki-plugin-data/commit/8a16166886238906c21c7babc44bccf49c7f50a1 $lang['use_dataresolve'] = 'Use DATARESOLVE calls for LIKE statements'; $lang['rownumbers'] = 'Enable "rownumbers" by default in all tables'; +$lang['hide_edit_button'] = 'Hide the edit button for form'; From d3b49ac3e6df0e3a89211b97473fc2ddf0d7dc8a Mon Sep 17 00:00:00 2001 From: endoanaconda Date: Mon, 15 Sep 2014 22:30:32 +0200 Subject: [PATCH 2/7] Update settings.php --- lang/en/settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/en/settings.php b/lang/en/settings.php index 82b7775..43fb7c4 100644 --- a/lang/en/settings.php +++ b/lang/en/settings.php @@ -5,4 +5,4 @@ // https://github.com/splitbrain/dokuwiki-plugin-data/commit/8a16166886238906c21c7babc44bccf49c7f50a1 $lang['use_dataresolve'] = 'Use DATARESOLVE calls for LIKE statements'; $lang['rownumbers'] = 'Enable "rownumbers" by default in all tables'; -$lang['hide_edit_button'] = 'Hide the edit button for form'; +$lang['hide_edit_button'] = 'Hide the edit button on page'; From 6a49b466f3a74a297823e170d112f9e6fc63134f Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 15 Sep 2014 23:15:24 +0200 Subject: [PATCH 3/7] tag cloud with amount behind tag --- syntax/cloudcount.php | 202 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 syntax/cloudcount.php diff --git a/syntax/cloudcount.php b/syntax/cloudcount.php new file mode 100644 index 0000000..8471ecf --- /dev/null +++ b/syntax/cloudcount.php @@ -0,0 +1,202 @@ + + */ +// must be run within Dokuwiki +if(!defined('DOKU_INC')) die(); +require_once(dirname(__FILE__).'/table.php'); + +class syntax_plugin_data_cloudcount extends syntax_plugin_data_table { + + /** + * will hold the data helper plugin + * @var $dthlp helper_plugin_data + */ + var $dthlp = null; + + /** + * Constructor. Load helper plugin + */ + function syntax_plugin_data_cloudcount(){ + $this->dthlp = plugin_load('helper', 'data'); + if(!$this->dthlp) msg('Loading the data helper failed. Make sure the data plugin is installed.',-1); + } + + /** + * What kind of syntax are we? + */ + function getType(){ + return 'substition'; + } + + /** + * What about paragraphs? + */ + function getPType(){ + return 'block'; + } + + /** + * Where to sort in? + */ + function getSort(){ + return 155; + } + + + /** + * Connect pattern to lexer + */ + function connectTo($mode) { + $this->Lexer->addSpecialPattern('----+ *cloudcount(?: [ a-zA-Z0-9_]*)?-+\n.*?\n----+',$mode,'plugin_data_cloudcount'); + } + + function _buildSQL(&$data){ + $ckey = array_keys($data['cols']); + $ckey = $ckey[0]; + + $from = ' '; + $where = ' '; + $pagesjoin = ''; + $tables = array(); + + $sqlite = $this->dthlp->_getDB(); + if(!$sqlite) return false; + + $fields = array('pageid' => 'page', 'class' => 'class', + 'title' => 'title'); + // prepare filters (no request filters - we set them ourselves) + if(is_array($data['filter']) && count($data['filter'])){ + + foreach($data['filter'] as $filter){ + $col = $filter['key']; + $closecompare = ($filter['compare'] == 'IN(' ? ')' : ''); + + if (preg_match('/^%(\w+)%$/', $col, $m) && isset($fields[$m[1]])) { + $where .= " ".$filter['logic']." pages." . $fields[$m[1]] . + " " . $filter['compare']." '".$filter['value']."'".$closecompare; + $pagesjoin = ' LEFT JOIN pages ON pages.pid = data.pid'; + }else{ + // filter by hidden column? + if(!$tables[$col]){ + $tables[$col] = 'T'.(++$cnt); + $from .= ' LEFT JOIN data AS '.$tables[$col].' ON '.$tables[$col].'.pid = data.pid'; + $from .= ' AND '.$tables[$col].".key = ".$sqlite->quote_string($col); + } + + $where .= ' '.$filter['logic'].' '.$tables[$col].'.value '.$filter['compare']. + " '".$filter['value']."'".$closecompare; //value is already escaped + } + } + } + + // build query + $sql = "SELECT data.value, COUNT(data.pid) as cnt + FROM data $from $pagesjoin + WHERE data.key = ".$sqlite->quote_string($ckey)." + $where + GROUP BY data.value"; + if(isset($data['min'])) $sql .= ' HAVING cnt >= '.$data['min']; + $sql .= ' ORDER BY cnt DESC'; + if($data['limit']) $sql .= ' LIMIT '.$data['limit']; + + return $sql; + } + + protected $before_item = '
    '; + protected $after_item = '
'; + protected $before_val = '
  • '; + protected $after_val = '
  • '; + + /** + * Create output or save the data + */ + function render($format, Doku_Renderer $renderer, $data) { + global $ID; + + if($format != 'xhtml') return false; + if(is_null($data)) return; + if(!$this->dthlp->ready()) return false; + $renderer->info['cache'] = false; + + $sqlite = $this->dthlp->_getDB(); + if(!$sqlite) return false; + + $ckey = array_keys($data['cols']); + $ckey = $ckey[0]; + + if(!isset($data['page'])) $data['page'] = $ID; + + $this->dthlp->_replacePlaceholdersInSQL($data); + + // build cloud data + $res = $sqlite->query($data['sql']); + $rows = $sqlite->res2arr($res); + $min = 0; + $max = 0; + $tags = array(); + foreach ($rows as $row) { + if(!$max) $max = $row['cnt']; + $min = $row['cnt']; + $tags[$row['value']]['cnt'] = $row['cnt']; + $tags[$row['value']]['value'] = $row['value']; + } + + $this->_cloud_weight($tags,$min,$max,5); + + print_r($tags); + + // output cloud + $renderer->doc .= sprintf($this->before_item,hsc($data['classes'])); + foreach($tags as $tag){ + + $output_tag_label = hsc($tag['value']) .'('.$tag['cnt'].')'; + + $renderer->doc .= sprintf($this->before_val,$tag['lvl']); + $renderer->doc .= ''.$output_tag_label.''; + $renderer->doc .= $this->after_val; + } + $renderer->doc .= $this->after_item; + return true; + } + + + /** + * Create a weighted tag distribution + * + * @param $tags array ref The tags to weight ( tag => count) + * @param $min int The lowest count of a single tag + * @param $max int The highest count of a single tag + * @param $levels int The number of levels you want. A 5 gives levels 0 to 4. + */ + function _cloud_weight(&$tags,$min,$max,$levels){ + $levels--; + + // calculate tresholds + $tresholds = array(); + for($i=0; $i<=$levels; $i++){ + $tresholds[$i] = pow($max - $min + 1, $i/$levels) + $min - 1; + } + + + // assign weights + foreach($tags as $tag){ + foreach($tresholds as $tresh => $val){ + if($tag['cnt'] <= $val){ + $tags[$tag['value']]['lvl'] = $tresh; + break; + } + $tags[$tag['value']]['lvl'] = $levels; + } + } + + // sort + ksort($tags); + } + +} + From 97e184ca4e10acdfdc9dd917f53c7aad6025285c Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 15 Sep 2014 23:42:38 +0200 Subject: [PATCH 4/7] - added flag [summarize : 1] in cloud. - Shows real weight/count of tag - summarize-flag already used for Data Table --- syntax/cloud.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/syntax/cloud.php b/syntax/cloud.php index cf5f04b..08933e9 100644 --- a/syntax/cloud.php +++ b/syntax/cloud.php @@ -140,17 +140,21 @@ function render($format, Doku_Renderer $renderer, $data) { foreach ($rows as $row) { if(!$max) $max = $row['cnt']; $min = $row['cnt']; - $tags[$row['value']] = $row['cnt']; + $tags[$row['value']]['cnt'] = $row['cnt']; + $tags[$row['value']]['value'] = $row['value']; } $this->_cloud_weight($tags,$min,$max,5); - + // output cloud $renderer->doc .= sprintf($this->before_item,hsc($data['classes'])); - foreach($tags as $tag => $lvl){ - $renderer->doc .= sprintf($this->before_val,$lvl); - $renderer->doc .= 'dthlp->_getTagUrlparam($data['cols'][$ckey], $tag['value'])). '" title="'.sprintf($this->getLang('tagfilter'),hsc($tag)). - '" class="wikilink1">'.hsc($tag).''; + '" class="wikilink1">'.$output_tag_label.''; $renderer->doc .= $this->after_val; } $renderer->doc .= $this->after_item; @@ -176,13 +180,13 @@ function _cloud_weight(&$tags,$min,$max,$levels){ } // assign weights - foreach($tags as $tag => $cnt){ + foreach($tags as $tag){ foreach($tresholds as $tresh => $val){ - if($cnt <= $val){ - $tags[$tag] = $tresh; + if($tag['cnt'] <= $val){ + $tags[$tag['value']]['lvl'] = $tresh; break; } - $tags[$tag] = $levels; + $tags[$tag['value']]['lvl'] = $levels; } } From f66b7aaa751bad94b7c939b4d0e96d57422650fb Mon Sep 17 00:00:00 2001 From: endoanaconda Date: Mon, 15 Sep 2014 23:46:10 +0200 Subject: [PATCH 5/7] Delete cloudcount.php --- syntax/cloudcount.php | 202 ------------------------------------------ 1 file changed, 202 deletions(-) delete mode 100644 syntax/cloudcount.php diff --git a/syntax/cloudcount.php b/syntax/cloudcount.php deleted file mode 100644 index 8471ecf..0000000 --- a/syntax/cloudcount.php +++ /dev/null @@ -1,202 +0,0 @@ - - */ -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); -require_once(dirname(__FILE__).'/table.php'); - -class syntax_plugin_data_cloudcount extends syntax_plugin_data_table { - - /** - * will hold the data helper plugin - * @var $dthlp helper_plugin_data - */ - var $dthlp = null; - - /** - * Constructor. Load helper plugin - */ - function syntax_plugin_data_cloudcount(){ - $this->dthlp = plugin_load('helper', 'data'); - if(!$this->dthlp) msg('Loading the data helper failed. Make sure the data plugin is installed.',-1); - } - - /** - * What kind of syntax are we? - */ - function getType(){ - return 'substition'; - } - - /** - * What about paragraphs? - */ - function getPType(){ - return 'block'; - } - - /** - * Where to sort in? - */ - function getSort(){ - return 155; - } - - - /** - * Connect pattern to lexer - */ - function connectTo($mode) { - $this->Lexer->addSpecialPattern('----+ *cloudcount(?: [ a-zA-Z0-9_]*)?-+\n.*?\n----+',$mode,'plugin_data_cloudcount'); - } - - function _buildSQL(&$data){ - $ckey = array_keys($data['cols']); - $ckey = $ckey[0]; - - $from = ' '; - $where = ' '; - $pagesjoin = ''; - $tables = array(); - - $sqlite = $this->dthlp->_getDB(); - if(!$sqlite) return false; - - $fields = array('pageid' => 'page', 'class' => 'class', - 'title' => 'title'); - // prepare filters (no request filters - we set them ourselves) - if(is_array($data['filter']) && count($data['filter'])){ - - foreach($data['filter'] as $filter){ - $col = $filter['key']; - $closecompare = ($filter['compare'] == 'IN(' ? ')' : ''); - - if (preg_match('/^%(\w+)%$/', $col, $m) && isset($fields[$m[1]])) { - $where .= " ".$filter['logic']." pages." . $fields[$m[1]] . - " " . $filter['compare']." '".$filter['value']."'".$closecompare; - $pagesjoin = ' LEFT JOIN pages ON pages.pid = data.pid'; - }else{ - // filter by hidden column? - if(!$tables[$col]){ - $tables[$col] = 'T'.(++$cnt); - $from .= ' LEFT JOIN data AS '.$tables[$col].' ON '.$tables[$col].'.pid = data.pid'; - $from .= ' AND '.$tables[$col].".key = ".$sqlite->quote_string($col); - } - - $where .= ' '.$filter['logic'].' '.$tables[$col].'.value '.$filter['compare']. - " '".$filter['value']."'".$closecompare; //value is already escaped - } - } - } - - // build query - $sql = "SELECT data.value, COUNT(data.pid) as cnt - FROM data $from $pagesjoin - WHERE data.key = ".$sqlite->quote_string($ckey)." - $where - GROUP BY data.value"; - if(isset($data['min'])) $sql .= ' HAVING cnt >= '.$data['min']; - $sql .= ' ORDER BY cnt DESC'; - if($data['limit']) $sql .= ' LIMIT '.$data['limit']; - - return $sql; - } - - protected $before_item = '
      '; - protected $after_item = '
    '; - protected $before_val = '
  • '; - protected $after_val = '
  • '; - - /** - * Create output or save the data - */ - function render($format, Doku_Renderer $renderer, $data) { - global $ID; - - if($format != 'xhtml') return false; - if(is_null($data)) return; - if(!$this->dthlp->ready()) return false; - $renderer->info['cache'] = false; - - $sqlite = $this->dthlp->_getDB(); - if(!$sqlite) return false; - - $ckey = array_keys($data['cols']); - $ckey = $ckey[0]; - - if(!isset($data['page'])) $data['page'] = $ID; - - $this->dthlp->_replacePlaceholdersInSQL($data); - - // build cloud data - $res = $sqlite->query($data['sql']); - $rows = $sqlite->res2arr($res); - $min = 0; - $max = 0; - $tags = array(); - foreach ($rows as $row) { - if(!$max) $max = $row['cnt']; - $min = $row['cnt']; - $tags[$row['value']]['cnt'] = $row['cnt']; - $tags[$row['value']]['value'] = $row['value']; - } - - $this->_cloud_weight($tags,$min,$max,5); - - print_r($tags); - - // output cloud - $renderer->doc .= sprintf($this->before_item,hsc($data['classes'])); - foreach($tags as $tag){ - - $output_tag_label = hsc($tag['value']) .'('.$tag['cnt'].')'; - - $renderer->doc .= sprintf($this->before_val,$tag['lvl']); - $renderer->doc .= ''.$output_tag_label.''; - $renderer->doc .= $this->after_val; - } - $renderer->doc .= $this->after_item; - return true; - } - - - /** - * Create a weighted tag distribution - * - * @param $tags array ref The tags to weight ( tag => count) - * @param $min int The lowest count of a single tag - * @param $max int The highest count of a single tag - * @param $levels int The number of levels you want. A 5 gives levels 0 to 4. - */ - function _cloud_weight(&$tags,$min,$max,$levels){ - $levels--; - - // calculate tresholds - $tresholds = array(); - for($i=0; $i<=$levels; $i++){ - $tresholds[$i] = pow($max - $min + 1, $i/$levels) + $min - 1; - } - - - // assign weights - foreach($tags as $tag){ - foreach($tresholds as $tresh => $val){ - if($tag['cnt'] <= $val){ - $tags[$tag['value']]['lvl'] = $tresh; - break; - } - $tags[$tag['value']]['lvl'] = $levels; - } - } - - // sort - ksort($tags); - } - -} - From c57369b0cf130f3d5cc86e93b205b569331a7bd9 Mon Sep 17 00:00:00 2001 From: endoanaconda Date: Mon, 13 Oct 2014 15:40:34 +0200 Subject: [PATCH 6/7] Update cloud.php --- syntax/cloud.php | 197 ----------------------------------------------- 1 file changed, 197 deletions(-) diff --git a/syntax/cloud.php b/syntax/cloud.php index 08933e9..8b13789 100644 --- a/syntax/cloud.php +++ b/syntax/cloud.php @@ -1,198 +1 @@ - - */ -// must be run within Dokuwiki -if(!defined('DOKU_INC')) die(); -require_once(dirname(__FILE__).'/table.php'); - -class syntax_plugin_data_cloud extends syntax_plugin_data_table { - - /** - * will hold the data helper plugin - * @var $dthlp helper_plugin_data - */ - var $dthlp = null; - - /** - * Constructor. Load helper plugin - */ - function syntax_plugin_data_cloud(){ - $this->dthlp = plugin_load('helper', 'data'); - if(!$this->dthlp) msg('Loading the data helper failed. Make sure the data plugin is installed.',-1); - } - - /** - * What kind of syntax are we? - */ - function getType(){ - return 'substition'; - } - - /** - * What about paragraphs? - */ - function getPType(){ - return 'block'; - } - - /** - * Where to sort in? - */ - function getSort(){ - return 155; - } - - - /** - * Connect pattern to lexer - */ - function connectTo($mode) { - $this->Lexer->addSpecialPattern('----+ *datacloud(?: [ a-zA-Z0-9_]*)?-+\n.*?\n----+',$mode,'plugin_data_cloud'); - } - - function _buildSQL(&$data){ - $ckey = array_keys($data['cols']); - $ckey = $ckey[0]; - - $from = ' '; - $where = ' '; - $pagesjoin = ''; - $tables = array(); - - $sqlite = $this->dthlp->_getDB(); - if(!$sqlite) return false; - - $fields = array('pageid' => 'page', 'class' => 'class', - 'title' => 'title'); - // prepare filters (no request filters - we set them ourselves) - if(is_array($data['filter']) && count($data['filter'])){ - - foreach($data['filter'] as $filter){ - $col = $filter['key']; - $closecompare = ($filter['compare'] == 'IN(' ? ')' : ''); - - if (preg_match('/^%(\w+)%$/', $col, $m) && isset($fields[$m[1]])) { - $where .= " ".$filter['logic']." pages." . $fields[$m[1]] . - " " . $filter['compare']." '".$filter['value']."'".$closecompare; - $pagesjoin = ' LEFT JOIN pages ON pages.pid = data.pid'; - }else{ - // filter by hidden column? - if(!$tables[$col]){ - $tables[$col] = 'T'.(++$cnt); - $from .= ' LEFT JOIN data AS '.$tables[$col].' ON '.$tables[$col].'.pid = data.pid'; - $from .= ' AND '.$tables[$col].".key = ".$sqlite->quote_string($col); - } - - $where .= ' '.$filter['logic'].' '.$tables[$col].'.value '.$filter['compare']. - " '".$filter['value']."'".$closecompare; //value is already escaped - } - } - } - - // build query - $sql = "SELECT data.value, COUNT(data.pid) as cnt - FROM data $from $pagesjoin - WHERE data.key = ".$sqlite->quote_string($ckey)." - $where - GROUP BY data.value"; - if(isset($data['min'])) $sql .= ' HAVING cnt >= '.$data['min']; - $sql .= ' ORDER BY cnt DESC'; - if($data['limit']) $sql .= ' LIMIT '.$data['limit']; - - return $sql; - } - - protected $before_item = '
      '; - protected $after_item = '
    '; - protected $before_val = '
  • '; - protected $after_val = '
  • '; - - /** - * Create output or save the data - */ - function render($format, Doku_Renderer $renderer, $data) { - global $ID; - - if($format != 'xhtml') return false; - if(is_null($data)) return; - if(!$this->dthlp->ready()) return false; - $renderer->info['cache'] = false; - - $sqlite = $this->dthlp->_getDB(); - if(!$sqlite) return false; - - $ckey = array_keys($data['cols']); - $ckey = $ckey[0]; - - if(!isset($data['page'])) $data['page'] = $ID; - - $this->dthlp->_replacePlaceholdersInSQL($data); - - // build cloud data - $res = $sqlite->query($data['sql']); - $rows = $sqlite->res2arr($res); - $min = 0; - $max = 0; - $tags = array(); - foreach ($rows as $row) { - if(!$max) $max = $row['cnt']; - $min = $row['cnt']; - $tags[$row['value']]['cnt'] = $row['cnt']; - $tags[$row['value']]['value'] = $row['value']; - } - $this->_cloud_weight($tags,$min,$max,5); - - // output cloud - $renderer->doc .= sprintf($this->before_item,hsc($data['classes'])); - foreach($tags as $tag){ - $output_tag_label = hsc($tag['value']); - if($data['summarize'] == 1){ $output_tag_label .= '('.$tag['cnt'].')'; } - - $renderer->doc .= sprintf($this->before_val,$tag['lvl']); - $renderer->doc .= ''.$output_tag_label.''; - $renderer->doc .= $this->after_val; - } - $renderer->doc .= $this->after_item; - return true; - } - - - /** - * Create a weighted tag distribution - * - * @param $tags array ref The tags to weight ( tag => count) - * @param $min int The lowest count of a single tag - * @param $max int The highest count of a single tag - * @param $levels int The number of levels you want. A 5 gives levels 0 to 4. - */ - function _cloud_weight(&$tags,$min,$max,$levels){ - $levels--; - - // calculate tresholds - $tresholds = array(); - for($i=0; $i<=$levels; $i++){ - $tresholds[$i] = pow($max - $min + 1, $i/$levels) + $min - 1; - } - - // assign weights - foreach($tags as $tag){ - foreach($tresholds as $tresh => $val){ - if($tag['cnt'] <= $val){ - $tags[$tag['value']]['lvl'] = $tresh; - break; - } - $tags[$tag['value']]['lvl'] = $levels; - } - } - - // sort - ksort($tags); - } - -} From 809c59e37c255770130c2620f7e6c77e1cfc0a84 Mon Sep 17 00:00:00 2001 From: endoanaconda Date: Mon, 13 Oct 2014 15:42:12 +0200 Subject: [PATCH 7/7] Update cloud.php sorry, this change is allready pulled in an other request, but came by mistake with this commit. please remove this.