1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.4 Rebuild Links?

Discussion in 'XenForo Questions and Support' started by Jafo, Jan 7, 2015.

  1. Jafo

    Jafo Active Member

  2. batpool52!

    batpool52! Well-Known Member

  3. Jafo

    Jafo Active Member

    How does that help exactly?
     
  4. batpool52!

    batpool52! Well-Known Member

    You can use the regex to un-parsed links to parsed links.
     
  5. Jafo

    Jafo Active Member

    There is no existing bbcode to match against?
     
  6. batpool52!

    batpool52! Well-Known Member

    Here is what I was able to do,

    Before:
    ============
    rebuild_links_before.PNG

    =============
    After:
    ===========

    rebuild_links_after.PNG
    Under the regular express textbox enter this
    Code:
    #(\s|^)((https?://)?(\w|-)+(\.(\w+|-)*)+(?<=\.net|org|edu|com|cc|br|jp|dk|gs|de|in)(\:[0-9]+)?(?:/[^\s]*)?)(?=\s|\b)#is
    and for the replacement string enter this:
    Code:
    [url]$0[/url]
    You'll need to do the edit to the file for success of the Post Content Find, replace the library\PostReplace\ControllerAdmin\PostReplace.php content with this
    PHP:
    <?php

    class PostReplace_ControllerAdmin_PostReplace extends XenForo_ControllerAdmin_Abstract
    {
        public function 
    actionIndex()
        {
            return 
    $this->responseView('PostReplace_ViewAdmin_PostReplace_Index''postreplace_index');
        }

        public function 
    actionReplace()
        {
            
    $this->_assertPostOnly();

            
    $input $this->_input->filter(array(
                
    'find' => XenForo_Input::STRING,
                
    'regex' => XenForo_Input::STRING,
                
    'replace' => XenForo_Input::STRING,
                
    'commit' => XenForo_Input::UINT,
                
    'page' => XenForo_Input::UINT,
            ));

            
    $posts $this->_getPRPostModel()->getPostsContaining($input['find']);

            foreach (
    $posts AS $postId => &$post)
            {
                if (
    preg_match_all($input['regex'], $post['message'], $matches))
                {
                    
    $post['found'] = $matches[0];
                   
                    foreach (
    $post['found'] as $pf => &$pp)
                    {
                        if (
    substr($ppstrlen($pp) - 1strlen($pp)) == '/')
                        {
                            
    $pp trim(substr($pp0strlen($pp) - 1));
                            
    $pp str_replace(array("\r\n""\r""\n""\t""\s"), ''$pp);
                        }
                    }
                   
                    
    $post['replaced'] = preg_replace($input['regex'], $input['replace'], $post['found']);

                    
    $message preg_replace($input['regex'], $input['replace'], $post['message']);

                    if (
    $input['commit'])
                    {
                        
    $dw XenForo_DataWriter::create('XenForo_DataWriter_DiscussionMessage_Post');

                        
    $dw->setOption(XenForo_DataWriter_DiscussionMessage::OPTION_IS_AUTOMATEDtrue);
                        
    $dw->setExistingData($posttrue);

                        
    $dw->set('message'$message);

                        
    $dw->save();
                    }
                }
                else
                {
                    unset(
    $posts[$postId]);
                }
            }

            
    $viewParams = array(
                
    'input' => $input,
                
    'posts' => $posts
            
    );

            return 
    $this->responseView('PostReplace_ViewAdmin_PostReplace_Replace''postreplace_index'$viewParams);
        }

        
    /**
         * @return PostReplace_Model_Post
         */
        
    protected function _getPRPostModel()
        {
            return 
    $this->getModelFromCache('PostReplace_Model_Post');
        }
    }
     

Share This Page