Per CSS Link in PHP ansprechen

Du hast ein PHP-Code Problem und benötigst Hilfe bei der Lösung
Antworten
Kopernikus
Beiträge: 390
Registriert: Fr 19. Okt 2012, 12:15

Per CSS Link in PHP ansprechen

Beitrag von Kopernikus »

Hallo allerseits

Ich habe ein kleines php Problem, was wohl auf mein noch sehr unausgeprägtes Wissen in PHP zurückzuführen ist. Vielleicht kann mir hier aber jemand weiterhelfen?

In meiner horizontalen Navigation kann ich über folgenden Befehl auch externe Links einbauen:

Code: Alles auswählen

 $ct->addLink('Home', xtc_href_link('index.php'), 249, 0);
Nun möchte ich gerne jeden dieser externen Link per CSS individuell ansprechen. Dafür müsste ich jedem Link (z.B. bindend an die ID) eine entsprechende Klasse zuweisen können. Doch wie genau funktioniert das?

Die function "addLink" wird in der templates\Webs\Source\Class\categories.php definiert. Wer hat mir hierzu einen Tipp?

Code: Alles auswählen

<?php

/** ----------------------------------------------------------------------------
 *
 * categories.php
 *
 * WEB-Shop Software http://www.webs.de/
 *
 * -----------------------------------------------------------------------------
 *
 * Released under the GNU General Public License
 *
 * @author Doc Olson (info@it-bites.de)
 * @version $Id: categories.php 2319 2012-10-09 11:39:10Z joerg $
 * @copyright 2012 WEB-Shop Software http://www.webs.de/
 *
 * ----------------------------------------------------------------------------- */
class categories
{

	protected $path = array();
	protected $cur_cat_id = 0;
	protected $categories = array();
	public $start_level = 0;
	public $min_level = 1;
	public $max_level = false;
	public $hide_empty = false;
	public $class_cur = 'current';
	public $class_active = 'active';
	public $class_cur_has_child = 'has_child';
	public $class_level = 'level_';
	public $class_cur_parent = 'current_parent';

	/**
	 * __construct
	 *
	 */
	public function __construct($cPath, $cur_cat_id)
	{
		$this->path = explode('_', $cPath);
		$this->cur_cat_id = $cur_cat_id;
	}

	/**
	 * addLink
	 *
	 * inserts a custom link into the category tree
	 *
	 *
	 * @param string $name
	 * @param string $link
	 * @param integer $parent_id
	 * @param integer $position
	 */
	public function addLink($name, $link, $parent_id = 0, $position = 0)
	{
		$level = 0;
		$this->getLevel($this->categories, $level, $parent_id);
		$parent_level = $level;

		// if parent is not found in the current tree
		if ($parent_level < 0) {
			return false;
		}

		/*
		 * only add link, if it is...
		 * a. a child of the current category
		 * b. to be placed on a level that should be open initially (min_level)
		 */
		if (
			($this->cur_cat_id != $parent_id && $parent_level + 1 >= $this->min_level) &&
			$parent_id != 0
		) {
			return false;
		}

		$cats = false;

		if ($parent_id == 0) {
			$cats = &$this->categories;
		} else {
			$cats = &$this->getBranch($this->categories, $parent_id);
		}

		if (!is_array($cats)) {
			return false;
		}

		$c = count($cats);
		if ($position >= $c) {
			$position = $c;
		}

		for ($i = count($cats); $i > $position; $i--) {
			$cats[$i] = $cats[$i - 1];
		}

		$cats[$position] = array(
			'id' => false,
			'parent' => $parent_id,
			'level' => $parent_level + 1,
			'title' => $name,
			'link' => $link,
			'current' => false
		);
	}

	/**
	 * getBranch
	 *
	 * returns a reference to the branch with the parent-id $parent
	 *
	 * @param array &$cats
	 * @param integer $parent_id
	 */
	protected function &getBranch(&$cats, $parent_id)
	{
		$result = false;

		for ($i = 0, $c = count($cats); $i < $c; $i++) {
			if ($cats[$i]['id'] == $parent_id) {
				if (!is_array($cats[$i]['children'])) {
					$cats[$i]['children'] = array();
				}
				$result = & $cats[$i]['children'];
			} else {
				if (is_array($cats[$i]['children']) && count($cats[$i]['children'])) {
					$result = & $this->getBranch($cats[$i]['children'], $parent_id);
				}
			}

			if (is_array($result)) {
				break;
			}
		}

		return $result;
	}

	/**
	 * determines on what level a category resides
	 * if the category is not found, -1 will be returned
	 *
	 * @param array $cats
	 * @param integer $cat_id
	 * @param integer $level
	 * @return integer
	 */
	private function getLevel(&$cats, &$level, $cat_id)
	{
		for ($i = 0, $c = count($cats); $i <= $c; $i++) {
			if (isset($cats[$i]['children']) && count($cats[$i]['children'])) {
				$level++;
				$res = $this->getLevel($cats[$i]['children'], $level, $cat_id);
				if ($res !== false) {
					return $res;
				}
			}

			if ($cats[$i]['id'] == $cat_id) {
				return $level;
			}
		}
		$level--;
		return false;
	}

	/**
	 * getCategories
	 *
	 */
	public function getCategories($cat_id = 0)
	{
		$this->categories = array_merge($this->categories, $this->getSubCategories($cat_id));
	}

	/**
	 * getSubCategories
	 *
	 * @param integer $cat_id
	 * @param integer $level
	 * @return array
	 */
	protected function getSubCategories($cat_id = 0, $level = 1)
	{
		$category = array();

		$group_check = '';
		if (GROUP_CHECK == 'true') {
			$group_check = 'AND c.group_permission_' .
				$_SESSION['customers_status']['customers_status_id'] . ' = 1 ';
		}

		$res = xtc_db_query(
			"-- categories.php template class
            SELECT c.categories_id, cd.categories_name
            FROM " . TABLE_CATEGORIES . " c
            INNER JOIN " . TABLE_CATEGORIES_DESCRIPTION . " cd
            ON c.categories_id = cd.categories_id
            WHERE
                c.parent_id = $cat_id AND
                c.categories_status = 1
                $group_check AND
                cd.language_id = " . (int)$_SESSION['languages_id'] . "
            ORDER BY c.sort_order, cd.categories_name"
		);

		while ($row = xtc_db_fetch_array($res, true)) {

			$current = false;
			$active = false;

			if ($row['categories_id'] == $this->cur_cat_id) {
				$current = true;
			}

			if (in_array($row['categories_id'], $this->path)) {
				$active = true;
				$current = true;
			}

			$prd_count = $this->countProducts($row['categories_id'], false, false);

			if (($prd_count > 0 && $this->hide_empty ) || !$this->hide_empty) {

				/*
				  // if only one product is present, the link will go to
				  // the product instead of the category
				  if ($prd_count == 1) {

				  $res2 = xtc_db_query("-- categories.php class
				  SELECT p.products_id, pd.products_name
				  FROM " . TABLE_PRODUCTS . " p
				  JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd
				  ON p.products_id = pd.products_id
				  JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " ptc
				  ON p.products_id = ptc.products_id
				  WHERE ptc.categories_id = " . $row['categories_id'] . "
				  AND pd.language_id = " . (int) $_SESSION['languages_id'] . "
				  AND p.products_status = 1"
				  );

				  $row2 = xtc_db_fetch_array($res2, true);
				  $link = xtc_href_link(
				  FILENAME_PRODUCT_INFO,
				  xtc_product_link(
				  $row2['products_id'],
				  $row2['products_name']
				  )
				  );
				  } else {
				  $link = xtc_href_link(
				  FILENAME_DEFAULT,
				  xtc_category_link($row['categories_id'], $row['categories_name'])
				  );
				  }
				 */

				$link = xtc_href_link(
					FILENAME_DEFAULT,
					xtc_category_link($row['categories_id'], $row['categories_name'])
				);

				$title = htmlspecialchars(
					$row['categories_name'],
					ENT_COMPAT,
					CHARSET,
					false
				);

				$cat = array(
					'id' => $row['categories_id'],
					'parent' => $cat_id,
					'level' => $level,
					'title' => $title,
					'link' => $link,
					'current' => $current,
					'active' => $active
				);

				if (SHOW_COUNTS == 'true' || $this->hide_empty) {
					$cat['prd_count'] = $this->countProducts($row['categories_id']);
				}

				if (
					( $level < $this->min_level || $active ) &&
					( $level < $this->max_level || !$this->max_level )
				) {
					$cat['children'] = $this->getSubCategories($row['categories_id'], $level + 1);
				}

				$category[] = $cat;
			}
		}

		return $category;
	}

	/**
	 * getMainCategory
	 *
	 * @return array
	 */
	public function getMainCategory($mainId = NULL)
	{
		$mainCategory = array();

    if ($mainId === NULL) {
      $mainId = (int)$this->path[0];
    }
		if ($mainId == 0) {
			$mainCategory = array(
				'title' => HEADER_TITLE_TOP,
				'link' => xtc_href_link(FILENAME_DEFAULT)
			);
		} else {

			$group_check = NULL;
			if (GROUP_CHECK == 'true') {
				$group_check = 'AND c.group_permission_' .
					$_SESSION['customers_status']['customers_status_id'] . ' = 1 ';
			}

			$res = xtc_db_query(
				"-- categories.php template class
				SELECT c.categories_id, cd.categories_name
				FROM " . TABLE_CATEGORIES . " c
				INNER JOIN " . TABLE_CATEGORIES_DESCRIPTION . " cd
				ON c.categories_id = cd.categories_id
				WHERE
					c.categories_id = $mainId AND
					c.categories_status = 1
					$group_check AND
					cd.language_id = " . (int)$_SESSION['languages_id'] . "
				ORDER BY c.sort_order, cd.categories_name"
			);

			while ($row = xtc_db_fetch_array($res, true)) {
				$link = xtc_href_link(
					FILENAME_DEFAULT,
					xtc_category_link($row['categories_id'], $row['categories_name'])
				);
				$title = htmlspecialchars(
					$row['categories_name'],
					ENT_COMPAT,
					CHARSET,
					false
				);
				$mainCategory = array(
					'title' => $title,
					'link' => $link
				);
			}
		}
		return $mainCategory;
	}

	/**
	 * getOutputHTML
	 *
	 * @param array $cats
	 * @param integer $level
	 * @return string
	 */
	public function getOutputHTML($cats = false, $level = 0)
	{
		if (!count($this->categories)) {
			return null;
		}

		$cats = $cats ? $cats : $this->categories;

		if ($level == 0) {
			$result = sprintf('<ul class="%s">' . "\n", $this->class_level . $level);
		} else {
			$result = '';
		}

		foreach ($cats as $key => $cat) {
			$classes = array();

			if ($key == 0) {
				$classes[] = 'first';
			}

			if (($key + 1) == count($cats)) {
				$classes[] = 'last';
			}

			if ($cat['active']) {
				$classes[] = $this->class_active;
			}

			if ($cat['current']) {
				$classes[] = $this->class_cur;

				if (count($cat['children']) > 0) {
					$classes[] = $this->class_cur_has_child;
				}
			}

			$prd_count = SHOW_COUNTS == 'true' ? ' (<em>' . $cat['prd_count'] . '</em>)' : '';
			if (isset($cat['children']) and !empty($cat['children'])) {
				$children = sprintf('<ul class="%s">' . "\n", $this->class_level . ($level + 1));
				$children .= $this->getOutputHTML($cat['children'], $cat['level']);
				$children .= "</ul>\n";
			} else {
				$children = '';
			}

			$classes = count($classes) ? ' class="' . implode(' ', $classes) . '"' : '';

			$result .= sprintf(
				'<li%s><a href="%s" title="%s"%s>%s%s</a>%s</li>',
				$classes, $cat['link'], $cat['title'], $classes, $cat['title'], $prd_count, $children
			) . "\n";
		}

		if ($level == 0) {
			$result .= "</ul>\n";
		}
		return $result;
	}

	/**
	 * getOutput
	 *
	 * @param array $cats
	 * @param integer $level
	 */
	public function getOutput($cats = false, $level = 0)
	{
		return $this->categories;
	}

	/**
	 * countProducts
	 *
	 * @param integer $cat_id
	 * @param boolean $include_inactive
	 * @return integer
	 */
	public function countProducts($cat_id, $include_inactive = false)
	{
		$count = 0;

		if ($include_inactive) {
			$active = '';
		} else {
			$active = "AND p.products_status = '1'";
		}

		$res = xtc_db_query(
			"SELECT count(*) AS total
            FROM " . TABLE_PRODUCTS . " p
            INNER JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c
            ON p.products_id = p2c.products_id
            WHERE p2c.categories_id = $cat_id
            $active
            AND (
                p.products_date_expire > NOW() OR
				p.products_date_expire IS NULL OR
				p.products_date_expire = '0000-00-00 00:00:00'
			)"
		);

		$res = xtc_db_fetch_array($res, true);
		$count += $res['total'];

		$res = xtc_db_query("SELECT categories_id FROM " . TABLE_CATEGORIES . " WHERE parent_id = $cat_id");

		if (xtc_db_num_rows($res, true)) {
			while ($row = xtc_db_fetch_array($res, true)) {
				$count += $this->countProducts($row['categories_id'], $include_inactive);
			}
		}

		return $count;
	}
}
Kopernikus
Beiträge: 390
Registriert: Fr 19. Okt 2012, 12:15

Re: Per CSS Link in PHP ansprechen

Beitrag von Kopernikus »

Dieser Link wurde mal wieder zu meiner Tagesaufgabe. Nun bin ich soweit, dass es gemäss eines PHP Cracks eigentlich funktionieren müsste. Doch das tut es nach wie vor nicht. Vielleicht kann sich einer hier mal kurz meinen Code ansehen.

Das Ganze beginnt in der zusätzlichen Klassen-Definition in der entsprechenden Function "addLink" (Datei: webs / source / class/categories.php) Hier kam nun das zusätzliche Attribut $class = ' ' dazu.

Code: Alles auswählen

    <?php

   /** ----------------------------------------------------------------------------
 *
 * categories.php
 *
 * WEB-Shop Software http://www.webs.de/
 *
 * -----------------------------------------------------------------------------
 *
 * Released under the GNU General Public License
 *
 * @author Doc Olson (info@it-bites.de)
 * @version $Id: categories.php 2319 2012-10-09 11:39:10Z joerg $
 * @copyright 2012 WEB-Shop Software http://www.webs.de/
 *
 * ----------------------------------------------------------------------------- */
    class categories
    {

            protected $path = array();
            protected $cur_cat_id = 0;
            protected $categories = array();
            public $start_level = 0;
            public $min_level = 1;
            public $max_level = false;
            public $hide_empty = false;
            public $class_cur = 'current';
            public $class_active = 'active';
            public $class_cur_has_child = 'has_child';
            public $class_level = 'level_';
            public $class_cur_parent = 'current_parent';

            /**
             * __construct
             *
             */
            public function __construct($cPath, $cur_cat_id)
            {
                    $this->path = explode('_', $cPath);
                    $this->cur_cat_id = $cur_cat_id;
            }

            /**
             * addLink
             *
             * inserts a custom link into the category tree
             *
             *
             * @param string $name
             * @param string $link
             * @param integer $parent_id
             * @param integer $position
             */
            public function addLink($name, $link, $parent_id = 0, $position = 0, $class = '')
            {
                    $level = 0;
                    $this->getLevel($this->categories, $level, $parent_id);
                    $parent_level = $level;

                    // if parent is not found in the current tree
                    if ($parent_level < 0) {
                            return false;
                    }

                    /*
                     * only add link, if it is...
                     * a. a child of the current category
                     * b. to be placed on a level that should be open initially (min_level)
                     */
                    if (
                            ($this->cur_cat_id != $parent_id && $parent_level + 1 >= $this->min_level) &&
                            $parent_id != 0
                    ) {
                            return false;
                    }

                    $cats = false;

                    if ($parent_id == 0) {
                            $cats = &$this->categories;
                    } else {
                            $cats = &$this->getBranch($this->categories, $parent_id);
                    }

                    if (!is_array($cats)) {
                            return false;
                    }

                    $c = count($cats);
                    if ($position >= $c) {
                            $position = $c;
                    }

                    for ($i = count($cats); $i > $position; $i--) {
                            $cats[$i] = $cats[$i - 1];
                    }

                    $cats[$position] = array(
                            'id' => false,
                            'parent' => $parent_id,
                            'level' => $parent_level + 1,
                            'title' => $name,
                            'link' => $link,
                            'class' => $class,
                            'current' => false
                    );
            }

            /**
             * getBranch
             *
             * returns a reference to the branch with the parent-id $parent
             *
             * @param array &$cats
             * @param integer $parent_id
             */
            protected function &getBranch(&$cats, $parent_id)
            {
                    $result = false;

                    for ($i = 0, $c = count($cats); $i < $c; $i++) {
                            if ($cats[$i]['id'] == $parent_id) {
                                    if (!is_array($cats[$i]['children'])) {
                                            $cats[$i]['children'] = array();
                                    }
                                    $result = & $cats[$i]['children'];
                            } else {
                                    if (is_array($cats[$i]['children']) && count($cats[$i]['children'])) {
                                            $result = & $this->getBranch($cats[$i]['children'], $parent_id);
                                    }
                            }

                            if (is_array($result)) {
                                    break;
                            }
                    }

                    return $result;
            }

            /**
             * determines on what level a category resides
             * if the category is not found, -1 will be returned
             *
             * @param array $cats
             * @param integer $cat_id
             * @param integer $level
             * @return integer
             */
            private function getLevel(&$cats, &$level, $cat_id)
            {
                    for ($i = 0, $c = count($cats); $i <= $c; $i++) {
                            if (isset($cats[$i]['children']) && count($cats[$i]['children'])) {
                                    $level++;
                                    $res = $this->getLevel($cats[$i]['children'], $level, $cat_id);
                                    if ($res !== false) {
                                            return $res;
                                    }
                            }

                            if ($cats[$i]['id'] == $cat_id) {
                                    return $level;
                            }
                    }
                    $level--;
                    return false;
            }

            /**
             * getCategories
             *
             */
            public function getCategories($cat_id = 0)
            {
                    $this->categories = array_merge($this->categories, $this->getSubCategories($cat_id));
            }

            /**
             * getSubCategories
             *
             * @param integer $cat_id
             * @param integer $level
             * @return array
             */
            protected function getSubCategories($cat_id = 0, $level = 1)
            {
                    $category = array();

                    $group_check = '';
                    if (GROUP_CHECK == 'true') {
                            $group_check = 'AND c.group_permission_' .
                                    $_SESSION['customers_status']['customers_status_id'] . ' = 1 ';
                    }

                    $res = xtc_db_query(
                            "-- categories.php template class
               SELECT c.categories_id, cd.categories_name
               FROM " . TABLE_CATEGORIES . " c
               INNER JOIN " . TABLE_CATEGORIES_DESCRIPTION . " cd
               ON c.categories_id = cd.categories_id
               WHERE
                   c.parent_id = $cat_id AND
                   c.categories_status = 1
                   $group_check AND
                   cd.language_id = " . (int)$_SESSION['languages_id'] . "
               ORDER BY c.sort_order, cd.categories_name"
                    );

                    while ($row = xtc_db_fetch_array($res, true)) {

                            $current = false;
                            $active = false;

                            if ($row['categories_id'] == $this->cur_cat_id) {
                                    $current = true;
                            }

                            if (in_array($row['categories_id'], $this->path)) {
                                    $active = true;
                                    $current = true;
                            }

                            $prd_count = $this->countProducts($row['categories_id'], false, false);

                            if (($prd_count > 0 && $this->hide_empty ) || !$this->hide_empty) {

                                    /*
                                      // if only one product is present, the link will go to
                                      // the product instead of the category
                                      if ($prd_count == 1) {

                                      $res2 = xtc_db_query("-- categories.php class
                                      SELECT p.products_id, pd.products_name
                                      FROM " . TABLE_PRODUCTS . " p
                                      JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd
                                      ON p.products_id = pd.products_id
                                      JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " ptc
                                      ON p.products_id = ptc.products_id
                                      WHERE ptc.categories_id = " . $row['categories_id'] . "
                                      AND pd.language_id = " . (int) $_SESSION['languages_id'] . "
                                      AND p.products_status = 1"
                                      );

                                      $row2 = xtc_db_fetch_array($res2, true);
                                      $link = xtc_href_link(
                                      FILENAME_PRODUCT_INFO,
                                      xtc_product_link(
                                      $row2['products_id'],
                                      $row2['products_name']
                                      )
                                      );
                                      } else {
                                      $link = xtc_href_link(
                                      FILENAME_DEFAULT,
                                      xtc_category_link($row['categories_id'], $row['categories_name'])
                                      );
                                      }
                                     */

                                    $link = xtc_href_link(
                                            FILENAME_DEFAULT,
                                            xtc_category_link($row['categories_id'], $row['categories_name'])
                                    );

                                    $title = htmlspecialchars(
                                            $row['categories_name'],
                                            ENT_COMPAT,
                                            CHARSET,
                                            false
                                    );

                                    $cat = array(
                                            'id' => $row['categories_id'],
                                            'parent' => $cat_id,
                                            'level' => $level,
                                            'title' => $title,
                                            'link' => $link,
                                            'current' => $current,
                                            'active' => $active
                                    );

                                    if (SHOW_COUNTS == 'true' || $this->hide_empty) {
                                            $cat['prd_count'] = $this->countProducts($row['categories_id']);
                                    }

                                    if (
                                            ( $level < $this->min_level || $active ) &&
                                            ( $level < $this->max_level || !$this->max_level )
                                    ) {
                                            $cat['children'] = $this->getSubCategories($row['categories_id'], $level + 1);
                                    }

                                    $category[] = $cat;
                            }
                    }

                    return $category;
            }

            /**
             * getMainCategory
             *
             * @return array
             */
            public function getMainCategory($mainId = NULL)
            {
                    $mainCategory = array();

        if ($mainId === NULL) {
          $mainId = (int)$this->path[0];
        }
                    if ($mainId == 0) {
                            $mainCategory = array(
                                    'title' => HEADER_TITLE_TOP,
                                    'link' => xtc_href_link(FILENAME_DEFAULT)
                            );
                    } else {

                            $group_check = NULL;
                            if (GROUP_CHECK == 'true') {
                                    $group_check = 'AND c.group_permission_' .
                                            $_SESSION['customers_status']['customers_status_id'] . ' = 1 ';
                            }

                            $res = xtc_db_query(
                                    "-- categories.php template class
                                    SELECT c.categories_id, cd.categories_name
                                    FROM " . TABLE_CATEGORIES . " c
                                    INNER JOIN " . TABLE_CATEGORIES_DESCRIPTION . " cd
                                    ON c.categories_id = cd.categories_id
                                    WHERE
                                            c.categories_id = $mainId AND
                                            c.categories_status = 1
                                            $group_check AND
                                            cd.language_id = " . (int)$_SESSION['languages_id'] . "
                                    ORDER BY c.sort_order, cd.categories_name"
                            );

                            while ($row = xtc_db_fetch_array($res, true)) {
                                    $link = xtc_href_link(
                                            FILENAME_DEFAULT,
                                            xtc_category_link($row['categories_id'], $row['categories_name'])
                                    );
                                    $title = htmlspecialchars(
                                            $row['categories_name'],
                                            ENT_COMPAT,
                                            CHARSET,
                                            false
                                    );
                                    $mainCategory = array(
                                            'title' => $title,
                                            'link' => $link
                                    );
                            }
                    }
                    return $mainCategory;
            }

            /**
             * getOutputHTML
             *
             * @param array $cats
             * @param integer $level
             * @return string
             */
            public function getOutputHTML($cats = false, $level = 0)
            {
                    if (!count($this->categories)) {
                            return null;
                    }

                    $cats = $cats ? $cats : $this->categories;

                    if ($level == 0) {
                            $result = sprintf('<ul class="%s">' . "\n", $this->class_level . $level);
                    } else {
                            $result = '';
                    }

                    foreach ($cats as $key => $cat) {
                            $classes = array();

                            if ($key == 0) {
                                    $classes[] = 'first';
                            }

                            if (($key + 1) == count($cats)) {
                                    $classes[] = 'last';
                            }

                            if ($cat['active']) {
                                    $classes[] = $this->class_active;
                            }

                            if ($cat['current']) {
                                    $classes[] = $this->class_cur;

                                    if (count($cat['children']) > 0) {
                                            $classes[] = $this->class_cur_has_child;
                                    }
                            }
                            if ($cat['class']) {
                                    $classes[] = $cat['class'];
                            }

                            $prd_count = SHOW_COUNTS == 'true' ? ' (<em>' . $cat['prd_count'] . '</em>)' : '';
                            if (isset($cat['children']) and !empty($cat['children'])) {
                                    $children = sprintf('<ul class="%s">' . "\n", $this->class_level . ($level + 1));
                                    $children .= $this->getOutputHTML($cat['children'], $cat['level']);
                                    $children .= "</ul>\n";
                            } else {
                                    $children = '';
                            }

                            $classes = count($classes) ? ' class="' . implode(' ', $classes) . '"' : '';

                            $result .= sprintf(
                                    '<li%s><a href="%s" title="%s"%s>%s%s</a>%s</li>',
                                    $classes, $cat['link'], $cat['title'], $classes, $cat['title'], $prd_count, $children
                            ) . "\n";
                    }

                    if ($level == 0) {
                            $result .= "</ul>\n";
                    }
                    return $result;
            }

            /**
             * getOutput
             *
             * @param array $cats
             * @param integer $level
             */
            public function getOutput($cats = false, $level = 0)
            {
                    return $this->categories;
            }

            /**
             * countProducts
             *
             * @param integer $cat_id
             * @param boolean $include_inactive
             * @return integer
             */
            public function countProducts($cat_id, $include_inactive = false)
            {
                    $count = 0;

                    if ($include_inactive) {
                            $active = '';
                    } else {
                            $active = "AND p.products_status = '1'";
                    }

                    $res = xtc_db_query(
                            "SELECT count(*) AS total
               FROM " . TABLE_PRODUCTS . " p
               INNER JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c
               ON p.products_id = p2c.products_id
               WHERE p2c.categories_id = $cat_id
               $active
               AND (
                   p.products_date_expire > NOW() OR
                                    p.products_date_expire IS NULL OR
                                    p.products_date_expire = '0000-00-00 00:00:00'
                            )"
                    );

                    $res = xtc_db_fetch_array($res, true);
                    $count += $res['total'];

                    $res = xtc_db_query("SELECT categories_id FROM " . TABLE_CATEGORIES . " WHERE parent_id = $cat_id");

                    if (xtc_db_num_rows($res, true)) {
                            while ($row = xtc_db_fetch_array($res, true)) {
                                    $count += $this->countProducts($row['categories_id'], $include_inactive);
                            }
                    }

                    return $count;
            }
    }
Und in der webs / source / boxes / categories_dropdown.php erfolgt dann der entsprechende Klassenaufruf (hier "ExtLink")

Code: Alles auswählen

 $ct->addLink('Home', xtc_href_link('index.php'), 249, 0, 'ExtLink'); 
Und dann noch die css Formatierung. Z.B. über

Code: Alles auswählen

a.ExtLink {
  color:#FF0000 !important;
}
Eigentlich müsste es jetzt doch gehen. Doch der entsprechende Eintrag bleibt unformatiert. :(
Kann mir jemand kurz die categories.php durchsehen und mir sagen, ob ich da irgendwo noch was übersehen habe?

Herzlichen Dank im Voraus
Xantiva
Beiträge: 948
Registriert: Mo 10. Mai 2010, 16:26
Shop Version: 1.0.10 [dev]
Kontaktdaten:

Re: Per CSS Link in PHP ansprechen

Beitrag von Xantiva »

Hallo Kopernikus,

poste doch mal bitte wenigsten das so erzeugte Listenelement. Oder besser eine URL um sich das anzusehen. So ist das nicht zu beantworten.

Und zu den restlichen Fragen hoffe ich, dass es bald mal eine Stellungnahme geben wird. :|

Ciao,
Mike
Mein Shop: http://www.basteln-selbermachen.de
Kopernikus
Beiträge: 390
Registriert: Fr 19. Okt 2012, 12:15

Re: Per CSS Link in PHP ansprechen

Beitrag von Kopernikus »

Hallo Mike

Besten Dank für Deine Antwort. Mit der geänderten categories.php und folgendem Eintrag im html template funktioniert das ganze nun wie gewünscht.

Code: Alles auswählen

<li><div class="navcontainer"><a href="{$LEVEL3CAT.link}" title="{$LEVEL3CAT.title}" class="{$LEVEL3CAT.class}">{$LEVEL3CAT.title}</a></div></li>
Gefehlt hat: class="{$LEVEL3CAT.class} :)

Nun erhalte ich jedoch ab und zu nach dem Login in den Admin folgende Fehlermeldung ausgespuckt:

Code: Alles auswählen

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/httpd/vhosts/mein-shop.com/httpdocs/webs/templates/webs/source/class/categories.php:1) in /home/httpd/vhosts/mein-shop.com/httpdocs/webs/includes/functions/sessions.php on line 119

Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/mein-shop.com/httpdocs/webs/templates/webs/source/class/categories.php:1) in /home/httpd/vhosts/mein-shop.com/httpdocs/webs/inc/xtc_redirect.inc.php on line 43
Gehe ich im Browser zurück und klicke dann nochmals auf Admin, klappt es eigenartiger Weise. Da in der Fehlermeldung auch meine geänderte categories.php eine Rolle spielt, gehe ich mal davon aus, dass dieser Fehler durch meine Änderung verursacht wird. Hast Du zufälligerweise eine Ahnung wo ich da suchen müsste?
Xantiva
Beiträge: 948
Registriert: Mo 10. Mai 2010, 16:26
Shop Version: 1.0.10 [dev]
Kontaktdaten:

Re: Per CSS Link in PHP ansprechen

Beitrag von Xantiva »

Leerzeile / Leerzeichen vor dem <?php
Leerzeile / Leerzeichen nach dem letzten ?> (weswegen wir die immer weglassen, sofern möglich)
Datei als UTF-8 mit BOM gespeichert?
Mein Shop: http://www.basteln-selbermachen.de
Kopernikus
Beiträge: 390
Registriert: Fr 19. Okt 2012, 12:15

Re: Per CSS Link in PHP ansprechen

Beitrag von Kopernikus »

Leerzeile / Leerzeichen vor dem <?php
Perfekt, das war's genau :D

Herzlichen Dank!
Antworten