Results 1 to 8 of 8

Thread: Multiple Categories MOD for Links

  1. #1
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default Multiple Categories MOD for Links

    OK, here is my idea for multiple categories. I think this is a workable concept and was fairly easy to implement. While I struggled a little with the SQL statement, the code is actually pretty easy.

    The primary purpose of the MOD is to show the INDEXU programmers that it is not all that hard to do. Having said that, they will need to deal with "removing" additional_cat1 and additional_cat1 from the code.

    What it does: It allows the link owner to add an unlimited number Multiple Categories for one link. That is to say, the link can appear in many categories. The link owner can change which categories the link can appear in. or the link owner can remove all additional categories so that the link only appears in its main category.

    Just a couple of things:
    1. Please do not post to this thread
    2. Currently the MOD is only designed to work with v5.4
    3. Make sure you back up your files before installing
    4. Use at your own risk
    5. Do not consider this a completed MOD.
    6. I do not support this MOD
    7. If you use this MOD, you owe me $0.05 (a nickel)
    If you want to post anything to this thread, please post Click here to Discuss the Multiple Categories MOD.

    I'm asking bruce to move any posts to this thread. In return, I'll edit this post and keep it current.

    I make no guarentees about this MOD. There is lots of code for the INDEXU's official version of multiple categories. I have not looked at all of it to see if there is a conflict with this MOD. The MOD seems to work but you have been warned. I have ignored as much as I could the code for additional_cat1 and additional_cat1. If the MOD bombs after using it for some period of time, the only thing you are entitled to is a refund of what you paid for it.

    There are things that probably need to but haven't benn don't yet. Primarily because I don't know what they are. I'll try to add them when I learn them. With "try" being the operative word. For example, there is no way for the admin to edit the idx_mcats file (this file holds the multiple categories for any link); you will need to use a SQL statement to edit the table or delete entries. The MOD does not currently allow for multiple categories during the add process.

    Which brings me to support of this MOD. There is none. I'll try to help but don't count on it. I won't install it. If you can't get it to install, then ask someone else to help you.

    If you use this MOD, you owe me a nickel which you can pay me the next time we meet.

    Now for the general instruction for the MOD

    1. Run the query to create the idx_mcats table
    2. Install the new browse.php file or edit your existing browse.php file
    3. Add the BuildTreeRecMC and DisplayCategoryListBoxMC functions to the end of the category.class.php file.
    4. Add two lines to the Modify function in the link.class.php file
    5. Install the new modify.php file or edit your existing modify.php file
    6. Change the modify_form.html to replace the current multiple categories with the new one


    .
    Last edited by esm; 05-14-2008 at 03:26 AM.
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

  2. #2
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default Step 1

    1. Run the following SQL statement in the Database, Query section of the Admin Control Panel or from phpmyadmin
    CREATE TABLE idx_mcats (
    mlink_id mediumint(9) unsigned ,
    mcat_id mediumint(9) unsigned
    );

    .
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

  3. #3
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default Step 2

    2. Replace the existing browse.php file with the following code (or make the indicated changes)
    // show links
    // exclude sponsored link

    $sp_expire = date('Y-m-d H:i:s');
    $query = "select link_id from idx_paid_listing where sponsored = 1 and expire > '$sp_expire'";
    $result = $dbConn->Execute($query);

    // mod start for multiple categories esm
    /*
    while (!$result->EOF) {
    $lid[] = $result->Fields('link_id');
    $result->MoveNext();
    }
    $links_obj = new clsLink;
    $links_obj->query = "
    select idx_link.*,
    if (isnull(premium) || expire < now() || paid != 1, 0, premium) premium
    from idx_link
    left join idx_paid_listing on (idx_link.link_id = idx_paid_listing.link_id)
    left join idx_pagerank on (idx_link.link_id = idx_pagerank.link_id)
    where (category_id = '$cat' or cat1 = '$cat' or cat2 = '$cat')
    and suspended = 0";
    while (list($k, $v) = @each($lid)) {
    $links_obj->query .= " and idx_link.link_id <> '$v'";
    }
    */


    while (!$result->EOF) {
    $lids[] = $result->Fields('link_id');
    $result->MoveNext();
    }
    foreach ($lids as $one_lid)
    {
    $query = "select category_id from idx_link where link_id = $one_lid limit 1";
    $result = $dbConn->Execute($query);
    $fcategory_id = $result->Fields('category_id');
    if ($fcategory_id==$cat) $lid[]= $one_lid;
    }

    $links_obj = new clsLink;
    $links_obj->query = "
    select
    idx_link.*,
    if (isnull(premium) || expire < now() || paid != 1, 0, premium) premium
    from idx_link
    left join idx_paid_listing on (idx_link.link_id = idx_paid_listing.link_id)
    left join idx_pagerank on (idx_link.link_id = idx_pagerank.link_id)
    where (idx_link.category_id = '$cat'
    or idx_link.link_id IN
    (
    SELECT mlink_id
    FROM idx_mcats
    where mcat_id='$cat'
    )

    ) and suspended = 0
    ";
    $mcount=count($lid);
    for ($i=0; $i<$mcount; $i++)
    {
    if (!empty($lid))
    {
    $mlink=$lid[$i];
    $in_clause.="$mlink,";
    }
    }
    if (!empty($in_clause))
    {
    $in_clause = substr($in_clause,0,strlen($in_clause)-1);
    $links_obj->query .= " and idx_link.link_id not IN(";
    $in_clause.=")";
    $links_obj->query.=$in_clause;
    }
    // mod end


    @reset($lid);
    if ($_COOKIE['COOKIE_SORT_BY']) {

    $links_obj->query .= " order by premium desc, $_COOKIE[COOKIE_SORT_BY] $_COOKIE[COOKIE_SORT_ORDER]";
    }
    else {
    $links_obj->query .= " order by premium desc, bid desc";
    }
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

  4. #4
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default Step 3

    3. Open the category.class.php file. Go to the bottom of the file and add the following just before the last } (left curly brace) which is just before ?>.

    Remember, put it just before the the LAST }

    // mod start for multiple categories esm
    //----------------------------------------------------------------------------

    function BuildTreeRecMC($cat_id = 0, $lv = 0) {
    global $dbConn, $cat_list, $category_list, $selected_catMC, $minus_list,
    $enable_category_ajax;


    global $mcats;

    if (!isset($this->not_allowed_cat))
    $this->not_allowed_cat = array ();

    // prepare to stop recursive, if has no value then go to next node
    if (!isset($cat_list[$cat_id]))
    return false;

    // do recursive on each node
    foreach ($cat_list[$cat_id] as $key => $cat_node) {

    // assign var
    $name = $cat_node['name'];
    $category_id = $cat_node['category_id'];
    $order_num = $cat_node['order_num'];
    $path = $cat_node['path'];


    if (in_array($category_id, $this->not_allowed_cat) && $this->exclude_not_allowed_cat) { }
    else {
    $category_list .= "<option value=\"$category_id\" ";

    if (is_array($mcats)){
    if (in_array($category_id,$mcats))
    $category_list .= " selected=\"selected\"";
    } else {
    if ($category_id == $selected_catMC)
    $category_list .= " selected=\"selected\"";
    }
    if ($path) {
    $cpath = $path;
    }
    else {
    $cpath = $this->GetCategoryPath($category_id);
    }
    $arr = explode($this->separator, $cpath);

    $plusmin = "";
    if ($enable_category_ajax) {
    $num_child = $dbConn->Lookup("count(category_id)", "idx_category", "parent_id = '$category_id'");
    if ($num_child && @in_array($category_id, $minus_list)) {
    $plusmin = "&nbsp;&nbsp;-&nbsp;&nbsp;";
    }
    elseif ($num_child) {
    $plusmin = "&nbsp;+&nbsp;&nbsp;";
    }
    else {
    $plusmin = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    }
    }

    $cpath = str_repeat('&nbsp; ', (@count($arr) - 1) * 3) . $plusmin . $arr[@count($arr) - 1];

    $category_list .= ">" . $cpath . "</option>\n";
    }

    // this will go to next first child node
    $this->BuildTreeRecMC($cat_node['category_id'], $lv + 1);
    }

    unset($cat_list[$category_id]);
    }


    function DisplayCategoryListBoxMC($cat, $show_main_category = false, $admin = 0) {
    global $dbConn, $cat_list, $category_list, $selected_catMC, $opened_list,
    $minus_list, $enable_category_ajax;

    $selected_catMC = $cat;
    $cat_list = array();

    // exclude not allowed submission
    $query = "select category_id from idx_category where permission = 2";
    $result = $dbConn->Execute($query);
    while ($row = $result->FetchRow()) {
    if ($cat != $row['category_id']) {
    $this->not_allowed_cat[] = $row['category_id'];
    }
    }
    $result->Close();

    $category_list = "<select name=\"catMC[]\" MULTIPLE SIZE=5>";

    $query_opened_list = "";
    $opened_list = array();
    $minus_list = array();
    if ($admin == 1) {
    $query = "select a.category_id, a.parent_id, a.name, b.path
    from idx_category a
    left join idx_category_path b on (a.category_id = b.category_id)
    where 0 = 0 $query_opened_list
    order by a.name";
    if (!empty($this->query))
    $query = $this->query;
    $this->exclude_not_allowed_cat = 0;
    } else {
    $query = "select a.category_id, a.parent_id, a.name, b.path
    from idx_category a
    left join idx_category_path b on (a.category_id = b.category_id)
    where visible = 1 $query_opened_list
    order by a.name";

    if (!empty($this->query))
    $query = $this->query;
    $this->exclude_not_allowed_cat = 1;
    }

    $result = $dbConn->Execute($query);
    // build array of node data
    while ($row = $result->FetchRow()) {
    $cat_list[$row['parent_id']][$row['category_id']] = $row;
    }
    if ($admin == 0 || $admin == 1) {
    if (sizeof($cat_list) != 0) {
    $this->BuildTreeRecMC();
    }
    }
    // editor
    elseif ($admin == 2) {
    $result->MoveFirst();
    $category_lists = array();
    while ($row = $result->FetchRow()) {
    $category_id = $row['category_id'];
    $category_list_item = "<option value=\"$category_id\" ";
    if ($category_id == $selected_catMC) $category_list_item .= " selected=\"selected\"";
    $cpath = $this->GetCategoryPath($category_id);
    $category_list_item .= ">" . $cpath . "</option>\n";
    $category_lists[$cpath] = $category_list_item;
    }
    @ksort($category_lists);
    $category_list .= @implode("\n", $category_lists);
    }

    $category_list .= "</select>";
    unset($this->not_allowed_cat);
    return $category_list;
    }
    // mod end


    } <--- The last curly brace
    ?> <--- End of file
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

  5. #5
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default Step 4

    4. Edit the link.class.php file and find the folling section of code (about line 1784)

    $add_cat1 = str_replace("<option value=\"\">", "<option value=\"0\">", $add_cat1);
    $add_cat1 = str_replace("Main Category", "Do not have additional category", $add_cat1);
    $add_cat2 = str_replace("<option value=\"\">", "<option value=\"0\">", $add_cat2);
    $add_cat2 = str_replace("Main Category", "Do not have additional category", $add_cat2);

    $tpl->assign('category', $category);
    $tpl->assign('error_msg', $error_msg);

    and make the following changes

    $add_cat1 = str_replace("<option value=\"\">", "<option value=\"0\">", $add_cat1);
    $add_cat1 = str_replace("Main Category", "Do not have additional category", $add_cat1);
    $add_cat2 = str_replace("<option value=\"\">", "<option value=\"0\">", $add_cat2);
    $add_cat2 = str_replace("Main Category", "Do not have additional category", $add_cat2);

    // mod start for multiple categories esm
    // $tpl->assign('add_cat1', $add_cat1);
    // $tpl->assign('add_cat2', $add_cat2);
    $add_catMC = $category_obj->DisplayCategoryListBoxMC((!isset($cat)) ? $category_id : $cat);
    $tpl->assign('add_catMC', $add_catMC);
    // end mod


    $tpl->assign('category', $category);
    $tpl->assign('error_msg', $error_msg);

    .
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

  6. #6
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default Step 5

    5. In the modify.php file make the indicated changes to the ShowFormModifyUrl function


    // check for invalid link_id
    $query = "select link_id from idx_link where link_id = '$link_id'";
    $result = $dbConn->Execute($query);

    if ($result)
    $lid = $result->Fields('link_id');

    // mod start for multiple categories esm
    $mcats=array();
    global $mcats;
    $query = "select mcat_id from idx_mcats where mlink_id = '$link_id' order by mcat_id";
    $cresult = $dbConn->Execute($query);
    while (!$cresult->EOF) {
    $mcats[] = $cresult->Fields('mcat_id');
    $cresult->MoveNext();
    }
    // mod


    if ($lid == "") {
    $error_msg = $msg['10148'];
    DisplayTemplate($theme_path . "modify_select.html", "\$error_msg");
    RunPostFilter(__FILE__);
    }
    In the modify.php file make the indicated changes to the ProcessFormModifyUrl function

    // successfully modified
    if ($modify_result == 0) {

    // mod start for multiple categories esm
    $catMC=$_POST['catMC'];
    if ($link_id>0 )
    {
    $query = "DELETE FROM idx_mcats WHERE mlink_id=$link_id";
    $result = $dbConn->Execute($query);
    }
    if (!empty($catMC) && $link_id>0 )
    {
    $query = "DELETE FROM idx_mcats WHERE mlink_id=$link_id";
    $result = $dbConn->Execute($query);
    if (is_array($catMC))
    {
    foreach ($catMC as $one_cat)
    {
    if ($one_cat>0 )
    {
    $query = "insert into idx_mcats set mlink_id=$link_id, mcat_id=$one_cat";
    $result = $dbConn->Execute($query);
    } else {
    }
    }
    } else {
    if ($one_cat>0 )
    {
    $query = "insert into idx_mcats set mlink_id=$link_id, mcat_id=$one_cat";
    $result = $dbConn->Execute($query);
    } else {
    }
    }
    }
    // mod end

    // send email submitter
    then further down

    // pending

    elseif ($modify_result == 1) {

    // mod start for multiple categories esm
    $catMC=$_POST['catMC'];
    if ($link_id>0 )
    {
    $query = "DELETE FROM idx_mcats WHERE mlink_id=$link_id";
    $result = $dbConn->Execute($query);
    }
    if (!empty($catMC) && $link_id>0 )
    {
    $query = "DELETE FROM idx_mcats WHERE mlink_id=$link_id";
    $result = $dbConn->Execute($query);
    if (is_array($catMC))
    {
    foreach ($catMC as $one_cat)
    {
    if ($one_cat>0 )
    {
    $query = "insert into idx_mcats set mlink_id=$link_id, mcat_id=$one_cat";
    $result = $dbConn->Execute($query);
    } else {
    }
    }
    } else {
    if ($one_cat>0 )
    {
    $query = "insert into idx_mcats set mlink_id=$link_id, mcat_id=$one_cat";
    $result = $dbConn->Execute($query);
    } else {
    }
    }
    }
    // mod end


    // send email submitter
    $body = EvalTemplate($theme_path . "mail/add_pending.mail", $links_obj->email_template_fields);
    $from = $email_address;
    @mail($email, $msg["10135"], $body, "From: $from \nX-Mailer: INDEXU_X-Mailer/1.0");

    .
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

  7. #7
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default Step 6

    6. Edit the modify_form.html file and find the folling section of code

    <label for="cat_div">Category</label>
    <div id="cat_div"><%$category%></div>

    <label for="add_cat1_div">Additional Category 1</label>
    <div id="add_cat1_div"><%$add_cat1%></div>

    <label for="add_cat2_div">Additional Category 2</label>
    <div id="add_cat2_div"><%$add_cat2%></div>


    <label for="contact_name">Contact Name</label>
    <input id="contact_name" type="text" name="contact_name" size="40" value="<%$contact_name%>" />
    and replace the two sections that refer to the Additional Category with the new section for Multiple Categories


    <label for="cat_div">Category</label>
    <div id="cat_div"><%$category%></div>

    <label for="add_cat2_div">Multiple Category</label>
    <div id="add_cat2_div"><%$add_catMC%></div>


    <label for="contact_name">Contact Name</label>
    <input id="contact_name" type="text" name="contact_name" size="40" value="<%$contact_name%>" />

    .
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

  8. #8
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default

    Please do not post to this thread. Click here to discuss.

    .
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

Similar Threads

  1. Multiple Categories?
    By blacknight in forum v5.x
    Replies: 3
    Last Post: 10-10-2006, 08:01 PM
  2. Multiple categories ?
    By Frank71 in forum v5.x
    Replies: 7
    Last Post: 08-13-2004, 09:42 AM
  3. Multiple Categories MOD
    By esm in forum v5.x
    Replies: 9
    Last Post: 08-03-2004, 11:39 PM
  4. Add multiple categories at once
    By craven in forum v5.x
    Replies: 2
    Last Post: 08-29-2003, 12:21 PM
  5. multiple categories...
    By rayhne in forum Pre-Sales Questions
    Replies: 13
    Last Post: 05-07-2003, 11:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •