Improve your dir_categs_edit for PhpLD 2.x

Discussion in 'Directories' started by opdir, Nov 19, 2006.

  1. #1
    As you know: PhpLd is an excellent PHP directory script, and we can get its free version for 2.x. but it's a tired thing to add many categories to your directory. the problem is when you complete a category inserting, you have to choose the parent category again for the next category, at the most time, it's same to the previous one. and another question is: when you enable urlrewrite, you have to replace the " " to "_" from the title every times. it sure is an anoying thing I think.

    Solution:
    Actully, you can modify the php code to solve these questions, but at this moment, we use Javascript to try to solve them now.

    Open the "dir_categs_edit.tpl" located at "/template/admin/" by notepad or other editor you'd like, find this line:

    "{validate form="dir_categs_edit" id="v_TITLE_URL_U" message=$smarty.capture.url_title_not_unique}"
    
    Code (markup):
    add some code below:

    
    <script type="text/javascript">
    {literal}
    title = document.getElementsByName("TITLE")[0];
    
    title.onchange = function(){
        title.value = title.value.replace(/^\s*|\s*$/g,"");
        titleUrl = document.getElementsByName("TITLE_URL")[0];
        titleUrl.value = this.value.replace(/ /ig,'_');
    }
    {/literal}
    </script>
    
    Code (markup):
    and this line:
    
    {html_options options=$categs selected=$PARENT_ID name="PARENT_ID"}
    
    Code (markup):
    add some code below:
    
    <script type="text/javascript">
    {literal}
    function GetParam(name)
    {
      var start=location.search.indexOf("?"+name+"=");
      if (start<0) start=location.search.indexOf("&"+name+"=");
      if (start<0) return '';
      start += name.length+2;
      var end=location.search.indexOf("&",start)-1;
      if (end<0) end=location.search.length;
      var result=location.search.substring(start,end);
      var result='';
      for(var i=start;i<=end;i++) {
        var c=location.search.charAt(i);
        result=result+(c=='+'?' ':c);
      }
      return unescape(result);
    }
    
    pCategory = document.getElementsByName("PARENT_ID")[0];
    pCategory.onchange = function(){
        if(location.href.indexOf("&parent=")==-1)
            document.forms[0].action = location.href + "&parent=" + pCategory.value;
        else
            document.forms[0].action = location.href.replace(/parent=\d+/,"parent=" + pCategory.value);
    }
    try{
     pCategory.value = GetParam("parent");
    }catch(e){alert(e.description);}
    {/literal}
    </script>
    
    Code (markup):
    OK, done!
    not try to add a new category, when you type the CategoryName, you'll find the titleUrl textbox has been filled automaticlly and when you finish inserting, you'll find the url on addressbar has been added a parameter: parent=1 and the parent dropdownlist has been selected to the previous one.

    Enjoy!

    if this code is useful, welcome to submit your directories to Open Directory. check this our: opdir.com. :)
     
    opdir, Nov 19, 2006 IP
    onlinedude likes this.
  2. YIAM

    YIAM Notable Member

    Messages:
    2,480
    Likes Received:
    240
    Best Answers:
    0
    Trophy Points:
    280
    #2
    YIAM, Nov 19, 2006 IP
  3. shenron

    shenron Notable Member

    Messages:
    4,965
    Likes Received:
    374
    Best Answers:
    0
    Trophy Points:
    295
    #3
    This is entirely true, but bare in mind that you'll have the same structure another thousand directories have, meaning there's no uniqueness there. ;)
     
    shenron, Nov 19, 2006 IP
  4. opdir

    opdir Peon

    Messages:
    174
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #4
    do you mean "directoryspy.com"?
     
    opdir, Nov 19, 2006 IP