We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 696
    • 46 Posts
    I want to allow my visitors to suggest links to add to my link page, a simple adpation to the FormBlog Chunk Would work but i want the pages that are created to be unpublished by default and i want it to create a weblink not a document...

    Can anyone help/Point me in the right direction, im can code in PHP but am still getting used to ModX’s layout and Functions...

    Thank you.
      • 32241
      • 1,495 Posts
      I think the best place to look at is on manager/actions folder, but I;m not sure which file that will give you the exact weblink admin page.
        Wendy Novianto
        [font=Verdana]PT DJAMOER Technology Media
        [font=Verdana]Xituz Media
        • 33393
        • 30 Posts
        Use the newspublisher snippet.

        Use a different chunk for the form. They are all the same fields but you don’t need a content or introtext area.

        Then set the fields in the array to reference, unpublished. -- or even a certain folder so you can check it for all submissions in the document tree in the manager. Then you can can check them before they are published. Ah heck, here’s the snippet I modified...

        I didn’t use a chunk, but just changed the form in the snippet. I also added a dropdownbox for the folders I use for link topics. You will certainly have to take that out I’d think, or change it to reflect your own.

        Right now I’m using this on a privateweb page on the frontend. I have no idea how safe it is for anonymous use, but I don’t think I changed anything significant...?

        Around line 162 is where the fields are to insert into the database.


        /*	NewsPublisher for MODx  Created by Raymond Irving, August 2005 Patch for 's and redirect to new post by Mark Kaplan, October 2005
        Publish news articles directly from the web
        Parameters:
        &folder			- folder id where comments are stored
        &makefolder	- set to 1 to automatically convert the parent document to a folder. Defaults to 0
        &postid			- document id to load after posting news item. Defaults to the page created
        &canpost		- comma delimitted web groups that can post comments. leave blank for public posting
        &badwords		- comma delimited list of words not allowed in post
        &template		- name of template to use for news post
        &headertpl	- header template (chunk name) to be inserted at the begining of the news content
        &footertpl	- footer template (chunk name) to be inserted at the end of the news content
        &formtpl		- form template (chunk name)
        &rtcontent	- name of a richtext content form field 
        &rtsummary	- name of a richtext summary form field 
        &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.
        Version 1.2 Beta  */
         
        // get user groups that can post articles
        $postgrp = isset($canpost) ? explode(",",$canpost):array();
        $allowAnyPost = count($postgrp)==0 ? true : false;
        
        // get clear cache
        $clearcache	 = isset($clearcache) ? 1:0;
        
        // get alias title
        $aliastitle	 = isset($aliastitle) ? 1:0;
        
        // get folder id where we should store articles
        // else store in current document
        // e.s. - hardcode dropdown list instead for selected folders
        //$folder = isset($folder) ? intval($folder):$modx->documentIdentifier;
        
        $tbl = $modx->getFullTableName("site_content");
        $atables = "id, pagetitle";
        $awhereclaws = "parent = 16 AND isfolder = 1 AND deleted = 0 AND hidemenu = 0";
        $aorderby = "pagetitle DESC";
        $alimit = "";
        
        $sqlgetfolders = $modx->db->select($atables, $tbl, $awhereclaws, $aorderby, $alimit);
        
        if ($sqlgetfolders){
        $topics .= "<select name='folder'>";
        while ($row = $etomite->fetchRow($sqlgetfolders)) {     
        $topics .= "<option value ='".$row['id']."'>".$row['pagetitle']."</option>";      
              } 
        $topics .= "</select>";
        }
        
        // set rich text content field
        $rtcontent = isset($rtcontent) ? $rtcontent:'content';
        
        // set rich text summary field
        $rtsummary = isset($rtsummary) ? $rtsummary:'introtext';
        
        // get header
        $header = isset($headertpl) ? "{{".$headertpl."}}":'';
        
        // get footer
        $footer = isset($footertpl) ? "{{".$footertpl."}}":'';
        
        // get postback status
        $isPostBack = isset($_POST['NewsPublisherForm']) ? true:false;
        
        // get badwords
        if(isset($badwords)) {
        	$badwords = str_replace(' ','', $badwords);
        	$badwords = "/".str_replace(',','|', $badwords)."/i";
        }
        
        // get menu status
        $hidemenu = isset($showinmenu) && $showinmenu==1 ? 0 : 1;
        
        // get template
        $template = isset($template) ? $modx->db->getValue('SELECT id FROM '.$modx->getFullTableName('site_templates').' WHERE templatename=\''.mysql_escape_string($template).'\''):$modx->config['default_template'];
        
        // get form template
        if(isset($formtpl)) $formTpl = $modx->getChunk($formtpl);
        if(empty($formTpl)) $formTpl = <<<FOR
        
        <form name="NewsPublisher" method="post">
          <input name="NewsPublisherForm" type="hidden" value="on" />
        <table class="form" border="0" width="100%">
          <tr>
            <td width="29%" class="formtags">
        	Page title: </td>
            <td width="71%"> <input name="pagetitle" type="text" size="40" value="[+pagetitle+]" /></td>
          </tr>
          <tr>
            <td width="29%" class="formtags">
        	Long title: </td>
            <td width="71%"> <input name="longtitle" type="text" size="40" value="[+longtitle+]" /></td>
          </tr>
          <tr>
            <td width="29%" class="formtags">
        	Description: </td>
            <td width="71%"> <input name="description" type="text" size="40" value="[+description+]" />
            </td>
          </tr>
          <tr>
            <td width="29%" class="formtags">
          Weblink: </td>
            <td width="71%"><input name="content" type="text" size="40" value="[+content+]" /> </td>
          </tr>
        	<tr>
            <td width="29%" class="formtags">
          Link category: </td>
            <td width="71%">$topics</td>
          </tr>
        </table>
        	<input name="send" type="submit" value="Create Web Link" />
        	</form>
        FOR;
        
        
        // switch block
        switch ($isPostBack) {
        	case true:	// process post back
        		// remove magic quotes from POST
        		if(get_magic_quotes_gpc()){
        			$_POST = array_map("stripslashes", $_POST);
        		}	
        		if(trim($_POST['pagetitle'])=='') $modx->webAlert('Missing page title.');
        		elseif($_POST[$rtcontent]=='') $modx->webAlert('Missing news content.');
        		else {
        			// get created date
        			$createdon = time();
        			
        			$user = $modx->getLoginUserName();
        			$userid = $modx->getLoginUserID();
        			if(!$user && $allowAnyPost) $user = 'anonymous';
        
        			// check if user has rights
        			if(!$allowAnyPost && !$modx->isMemberOfWebGroup($postgrp)) {
        				return 'You are not allowed to publish articles';
        			}
        
        			$allowedTags = '<p><br><a><i><em><b><blockquote><strong><pre><table><th><td><tr><img><span><div><h1><h2><h3><h4><h5><font><ul><ol><li><dl><dt><dd>';
        			
        			// format content
        			$content = $modx->stripTags($_POST[$rtcontent],$allowedTags);
        			$content = str_replace('[+user+]',$user,$content);
        			$content = str_replace('[+createdon+]',strftime('%d-%b-%Y %H:%M',$createdon),$content);
        			foreach($_POST as $n=>$v) {
        				if(!empty($badwords)) $v = preg_replace($badwords,'[Filtered]',$v); // remove badwords
        				$v = $modx->stripTags(htmlspecialchars($v));
        				$v = str_replace("\n",'<br />',$v);
        				$content = str_replace('[+'.$n.'+]',$v,$content);
        			}
        			
        			$title = mysql_escape_string($modx->stripTags($_POST['pagetitle']));
        			$longtitle = mysql_escape_string($modx->stripTags($_POST['longtitle']));
        			$description = mysql_escape_string($modx->stripTags($_POST['description']));
        			$introtext = mysql_escape_string($modx->stripTags($_POST[$rtsummary],$allowedTags));
        			$folder = mysql_escape_string($modx->stripTags($_POST['folder'])); //added for dropdown
        							
        			// set menu index
        			$mnuidx = $modx->db->getValue('SELECT MAX(menuindex)+1 as \'mnuidx\' FROM '.$modx->getFullTableName('site_content').' WHERE parent=\''.$folder.'\'');
        			if($mnuidx<1) $mnuidx = 0;
        			
        			// post news content
        			$flds = array(
        				'type' => 'reference',
        				'pagetitle'	=> $title,
        				'longtitle'	=> $longtitle,
        				'description'=> $description,
        				'introtext'	=> $introtext,
        				'alias'		=> $alias,
        				'parent'	=> $folder, 
        				'createdon' => $createdon,
        				'createdby' => ($userid>0 ? $userid * -1:0),
        				'editedon' 	=> '0',
        				'editedby' 	=> '0',
        				'published' => '1',
        				'pub_date'	 => $pub_date,
        				'unpub_date' => $unpub_date,
        				'deleted' 	=> '0',
        				'hidemenu' 	=> '0',
        				'menuindex'	=> $mnuidx,
        				'template' 	=> '0',
        				'content' 	=> mysql_escape_string($header.$content.$footer)
        			);
        			$redirectid = $modx->db->insert($flds,$modx->getFullTableName('site_content'));
        			if(!empty($makefolder)) {
        				// convert parent into folder
        				$modx->db->update(array('isfolder'=>'1'),$modx->getFullTableName('site_content'),'id=\''.$folder.'\'');
        			}
        
        			// empty cache
        			if($clearcache==1){
        				include_once $modx->config['base_path']."manager/processors/cache_sync.class.processor.php";
        				$sync = new synccache();
        				$sync->setCachepath("assets/cache/");
        				$sync->setReport(false);
        				$sync->emptyCache(); // first empty the cache		
        			}
        
        			// get redirect/post id
        			$redirectid = $modx->db->getValue('SELECT id as \'redirectid\' FROM '.$modx->getFullTableName('site_content').' WHERE createdon=\''.$createdon.'\'');
        			$postid = isset($postid) ? $postid:$redirectid;
        			
        			// redirect to post id
        			$modx->sendRedirect($modx->makeUrl($postid));
        		}
        	
        	default:	// display news form
        		// check if user has rights to post comments
        		if(!$allowAnyPost && !$modx->isMemberOfWebGroup($postgrp)) {
        			$formTpl = '';
        		}
        		else {
        			foreach($_POST as $n=>$v) {
        				$formTpl = str_replace('[+'.$n.'+]',$v,$formTpl);
        			}	
        		}
        		// return form
        		return $message.$formTpl;
        		break;
        }
        
        
        
        
        


        You should set ’published’ => ’1’ on line 175 to 0 if you want it to be unpublished until you approve it.
          "Adversus solem ne loquitor." -don’t speak against the sun (don’t waste your time arguing the obvious) Something I sometimes need to be reminded of.
          • 4273
          • 356 Posts
          using the newslist snippet like this still shows the "by author" field is there a way to hide this ?
            SMF Bookmark Mod - check it out
            http://mods.simplemachines.org/index.php?mod=350
            • 25663 MODX Staff
            • 12,272 Posts
            Edit a template that contain the placeholders to remove them. I should be documented in the comments on NewsListing.
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
              • 33393
              • 30 Posts
              I need to refine this, but I think it basically works. I used the NewsSnippet as a starting point. It would be great if anyone could comment on how to improve this. I’m not a pro by any means.

              It really only needs two fields, the url, and the name. But description is helpful too depending on your need and the email of the person-- eh? Could drop it.

              I tried to get fancy and validate the host name of the submitted url, but it doesn’t seem to work everytime-- for instance when there is a www. (May have to drop that too.)

              I’m wondering about additional / alternate cleaning of user input. I haven’t read a great deal yet about sql injection etc-- is it enough?

              //replace with the folder id of an unpublished folder to hold the submissions
              $folder = 1241; 
              
              $message = <<<MSG
              <p>Please fill out the form below to submit a link.</p>
              MSG;
              
              $formTpl = <<<FRM
              <form action="[~[*id*]~]" method="POST">
              <input name="linkSubmitted" type="hidden" value="on" />
              <table class="form" border="0" width="100%">
              	<tr>
                  <td width="100" class="formLabels">Site Name*</td>
                  <td><input name="pagetitle" type="text" size="40" value="$pagetitle" /></td>
                </tr>
                <tr>
                  <td width="100" class="formLabels">URL*</td>
                  <td><input name="content" type="text" size="40" value="http://" /> </td>
                </tr>
              	<tr>
                  <td width="100" class="formLabels">Brief Description</td>
                  <td><textarea rows="3" cols="30" name="description">$description</textarea>
              		</td>
                </tr>
              	<tr>
                  <td width="100" class="formLabels">Your email</td>
                  <td><input name="longtitle" type="text" size="40" value="$longtitle" /> </td>
                </tr> 
              	<tr>
                  <td width="100" class="formLabels"></td>
                  <td><input type="submit" /> <input type="reset" />
              		</td>
                </tr>   
              </table>
              	</form> 
              FRM;
              
              if (!empty($_POST)) {
              
              		if(get_magic_quotes_gpc()) {
              			$_POST = array_map("stripslashes", $_POST);
              		}	
                  
              		$error_border = " style='border:1px solid #cc0000' ";
              		$style = "<span style='color:#cc0000;font-size:10px'>";
              		$end   = "</span>"; 
              				
              		$t = $c = $errormsg = '';
                  $t = trim($_POST['pagetitle']);
                  $c = trim($_POST['content']);
              		
              		if ($t == '') { 
              		$errormsg .= $style."*Site Name is a required field.<br>".$end; 
              		$error_name = $error_border;
              		}
              		
              		if ($c == '') { 
              		  $errormsg .= $style."*URL is a required field.<br>".$end; 
              			$error_url = $error_border;
              		  $content = "http://";
              		}
              		
              		if ($c == "http://") { 
              		  $errormsg .= $style."*URL is a required field.<br>".$end;
              			$error_url = $error_border; 
              		  $content = "http://";
              		}
              		
              		if (($c != '') and ($c != "http://")) {
              		  $get_host = parse_url($c);
              		  $hostexist = checkdnsrr($get_host[host]);
              		
              		if ($hostexist == FALSE) { 
              		  $errormsg .= $style."*The host, ".$get_host[host].", does not appear valid. Please check the URL.<br>".$end;
              		  $error_url = $error_border;
              			$content = mysql_escape_string($modx->stripTags(trim($_POST['content'])));
              		    }
              	  }
              		
              		if (!empty($errormsg)) {
              		  $pagetitle = mysql_escape_string($modx->stripTags(trim($_POST['pagetitle'])));
              		  $longtitle = mysql_escape_string($modx->stripTags(trim($_POST['longtitle'])));
              		  $description = mysql_escape_string($modx->stripTags(trim($_POST['description'])));
              			
              		
              $formTpl =<<<FRM
              <form action="[~[*id*]~]" method="POST">
              <input name="linkSubmitted" type="hidden" value="on" />
              <table class="form" border="0" width="100%">
              	<tr>
                  <td width="100">Site Name*</td>
                  <td><input $error_name name="pagetitle" type="text" size="40" value="$pagetitle" /></td>
                </tr>
                <tr>
                  <td width="100">URL*</td>
                  <td><input $error_url name="content" type="text" size="40" value="$content" /> </td>
                </tr>
              	<tr>
                  <td width="100">Brief Description</td>
                  <td><textarea rows="3" cols="30" name="description">$description</textarea>
              		</td>
                </tr>
              	<tr>
                  <td width="100">Your email</td>
                  <td><input name="longtitle" type="text" size="40" value="$longtitle" /> </td>
                </tr> 
              	<tr>
                  <td width="100" class="formLabels"></td>
                  <td><input type="submit" /> <input type="reset" />
              		</td>
                </tr>   
              </table>
              	</form> 
              FRM;
              	
              		return $message.$errormsg.$formTpl;
              		}
              
              		$pagetitle = mysql_escape_string($modx->stripTags(trim($_POST['pagetitle'])));
              		$content = mysql_escape_string($modx->stripTags(trim($_POST['content'])));
              		$longtitle = mysql_escape_string($modx->stripTags(trim($_POST['longtitle'])));
              		$description = mysql_escape_string($modx->stripTags(trim($_POST['description'])));	
                  $createdon = time();
              	
              			// post news content
              			$flds = array(
              				'type'        => 'reference',
              				'pagetitle'	  => $pagetitle,
              				'longtitle'	  => $longtitle,
              				'description' => $description,
              				'parent'	    => $folder, 
              				'createdon'   => $createdon,
              				'published'   => '0',
              				'deleted' 	  => '0',
              				'hidemenu' 	  => '1',
              				'template' 	  => '0',
              				'content' 	  => $content
              			);
              
              if ($fireinthehole = $modx->db->insert($flds,$modx->getFullTableName('site_content'))) { 
              $message = "<p>Thank you for submitting a link!</p><p>Someone will have to approve your submission before publishing it to the website.</p>";
              return $message;
                  }    
              } 
              
              if (empty($_POST)) {
              return $message.$formTpl;
              }
              

                "Adversus solem ne loquitor." -don’t speak against the sun (don’t waste your time arguing the obvious) Something I sometimes need to be reminded of.
                • 696
                • 46 Posts
                This works perfectly... its now in use on my site cezz.co.uk...

                I did make a few alterations to the code to fit my needs afterwards, and with the addition of the recently updated DropMenu to show weblinks with the exsact link to the site rather than the page link it makes it SEO friendly aswell...

                Thank you for your help i will post my revisted version when i have two min free...
                  • 867
                  • 241 Posts
                  Quote from: Aikdo at Nov 27, 2006, 09:36 AM

                  This works perfectly... its now in use on my site cezz.co.uk...

                  I did make a few alterations to the code to fit my needs afterwards, and with the addition of the recently updated DropMenu to show weblinks with the exsact link to the site rather than the page link it makes it SEO friendly aswell...

                  Thank you for your help i will post my revisted version when i have two min free...
                  UP!!

                  Thanks.. rolleyes
                    • 22815
                    • 1,097 Posts
                    Um, where?
                      No, I don&#39;t know what OpenGeek&#39;s saying half the time either.
                      MODx Documentation: The Wiki | My Wiki contributions | Main MODx Documentation
                      Forum: Where to post threads about add-ons | Forum Rules
                      Like MODx? donate (and/or share your resources)
                      Like me? See my Amazon wishlist
                      MODx "Most Promising CMS" - so appropriate!
                      • 867
                      • 241 Posts
                      Where ever he want ?
                      Right there.. grin

                      +
                      Alchime
                      (fr)