Example #1
0
 /**
  * Prepares the stream items for mosets tree
  *
  * @since   1.3
  * @access  public
  * @param   string
  * @return  
  */
 public function onPrepareStream(SocialStreamItem &$stream, $includePrivacy = true)
 {
     if (!$this->exists() || $stream->context != 'mtree') {
         return;
     }
     // Decorate the stream
     $stream->display = SOCIAL_STREAM_DISPLAY_FULL;
     $stream->color = '#6f90b5';
     $stream->fonticon = 'ies-comments-2';
     $stream->label = JText::_('APP_USER_MTREE_STREAM_LABEL');
     // Get the link object
     $db = JFactory::getDbo();
     $link = new mtLinks($db);
     $link->load($stream->contextId);
     $this->decorate($link);
     $this->set('actor', $stream->actor);
     $this->set('link', $link);
     $stream->title = parent::display('streams/title');
     $stream->content = parent::display('streams/content');
 }
 function copyCategory($cat_id, $dest, $copy_subcats, $copy_relcats, $copy_listings, $copy_reviews, $reset_hits, $reset_rating, $increment = null)
 {
     global $mtconf;
     static $copied_cat_ids;
     $database =& JFactory::getDBO();
     # Get original cat's info
     $this->_db->setQuery("SELECT * FROM {$this->_tbl} WHERE cat_id = '" . $cat_id . "' LIMIT 1");
     $org_cat = $this->_db->loadObject();
     # Get $dest (New cat parent)'s lft & rgt
     if (is_null($increment)) {
         $this->_db->setQuery("SELECT lft, rgt FROM {$this->_tbl} WHERE cat_id = '" . $dest . "' LIMIT 1");
         $new_cat = $this->_db->loadObject();
         $inc = $new_cat->rgt - $org_cat->lft;
         $copied_cat_ids = array();
     } else {
         $inc = $increment;
     }
     # Change cat_parent
     $org_cat->cat_parent = $dest;
     # Copy cat
     $this->_db->setQuery('INSERT INTO ' . $this->_tbl . ' (cat_name, cat_desc, cat_parent, cat_links, cat_cats, cat_featured, cat_published, cat_created, cat_approved, cat_template, metakey, metadesc, ordering, lft, rgt) ' . ' VALUES(' . $this->_db->quote($org_cat->cat_name) . ', ' . $this->_db->quote($org_cat->cat_desc) . ', ' . $this->_db->quote($org_cat->cat_parent) . ', ' . ($copy_listings ? $org_cat->cat_links : '0') . ', ' . $this->_db->quote($org_cat->cat_cats) . ', ' . $this->_db->quote($org_cat->cat_featured) . ', ' . $this->_db->quote($org_cat->cat_published) . ', ' . $this->_db->quote($org_cat->cat_created) . ', ' . $this->_db->quote($org_cat->cat_approved) . ', ' . $this->_db->quote($org_cat->cat_template) . ', ' . $this->_db->quote($org_cat->metakey) . ', ' . $this->_db->quote($org_cat->metadesc) . ', ' . $this->_db->quote($org_cat->ordering) . ', ' . $this->_db->quote($org_cat->lft + $inc) . ', ' . $this->_db->quote($org_cat->rgt + $inc) . ')');
     $this->_db->query();
     $new_cat_parent = $this->_db->insertid();
     $copied_cat_ids[] = $new_cat_parent;
     # Copy image
     $file_s = $mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_cat_small_image') . $org_cat->cat_image;
     $file_o = $mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_cat_original_image') . $org_cat->cat_image;
     if ($org_cat->cat_image && is_writable($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_cat_small_image')) && is_writable($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_cat_original_image'))) {
         if (copy($file_s, $mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_cat_small_image') . $new_cat_parent . "_" . substr($org_cat->cat_image, strpos($org_cat->cat_image, "_") + 1)) && copy($file_o, $mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_cat_original_image') . $new_cat_parent . "_" . substr($org_cat->cat_image, strpos($org_cat->cat_image, "_") + 1))) {
             $this->_db->setQuery('UPDATE #__mt_cats SET cat_image = ' . $this->_db->quote($new_cat_parent . "_" . substr($org_cat->cat_image, strpos($org_cat->cat_image, "_") + 1)) . ' WHERE cat_id = ' . $this->_db->quote($new_cat_parent));
             $this->_db->query();
         }
     }
     # Copy Related Categories
     $this->_db->setQuery("SELECT rel_id FROM #__mt_relcats WHERE cat_id = '" . $cat_id . "'");
     $rel_ids = $this->_db->loadResultArray();
     if (count($rel_ids) > 0 && $copy_relcats == 1) {
         foreach ($rel_ids as $rel_id) {
             $this->_db->setQuery("INSERT INTO #__mt_relcats ( cat_id, rel_id ) VALUES ( '{$new_cat_parent}', '{$rel_id}' )");
             $this->_db->query();
         }
     }
     # Copy listings
     if ($copy_listings == 1) {
         $this->_db->setQuery("SELECT l.link_id FROM #__mt_links AS l, #__mt_cl AS cl WHERE l.link_id = cl.link_id AND cl.cat_id ='" . $cat_id . "' AND cl.main = '1'");
         $listings = $this->_db->loadResultArray();
         if (count($listings) > 0) {
             foreach ($listings as $listing) {
                 $l = new mtLinks($database);
                 $l->copyLink($listing, $new_cat_parent, $reset_hits, $reset_rating, $copy_reviews, 1);
             }
         }
         # Copy soft listing / CL mapping
         /*
         $this->_db->setQuery( "INSERT INTO #__mt_cl( link_id, cat_id, main ) SELECT link_id, '".$new_cat_parent."', '0' FROM #__mt_cl WHERE cat_id = '".$cat_id."' AND main = '0'" );
         $this->_db->query();
         echo $this->_db->getQuery();
         */
     }
     # Copy Sub categories
     $this->_db->setQuery("SELECT cat_id FROM {$this->_tbl} WHERE cat_parent = '" . $cat_id . "'");
     $subcats = $this->_db->loadResultArray();
     if (count($subcats) > 0 && $copy_subcats == 1) {
         foreach ($subcats as $subcat) {
             $this->copyCategory($subcat, $new_cat_parent, $copy_subcats, $copy_relcats, $copy_listings, $copy_reviews, $reset_hits, $reset_rating, $inc);
         }
     }
     return $copied_cat_ids;
 }
Example #3
0
         if (empty($title)) {
             $title = shAppendListing($mtLink->link_name, $mtLink->link_id, false, $shLangIso, $option, $shLangName);
         } else {
             $title = array_merge($title, shAppendListing($mtLink->link_name, $mtLink->link_id, false, $shLangIso, $option, $shLangName));
         }
         $title[] = $sh_LANG[$shLangIso]['_MT_SEF_EDIT_LISTING'];
     } else {
         $dosef = false;
     }
     break;
     # Delete listing
 # Delete listing
 case 'deletelisting':
     if (!empty($link_id)) {
         $database = JFactory::getDbo();
         $mtLink = new mtLinks($database);
         $mtLink->load($link_id);
         if ($sefConfig->shMTreeInsertCategories > 0) {
             if (empty($title)) {
                 $title = shAppendCat($mtLink->cat_id, $option, $shLangName);
             } else {
                 $title = array_merge($title, shAppendCat($mtLink->cat_id, $option, $shLangName));
             }
         }
         if (empty($title)) {
             $title = shAppendListing($mtLink->link_name, $mtLink->link_id, false, $shLangIso, $option, $shLangName);
         } else {
             $title = array_merge($title, shAppendListing($mtLink->link_name, $mtLink->link_id, false, $shLangIso, $option, $shLangName));
         }
         $title[] = $sh_LANG[$shLangIso]['_MT_SEF_DELETE_LISTING'];
     } else {
Example #4
0
function savelisting($option)
{
    global $Itemid, $mtconf, $mainframe, $link_id;
    // Check for request forgeries
    JRequest::checkToken() or jexit('Invalid Token');
    $database =& JFactory::getDBO();
    $my =& JFactory::getUser();
    require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'mfields.class.php';
    require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'tools.mtree.php';
    $raw_filenames = array();
    # Get cat_id / remove_image / link_image
    $cat_id = JRequest::getInt('cat_id', 0);
    $other_cats = explode(',', JRequest::getString('other_cats', null, 'post'));
    JArrayHelper::toInteger($other_cats);
    if (isset($other_cats) && empty($other_cats[0])) {
        $other_cats = array();
    }
    # Check if any malicious user is trying to submit link
    if ($mtconf->get('user_addlisting') == 1 && $my->id < 1 && $link_id == 0 || $mtconf->get('user_addlisting') == -1 && $link_id == 0 || $mtconf->get('user_allowmodify') == 0 && $link_id > 0) {
        echo _NOT_EXIST;
    } else {
        # Allowed
        $row = new mtLinks($database);
        $post = JRequest::get('post');
        if (!@$row->bind($post)) {
            echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
            exit;
        }
        $isNew = $row->link_id < 1 ? 1 : 0;
        # Assignment for new record
        if ($isNew) {
            $jdate = JFactory::getDate();
            $row->link_created = $jdate->toMySQL();
            $row->publish_up = $jdate->toMySQL();
            $row->ordering = 999;
            // Set an expire date for listing if enabled in configuration
            if ($mtconf->get('days_to_expire') > 0) {
                $jdate->setOffset(intval($mtconf->get('days_to_expire')) * 24);
                $row->publish_down = $jdate->toMySQL(true);
                $jdate->setOffset(intval($mtconf->get('days_to_expire')) * -24);
            }
            if ($my->id > 0) {
                $row->user_id = $my->id;
            } else {
                $database->setQuery('SELECT id FROM #__users WHERE usertype = \'Super Administrator\' LIMIT 1');
                $row->user_id = $database->loadResult();
            }
            if (empty($row->alias)) {
                $row->alias = JFilterOutput::stringURLSafe($row->link_name);
            }
            // Approval for adding listing
            if ($mtconf->get('needapproval_addlisting')) {
                $row->link_approved = '0';
            } else {
                $row->link_approved = 1;
                $row->link_published = 1;
                $row->updateLinkCount(1);
                $cache =& JFactory::getCache('com_mtree');
                $cache->clean();
            }
            # Modification to existing record
        } else {
            # Validate that this user is the rightful owner
            $database->setQuery("SELECT user_id FROM #__mt_links WHERE link_id = '" . $row->link_id . "'");
            $user_id = $database->loadResult();
            if ($user_id != $my->id) {
                echo _NOT_EXIST;
            } else {
                // Get the name of the old photo and last modified date
                $sql = "SELECT link_id, link_modified, link_created FROM #__mt_links WHERE link_id='" . $row->link_id . "'";
                $database->setQuery($sql);
                $old = $database->loadObject();
                // Retrive last modified date
                $old_modified = $old->link_modified;
                $link_created = $old->link_created;
                // $row->link_published = 1;
                $row->user_id = $my->id;
                // Get other info from original listing
                // $database->setQuery( "SELECT link_name, link_desc, link_hits, link_votes, link_rating, link_featured, link_created, link_visited, ordering, publish_down, publish_up, attribs, internal_notes, link_published, link_approved FROM #__mt_links WHERE link_id = '$row->link_id'" );
                $database->setQuery("SELECT * FROM #__mt_links WHERE link_id = '{$row->link_id}'");
                $original = $database->loadObject();
                $original_link_id = $row->link_id;
                $row->link_modified = $row->getLinkModified($original_link_id, $post);
                foreach ($original as $k => $v) {
                    if (in_array($k, array('link_hits', 'link_votes', 'link_rating', 'link_featured', 'link_created', 'link_visited', 'ordering', 'publish_down', 'publish_up', 'attribs', 'internal_notes', 'link_published', 'link_approved'))) {
                        $row->{$k} = $v;
                    }
                }
                if (!isset($row->metadesc) && isset($original->metadesc) && !empty($original->metadesc)) {
                    $row->metadesc = $original->metadesc;
                }
                if (!isset($row->metakey) && isset($original->metakey) && !empty($original->metakey)) {
                    $row->metakey = $original->metakey;
                }
                // Remove any listing that is waiting for approval for this listing
                $database->setQuery('SELECT link_id FROM #__mt_links WHERE link_approved = \'' . -1 * $row->link_id . '\' LIMIT 1');
                $tmp_pending_link_id = $database->loadResult();
                if ($tmp_pending_link_id > 0) {
                    $database->setQuery('SELECT CONCAT(' . $database->quote(JPATH_SITE . $mtconf->get('relative_path_to_attachments')) . ',raw_filename) FROM #__mt_cfvalues_att WHERE link_id = ' . $database->quote($tmp_pending_link_id));
                    $raw_filenames = array_merge($raw_filenames, $database->loadResultArray());
                    $database->setQuery("DELETE FROM #__mt_cfvalues WHERE link_id = '" . $tmp_pending_link_id . "'");
                    $database->query();
                    $database->setQuery("DELETE FROM #__mt_cfvalues_att WHERE link_id = '" . $tmp_pending_link_id . "'");
                    $database->query();
                    $database->setQuery("DELETE FROM #__mt_links WHERE link_id = '" . $tmp_pending_link_id . "' LIMIT 1");
                    $database->query();
                    $database->setQuery("DELETE FROM #__mt_cl WHERE link_id = '" . $tmp_pending_link_id . "'");
                    $database->query();
                    $database->setQuery("SELECT filename FROM #__mt_images WHERE link_id = '" . $tmp_pending_link_id . "'");
                    $tmp_pending_images = $database->loadResultArray();
                    if (count($tmp_pending_images)) {
                        foreach ($tmp_pending_images as $tmp_pending_image) {
                            unlink($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_small_image') . $tmp_pending_image);
                            unlink($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_medium_image') . $tmp_pending_image);
                            unlink($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_original_image') . $tmp_pending_image);
                        }
                    }
                    $database->setQuery("DELETE FROM #__mt_images WHERE link_id = '" . $tmp_pending_link_id . "'");
                    $database->query();
                }
                // Approval for modify listing
                if ($original->link_published && $original->link_approved) {
                    if ($mtconf->get('needapproval_modifylisting')) {
                        $row->link_approved = -1 * $row->link_id;
                        $row->link_id = null;
                    } else {
                        $row->link_approved = 1;
                        $cache =& JFactory::getCache('com_mtree');
                        $cache->clean();
                        // Get old state (approved, published)
                        $database->setQuery("SELECT cat_id FROM #__mt_cl AS cl WHERE link_id ='" . $row->link_id . "' AND main = 1 LIMIT 1");
                        $old_state = $database->loadObject();
                        if ($row->cat_id != $old_state->cat_id) {
                            $row->updateLinkCount(1);
                            $row->updateLinkCount(-1, $old_state->cat_id);
                        }
                    }
                }
            }
        }
        // End of $isNew
        # Load field type
        $database->setQuery('SELECT cf_id, field_type, hidden, published FROM #__mt_customfields');
        $fieldtype = $database->loadObjectList('cf_id');
        $hidden_cfs = array();
        foreach ($fieldtype as $ft) {
            if ($ft->hidden && $ft->published) {
                $hidden_cfs[] = $ft->cf_id;
            }
        }
        # Load original custom field values, for use in mosetstree plugins
        $sql = "SELECT cf_id, value FROM #__mt_cfvalues WHERE link_id='" . $row->link_id . "' AND attachment <= 0";
        if (!empty($hidden_cfs)) {
            $sql .= " AND cf_id NOT IN (" . implode(',', $hidden_cfs) . ")";
        }
        $database->setQuery($sql);
        $original_cfs = $database->loadAssocList('cf_id');
        if (!empty($original_cfs)) {
            foreach ($original_cfs as $key_cf_id => $value) {
                $original_cfs[$key_cf_id] = $value['value'];
            }
        }
        # Erase Previous Records, make way for the new data
        $sql = "DELETE FROM #__mt_cfvalues WHERE link_id='" . $row->link_id . "' AND attachment <= 0";
        if (!empty($hidden_cfs)) {
            $sql .= " AND cf_id NOT IN (" . implode(',', $hidden_cfs) . ")";
        }
        $database->setQuery($sql);
        if (!$database->query()) {
            echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
            exit;
        }
        if (!empty($fieldtype)) {
            $load_ft = array();
            foreach ($fieldtype as $ft) {
                if (!in_array($ft->field_type, $load_ft)) {
                    $load_ft[] = $ft->field_type;
                }
            }
            $database->setQuery('SELECT ft_class FROM #__mt_fieldtypes WHERE field_type IN (\'' . implode('\',\'', $load_ft) . '\')');
            $ft_classes = $database->loadResultArray();
            foreach ($ft_classes as $ft_class) {
                eval($ft_class);
            }
        }
        # Collect all active custom field's id
        $active_cfs = array();
        $additional_cfs = array();
        $core_params = array();
        foreach ($post as $k => $v) {
            $v = JRequest::getVar($k, '', 'post', '', 2);
            if (substr($k, 0, 2) == "cf" && (!is_array($v) && (!empty($v) || $v == '0') || is_array($v) && !empty($v[0]))) {
                if (strpos(substr($k, 2), '_') === false && is_numeric(substr($k, 2))) {
                    // This custom field uses only one input. ie: cf17, cf23, cf2
                    $active_cfs[intval(substr($k, 2))] = $v;
                    if (is_array($v) && array_key_exists(intval(substr($k, 2)), $original_cfs)) {
                        $original_cfs[intval(substr($k, 2))] = explode('|', $original_cfs[intval(substr($k, 2))]);
                    }
                } else {
                    // This custom field uses more than one input. The date field is an example of cf that uses this. ie: cf13_0, cf13_1, cf13_2
                    $ids = explode('_', substr($k, 2));
                    if (count($ids) == 2 && is_numeric($ids[0]) && is_numeric($ids[1])) {
                        $additional_cfs[intval($ids[0])][intval($ids[1])] = $v;
                    }
                }
            } elseif (substr($k, 0, 7) == 'keep_cf') {
                $cf_id = intval(substr($k, 7));
                $keep_att_ids[] = $cf_id;
                # Perform parseValue on Core Fields
            } elseif (substr($k, 0, 2) != "cf" && isset($row->{$k})) {
                if (strpos(strtolower($k), 'link_') === false) {
                    $core_field_type = 'core' . $k;
                } else {
                    $core_field_type = 'core' . str_replace('link_', '', $k);
                }
                $class = 'mFieldType_' . $core_field_type;
                if (class_exists($class)) {
                    if (empty($core_params)) {
                        $database->setQuery('SELECT field_type, params FROM #__mt_customfields WHERE iscore = 1');
                        $core_params = $database->loadObjectList('field_type');
                    }
                    $mFieldTypeObject = new $class(array('params' => $core_params[$core_field_type]->params));
                    $v = call_user_func(array(&$mFieldTypeObject, 'parseValue'), $v);
                    $row->{$k} = $v;
                }
            }
        }
        # OK. Store new or updated listing into database
        if (!$row->store()) {
            echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
            exit;
        } else {
            if (!$isNew && $row->link_id > 0) {
                // Find if there are any additional categories assigned to the listinig
                if ($original_link_id != $row->link_id) {
                    $database->setQuery('SELECT DISTINCT cat_id FROM #__mt_cl WHERE link_id = ' . $database->Quote($original_link_id) . ' and main=\'0\' ');
                    $tmp_cats = $database->loadResultArray();
                    if (!empty($tmp_cats)) {
                        foreach ($tmp_cats as $tmp_cat_id) {
                            $database->setQuery('INSERT INTO #__mt_cl (`link_id`,`cat_id`,`main`) VALUES(' . $database->Quote($row->link_id) . ',' . $database->Quote($tmp_cat_id) . ',\'0\')');
                            $database->query();
                        }
                    }
                    unset($tmp_cats);
                }
            }
        }
        # Update "Also appear in these categories" aka other categories
        if ($mtconf->get('allow_user_assign_more_than_one_category')) {
            $mtCL = new mtCL_main0($database);
            $mtCL->load($row->link_id);
            $mtCL->update($other_cats);
        }
        // $files_cfs is used to store attachment custom fields.
        // This will be used in the next foreach loop to
        // prevent it from storing it's value to #__mt_cfvalues
        // table
        $file_cfs = array();
        // $file_values is used to store parsed data through
        // mFieldType_* which will be done in the next foreach
        // loop
        $file_values = array();
        $files = JRequest::get('files');
        foreach ($files as $k => $v) {
            if (substr($k, 0, 2) == "cf" && is_numeric(substr($k, 2)) && $v['error'] == 0) {
                $active_cfs[intval(substr($k, 2))] = $v;
                $file_cfs[] = substr($k, 2);
            }
        }
        if (!empty($active_cfs)) {
            $database->setQuery('SELECT cf_id, params FROM #__mt_customfields WHERE iscore = 0 AND cf_id IN (\'' . implode('\',\'', array_keys($active_cfs)) . '\') LIMIT ' . count($active_cfs));
            $params = $database->loadObjectList('cf_id');
            foreach ($active_cfs as $cf_id => $v) {
                if (class_exists('mFieldType_' . $fieldtype[$cf_id]->field_type)) {
                    $class = 'mFieldType_' . $fieldtype[$cf_id]->field_type;
                } else {
                    $class = 'mFieldType';
                }
                # Perform parseValue on Custom Fields
                $mFieldTypeObject = new $class(array('id' => $cf_id, 'params' => $params[$cf_id]->params));
                if (array_key_exists($cf_id, $additional_cfs) && !empty($additional_cfs[$cf_id])) {
                    $arr_v = $additional_cfs[$cf_id];
                    array_unshift($arr_v, $v);
                    $v =& $mFieldTypeObject->parseValue($arr_v);
                    $active_cfs[$cf_id] = $v;
                } else {
                    $v =& $mFieldTypeObject->parseValue($v);
                }
                if (in_array($cf_id, $file_cfs)) {
                    $file_values[$cf_id] = $v;
                }
                if ((!empty($v) || $v == '0') && !in_array($cf_id, $file_cfs)) {
                    # -- Now add the row
                    $sql = 'INSERT INTO #__mt_cfvalues (`cf_id`, `link_id`, `value`)' . ' VALUES (' . $database->quote($cf_id) . ', ' . $database->quote($row->link_id) . ', ' . $database->quote(is_array($v) ? implode("|", $v) : $v) . ')';
                    $database->setQuery($sql);
                    if (!$database->query()) {
                        echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
                        exit;
                    }
                }
                unset($mFieldTypeObject);
            }
            // End of foreach
        }
        # If this link is pending approval for modification, copy over hidden values
        if (!$isNew && $mtconf->get('needapproval_modifylisting') && !empty($hidden_cfs)) {
            $sql = 'INSERT INTO #__mt_cfvalues (`cf_id`, `link_id`, `value`)' . ' SELECT `cf_id`, \'' . $row->link_id . '\', `value` FROM #__mt_cfvalues WHERE link_id = ' . $original_link_id . ' AND cf_id IN (' . implode(',', $hidden_cfs) . ')';
            $database->setQuery($sql);
            $database->query();
        }
        # Remove all attachment except those that are kept
        if (isset($keep_att_ids) && !empty($keep_att_ids)) {
            $database->setQuery('SELECT CONCAT(' . $database->quote(JPATH_SITE . $mtconf->get('relative_path_to_attachments')) . ',raw_filename) FROM #__mt_cfvalues_att WHERE link_id = ' . $database->quote($row->link_id) . ' AND cf_id NOT IN (\'' . implode('\',\'', $keep_att_ids) . '\')');
            $raw_filenames = array_merge($raw_filenames, $database->loadResultArray());
            $database->setQuery('DELETE FROM #__mt_cfvalues_att WHERE link_id = \'' . $row->link_id . '\' AND cf_id NOT IN (\'' . implode('\',\'', $keep_att_ids) . '\')');
            $database->query();
            $database->setQuery('DELETE FROM #__mt_cfvalues WHERE link_id = \'' . $row->link_id . '\' AND cf_id NOT IN (\'' . implode('\',\'', $keep_att_ids) . '\') AND attachment > 0');
            $database->query();
        } else {
            $database->setQuery('SELECT CONCAT(' . $database->quote(JPATH_SITE . $mtconf->get('relative_path_to_attachments')) . ',raw_filename) FROM #__mt_cfvalues_att WHERE link_id = ' . $database->quote($row->link_id));
            $raw_filenames = array_merge($raw_filenames, $database->loadResultArray());
            $database->setQuery('DELETE FROM #__mt_cfvalues_att WHERE link_id = \'' . $row->link_id . '\'');
            $database->query();
            $database->setQuery('DELETE FROM #__mt_cfvalues WHERE link_id = \'' . $row->link_id . '\' AND attachment > 0');
            $database->query();
        }
        if (!$isNew && isset($keep_att_ids) && !empty($keep_att_ids) && $mtconf->get('needapproval_modifylisting') && $row->link_published == 1) {
            $database->setQuery("SELECT * FROM #__mt_cfvalues_att WHERE link_id = '" . $original_link_id . "' AND cf_id IN ('" . implode("','", $keep_att_ids) . "')");
            $listing_atts = $database->loadObjectList();
            foreach ($listing_atts as $listing_att) {
                $file_extension = pathinfo($listing_att->raw_filename);
                $file_extension = strtolower($file_extension['extension']);
                $database->setQuery('INSERT INTO #__mt_cfvalues_att (`link_id`,`cf_id`,`raw_filename`,`filename`,`filesize`,`extension`) ' . 'VALUES (' . $row->link_id . ', ' . $database->Quote($listing_att->cf_id) . ', ' . $database->Quote($listing_att->raw_filename) . ', ' . $database->Quote($listing_att->filename) . ', ' . $database->Quote($listing_att->filesize) . ', ' . $database->Quote($listing_att->extension) . ')');
                $database->query();
                $att_id = $database->insertid();
                $database->setQuery('UPDATE #__mt_cfvalues_att SET raw_filename = ' . $database->Quote($att_id . '.' . $file_extension) . ' WHERE att_id = ' . $database->Quote($att_id) . ' LIMIT 1');
                $database->query();
                copy($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_attachments') . $listing_att->raw_filename, $mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_attachments') . $att_id . "." . $file_extension);
            }
            $database->setQuery('INSERT INTO #__mt_cfvalues (cf_id,link_id,value,attachment) ' . "\nSELECT cf_id,'" . $row->link_id . "',value,attachment " . "FROM #__mt_cfvalues " . "WHERE link_id = '" . $original_link_id . "' AND cf_id IN ('" . implode("','", $keep_att_ids) . "')");
            $database->query();
        }
        jimport('joomla.filesystem.file');
        foreach ($files as $k => $v) {
            if (substr($k, 0, 2) == "cf" && is_numeric(substr($k, 2)) && $v['error'] == 0) {
                $cf_id = intval(substr($k, 2));
                if (array_key_exists($cf_id, $file_values)) {
                    $file = $file_values[$cf_id];
                    if (!empty($file['data'])) {
                        $data = $file['data'];
                    } else {
                        $fp = fopen($v['tmp_name'], "r");
                        $data = fread($fp, $v['size']);
                        fclose($fp);
                    }
                } else {
                    $file = $v;
                    $fp = fopen($v['tmp_name'], "r");
                    $data = fread($fp, $v['size']);
                    fclose($fp);
                }
                $database->setQuery('SELECT CONCAT(' . $database->quote(JPATH_SITE . $mtconf->get('relative_path_to_attachments')) . ',raw_filename) FROM #__mt_cfvalues_att WHERE link_id = ' . $database->quote($row->link_id) . ' AND cf_id = ' . $database->quote($cf_id));
                $raw_filenames = array_merge($raw_filenames, $database->loadResultArray());
                $database->setQuery('DELETE FROM #__mt_cfvalues_att WHERE link_id = ' . $database->quote($row->link_id) . ' AND cf_id = ' . $database->quote($cf_id));
                $database->query();
                $database->setQuery('DELETE FROM #__mt_cfvalues WHERE cf_id = ' . $database->quote($cf_id) . ' AND link_id = ' . $database->quote($row->link_id) . ' AND attachment > 0');
                $database->query();
                $database->setQuery('INSERT INTO #__mt_cfvalues_att (link_id, cf_id, raw_filename, filename, filesize, extension) ' . ' VALUES(' . $database->quote($row->link_id) . ', ' . $database->quote($cf_id) . ', ' . $database->quote($file['name']) . ', ' . $database->quote($file['name']) . ', ' . $database->quote($file['size']) . ', ' . $database->quote($file['type']) . ')');
                if ($database->query() !== false) {
                    $att_id = $database->insertid();
                    $file_extension = strrchr($file['name'], '.');
                    if ($file_extension === false) {
                        $file_extension = '';
                    }
                    if (JFile::write(JPATH_SITE . $mtconf->get('relative_path_to_attachments') . $att_id . $file_extension, $data)) {
                        $database->setQuery('UPDATE #__mt_cfvalues_att SET raw_filename = ' . $database->quote($att_id . $file_extension) . ' WHERE att_id = ' . $database->quote($att_id) . ' LIMIT 1');
                        $database->query();
                        $sql = 'INSERT INTO #__mt_cfvalues (`cf_id`, `link_id`, `value`, `attachment`) ' . 'VALUES (' . $database->quote($cf_id) . ', ' . $database->quote($row->link_id) . ', ' . $database->quote($file['name']) . ',1)';
                        $database->setQuery($sql);
                        $database->query();
                    } else {
                        // Move failed, remove record from previously INSERTed row in #__mt_cfvalues_att
                        $database->setQuery('DELETE FROM #__mt_cfvalues_att WHERE att_id = ' . $database->quote($att_id) . ' LIMIT 1');
                        $database->query();
                    }
                }
            }
        }
        if (!empty($raw_filenames)) {
            JFile::delete($raw_filenames);
        }
        if ($mtconf->get('allow_imgupload') || !$mtconf->get('allow_imgupload') && $mtconf->get('needapproval_modifylisting')) {
            if ($mtconf->get('allow_imgupload')) {
                $keep_img_ids = JRequest::getVar('keep_img', null, 'post');
                JArrayHelper::toInteger($keep_img_ids, array());
                // If image upload is disabled, it will get the image IDs from database and make sure
                // the images are not lost after approval
            } else {
                $database->setQuery('SELECT img_id FROM #__mt_images WHERE link_id = ' . $database->quote($original_link_id));
                $keep_img_ids = $database->loadResultArray();
            }
            $redirectMsg = '';
            if (is_writable($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_small_image')) && is_writable($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_medium_image')) && is_writable($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_original_image'))) {
                // Duplicate listing images for approval
                if (!$isNew && !empty($keep_img_ids) && is_array($keep_img_ids) && $mtconf->get('needapproval_modifylisting')) {
                    foreach ($keep_img_ids as $keep_img_id) {
                        $database->setQuery('SELECT * FROM #__mt_images WHERE link_id = ' . $database->quote($original_link_id) . ' AND img_id = ' . $database->quote($keep_img_id) . ' LIMIT 1');
                        $original_image = $database->loadObject();
                        $file_extension = pathinfo($original_image->filename);
                        $file_extension = strtolower($file_extension['extension']);
                        $database->setQuery('INSERT INTO #__mt_images (link_id,filename,ordering) ' . "\n VALUES ('" . $row->link_id . "', '" . $original_image->filename . '_' . $row->link_id . "', '" . $original_image->ordering . "')");
                        $database->query();
                        $new_img_ids[$keep_img_id] = $database->insertid();
                        $database->setQuery("UPDATE #__mt_images SET filename = '" . $new_img_ids[$keep_img_id] . '_' . $row->link_id . '.' . $file_extension . "' WHERE img_id = '" . $new_img_ids[$keep_img_id] . "' LIMIT 1");
                        $database->query();
                        copy($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_small_image') . $original_image->filename, $mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_small_image') . $new_img_ids[$keep_img_id] . '_' . $row->link_id . '.' . $file_extension);
                        copy($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_medium_image') . $original_image->filename, $mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_medium_image') . $new_img_ids[$keep_img_id] . '_' . $row->link_id . '.' . $file_extension);
                        copy($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_original_image') . $original_image->filename, $mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_original_image') . $new_img_ids[$keep_img_id] . '_' . $row->link_id . '.' . $file_extension);
                    }
                }
                # Remove all images except those that are kept when modification does not require approval
                $image_filenames = array();
                if (!$mtconf->get('needapproval_modifylisting')) {
                    if (isset($keep_img_ids) && !empty($keep_img_ids)) {
                        $database->setQuery('SELECT filename FROM #__mt_images WHERE link_id = \'' . $row->link_id . '\' AND img_id NOT IN (\'' . implode('\',\'', $keep_img_ids) . '\')');
                        $image_filenames = $database->loadResultArray();
                        $database->setQuery('DELETE FROM #__mt_images WHERE link_id = \'' . $row->link_id . '\' AND img_id NOT IN (\'' . implode('\',\'', $keep_img_ids) . '\')');
                        $database->query();
                    } else {
                        $database->setQuery('SELECT filename FROM #__mt_images WHERE link_id = \'' . $row->link_id . '\'');
                        $image_filenames = $database->loadResultArray();
                        $database->setQuery('DELETE FROM #__mt_images WHERE link_id = \'' . $row->link_id . '\'');
                        $database->query();
                    }
                }
                if (!empty($image_filenames)) {
                    foreach ($image_filenames as $image_filename) {
                        unlink($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_small_image') . $image_filename);
                        unlink($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_medium_image') . $image_filename);
                        unlink($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_original_image') . $image_filename);
                    }
                }
                $files_exceed_limit = false;
                if (isset($files['image'])) {
                    for ($i = 0; $i < count($files['image']['name']) && ($i < $mtconf->get('images_per_listing') - count($keep_img_ids) || $mtconf->get('images_per_listing') == '0'); $i++) {
                        if ($mtconf->get('image_maxsize') > 0 && $files['image']['size'][$i] > $mtconf->get('image_maxsize')) {
                            // Uploaded file exceed file limit
                            $files_exceed_limit = true;
                        } elseif (!empty($files['image']['name'][$i]) && $files['image']['error'][$i] == 0 && $files['image']['size'][$i] > 0) {
                            $file_extension = pathinfo($files['image']['name'][$i]);
                            $file_extension = strtolower($file_extension['extension']);
                            $mtImage = new mtImage();
                            $mtImage->setMethod($mtconf->get('resize_method'));
                            $mtImage->setQuality($mtconf->get('resize_quality'));
                            $mtImage->setSize($mtconf->get('resize_listing_size'));
                            $mtImage->setTmpFile($files['image']['tmp_name'][$i]);
                            $mtImage->setType($files['image']['type'][$i]);
                            $mtImage->setName($files['image']['name'][$i]);
                            $mtImage->setSquare($mtconf->get('squared_thumbnail'));
                            $mtImage->resize();
                            $mtImage->setDirectory($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_small_image'));
                            $mtImage->saveToDirectory();
                            $mtImage->setSize($mtconf->get('resize_medium_listing_size'));
                            $mtImage->setSquare(false);
                            $mtImage->resize();
                            $mtImage->setDirectory($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_medium_image'));
                            $mtImage->saveToDirectory();
                            move_uploaded_file($files['image']['tmp_name'][$i], $mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_original_image') . $files['image']['name'][$i]);
                            $database->setQuery('INSERT INTO #__mt_images (link_id, filename, ordering) ' . ' VALUES(' . $database->quote($row->link_id) . ', ' . $database->quote($files['image']['name'][$i]) . ', \'9999\')');
                            $database->query();
                            $img_id = $database->insertid();
                            rename($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_small_image') . $files['image']['name'][$i], $mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_small_image') . $img_id . '.' . $file_extension);
                            rename($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_medium_image') . $files['image']['name'][$i], $mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_medium_image') . $img_id . '.' . $file_extension);
                            rename($mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_original_image') . $files['image']['name'][$i], $mtconf->getjconf('absolute_path') . $mtconf->get('relative_path_to_listing_original_image') . $img_id . '.' . $file_extension);
                            $database->setQuery('UPDATE #__mt_images SET filename = ' . $database->quote($img_id . '.' . $file_extension) . ' WHERE img_id = ' . $database->quote($img_id));
                            $database->query();
                        }
                    }
                }
                if ($files_exceed_limit) {
                    if ($mtconf->get('image_maxsize') > 1048576) {
                        $image_upload_limit = round($mtconf->get('image_maxsize') / 1048576) . 'MB';
                    } else {
                        $image_upload_limit = round($mtconf->get('image_maxsize') / 1024) . 'KB';
                    }
                    $redirectMsg .= sprintf(JText::_('Image is not saved because it exceeded file size limit'), $image_upload_limit);
                }
                $img_sort_hash = JRequest::getVar('img_sort_hash', null, 'post');
                if (!empty($img_sort_hash)) {
                    $arr_img_sort_hashes = split("[&]*img\\[\\]=\\d*", $img_sort_hash);
                    $i = 1;
                    foreach ($arr_img_sort_hashes as $arr_img_sort_hash) {
                        if (!empty($arr_img_sort_hash) && $arr_img_sort_hash > 0) {
                            $sql = 'UPDATE #__mt_images SET ordering = ' . $database->quote($i) . ' WHERE img_id = ';
                            if (isset($new_img_ids) && !empty($new_img_ids)) {
                                $sql .= $database->quote(intval($new_img_ids[$arr_img_sort_hash]));
                            } else {
                                $sql .= $database->quote(intval($arr_img_sort_hash));
                            }
                            $sql .= ' LIMIT 1';
                            $database->setQuery($sql);
                            $database->query();
                            $i++;
                        }
                    }
                }
                $images = new mtImages($database);
                $images->reorder('link_id=' . $row->link_id);
            } else {
                if (isset($files['image'])) {
                    $redirectMsg .= JText::_('Image directories not writable');
                }
            }
        }
        # Send e-mail notification to user/admin upon adding a new listing
        // Get owner's email
        if ($my->id > 0) {
            $database->setQuery("SELECT email, name, username FROM #__users WHERE id = '" . $my->id . "' LIMIT 1");
            $author = $database->loadObject();
        } else {
            if (!empty($row->email)) {
                $author->email = $row->email;
            } else {
                $author->email = JText::_('Not specified');
            }
            $author->username = JText::_('None');
            $author->name = JText::_('Non registered user');
        }
        $uri =& JURI::getInstance();
        if ($isNew) {
            # To User
            if ($mtconf->get('notifyuser_newlisting') == 1 && ($my->id > 0 || !empty($author->email) && preg_match("/[\\w\\.\\-]+@\\w+[\\w\\.\\-]*?\\.\\w{1,4}/", $author->email) == true)) {
                if ($row->link_approved == 0) {
                    $subject = sprintf(JText::_('New listing email subject waiting approval'), $row->link_name);
                    $msg = JText::_('New listing email msg waiting approval');
                } else {
                    $subject = sprintf(JText::_('New listing email subject approved'), $row->link_name);
                    $msg = sprintf(JText::_('New listing email msg approved'), $row->link_name, $uri->toString(array('scheme', 'host', 'port')) . JRoute::_("index.php?option=com_mtree&task=viewlink&link_id={$row->link_id}&Itemid={$Itemid}"), $mtconf->getjconf('fromname'));
                }
                JUTility::sendMail($mtconf->getjconf('mailfrom'), $mtconf->getjconf('fromname'), $author->email, $subject, wordwrap($msg));
            }
            # To Admin
            if ($mtconf->get('notifyadmin_newlisting') == 1) {
                if ($row->link_approved == 0) {
                    $subject = sprintf(JText::_('New listing email subject waiting approval'), $row->link_name);
                    $msg = sprintf(JText::_('Admin new listing msg waiting approval'), $row->link_name, $row->link_name, $row->link_id, $author->name, $author->username, $author->email);
                } else {
                    $subject = sprintf(JText::_('New listing email subject approved'), $row->link_name);
                    $msg = sprintf(JText::_('Admin new listing msg approved'), $row->link_name, $uri->toString(array('scheme', 'host', 'port')) . JRoute::_("index.php?option=com_mtree&task=viewlink&link_id={$row->link_id}&Itemid={$Itemid}"), $row->link_name, $row->link_id, $author->name, $author->username, $author->email);
                }
                mosMailToAdmin($subject, $msg);
            }
        } elseif ($row->link_published == 1) {
            # To User
            if ($mtconf->get('notifyuser_modifylisting') == 1 && $my->id > 0) {
                if ($row->link_approved < 0) {
                    $subject = sprintf(JText::_('Modify listing email subject waiting approval'), $row->link_name);
                    $msg = sprintf(JText::_('Modify listing email msg waiting approval'), $row->link_name, $uri->toString(array('scheme', 'host', 'port')) . JRoute::_("index.php?option=com_mtree&task=viewlink&link_id={$old->link_id}&Itemid={$Itemid}"));
                } else {
                    $subject = sprintf(JText::_('Modify listing email subject approved'), $row->link_name);
                    $msg = sprintf(JText::_('Modify listing email msg approved'), $row->link_name, $uri->toString(array('scheme', 'host', 'port')) . JRoute::_("index.php?option=com_mtree&task=viewlink&link_id={$old->link_id}&Itemid={$Itemid}"), $mtconf->getjconf('fromname'));
                }
                JUTility::sendMail($mtconf->getjconf('mailfrom'), $mtconf->getjconf('fromname'), $author->email, $subject, wordwrap($msg));
            }
            # To Admin
            if ($mtconf->get('notifyadmin_modifylisting') == 1) {
                $diff_desc = diff_main($original->link_desc, $row->link_desc, true);
                diff_cleanup_semantic($diff_desc);
                $diff_desc = diff_prettyhtml($diff_desc);
                $msg = "<style type=\"text/css\">\n";
                $msg .= "ins{text-decoration:underline}\n";
                $msg .= "del{text-decoration:line-through}\n";
                $msg .= "</style>";
                if ($row->link_approved < 0) {
                    $subject = sprintf(JText::_('Modify listing email subject waiting approval'), $row->link_name);
                    $msg .= nl2br(sprintf(JText::_('Admin modify listing msg waiting approval'), $row->link_name, $uri->toString(array('scheme', 'host', 'port')) . JRoute::_("index.php?option=com_mtree&task=viewlink&link_id={$old->link_id}&Itemid={$Itemid}"), $row->link_name, $row->link_id, $author->name, $author->username, $author->email, $diff_desc));
                } else {
                    $subject = sprintf(JText::_('Modify listing email subject approved'), $row->link_name);
                    $msg .= nl2br(sprintf(JText::_('Admin modify listing msg approved'), $row->link_name, $uri->toString(array('scheme', 'host', 'port')) . JRoute::_("index.php?option=com_mtree&task=viewlink&link_id={$old->link_id}&Itemid={$Itemid}"), $row->link_name, $row->link_id, $author->name, $author->username, $author->email, $diff_desc));
                }
                mosMailToAdmin($subject, $msg, 1);
            }
        }
        // Fire mosetstree onAfterModifyListing plugin
        $dispatcher =& JDispatcher::getInstance();
        JPluginHelper::importPlugin('mosetstree');
        $dispatcher->trigger('onAfterModifyListing', array((array) $original, $original_cfs, (array) $row, $active_cfs, $old->link_id, $cat_id));
        if (isset($original) && $original->link_published && $original->link_approved) {
            if ($isNew && $mtconf->get('needapproval_addlisting')) {
                $redirect_url = "index.php?option={$option}&task=listcats&cat_id={$cat_id}&Itemid={$Itemid}";
            } elseif (!$isNew && $mtconf->get('needapproval_modifylisting')) {
                $redirect_url = "index.php?option={$option}&task=viewlink&link_id={$old->link_id}&Itemid={$Itemid}";
            } else {
                $redirect_url = "index.php?option={$option}&task=viewlink&link_id={$row->link_id}&Itemid={$Itemid}";
            }
        } else {
            $redirect_url = "index.php?option={$option}&task=mypage&Itemid={$Itemid}";
        }
        $mainframe->redirect(JRoute::_($redirect_url), ($isNew ? $mtconf->get('needapproval_addlisting') ? JText::_('Listing will be reviewed') : JText::_('Listing have been added') : ($mtconf->get('needapproval_modifylisting') ? JText::_('Listing modification will be reviewed') : JText::_('Listing have been updated'))) . (!empty($redirectMsg) ? '<br /> ' . $redirectMsg : ''));
    }
}
Example #5
0
function MtreeBuildRoute(&$query)
{
    global $mtconf, $listing_tasks;
    $segments = array();
    $db =& JFactory::getDBO();
    if (!class_exists('mtLinks')) {
        require_once $mtconf->getjconf('absolute_path') . '/administrator/components/com_mtree/admin.mtree.class.php';
    }
    if (!isset($query['task'])) {
        return $segments;
    }
    switch ($query['task']) {
        case 'listcats':
            if (isset($query['cat_id'])) {
                $segments = appendCat($query['cat_id']);
                unset($query['cat_id']);
                if (isset($query['start'])) {
                    $page = getPage($query['start'], $mtconf->get('fe_num_of_links'));
                    $segments[] = $mtconf->get('sef_category_page') . $page;
                }
            }
            break;
        case 'viewlink':
            $mtLink = new mtLinks($db);
            $mtLink->load($query['link_id']);
            $segments = array_merge($segments, appendCat($mtLink->cat_id));
            if (isset($query['start'])) {
                //	http://example.com/c/mtree/Computer/Games/Donkey_Kong/reviews23
                $page = getPage($query['start'], $mtconf->get('fe_num_of_reviews'));
                $segments = array_merge($segments, appendListing($mtLink->link_name, $mtLink->link_id, $mtLink->alias, false));
                $segments[] = $mtconf->get('sef_reviews_page') . $page;
            } else {
                $segments = array_merge($segments, appendListing($mtLink->link_name, $mtLink->link_id, $mtLink->alias, false));
            }
            unset($query['link_id']);
            break;
        case 'mypage':
            $segments[] = $mtconf->get('sef_mypage');
            if (isset($query['start'])) {
                $page = getPage($query['start'], $mtconf->get('fe_num_of_links'));
                $segments[] = $mtconf->get('sef_category_page') . $page;
            }
            break;
        case 'listfeatured':
        case 'listnew':
        case 'listupdated':
        case 'listfavourite':
        case 'listpopular':
        case 'listmostrated':
        case 'listtoprated':
        case 'listmostreview':
            $type = strtoupper(substr($query['task'], 4));
            $cat_id = getId('cat', $query);
            $segments = appendCat($cat_id);
            $segments[] = $mtconf->get('sef_' . strtolower($type));
            if (isset($query['start'])) {
                $page = getPage($query['start'], $mtconf->get('fe_num_of_' . strtolower($type)));
                $segments[] = $mtconf->get('sef_category_page') . $page;
            }
            break;
        case 'advsearch':
            $segments[] = $mtconf->get('sef_advsearch');
            break;
        case 'advsearch2':
            $segments[] = $mtconf->get('sef_advsearch2');
            $search_id = getId('search', $query);
            $page = 1;
            if (isset($query['start'])) {
                $page = getPage($query['start'], $mtconf->get('fe_num_of_searchresults'));
                $segments[] = $search_id;
                $segments[] = $page;
            } else {
                $segments[] = $search_id;
            }
            break;
        case 'listalpha':
            $cat_id = getId('cat', $query);
            $segments = appendCat($cat_id);
            $segments[] = $mtconf->get('sef_listalpha');
            $segments[] = urlencode($query['alpha']);
            unset($query['alpha']);
            if (isset($query['start'])) {
                $page = getPage($query['start'], $mtconf->get('fe_num_of_links'));
                $segments[] = $page;
            }
            break;
        case 'viewowner':
        case 'viewusersreview':
        case 'viewusersfav':
            $user_id = getId('user', $query);
            $db->setQuery("SELECT username FROM #__users WHERE id= " . $db->quote($user_id) . " AND block='0'");
            $username = $db->loadResult();
            if (!empty($username)) {
                switch ($query['task']) {
                    default:
                        $segments[] = $mtconf->get('sef_owner');
                        break;
                    case 'viewusersreview':
                        $segments[] = $mtconf->get('sef_reviews');
                        break;
                    case 'viewusersfav':
                        $segments[] = $mtconf->get('sef_favourites');
                        break;
                }
                $segments[] = murlencode($username);
            }
            if (isset($query['start'])) {
                $page = getPage($query['start'], $mtconf->get('fe_num_of_links'));
                $segments[] = $page;
            }
            break;
        case 'viewimage':
            $segments[] = $mtconf->get('sef_image');
            $segments[] = getId('img', $query);
            break;
        case 'replyreview':
            $segments[] = $mtconf->get('sef_replyreview');
            $segments[] = getId('rev', $query);
            break;
        case 'reportreview':
            $segments[] = $mtconf->get('sef_reportreview');
            $segments[] = getId('rev', $query);
            break;
            // Listing's tasks
        // Listing's tasks
        case array_key_exists($query['task'], $listing_tasks) !== false:
            $mtLink = new mtLinks($db);
            $mtLink->load($query['link_id']);
            $segments = appendCatListing($mtLink, false);
            $segments[] = $listing_tasks[$query['task']];
            unset($query['link_id']);
            break;
        case 'addlisting':
        case 'addcategory':
            if (isset($query['link_id'])) {
                $mtLink = new mtLinks($db);
                $mtLink->load(getId('link', $query));
                $segments = appendCat($mtLink->cat_id);
            } elseif (isset($query['cat_id'])) {
                $segments = appendCat(getId('cat', $query));
            }
            if ($query['task'] == 'addlisting') {
                $segments[] = $mtconf->get('sef_addlisting');
            } else {
                $segments[] = $mtconf->get('sef_addcategory');
            }
            break;
        case 'searchby':
            $cf_id = getId('cf', $query);
            $cat_id = getId('cat', $query);
            $segments = appendCat($cat_id);
            $segments[] = $mtconf->get('sef_searchby');
            $segments[] = appendTag($cf_id);
            $segments[] = $query['value'];
            if (isset($query['start'])) {
                $page = getPage($query['start'], $mtconf->get('fe_num_of_searchresults'));
                $segments[] = $page;
            }
            unset($query['value']);
            break;
        case 'search':
            $cat_id = getId('cat', $query);
            $segments = appendCat($cat_id);
            $segments[] = $mtconf->get('sef_search');
            $badchars = array('#', '>', '<', '\\');
            $searchword = urldecode(trim(str_replace($badchars, '', $query['searchword'])));
            // limit searchword to 20 characters
            if (JString::strlen($searchword) > 20) {
                $searchword = JString::substr($searchword, 0, 19);
            }
            if (strpos($searchword, '?') !== false or strpos($searchword, '%') !== false or strpos($searchword, '/') !== false) {
                $searchword = urlencode($searchword);
            }
            $searchword = urlencode($searchword);
            if (isset($searchword) && !empty($searchword)) {
                $segments[] = $searchword;
            }
            // Retrieve configuration options - needed to know which SEF URLs are used
            $app =& JFactory::getApplication();
            // Allows for searching on strings that include ".xxx" that appear to Apache as an extension
            if ($app->getCfg('sef') && $app->getCfg('sef_rewrite') && !$app->getCfg('sef_suffix') && strpos($searchword, '.') !== false) {
                $segments[] .= '/';
            }
            unset($query['searchword']);
            break;
        case 'rss':
            $cat_id = getId('cat', $query);
            $segments = appendCat($cat_id);
            $segments[] = $mtconf->get('sef_rss');
            if (isset($query['type']) && $query['type'] == 'new') {
                $segments[] = $mtconf->get('sef_rss_new');
            } else {
                $segments[] = $mtconf->get('sef_rss_updated');
            }
            unset($query['type']);
            break;
    }
    if ($query['task'] != 'search') {
        unset($query['start']);
    }
    unset($query['limit']);
    unset($query['task']);
    return $segments;
}
Example #6
0
function search($option)
{
    global $mainframe, $mtconf;
    $database =& JFactory::getDBO();
    $search_text = JRequest::getVar('search_text', '', 'post');
    $search_where = JRequest::getInt('search_where', 0, 'post');
    // 1: Listing, 2: Category
    $limit = $mainframe->getUserStateFromRequest("viewlistlimit", 'limit', $mtconf->getjconf('list_limit'));
    $limitstart = $mainframe->getUserStateFromRequest("viewcli{$option}limitstart", 'limitstart', 0);
    # Detect search command
    # Quick Go
    $id_found = 0;
    if (substr($search_text, 0, 3) == "id:") {
        $temp = explode(":", $search_text);
        if (is_numeric($temp[1])) {
            $id_found = $temp[1];
        }
    }
    # Search query
    if ($search_where == 1) {
        if ($id_found) {
            $link = new mtLinks($database);
            $link->load($id_found);
            if (!empty($link->link_name)) {
                $mainframe->redirect("index2.php?option=com_mtree&task=editlink&link_id=" . $id_found);
            } else {
                $mainframe->redirect("index2.php?option=com_mtree", JText::_('Your search does not return any result'));
            }
        } else {
            // Total Results
            $database->setQuery('SELECT COUNT(*) FROM #__mt_links ' . "\nWHERE link_name LIKE '%" . $database->getEscaped($search_text, true) . "%'");
            $total = $database->loadResult();
            // Page Navigation
            jimport('joomla.html.pagination');
            $pageNav = new JPagination($total, $limitstart, $limit);
            // Links
            $database->setQuery("SELECT l.*, COUNT(r.rev_id) AS reviews FROM #__mt_links AS l" . "\nLEFT JOIN #__mt_reviews AS r ON r.link_id = l.link_id" . "\nWHERE l.link_name LIKE '%" . $database->getEscaped($search_text, true) . "%'" . "\nGROUP BY l.link_id" . "\nORDER BY l.link_name ASC" . "\nLIMIT " . $pageNav->limitstart . ', ' . $pageNav->limit);
        }
    } else {
        if ($id_found) {
            $cat = new mtCats($database);
            $cat->load($id_found);
            if (!empty($cat->cat_name)) {
                $mainframe->redirect("index2.php?option=com_mtree&task=editcat&cat_id=" . $id_found);
            } else {
                $mainframe->redirect("index2.php?option=com_mtree", JText::_('Your search does not return any result'));
            }
        } else {
            // Total Results
            $database->setQuery("SELECT COUNT(*) FROM #__mt_cats WHERE cat_name LIKE '%" . $database->getEscaped($search_text, true) . "%'");
            $total = $database->loadResult();
            // Page Navigation
            jimport('joomla.html.pagination');
            $pageNav = new JPagination($total, $limitstart, $limit);
            // Categories
            $database->setQuery("SELECT * FROM #__mt_cats WHERE cat_name LIKE '%" . $database->getEscaped($search_text, true) . "%' ORDER BY cat_name ASC LIMIT {$pageNav->limitstart}, {$pageNav->limit}");
        }
    }
    $results = $database->loadObjectList();
    # Get Pathway
    $pathWay = new mtPathWay();
    # Results Output
    if ($search_where == 1) {
        // Links
        HTML_mtree::searchresults_links($results, $pageNav, $pathWay, $search_where, $search_text, $option);
    } else {
        // Categories
        HTML_mtree::searchresults_categories($results, $pageNav, $pathWay, $search_where, $search_text, $option);
    }
}
Example #7
0
function mtAppendPathWay($option, $task, $cat_id = 0, $link_id = 0, $img_id = 0)
{
    global $mainframe, $Itemid;
    $database =& JFactory::getDBO();
    $mtPathWay = new mtPathWay();
    $pathway =& $mainframe->getPathway();
    switch ($task) {
        case "listcats":
        case "addcategory":
            // Show "Add Category Path?"
            $cids = $mtPathWay->getPathWay($cat_id);
            break;
        case "viewlink":
        case "writereview":
        case "rate":
        case "recommend":
        case "viewgallery":
            $mtLink = new mtLinks($database);
            $mtLink->load($link_id);
            $cat_id = $mtLink->getCatID();
            $cids = $mtPathWay->getPathWay($cat_id);
            break;
        case "viewimage":
            if ($img_id > 0) {
                $database->setQuery('SELECT link_id FROM #__mt_images WHERE img_id = \'' . $img_id . '\' LIMIT 1');
                $link_id = $database->loadResult();
                if (!is_null($link_id)) {
                    $mtLink = new mtLinks($database);
                    $mtLink->load($link_id);
                    $cat_id = $mtLink->getCatID();
                    $cids = $mtPathWay->getPathWay($cat_id);
                }
            }
            break;
            // Adding listing from a category
        // Adding listing from a category
        case "addlisting":
            if ($cat_id > 0) {
                $cids = $mtPathWay->getPathWay($cat_id);
            } elseif ($link_id > 0) {
                $mtLink = new mtLinks($database);
                $mtLink->load($link_id);
                $cat_id = $mtLink->getCatID();
                $cids = $mtPathWay->getPathWay($cat_id);
            }
            // Show "Add Listing" Path?
            break;
        case "listnew":
            $pathway->addItem(JText::_('New listing'));
            break;
        case "listfeatured":
            $pathway->addItem(JText::_('Featured listing'));
            break;
        case "listpopular":
            $pathway->addItem(JText::_('Popular listing'));
            break;
        case "listmostrated":
            $pathway->addItem(JText::_('Most rated listing'));
            break;
        case "listtoprated":
            $pathway->addItem(JText::_('Top rated listing'));
            break;
        case "listmostreview":
            $pathway->addItem(JText::_('Most reviewed listing'));
            break;
        case "advsearch":
            $pathway->addItem(JText::_('Advanced search'));
            break;
        case "advsearch2":
            $pathway->addItem(JText::_('Advanced search results'));
            break;
        case "search":
            $pathway->addItem(JText::_('Search results'));
            break;
    }
    if (isset($cids) && is_array($cids) && count($cids) > 0) {
        foreach ($cids as $cid) {
            $pathway->addItem($mtPathWay->getCatName($cid), "index.php?option={$option}&task=listcats&cat_id={$cid}");
        }
        // Append the curreny category name
        $pathway->addItem($mtPathWay->getCatName($cat_id), "index.php?option={$option}&task=listcats&cat_id={$cat_id}");
    } elseif ($cat_id > 0) {
        $pathway->addItem($mtPathWay->getCatName($cat_id), "index.php?option={$option}&task=listcats&cat_id={$cat_id}");
    }
    if (in_array($task, array("viewlink", "writereview", "rate", "recommend", "viewgallery"))) {
        $pathway->addItem($mtLink->link_name, "index.php?option={$option}&task=viewlink&link_id={$link_id}");
    }
}
    function print_startmenu($task, $cat_parent)
    {
        global $mtconf;
        $database =& JFactory::getDBO();
        # Count the number of pending links/cats/reviews/reports/claims
        $database->setQuery("SELECT COUNT(*) FROM #__mt_cats WHERE cat_approved='0'");
        $pending_cats = $database->loadResult();
        $database->setQuery("SELECT COUNT(*) FROM #__mt_links WHERE link_approved <= 0");
        $pending_links = $database->loadResult();
        $database->setQuery("SELECT COUNT(*) FROM #__mt_reviews WHERE rev_approved='0'");
        $pending_reviews = $database->loadResult();
        $database->setQuery("SELECT COUNT(*) FROM #__mt_reports WHERE rev_id = 0 && link_id > 0");
        $pending_reports = $database->loadResult();
        $database->setQuery("SELECT COUNT(*) FROM #__mt_reviews WHERE ownersreply_text != '' AND ownersreply_approved = '0'");
        $pending_reviewsreply = $database->loadResult();
        $database->setQuery("SELECT COUNT(*) FROM #__mt_reports WHERE rev_id > 0 && link_id > 0");
        $pending_reviewsreports = $database->loadResult();
        $database->setQuery("SELECT COUNT(*) FROM #__mt_claims");
        $pending_claims = $database->loadResult();
        HTML_mtree::print_style();
        ?>
	<table cellpadding="3" cellspacing="0" border="0" width="100%">
	<tr>
		<td align="left" valign="top" width="160" height="0">

			<style type="text/css">

			</style>

			<table cellpadding="2" cellspacing="0" border="0" width="160" height="100%" align="left" style="border: 1px solid #cccccc;">
				<tr><td colspan="2" style="background: #DDE1E6; border-bottom: 1px solid #cccccc;font-weight:bold;"><?php 
        echo JText::_('Title');
        ?>
</td></tr>
				
				<?php 
        if (!$mtconf->get('admin_use_explorer')) {
            ?>
				<tr>
					<td width="20" align="center" style="background-color:#DDE1E6"><img src="../includes/js/ThemeOffice/home.png" width="16" height="16" /></td>
					<td width="100%" style="background-color:#F1F3F5"> <a class="mt_menu<?php 
            echo $task == "listcats" || $task == "editcat" || $task == "" ? "_selected" : "";
            ?>
" href="index2.php?option=com_mtree&task=listcats"><?php 
            echo JText::_('Navigate tree');
            ?>
</a></td>
				</tr>
				<?php 
        }
        ?>
				<tr>
					<td align="center" style="background-color:#DDE1E6"><img src="../components/com_mtree/img/page_white_add.png" width="16" height="16" /></td>
					<td style="background-color:#F1F3F5"> <a class="mt_menu<?php 
        echo $task == "newlink" ? "_selected" : "";
        ?>
" href="index2.php?option=com_mtree&amp;task=newlink&amp;cat_parent=<?php 
        echo $cat_parent;
        ?>
"><?php 
        echo JText::_('Add listing');
        ?>
</a></td>
				</tr>

				<tr>
					<td align="center" style="background-color:#DDE1E6"><img src="../components/com_mtree/img/folder_add.png" width="16" height="16" /></td>
					<td style="background-color:#F1F3F5"> <a class="mt_menu<?php 
        echo $task == "newcat" ? "_selected" : "";
        ?>
" href="index2.php?option=com_mtree&amp;task=newcat&amp;cat_parent=<?php 
        echo $cat_parent;
        ?>
"><?php 
        echo JText::_('Add cat');
        ?>
</a></td>
				</tr>
				<?php 
        # Pending Approvals
        if ($pending_links > 0 or $pending_cats > 0 or $pending_reviews > 0 or $pending_reports > 0 or $pending_reviewsreply > 0 or $pending_reviewsreports > 0 or $pending_claims > 0) {
            ?>
				<tr><td colspan="2" style="background: #DDE1E6; border-bottom: 1px solid #cccccc;border-top: 1px solid #cccccc;font-weight:bold;"><?php 
            echo JText::_('Pending approval');
            ?>
</td></tr>
					
				<?php 
            if ($pending_cats > 0) {
                ?>
				<tr>
					<td style="background-color:#DDE1E6"><img src="../components/com_mtree/img/folder.png" width="18" height="18" /></td>
					<td style="background-color:#F1F3F5">&nbsp;<a class="mt_menu<?php 
                echo $task == "listpending_cats" ? "_selected" : "";
                ?>
" href="index2.php?option=com_mtree&task=listpending_cats"><?php 
                echo JText::_('Categories');
                ?>
 (<?php 
                echo $pending_cats;
                ?>
)</a></td>
				</tr>
					<?php 
            }
            if ($pending_links > 0) {
                ?>
				<tr>
					<td style="background-color:#DDE1E6"><img src="../components/com_mtree/img/page_white.png" width="16" height="16" /></td>
					<td style="background-color:#F1F3F5">&nbsp;<a class="mt_menu<?php 
                echo $task == "listpending_links" ? "_selected" : "";
                ?>
" href="index2.php?option=com_mtree&task=listpending_links"><?php 
                echo JText::_('Listings');
                ?>
 (<?php 
                echo $pending_links;
                ?>
)</a></td>
				</tr>
				<?php 
            }
            if ($pending_reviews > 0) {
                ?>
				<tr>
					<td style="background-color:#DDE1E6"><img src="../components/com_mtree/img/comment.png" width="16" height="16" /></td>
					<td style="background-color:#F1F3F5">&nbsp;<a class="mt_menu<?php 
                echo $task == "listpending_reviews" ? "_selected" : "";
                ?>
" href="index2.php?option=com_mtree&task=listpending_reviews"><?php 
                echo JText::_('Reviews');
                ?>
 (<?php 
                echo $pending_reviews;
                ?>
)</a></td>
				</tr>
				<?php 
            }
            if ($pending_reports > 0) {
                ?>
				<tr>
					<td style="background-color:#DDE1E6"><img src="../components/com_mtree/img/error.png" width="16" height="16" /></td>
					<td style="background-color:#F1F3F5">&nbsp;<a class="mt_menu<?php 
                echo $task == "listpending_reports" ? "_selected" : "";
                ?>
" href="index2.php?option=com_mtree&task=listpending_reports"><?php 
                echo JText::_('Reports');
                ?>
 (<?php 
                echo $pending_reports;
                ?>
)</a></td>
				</tr>
				<?php 
            }
            if ($pending_reviewsreply > 0) {
                ?>
				<tr>
					<td style="background-color:#DDE1E6"><img src="../components/com_mtree/img/user_comment.png" width="16" height="16" /></td>
					<td style="background-color:#F1F3F5">&nbsp;<a class="mt_menu<?php 
                echo $task == "listpending_reviewsreply" ? "_selected" : "";
                ?>
" href="index2.php?option=com_mtree&task=listpending_reviewsreply"><?php 
                echo JText::_('Owners replies');
                ?>
 (<?php 
                echo $pending_reviewsreply;
                ?>
)</a></td>
				</tr>
				<?php 
            }
            if ($pending_reviewsreports > 0) {
                ?>
				<tr>
					<td style="background-color:#DDE1E6"><img src="../components/com_mtree/img/error.png" width="16" height="16" /></td>
					<td style="background-color:#F1F3F5">&nbsp;<a class="mt_menu<?php 
                echo $task == "listpending_reviewsreports" ? "_selected" : "";
                ?>
" href="index2.php?option=com_mtree&task=listpending_reviewsreports"><?php 
                echo JText::_('Reviews reports');
                ?>
 (<?php 
                echo $pending_reviewsreports;
                ?>
)</a></td>
				</tr>
				<?php 
            }
            if ($pending_claims > 0) {
                ?>
				<tr>
					<td style="background-color:#DDE1E6"><img src="../components/com_mtree/img/user_green.png" width="16" height="16" /></td>
					<td style="background-color:#F1F3F5">&nbsp;<a class="mt_menu<?php 
                echo $task == "listpending_claims" ? "_selected" : "";
                ?>
" href="index2.php?option=com_mtree&task=listpending_claims"><?php 
                echo JText::_('Claims');
                ?>
 (<?php 
                echo $pending_claims;
                ?>
)</a></td>
				</tr>
				<?php 
            }
        }
        # End of Pending Approvals
        # dTree
        if ($mtconf->get('admin_use_explorer')) {
            ?>
				<tr><td colspan="2" style="background: #DDE1E6; border-bottom: 1px solid #cccccc;border-top: 1px solid #cccccc;font-weight:bold;"><?php 
            echo JText::_('Explorer');
            ?>
</td></tr>
				<tr><td colspan="2" style="background-color:#F1F3F5;">
				<?php 
            $cats = HTML_mtree::getChildren(0, $mtconf->get('explorer_tree_level'));
            ?>
				<link rel="StyleSheet" href="components/com_mtree/dtree.css" type="text/css" />
				<script type="text/javascript" src="../components/com_mtree/js/dtree.js"></script>

				<script type="text/javascript">
					<!--
					
					fpath = '../components/com_mtree/img/dtree/folder.gif';
					d = new dTree('d');

					d.config.closeSameLevel = true; 

					d.icon.root = '../includes/js/ThemeOffice/home.png',
					d.icon.folder = '../components/com_mtree/img/dtree/folder.gif',
					d.icon.folderOpen = '../components/com_mtree/img/dtree/folderopen.gif',
					d.icon.node = '../components/com_mtree/img/dtree/page.gif',
					d.icon.empty = '../components/com_mtree/img/dtree/empty.gif',
					d.icon.line = '../components/com_mtree/img/dtree/line.png',
					d.icon.join = '../components/com_mtree/img/dtree/join.png',
					d.icon.joinBottom = '../components/com_mtree/img/dtree/joinbottom.png',
					d.icon.plus = '../components/com_mtree/img/dtree/plus.png',
					d.icon.plusBottom = '../components/com_mtree/img/dtree/plusbottom.png',
					d.icon.minus = '../components/com_mtree/img/dtree/minus.gif',
					d.icon.minusBottom = '../components/com_mtree/img/dtree/minusbottom.gif',
					d.icon.nlPlus = '../components/com_mtree/img/dtree/nolines_plus.gif',
					d.icon.nlMinus = '../components/com_mtree/img/dtree/nolines_minus.gif'

					d.add(0,-1,'<?php 
            echo JText::_('Root');
            ?>
', 'index2.php?option=com_mtree');
					<?php 
            foreach ($cats as $cat) {
                echo "\nd.add(";
                echo $cat->cat_id . ",";
                echo $cat->cat_parent . ",";
                // Print Category Name
                echo "'" . addslashes(htmlspecialchars($cat->cat_name, ENT_QUOTES));
                echo "',";
                echo "pp(" . $cat->cat_id . "),";
                echo "'','',";
                echo "fpath";
                echo ");";
            }
            ?>
					document.write(d);
					
					function pp(cid) {
						return 'index2.php?option=com_mtree&task=listcats&cat_id='+cid;
					}
					//-->
				</script>

				</td></tr>
				<?php 
        }
        # End of  dTree
        # This Directory
        if ($task == 'listcats' || $task == 'editcat' || $task == 'editcat_browse_cat' || $task == 'editcat_add_relcat' || $task == 'editcat_remove_relcat') {
            if ($cat_parent > 0) {
                # Lookup all information about this directory
                $thiscat = new mtCats($database);
                $thiscat->load($cat_parent);
                ?>
				<tr><td colspan="2" align="left" style="color: black; padding-left: 20px;font-weight:bold;background: #DDE1E6 url(../components/com_mtree/img/dtree/folderopen.gif) no-repeat center left; border-bottom: 1px solid #cccccc;border-top: 1px solid #cccccc;"><?php 
                echo JText::_('This category');
                ?>
</td></tr>
				<tr class="row0"><td colspan="2" style="background-color:#F1F3F5">
					<?php 
                $published_img = $thiscat->cat_published ? 'tick.png' : 'publish_x.png';
                $featured_img = $thiscat->cat_featured ? 'tick.png' : 'publish_x.png';
                $tcat = new mtDisplay();
                $tcat->add(JText::_('Name'), '<a href="index2.php?option=com_mtree&task=editcat&cat_id=' . $thiscat->cat_id . '&cat_parent=' . $thiscat->cat_parent . '">' . $thiscat->cat_name . '</a>');
                $tcat->add(JText::_('Cat id'), $thiscat->cat_id);
                $tcat->add(JText::_('Listings'), $thiscat->cat_links);
                $tcat->add(JText::_('Categories'), $thiscat->cat_cats);
                $tcat->add(JText::_('Related categories2'), $thiscat->getNumOfRelCats());
                $tcat->add(JText::_('Published'), '<img src="images/' . $published_img . '" width="12" height="12" border="0" alt="" />');
                $tcat->add(JText::_('Featured'), '<img src="images/' . $featured_img . '" width="12" height="12" border="0" alt="" />');
                $tcat->display();
                ?>
				</td></tr>

				<?php 
            }
            # This Listing
        } elseif ($task == 'editlink' || $task == 'editlink_change_cat' || $task == 'reviews_list' || $task == 'newreview' || $task == 'editreview' || $task == 'editlink_browse_cat' || $task == 'editlink_add_cat' || $task == 'editlink_remove_cat') {
            global $link_id;
            if ($link_id[0] > 0) {
                $thislink = new mtLinks($database);
                $thislink->load($link_id[0]);
                $database->setQuery('SELECT COUNT(*) FROM #__mt_reviews WHERE link_id = ' . $database->quote($link_id[0]) . ' AND rev_approved = 1');
                $reviews = $database->loadResult();
                ?>
				<tr><td colspan="2" align="left" style="color: black; padding-left: 20px;font-weight:bold;background: #DDE1E6 url(../includes/js/ThemeOffice/document.png) no-repeat center left; border-bottom: 1px solid #cccccc;border-top: 1px solid #cccccc;"><?php 
                echo JText::_('This listing');
                ?>
</td></tr>
				<tr class="row0"><td colspan="2" style="background-color:#F1F3F5">
					<?php 
                $tlisting = new mtDisplay();
                $tlisting->add(JText::_('Name'), '<a href="index2.php?option=com_mtree&task=editlink&link_id=' . $thislink->link_id . '">' . $thislink->link_name . '</a>');
                $tlisting->add(JText::_('Listing id'), $thislink->link_id);
                $tlisting->add(JText::_('Category'), '<a href="index2.php?option=com_mtree&task=listcats&cat_id=' . $thislink->cat_id . '">' . $thislink->getCatName() . '</a>');
                $tlisting->add(JText::_('Reviews'), '<a href="index2.php?option=com_mtree&task=reviews_list&link_id=' . $thislink->link_id . '">' . $reviews . '</a>');
                $tlisting->add(JText::_('Hits'), $thislink->link_hits);
                $tlisting->add(JText::_('Modified2'), tellDateTime($thislink->link_modified));
                $tlisting->display();
                ?>
				</td></tr>
						<?php 
            }
        }
        // Search
        $search_text = JRequest::getVar('search_text', '', 'post');
        $search_where = JRequest::getInt('search_where', 0, 'post');
        // 1: Listing, 2: Category
        ?>

				<tr><td colspan="2" style="background: #DDE1E6; border-bottom: 1px solid #cccccc;border-top: 1px solid #cccccc;font-weight:bold;"><?php 
        echo JText::_('Search');
        ?>
</td></tr>
				<tr><td colspan="2" align="left" style="background-color:#F1F3F5">
					<form action="index2.php" method="post">
					<input class="text_area" type="text" name="search_text" size="10" maxlength="250" value="<?php 
        echo $search_text;
        ?>
" /> <input type="submit" value="<?php 
        echo JText::_('Search');
        ?>
" class="button" />
					<select name="search_where" class="inputbox" size="1">
						<option value="1"<?php 
        echo $search_where == 1 ? ' selected' : '';
        ?>
><?php 
        echo JText::_('Listings');
        ?>
</option>
						<option value="2"<?php 
        echo $search_where == 2 ? ' selected' : '';
        ?>
><?php 
        echo JText::_('Categories');
        ?>
</option>
					</select>
					<a href="index2.php?option=com_mtree&task=advsearch"><?php 
        echo JText::_('Advanced search short');
        ?>
</a>
					<input type="hidden" name="option" value="com_mtree" />
					<input type="hidden" name="task" value="search" />
					<input type="hidden" name="limitstart" value="0" />
					</form>
				</td></tr>

				<tr><td colspan="2" style="background: #DDE1E6; border-bottom: 1px solid #cccccc;border-top: 1px solid #cccccc;font-weight:bold;"><?php 
        echo JText::_('More');
        ?>
</td></tr>
				<tr>
					<td style="background: #DDE1E6;"><img src="../components/com_mtree/img/zoom.png" width="16" height="16" /></td>
					<td style="background-color:#F1F3F5">&nbsp;<a class="mt_menu" href="index2.php?option=com_mtree&task=spy"><?php 
        echo JText::_('Spy directory');
        ?>
</a></td>
				</tr>
				<tr>
					<td style="background: #DDE1E6;"><img src="../includes/js/ThemeOffice/config.png" width="16" height="16" /></td>
					<td style="background-color:#F1F3F5">&nbsp;<a class="mt_menu<?php 
        echo $task == "config" ? "_selected" : "";
        ?>
" href="index2.php?option=com_mtree&task=config"><?php 
        echo JText::_('Configuration');
        ?>
</a></td>
				</tr>
				<?php 
        /* ?>
        			<tr>
        				<td style="background: #DDE1E6;"><img src="../components/com_mtree/img/table_link.png" width="16" height="16" /></td>
        				<td style="background-color:#F1F3F5">&nbsp;<a class="mt_menu<?php echo ($task=="linkchecker") ? "_selected": ""; ?>" href="index2.php?option=com_mtree&task=linkchecker"><?php echo JText::_( 'Link checker' ) ?></a></td>
        			</tr>
        			<?php */
        ?>
				<tr>
					<td style="background: #DDE1E6;"><img src="../includes/js/ThemeOffice/template.png" width="16" height="16" /></td>
					<td style="background-color:#F1F3F5">&nbsp;<a class="mt_menu<?php 
        echo $task == "templates" ? "_selected" : "";
        ?>
" href="index2.php?option=com_mtree&task=templates"><?php 
        echo JText::_('Templates');
        ?>
</a></td>
				</tr>
				<tr>
					<td style="background: #DDE1E6;"><img src="../includes/js/ThemeOffice/content.png" width="16" height="16" /></td>
					<td style="background-color:#F1F3F5">&nbsp;<a class="mt_menu<?php 
        echo $task == "customfields" ? "_selected" : "";
        ?>
" href="index2.php?option=com_mtree&task=customfields"><?php 
        echo JText::_('Custom fields');
        ?>
</a></td>
				</tr>

				<tr>
					<td style="background: #DDE1E6;"><img src="../includes/js/ThemeOffice/query.png" width="16" height="16" /></td>
					<td style="background-color:#F1F3F5">&nbsp;<a class="mt_menu<?php 
        echo $task == "csv" ? "_selected" : "";
        ?>
" href="index2.php?option=com_mtree&task=csv"><?php 
        echo JText::_('Export');
        ?>
</a></td>
				</tr>
				<tr>
					<td style="background: #DDE1E6;"><img src="../includes/js/ThemeOffice/globe3.png" width="16" height="16" /></td>
					<td style="background-color:#F1F3F5">&nbsp;<a class="mt_menu" href="index.php?option=com_mtree&amp;task=geocode"><?php 
        echo JText::_('Locate Listings in Map');
        ?>
</a></td>
				</tr>
				<tr>
					<td style="background: #DDE1E6;"><img src="../includes/js/ThemeOffice/globe3.png" width="16" height="16" /></td>
					<td style="background-color:#F1F3F5">&nbsp;<a class="mt_menu" href="index2.php?option=com_mtree&amp;task=globalupdate"><?php 
        echo JText::_('Recount categories listings');
        ?>
</a></td>
				</tr>
				<tr>
					<td style="background: #DDE1E6;"><img src="../includes/js/ThemeOffice/credits.png" width="16" height="16" /></td>
					<td style="background-color:#F1F3F5">&nbsp;<a class="mt_menu<?php 
        echo $task == "about" ? "_selected" : "";
        ?>
" href="index2.php?option=com_mtree&task=about"><?php 
        echo JText::_('About mosets tree');
        ?>
</a></td>
				</tr>

			</table>		
		</td>
		<td valign="top">
		<?php 
    }