Changeset 2924:c59b30cb0663
- Timestamp:
- 01/21/15 15:52:16 (11 years ago)
- Branch:
- default
- Location:
- plugins/tags
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/tags/_admin.php
r2849 r2924 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 12 13 if (!defined('DC_CONTEXT_ADMIN')) { return; } 13 14 … … 36 37 $core->addBehavior('adminBeforeUserUpdate',array('tagsBehaviors','setTagListFormat')); 37 38 38 $core->addBehavior('coreInitWikiPost',array('tagsBehaviors','coreInitWikiPost'));39 40 39 $core->addBehavior('adminDashboardFavorites',array('tagsBehaviors','dashboardFavorites')); 41 40 42 41 $core->addBehavior('adminPageHelpBlock', array('tagsBehaviors', 'adminPageHelpBlock')); 43 42 43 $core->addBehavior('adminPostEditor', array('tagsBehaviors','adminPostEditor')); 44 44 $core->addBehavior('ckeditorExtraPlugins', array('tagsBehaviors', 'ckeditorExtraPlugins')); 45 46 # BEHAVIORS47 class tagsBehaviors48 {49 public static function ckeditorExtraPlugins(ArrayObject $extraPlugins, $context)50 {51 global $core;52 53 if ($context!='post') {54 return;55 }56 $extraPlugins[] = array(57 'name' => 'dctags',58 'button' => 'dcTags',59 'url' => DC_ADMIN_URL.'index.php?pf=tags/js/ckeditor-tags-plugin.js'60 );61 }62 63 public static function adminPageHelpBlock($blocks)64 {65 $found = false;66 foreach($blocks as $block) {67 if ($block == 'core_post') {68 $found = true;69 break;70 }71 }72 if (!$found) {73 return null;74 }75 $blocks[] = 'tag_post';76 }77 78 public static function dashboardFavorites($core,$favs)79 {80 $favs->register('tags', array(81 'title' => __('Tags'),82 'url' => $core->adminurl->get('admin.plugin.tags',array('m' => 'tags')),83 'small-icon' => dcPage::getPF('tags/icon.png'),84 'large-icon' => dcPage::getPF('tags/icon-big.png'),85 'permissions' => 'usage,contentadmin'86 ));87 }88 89 public static function coreInitWikiPost($wiki2xhtml)90 {91 $wiki2xhtml->registerFunction('url:tag',array('tagsBehaviors','wiki2xhtmlTag'));92 }93 94 public static function wiki2xhtmlTag($url,$content)95 {96 $url = substr($url,4);97 if (strpos($content,'tag:') === 0) {98 $content = substr($content,4);99 }100 101 102 $tag_url = html::stripHostURL($GLOBALS['core']->blog->url.$GLOBALS['core']->url->getURLFor('tag'));103 $res['url'] = $tag_url.'/'.rawurlencode(dcMeta::sanitizeMetaID($url));104 $res['content'] = $content;105 106 return $res;107 }108 109 public static function tagsField($main,$sidebar,$post)110 {111 $meta =& $GLOBALS['core']->meta;112 113 if (!empty($_POST['post_tags'])) {114 $value = $_POST['post_tags'];115 } else {116 $value = ($post) ? $meta->getMetaStr($post->post_meta,'tag') : '';117 }118 $sidebar['metas-box']['items']['post_tags']=119 '<h5><label class="s-tags" for="post_tags">'.__('Tags').'</label></h5>'.120 '<div class="p s-tags" id="tags-edit">'.form::textarea('post_tags',20,3,$value,'maximal').'</div>';121 }122 123 public static function setTags($cur,$post_id)124 {125 $post_id = (integer) $post_id;126 127 if (isset($_POST['post_tags'])) {128 $tags = $_POST['post_tags'];129 $meta =& $GLOBALS['core']->meta;130 $meta->delPostMeta($post_id,'tag');131 132 foreach ($meta->splitMetaValues($tags) as $tag) {133 $meta->setPostMeta($post_id,'tag',$tag);134 }135 }136 }137 138 139 public static function adminPostsActionsPage($core,$ap)140 {141 $ap->addAction(142 array(__('Tags') => array(__('Add tags') => 'tags')),143 array('tagsBehaviors','adminAddTags')144 );145 146 if ($core->auth->check('delete,contentadmin',$core->blog->id)) {147 $ap->addAction(148 array(__('Tags') => array(__('Remove tags') => 'tags_remove')),149 array('tagsBehaviors','adminRemoveTags')150 );151 }152 }153 154 public static function adminAddTags($core, dcPostsActionsPage $ap, $post)155 {156 if (!empty($post['new_tags']))157 {158 $meta =& $core->meta;159 $tags = $meta->splitMetaValues($post['new_tags']);160 $posts = $ap->getRS();161 while ($posts->fetch())162 {163 # Get tags for post164 $post_meta = $meta->getMetadata(array(165 'meta_type' => 'tag',166 'post_id' => $posts->post_id));167 $pm = array();168 while ($post_meta->fetch()) {169 $pm[] = $post_meta->meta_id;170 }171 foreach ($tags as $t) {172 if (!in_array($t,$pm)) {173 $meta->setPostMeta($posts->post_id,'tag',$t);174 }175 }176 }177 dcPage::addSuccessNotice(sprintf(178 __(179 'Tag has been successfully added to selected entries',180 'Tags have been successfully added to selected entries',181 count($tags))182 )183 );184 $ap->redirect(true);185 }186 else187 {188 $tag_url = $core->blog->url.$core->url->getURLFor('tag');189 190 $opts = $core->auth->getOptions();191 $type = isset($opts['tag_list_format']) ? $opts['tag_list_format'] : 'more';192 193 194 $ap->beginPage(195 dcPage::breadcrumb(196 array(197 html::escapeHTML($core->blog->name) => '',198 __('Entries') => $ap->getRedirection(true),199 __('Add tags to this selection') => ''200 )),201 dcPage::jsLoad('js/jquery/jquery.autocomplete.js').202 dcPage::jsMetaEditor().203 '<script type="text/javascript">'."\n".204 "//<![CDATA[\n".205 "var editor_tags_options = {\n".206 "meta_url : 'plugin.php?p=tags&m=tag_posts&tag=',\n".207 "list_type : '".html::escapeJS($type)."',\n".208 "text_confirm_remove : '".html::escapeJS(__('Are you sure you want to remove this tag?'))."',\n".209 "text_add_meta : '".html::escapeJS(__('Add a tag to this entry'))."',\n".210 "text_choose : '".html::escapeJS(__('Choose from list'))."',\n".211 "text_all : '".html::escapeJS(__('all'))."',\n".212 "text_separation : '".html::escapeJS(__('Enter tags separated by coma'))."',\n".213 "};\n".214 "\n//]]>\n".215 "</script>\n".216 '<script type="text/javascript" src="index.php?pf=tags/js/jquery.autocomplete.js"></script>'.217 '<script type="text/javascript" src="index.php?pf=tags/js/posts_actions.js"></script>'.218 '<script type="text/javascript">'."\n".219 "//<![CDATA[\n".220 "dotclear.msg.tags_autocomplete = '".html::escapeJS(__('used in %e - frequency %p%'))."';\n".221 "dotclear.msg.entry = '".html::escapeJS(__('entry'))."';\n".222 "dotclear.msg.entries = '".html::escapeJS(__('entries'))."';\n".223 "\n//]]>\n".224 "</script>\n".225 '<link rel="stylesheet" type="text/css" href="index.php?pf=tags/style.css" />'226 );227 echo228 '<form action="'.$ap->getURI().'" method="post">'.229 $ap->getCheckboxes().230 '<div><label for="new_tags" class="area">'.__('Tags to add:').'</label> '.231 form::textarea('new_tags',60,3).232 '</div>'.233 $core->formNonce().$ap->getHiddenFields().234 form::hidden(array('action'),'tags').235 '<p><input type="submit" value="'.__('Save').'" '.236 'name="save_tags" /></p>'.237 '</form>';238 $ap->endPage();239 }240 }241 public static function adminRemoveTags($core, dcPostsActionsPage $ap, $post)242 {243 if (!empty($post['meta_id']) &&244 $core->auth->check('delete,contentadmin',$core->blog->id))245 {246 $meta =& $core->meta;247 $posts = $ap->getRS();248 while ($posts->fetch())249 {250 foreach ($_POST['meta_id'] as $v)251 {252 $meta->delPostMeta($posts->post_id,'tag',$v);253 }254 }255 dcPage::addSuccessNotice(sprintf(256 __(257 'Tag has been successfully removed from selected entries',258 'Tags have been successfully removed from selected entries',259 count($_POST['meta_id']))260 )261 );262 $ap->redirect(true);263 }264 else265 {266 $meta =& $core->meta;267 $tags = array();268 269 foreach ($ap->getIDS() as $id) {270 $post_tags = $meta->getMetadata(array(271 'meta_type' => 'tag',272 'post_id' => (integer) $id))->toStatic()->rows();273 foreach ($post_tags as $v) {274 if (isset($tags[$v['meta_id']])) {275 $tags[$v['meta_id']]++;276 } else {277 $tags[$v['meta_id']] = 1;278 }279 }280 }281 if (empty($tags)) {282 throw new Exception(__('No tags for selected entries'));283 }284 $ap->beginPage(285 dcPage::breadcrumb(286 array(287 html::escapeHTML($core->blog->name) => '',288 __('Entries') => 'posts.php',289 __('Remove selected tags from this selection') => ''290 )));291 $posts_count = count($_POST['entries']);292 293 echo294 '<form action="'.$ap->getURI().'" method="post">'.295 $ap->getCheckboxes().296 '<div><p>'.__('Following tags have been found in selected entries:').'</p>';297 298 foreach ($tags as $k => $n) {299 $label = '<label class="classic">%s %s</label>';300 if ($posts_count == $n) {301 $label = sprintf($label,'%s','<strong>%s</strong>');302 }303 echo '<p>'.sprintf($label,304 form::checkbox(array('meta_id[]'),html::escapeHTML($k)),305 html::escapeHTML($k)).306 '</p>';307 }308 309 echo310 '<p><input type="submit" value="'.__('ok').'" />'.311 312 $core->formNonce().$ap->getHiddenFields().313 form::hidden(array('action'),'tags_remove').314 '</p></div></form>';315 $ap->endPage();316 }317 318 }319 320 public static function postHeaders()321 {322 $tag_url = $GLOBALS['core']->blog->url.$GLOBALS['core']->url->getURLFor('tag');323 324 $opts = $GLOBALS['core']->auth->getOptions();325 $type = isset($opts['tag_list_format']) ? $opts['tag_list_format'] : 'more';326 327 return328 '<script type="text/javascript">'."\n".329 "//<![CDATA[\n".330 "var editor_tags_options = {\n".331 "meta_url : 'plugin.php?p=tags&m=tag_posts&tag=',\n".332 "list_type : '".html::escapeJS($type)."',\n".333 "text_confirm_remove : '".html::escapeJS(__('Are you sure you want to remove this tag?'))."',\n".334 "text_add_meta : '".html::escapeJS(__('Add a tag to this entry'))."',\n".335 "text_choose : '".html::escapeJS(__('Choose from list'))."',\n".336 "text_all : '".html::escapeJS(__('all'))."',\n".337 "text_separation : '".html::escapeJS(__('Enter tags separated by coma'))."',\n".338 "};\n".339 "\n//]]>\n".340 "</script>\n".341 '<script type="text/javascript" src="index.php?pf=tags/js/jquery.autocomplete.js"></script>'.342 '<script type="text/javascript" src="index.php?pf=tags/js/post.js"></script>'.343 '<script type="text/javascript">'."\n".344 "//<![CDATA[\n".345 "jsToolBar.prototype.elements.tag.title = '".html::escapeJS(__('Tag'))."';\n".346 "jsToolBar.prototype.elements.tag.url = '".html::escapeJS($tag_url)."';\n".347 "dotclear.msg.tags_autocomplete = '".html::escapeJS(__('used in %e - frequency %p%'))."';\n".348 "dotclear.msg.entry = '".html::escapeJS(__('entry'))."';\n".349 "dotclear.msg.entries = '".html::escapeJS(__('entries'))."';\n".350 "\n//]]>\n".351 "</script>\n".352 '<link rel="stylesheet" type="text/css" href="index.php?pf=tags/style.css" />';353 }354 355 public static function adminUserForm($args)356 {357 if ($args instanceof dcCore) {358 $opts = $args->auth->getOptions();359 }360 elseif ($args instanceof record) {361 $opts = $args->options();362 }363 else {364 $opts = array();365 }366 367 $combo = array();368 $combo[__('Short')] = 'more';369 $combo[__('Extended')] = 'all';370 371 $value = array_key_exists('tag_list_format',$opts) ? $opts['tag_list_format'] : 'more';372 373 echo374 '<p><label for="user_tag_list_format" class="classic">'.__('Tags list format:').'</label> '.375 form::combo('user_tag_list_format',$combo,$value).376 '</p>';377 }378 379 public static function setTagListFormat($cur,$user_id = null)380 {381 if (!is_null($user_id)) {382 $cur->user_options['tag_list_format'] = $_POST['user_tag_list_format'];383 }384 }385 } -
plugins/tags/_define.php
r2662 r2924 16 16 /* Description*/ "Tags for posts", 17 17 /* Author */ "Olivier Meunier", 18 /* Version */ '1. 3',18 /* Version */ '1.4', 19 19 array( 20 20 'permissions' => 'usage,contentadmin', 21 'priority' => 998,21 'priority' => 1001, // Must be higher than dcLegacyEditor/dcCKEditor priority (ie 1000) 22 22 'type' => 'plugin' 23 23 ) -
plugins/tags/_prepend.php
r2095 r2924 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 12 13 if (!defined('DC_RC_PATH')) { return; } 13 14 … … 15 16 $core->url->register('tags', 'tags', '^tags$', array('urlTags', 'tags')); 16 17 $core->url->register('tag_feed', 'feed/tag', '^feed/tag/(.+)$', array('urlTags', 'tagFeed')); 18 19 $__autoload['tagsBehaviors'] = dirname(__FILE__).'/inc/tags.behaviors.php'; 20 21 $core->addBehavior('coreInitWikiPost',array('tagsBehaviors','coreInitWikiPost')); -
plugins/tags/js/post.js
r2546 r2924 66 66 67 67 }); 68 69 // Toolbar button for tags70 jsToolBar.prototype.elements.tagSpace = {71 type: 'space',72 format:{73 wysiwyg:true,74 wiki:true,75 xhtml:true76 }77 };78 79 jsToolBar.prototype.elements.tag = {type: 'button', title: 'Keyword', fn:{} };80 jsToolBar.prototype.elements.tag.context = 'post';81 jsToolBar.prototype.elements.tag.icon = 'index.php?pf=tags/img/tag-add.png';82 jsToolBar.prototype.elements.tag.fn.wiki = function() {83 this.encloseSelection('','',function(str) {84 if (str == '') { window.alert(dotclear.msg.no_selection); return ''; }85 if (str.indexOf(',') != -1) {86 return str;87 } else {88 window.dc_tag_editor.addMeta(str);89 return '['+str+'|tag:'+str+']';90 }91 });92 };93 jsToolBar.prototype.elements.tag.fn.xhtml = function() {94 var url = this.elements.tag.url;95 this.encloseSelection('','',function(str) {96 if (str == '') { window.alert(dotclear.msg.no_selection); return ''; }97 if (str.indexOf(',') != -1) {98 return str;99 } else {100 window.dc_tag_editor.addMeta(str);101 return '<a href="'+this.stripBaseURL(url+'/'+str)+'">'+str+'</a>';102 }103 });104 };105 jsToolBar.prototype.elements.tag.fn.wysiwyg = function() {106 var t = this.getSelectedText();107 108 if (t == '') { window.alert(dotclear.msg.no_selection); return; }109 if (t.indexOf(',') != -1) { return; }110 111 var n = this.getSelectedNode();112 var a = document.createElement('a');113 a.href = this.stripBaseURL(this.elements.tag.url+'/'+t);114 a.appendChild(n);115 this.insertNode(a);116 window.dc_tag_editor.addMeta(t);117 };
Note: See TracChangeset
for help on using the changeset viewer.