Seite 1 von 1
(erledigt) CSS und class ich bin überfordert
Verfasst: Do 20.Dez, 2007 15:08
von Overhead
Hallo zusammen,
Wenn ich das richtig verstehe definieren die class bestimmte Eigenschaften
aus einem php heraus..
wenn ich z.B.
Code: Alles auswählen
// Link relationships
define('INTERNAL_LINK_REL', '');
define('EXTERNAL_LINK_REL', 'nofollow');
// Link targets
define('INTERNAL_LINK_TARGET', '');
define('EXTERNAL_LINK_TARGET', '_blank');
// Link classes
define('INTERNAL_LINK_CLASS', 'postlink-local');
define('EXTERNAL_LINK_CLASS', '');
eine Definition für interne und exteren Links innerhalb meiner php Umgebung mache dann funktioniert der Code wie oben angezeigt.
Wenn ich jetzt zusätzlich via css den class eine Farbänderung verpassen möchte, dann müsste ich doch die Farbe im css bloß jeweils vordefinieren.
also z.B.
Code: Alles auswählen
a:link { color: #CD2626; text-decoration: none; }
a.postlink-local:link {color: #898989; text-decoration:none; }
usw. das funktioniert aber so nicht - ich komme einfach nicht dahinter wie ich die Links dazu bekomme via css die jeweilgen Farbvorgaben auch zu befolgen - oder habe ich schon vom Ansatz her ein Brett vor dem Kopf weil ich das ganz anders machen müsste?
cu Overhead
Verfasst: Do 20.Dez, 2007 15:45
von oxpus
Wie packst Du denn die Konstanten in die Links?
Nach irgendwas müssen die doch schon unterschieden werden.
Die Farbdefinitionen mittels CSS hingegen hängt davon ab, wie Du die Links definierst.
So, wie Du die CSS-Anweisungen aufgebaut hast, funktionieren die nur bei folgenden Links:
Code: Alles auswählen
<a href="link">Text</a>
<a href="link" class="postlink-local">Text</a>
Allerdings sollte man keine Klassen mit einem Minus, sondern besser nur mit Unterstrich definieren.
So wird dann aus "postlink-local" eben "postlink_local".
Das kann dann auch ein Grund sein, warum diese Links nicht formatiert werden.
BTW:
Wenn Du mit Firefox arbeitest, kannst Du in der Fehler-Konsole nachschauen, ob es CSS-Fehler hier gibt. Das hilft meist schon sehr bei der Fehlersuche...
Verfasst: Do 20.Dez, 2007 16:08
von Overhead
@ oxpus
das war nur ein Ausschnitt...
Code: Alles auswählen
a:link { color: #CD2626; text-decoration: none; }
a:visited { color: #CD2626; text-decoration: none; }
a:hover { color: #CD2626; text-decoration: underline; }
a:active { color: #CD2626; text-decoration: none; }
/*postlink-local */
a.postlink-local:link {color: #898989; text-decoration:none; }
a.postlink-local:visited {color: #898989; text-decoration:none; }
a.postlink-local:hover {color: #d2d2d2; text-decoration:underline; }
a.postlink-local:active {color: #d3d3d3; text-decoration:none; }
und so sehen zumindest bestimmte links dann aus - es geht hier um url Links die intern und extern unterschieden werden wollen - durch die differente Farbgebung wir zumindest eine Auffälligkeit gegenüber den Mods und Admins erzeugt - leider funktioniert das eben überhaupt nicht!
Die class werden innerhalb eines php Files definiert und via fuctions zum laufen gebracht - wie gesagt der php Teil funktioniert - was ich nicht hinbekomme ich das einfärben via css.
cu Overhead
Verfasst: Do 20.Dez, 2007 16:46
von oxpus
Die Definitionen kenne ich, aber ich fragte, wie die Links aussehen, die im PHP-Script definiert werden?
Verfasst: Do 20.Dez, 2007 17:26
von Overhead
@ oxpus
so...
Code: Alles auswählen
<?php
* Make sure this file has not already been included.
*/
if (!defined('INCLUDES_PRIME_LINKS'))
{
define('INCLUDES_PRIME_LINKS', true);
// Options
define('ALL_SUBDOMAINS_INTERNAL', true);
define('ANONYMIZE_EXTERNAL_LINKS', 'http://anonym.to?');
// Link relationships
define('INTERNAL_LINK_REL', '');
define('EXTERNAL_LINK_REL', 'nofollow');
// Link targets
define('INTERNAL_LINK_TARGET', '');
define('EXTERNAL_LINK_TARGET', '_blank');
// Link classes
define('INTERNAL_LINK_CLASS', 'postlink-local');
define('EXTERNAL_LINK_CLASS', '');
/**
* Decodes all HTML entities (html_entity_decode() doesn't decode numberical entities).
*/
function decode_entities($text)
{
$text = html_entity_decode($text, ENT_QUOTES, 'ISO-8859-1'); //UTF-8 does not work!
$text = preg_replace('/&#(\d+);/me', 'chr($1)', $text); //decimal notation
$text = preg_replace('/&#x([a-f0-9]+);/mei', 'chr(0x$1)', $text); //hex notation
return($text);
}
/**
* Removes subdomains from a URL.
*/
function remove_subdomains($url)
{
$url = preg_replace('#^(http|https)://[^/]+?\.((?:[a-z0-9-]+\.[a-z]+)|localhost/)#i', '$1://$2', $url);
return($url);
}
/**
* Determines if a URL is local or external.
*/
function is_link_local($url, $board_url = false)
{
if ($board_url === false)
{
$board_url = generate_board_url(true);
$board_url = ALL_SUBDOMAINS_INTERNAL ? remove_subdomains($board_url) : $board_url;
}
$is_local = (strpos($url, $board_url) === 0);
if (!$is_local)
{
$protocol = substr($url, 0, strpos($url, ':'));
$is_local = !$protocol || ($protocol && !in_array($protocol, array('http', 'https', 'mailto', 'ftp', 'gopher')));
}
return($is_local);
}
/**
*/
function prime_links($message)
{
// A quick check before we start using regular expressions
if (strpos($message, '<a ') === false)
{
return($message);
}
$board_url = generate_board_url(true);
$board_url = ALL_SUBDOMAINS_INTERNAL ? remove_subdomains($board_url) : $board_url;
preg_match_all('/(<a[^>]+?>)/i', $message, $matches, PREG_SET_ORDER);
foreach ($matches as $links)
{
$is_local = false;
$link = $new_link = $links[0];
$href = preg_replace('/^.*href="([^"]*)".*$/i', '$1', $link);
if ($href == $link) //no link was found
{
continue;
}
$href = decode_entities($href);
$href = ALL_SUBDOMAINS_INTERNAL ? remove_subdomains($href) : $href;
$is_local = is_link_local($href, $board_url);
$new_class = $is_local ? INTERNAL_LINK_CLASS : EXTERNAL_LINK_CLASS;
$new_target = $is_local ? INTERNAL_LINK_TARGET : EXTERNAL_LINK_TARGET;
$new_rel = $is_local ? INTERNAL_LINK_REL : EXTERNAL_LINK_REL;
if ($new_class)
{
$class = preg_replace('/^.*class="([^"]*)".*$/i', '$1', $link);
$class = $class == $link ? '' : $class; // Was class found?
$old_class = $class == 'postlink' ? '' : $class;
$new_class = trim(implode(' ', array_unique(array_merge(explode(' ', $old_class), (array)$new_class)))); // This will append the new class instead of replacing the existing one.
$new_link = $class ? str_replace("class=\"$class\"", "class=\"$new_class\"", $new_link) : str_replace('>', " class=\"$new_class\">", $new_link);
}
if ($new_target)
{
$click = preg_replace('/^.*onclick="([^"]*)".*$/i', '$1', $link);
$click = $click == $link ? '' : $click; // Was onclick found?
$new_click = "this.target='$new_target';";
$new_link = $click ? str_replace("onclick=\"$click\"", "onclick=\"$new_click\"", $new_link) : str_replace('>', " onclick=\"$new_click\">", $new_link);
// The target attribute is not allowed in STRICT doctypes. If you want to use it anyway, just uncomment the following lines.
// $target = preg_replace('/^.*target="([^"]*)".*$/i', '$1', $link);
// $target = $target == $link ? '' : $target; // Was target found?
// $new_link = $target ? str_replace("target=\"$target\"", "target=\"$new_target\"", $new_link) : str_replace('>', " target=\"$new_target\">", $new_link);
}
if ($new_rel)
{
$rel = preg_replace('/^.*rel="([^"]*)".*$/i', '$1', $link);
$rel = $rel == $link ? '' : $rel; // Was rel found?
$new_rel = trim(implode(' ', array_unique(array_merge(explode(' ', $rel), (array)$new_rel)))); // This will append the new rel instead of replacing the existing one.
$new_link = $rel ? str_replace("rel=\"$rel\"", "rel=\"$new_rel\"", $new_link) : str_replace('>', " rel=\"$new_rel\">", $new_link);
}
if (!$is_local && ANONYMIZE_EXTERNAL_LINKS)
{
$new_link = str_replace('href="', 'href="' . ANONYMIZE_EXTERNAL_LINKS, $new_link);
}
$searches[] = $link;
$replacements[] = $new_link;
}
$message = str_replace($searches, $replacements, $message);
return($message);
}
}
?>
Verfasst: Do 20.Dez, 2007 20:11
von oxpus
Ah... ja...
Wird denn zumindest im Quelltext der Seite dann die korrekte CSS-Klasse angezeigt oder ist die nicht korrekt ersetzt worden?
Verfasst: Do 20.Dez, 2007 20:24
von Overhead
@ oxpus
ja schau her...
Code: Alles auswählen
<div class="content"><a href="http://anonym.to?http://www.google.de" class="postlink" onclick="this.target='_blank';" rel="nofollow">google</a></div>
cu Overhead
Verfasst: Do 20.Dez, 2007 23:11
von oxpus
Nun, die Klasse "postlink" hast Du aber nicht definiert

Verfasst: Fr 21.Dez, 2007 10:37
von Overhead
@ Oxpus
wird die nicht zum Standard wenn ich für die internen Links postlink-local definiere?
Dann sollte ich wohl das mal zusätzlich machen und dann wahrscheinlich in der colours.css die Bezeichnung ändern - oder doch lieber in der common - damit ich auf der sichern Seite bin?
cu Overhead
Verfasst: Fr 21.Dez, 2007 12:34
von oxpus

?
*knoten*
Du hast im Quelltext als Klasse "postlink" in dem Link stehen, nicht postlink-local.
Letzteres ist aber als CSS-Klasse definiert, daher werden die Links mit "postlink"
nicht formatiert!
Also entweder die richtige Klasse eintragen oder ganz weglassen.
Verfasst: Fr 21.Dez, 2007 16:20
von Overhead
Ich habe es gelöst - durch den zusätzlichen Eintrag postlink (Danke Oxpus!) und dadurch das ich die colours.css editiert habe dort nach den Links die jeweiligen Faben für die postlinks definieren und gut ist es
also im oberen code Zeile 20 auf
und in der colours.css hinzufügen
Code: Alles auswählen
/*postlink */
a.postlink:link {color: #CD2626; }
a.postlink:visited {color: #CD2626; }
a.postlink:hover {color: #CD2626; }
a.postlink:active {color: #CD2626; }
Jetzt wird jeder externe Link rot eingefärbt und über anonym.to weitergeleitet die internen behalten ihre Farbe.
cu Overhead