最近の更新

関連


その他いろいろ

多機能フィードリーダSynapse製作中

2月までは目が回るほど忙しい

MODxでつくる! 最強のCMSサイト カバー
MODxでつくる! 最強のCMSサイト

NewsPublisherTagging

チェックボックスで投稿時にタグ(カテゴリ)をつける
初出:2007年03/31 更新:2007年04/04

この文書のキーワード: PHP, MODx

NewsPublisherTaggingとは

標準のNewsPublisherにチェックボックスによるタグ付けを追加したスニペットです。 使用例
ダウンロードはこちらから→snippet.NewsPublisherTagging.1.4-1.0.zip

※ このスニペットはカテゴリタグを付けるためのものです。表示には別途CategoryTagsの導入(+Ditto改造)が必要です。

See also: WordPress Integrator.

変更履歴

NewsPublisherからの変更点

使い方

  1. テンプレート変数の作成

    テンプレート変数blogTagsを作成し、入力を"Checkbox"に、Widgetを"Delimited List"、そのDelimiterを,などと指定します。(Dittoが内部的なセパレータに|を使う関係で|を含むものはさけた方が良いでしょう)

  2. 投稿画面の編集

    チャンクFromBlogを開き、適当な位置に[+tags+]を挿入します。

  3. スニペットの引数指定

    Add a Blog Entryの編集画面を開き、

    [!NewsPublisher? &folder=`2` &canpost=`Site Admins` &formtpl=`FormBlog` &footertpl=`FormBlogComments` &makefolder=`1` &rtcontent=`tvblogContent` &tvtags=`tvblogTags` &template=`7bitlog`!]
    
    を参考に変更します。(&tvtags接頭辞tvに注意)

  4. Dittoによるタグ別表示

    タグ別表示をするページを新規作成するなりして、

    [[Ditto? &startID=`2` &tpl=`DittoTemplate` &summarize=`3` &multiLevel=`0` &commentsChunk=`FormBlogComments` &hiddenTVs=`blogTags` &tags=`tag2*tag4` &tagData=`tvblogTags` &tagDelimiter=`,`]]
    
    を参考に限定するタグを指定します。&hiddenTVsには接頭辞tvをつけず、&tagDataにはつけることに注意してください。

NewsPublisherをタグ付け対応化するdiff

どこを変えたかわかりやすいようにdiffもおいときます。

--- /snippet.NewsPublisher.original.php	Mon Jun 26 03:56:21 2006
+++ /snippet.NewsPublisherTagging.1.4-1.0.php	Tue Jun 27 06:35:16 2006
@@ -1,4 +1,19 @@
-/*<?/**/#::::::::::::::::::::::::::::::::::::::::
+/*<?/**/
+#::::::::::::::::::::::::::::::::::::::::
+#
+#  Snippet Name: NewsPublisherTagging
+#  Short Desc: Create articles directly from front end (news, blogs, PR, etc.)
+#  Created By: uglydog (http://nanabit.net/), June 2006
+#  Based On: NewsPublisher 1.4 by Raymond Irving (xwisdom@yahoo.com), August 2005
+#
+#  Version: 1.0
+#  Modified: June 27, 2006
+#
+#  Changelog: 
+#
+#::::::::::::::::::::::::::::::::::::::::
+
+#::::::::::::::::::::::::::::::::::::::::
 #
 #  Snippet Name: NewsPublisher 
 #  Short Desc: Create articles directly from front end (news, blogs, PR, etc.)
@@ -31,6 +46,7 @@
 #    &formtpl     - form template (chunk name)
 #    &rtcontent   - name of a richtext content form field 
 #    &rtsummary   - name of a richtext summary form field 
+#    &tvtags      - name of a checkbox(delimited list format) template variable
 #    &showinmenu  - sets the flag to true or false (1|0) as to whether or not it shows in the menu. defaults to false (0)
 #    &aliastitle  - set to 1 to use page title as alias suffix. Defaults to 0 - date created.
 #    &clearcache  - when set to 1 the system will automatically clear the site cache after publishing an article.
@@ -57,6 +73,9 @@
 // set rich text summary field
 $rtsummary = isset($rtsummary) ? $rtsummary:'introtext';
 
+// TV(checkbox) name
+$tvtags = isset($tvtags) ? $tvtags:'';
+
 // get header
 $header = isset($headertpl) ? "":'';
 
@@ -96,6 +115,7 @@
         <a onClick="document.NewsPublisher.unpub_date.value=\'\'; return true;" onMouseover="window.status=\'Remove date\'; return true;" onMouseout="window.status=\'\'; return true;" style="cursor:pointer; cursor:hand"><img align="absmiddle" src="manager/media/images/icons/cal_nodate.gif" width="16" height="16" border="0" alt="Remove date"></a><br />
         Summary:<br /><textarea name="introtext" cols="50" rows="5">[+introtext+]</textarea><br />
         Content:<br /><textarea name="content" cols="50" rows="8">[+content+]</textarea><br />
+        Tags:<br />[+tags+]<br />
         <input name="send" type="submit" value="Submit" />
     </form>
     <script language="JavaScript" src="manager/media/script/datefunctions.js"></script>
@@ -153,6 +173,15 @@
 
             $allowedTags = '<p><br><a><i><em><b><strong><pre><table><th><td><tr><img><span><div><h1><h2><h3><h4><h5><font><ul><ol><li><dl><dt><dd>';
 
+            // tagging
+            $tags = array();
+            foreach($_POST as $n=>$v) {
+            	if( substr($n, 0, 5)=='tags-' && $v=='on' ){
+            		array_push($tags, substr($n, 5));
+            		unset($_POST[$n]);
+            	}
+            }
+            $tags_tvcontent = implode('||', $tags);
             // format content
             $content = $modx->stripTags($_POST[$rtcontent],$allowedTags);
             $content = str_replace('[+user+]',$user,$content);
@@ -223,11 +252,24 @@
                 'content'         => mysql_escape_string($header.$content.$footer)
             );
             $redirectid = $modx->db->insert($flds,$modx->getFullTableName('site_content'));
-
             // Doc group thing
             // look in save_content.processor.php for tips (or below)
             $lastInsertId = $modx->db->getInsertId();
 
+            //add tag data
+            if($tags_tvcontent){
+            	$rs = $modx->dbQuery("SELECT id FROM ".$modx->getFullTableName('site_tmplvars')." WHERE name='".substr($tvtags, 2)."' LIMIT 1;");
+	            if($row = $modx->fetchRow($rs, 'assoc')){
+		            $tmplflds = array(
+		            	'tmplvarid' => $row['id'],
+		            	'contentid' => $lastInsertId,
+		            	'value' => mysql_escape_string($tags_tvcontent)
+		            );
+		            $modx->db->insert($tmplflds,$modx->getFullTableName('site_tmplvar_contentvalues'));
+		        }
+	        }
+
+
             // Get doc groups based on $folder (parent id)
             $parentDocGroupsSql = "SELECT * FROM " . $modx->getFullTableName('document_groups'). " where document=".$folder;
             $parentDocGroupsRs = $modx->db->query($parentDocGroupsSql);
@@ -310,6 +352,20 @@
         } else {
             foreach($_POST as $n=>$v) {
                 $formTpl = str_replace('[+'.$n.'+]',$v,$formTpl);
+            }
+            //tag area
+            if($tvtags){
+                $rs = $modx->dbQuery("SELECT elements FROM ".$modx->getFullTableName('site_tmplvars')." WHERE name='".substr($tvtags, 2)."' LIMIT 1;");
+                if($row = $modx->fetchRow($rs, 'assoc')){
+                    $default_tags = explode('||', $row['elements']);
+                    if($default_tags){
+	                    $tag_area = '';
+	                    foreach($default_tags as $tag){
+	                    	$tag_area.= '<input type="checkbox" name="tags-'.$tag.'" id="tags-'.$tag.'" />'.$tag."<br />\n";
+	                    }
+	                    $formTpl = str_replace('[+tags+]',$tag_area,$formTpl);
+	                }
+                }
             }
         }
         // return form