Skip to content

Commit bc5d331

Browse files
committed
Merge pull request dignajar#54 from ForestMist/master
Tags with spaces
2 parents 4543f1b + 98f180f commit bc5d331

File tree

13 files changed

+62
-23
lines changed

13 files changed

+62
-23
lines changed

admin/boot/rules/98-blog.bit

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ if( ($url['controller']!=null) && ($url['action']!=null) )
4747
{
4848
$layout['title'] .= !empty($post['title'])?' - '.$post['title']:'';
4949
$layout['description'] = $post['description'];
50-
$layout['keywords'] = implode(',',$post['tags']);
50+
$layout['keywords'] = implode(',', array_map('array_pop', $post['tags']));
5151
$layout['canonical'] = Url::post($post, true);
5252

5353
$where_am_i[1] = 'post';

admin/kernel/db/db_tags.class.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function add($args)
5353
$id = $this->get_autoinc();
5454
$this->set_autoinc();
5555

56-
$node = $this->xml->list->addGodChild('tag', array('id'=>$id, 'name'=>$args['name']));
56+
$node = $this->xml->list->addGodChild('tag', array('id'=>$id, 'name'=>$args['name'], 'name_human'=>$args['name_human']));
5757

5858
return $id;
5959
}
@@ -89,6 +89,7 @@ public function get($args)
8989
$tmp = array();
9090
$tmp['id'] = $node[0]->getAttribute('id');
9191
$tmp['name'] = $node[0]->getAttribute('name');
92+
$tmp['name_human'] = $node[0]->getAttribute('name_human');
9293

9394
return $tmp;
9495
}
@@ -116,7 +117,7 @@ public function get_by_idpost($args)
116117
$id_tag = $node->getAttribute('id_tag');
117118
$tag = $this->get(array('id'=>$id_tag));
118119

119-
array_push($tmp, $tag['name']);
120+
array_push($tmp, array('name'=>$tag['name'], 'name_human'=>$tag['name_human']));
120121
}
121122

122123
return $tmp;
@@ -127,9 +128,9 @@ public function add_tags($args)
127128
{
128129
$tmp = $this->recondition($args['tags']);
129130

130-
foreach($tmp as $tag_name)
131+
foreach($tmp as $tag)
131132
{
132-
$id = $this->add(array('name'=>$tag_name));
133+
$id = $this->add(array('name'=>$tag['name'], 'name_human'=>$tag['name_human']));
133134

134135
$this->link(array('id_tag'=>$id, 'id_post'=>$args['id_post']));
135136
}
@@ -183,11 +184,12 @@ public function get_cloud()
183184
{
184185
$id = (int)$tag->getAttribute('id');
185186
$name = (string)$tag->getAttribute('name');
187+
$name_human = (string)$tag->getAttribute('name_human');
186188

187189
$where = '@id_tag="'.$id.'"';
188190
$nodes = $this->xml->xpath('/tags/links/link['.$where.']');
189191

190-
$tmp[$name] = count($nodes);
192+
$tmp[$name] = array('amount'=>count($nodes), 'name_human'=>$name_human);
191193
}
192194

193195
return $tmp;
@@ -217,16 +219,16 @@ private function set_autoinc($value = 1)
217219
// Recive an string $tags and convert this to an array
218220
private function recondition($tags)
219221
{
220-
$tags = Text::strip_spaces($tags);
221-
222222
$explode = explode(',', $tags);
223223

224224
$tmp_array = array();
225225
foreach( $explode as $tag )
226226
{
227+
$tag = trim($tag);
227228
if(!empty($tag))
228-
array_push($tmp_array, $tag);
229+
array_push($tmp_array, array('name'=>Text::strip_spaces($tag), 'name_human'=>$tag));
229230
}
231+
230232
return( $tmp_array );
231233
}
232234

admin/kernel/helpers/post.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static function tags($return2array=false)
9494

9595
$html = '<ul>';
9696
foreach($tags as $tag)
97-
$html .= '<li><a class="tag" href="'.Url::tag($tag).'">'.$tag.'</a></li>';
97+
$html .= '<li><a class="tag" href="'.Url::tag($tag['name']).'">'.$tag['name_human'].'</a></li>';
9898
$html .= '</ul>';
9999

100100
return $html;

admin/views/post/includes/tags.bit

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
if(!empty($post_edit['tags']))
66
{
7-
$value = implode(', ',$post_edit['tags']);
7+
$value = implode(', ', array_map('array_pop', $post_edit['tags']));
88
}
99

1010
echo Html::div_open( array('class'=>'form_block', 'hidden'=>!$settings['advanced_post_options']) );

bludit.php

+20
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ function post_to_json($post, $tojson=true)
3737
// Category
3838
$category = $_DB_CATEGORIES->get( array('id'=>$post['id_cat']) );
3939
array_push($post['tags'], $category['name']);
40+
/*
41+
The above array_push line may need to be rewritten.
42+
43+
$post['tags'] now has the following structure...
44+
45+
Array
46+
(
47+
[0] => Array
48+
(
49+
[name] => startrek
50+
[name_human] => star trek
51+
)
52+
[1] => Array
53+
(
54+
[name] => icecream
55+
[name_human] => ice cream
56+
)
57+
)
58+
59+
*/
4060

4161
// Content
4262
// Src images relatives to absolute

plugins/open_graph/plugin.bit

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class PLUGIN_OPEN_GRAPH extends Plugin
4848
// tags
4949
$og['tags'] .= '<meta property="article:tag" content="'.$post['category'].'">'.PHP_EOL;
5050
foreach($post['tags'] as $tag)
51-
$og['tags'] .= '<meta property="article:tag" content="'.$tag.'">'.PHP_EOL;
51+
$og['tags'] .= '<meta property="article:tag" content="'.$tag['name_human'].'">'.PHP_EOL;
5252
}
5353
elseif( ($where_am_i[1]=='page') && !empty($page) )
5454
{

plugins/tag_cloud/plugin.bit

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ class PLUGIN_TAG_CLOUD extends Plugin
4545

4646
$html = '';
4747

48-
foreach($cloud as $tag=>$amount)
48+
foreach($cloud as $tag=>$val)
4949
{
50-
$amount = $amount + $this->database('min_size');
50+
$amount = $val['amount'] + $this->database('min_size');
5151

5252
// Max size 40px
5353
$size = min($amount, $this->database('max_size'));
@@ -57,7 +57,7 @@ class PLUGIN_TAG_CLOUD extends Plugin
5757

5858
$style = 'font-size:'.$size.'px; margin-right: 5px; display: inline-block;';
5959

60-
$html .= '<a class="level_'.$size.'" style="'.$style.'" href="'.Url::tag($tag).'">'.$tag.'</a>';
60+
$html .= '<a class="level_'.$size.'" style="'.$style.'" href="'.Url::tag($tag).'">'.$val['name_human'].'</a>';
6161
}
6262

6363
return $html;

themes/echo/views/blog/includes/post_body.bit

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if(!empty($post['tags']))
2525
$tags = $post['tags'];
2626

2727
foreach($tags as $key=>$tag)
28-
$tags[$key] = '<a class="tag" href="'.Url::tag($tag).'">'.$tag.'</a>';
28+
$tags[$key] = '<a class="tag" href="'.Url::tag($tag['name']).'">'.$tag['name_human'].'</a>';
2929

3030
$tags = implode(', ',$tags);
3131

themes/echo/views/page/view.bit

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
<article>
22

3-
<h2 class="post-title"><?php echo Page::title() ?></h2>';
3+
<h2 class="post-title"><?php echo Page::title() ?></h2>
44

55
<?php echo Page::content() ?>
66

77
</article>
8-
9-
?>
10-

themes/echo/views/post/includes/post_body.bit

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if(!empty($post['tags']))
2525
$tags = $post['tags'];
2626

2727
foreach($tags as $key=>$tag)
28-
$tags[$key] = '<a class="tag" href="'.Url::tag($tag).'">'.$tag.'</a>';
28+
$tags[$key] = '<a class="tag" href="'.Url::tag($tag['name']).'">'.$tag['name_human'].'</a>';
2929

3030
$tags = implode(', ',$tags);
3131

themes/medium/init.bit

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ $layout['view'] = 'post/view.bit';
66

77
$layout['title'] = !empty($post['title'])?' - '.$post['title']:'';
88
$layout['description'] = $post['description'];
9-
$layout['keywords'] = implode(',',$post['tags']);
9+
$layout['keywords'] = implode(',', array_map('array_pop', $post['tags']));
1010
$layout['canonical'] = Url::post($post, true);
1111

1212
$where_am_i[1] = 'post';

themes/techie/views/blog/taglist.bit

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ echo '<footer class="tag_container">';
55
echo '<a title="'.$Language->get('TAGS').'" id="'.$post['slug'].'" class="tag_button" onclick="toggleTags(this)"></a>';
66
echo '<div class="tag_list">';
77
foreach($post['tags'] as $tag)
8-
echo '<a class="tag" href="'.Url::tag($tag).'">'.$tag.'</a>';
8+
echo '<a class="tag" href="'.Url::tag($tag['name']).'">'.$tag['name_human'].'</a>';
99
echo '</div>';
1010
echo '</footer>';
1111
}

update.php

+20
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,26 @@ function add_if_not($obj, $name, $value)
263263

264264
echo Html::p( array('class'=>'pass', 'content'=>'File created: '.FILE_XML_TAGS) );
265265
}
266+
else
267+
{
268+
// upgrade tag names to support spaces
269+
$xml = file_get_contents( FILE_XML_TAGS );
270+
$obj = new NBXML($xml, 0, FALSE, '', FALSE);
271+
$count = 0;
272+
foreach ($obj->{'list'}->children() as $tag)
273+
{
274+
if ($tag->getAttribute('name_human') === '')
275+
{
276+
$tag->addAttribute('name_human', $tag->getAttribute('name'));
277+
$count = $count + 1;
278+
}
279+
}
280+
$obj->asXml( FILE_XML_TAGS );
281+
if ($count > 0)
282+
{
283+
echo Html::p( array('class'=>'pass', 'content'=>'DB updated: '.FILE_XML_TAGS) );
284+
}
285+
}
266286

267287
// =====================================================
268288
// pages.xml

0 commit comments

Comments
 (0)