Tikko šis murgs
buttons.php
$info_button_article = '<a class="button1 icon" href="/article/' . $r_id . '/info"><img src="/internal/img/icons/info.png" alt="Papildu info" title="Papildu info"/></a>';
$plus_button_article = '<a class="button1 icon" href="/article/' . $r_id . '/plus"><img src="/internal/img/icons/plus.png" alt="Man patīk!" title="Man patīk. :)"/></a>';
$minus_button_article = '<a class="button1 icon" href="/article/' . $r_id . '/minus"><img src="/internal/img/icons/minus.png" alt="Man nepatīk!" title="Man nepatīk. :("/></a>';
$edit_button_article = '<a class="button1 icon" href="/article/' . $r_id . '/edit"><img src="/internal/img/icons/edit.png" alt="Labot" title="Labot ierakstu"/></a>';
$delete_button_article = '<a class="button1 icon" href="/article/' . $r_id . '/delete"><img src="/internal/img/icons/delete.png" alt="Dzēst" title="Dzēst ierakstu"/></a>';
$lock_button_article = '<a class="button1 icon" href="/article/' . $r_id . '/lock"><img src="/internal/img/icons/lock.png" alt="Slēgt komentārus" title="Slēgt komentārus"/></a>';
$unlock_button_article = '<a class="button1 icon" href="/article/' . $r_id . '/unlock"><img src="/internal/img/icons/unlock.png" alt="Atslēgt komentārus" title="Atslēgt komentārus"/></a>';
article.php
include("internal/buttons.php");
$info_button = $info_button_article;
if ($auth->id) {
$plus_button = $plus_button_article;
$minus_button = $minus_button_article;
}
if (in_array($auth->class, $mod)) {
$edit_button = $edit_button_article;
$delete_button = $delete_button_article;
$lock_button = $lock_button_article;
$unlock_button = $unlock_button_article;
}
[..]
echo '<div class="tools">' . $plus_button . $minus_button . $info_button . $edit_button . $delete_button . $lock_button . $unlock_button . '</div>';
Kļuva par šo
functions.php
function article_buttons($id, $author_id, $state, $current_class) {
$buttons = array();
if ($auth->id == $author_id or $current_class == '1' or $current_class == '2') {
if ($state == 'locked') {
//raksta atslēgšanas poga
$buttons['6'] = '<a class="button1 icon" href="/article/' . $id . '/unlock"><img src="/internal/img/icons/unlock.png" alt="Atslēgt komentārus" title="Atslēgt komentārus"/></a>';
}
else {
//raksta slēgšanas poga
$buttons['6'] = '<a class="button1 icon" href="/article/' . $id . '/lock"><img src="/internal/img/icons/lock.png" alt="Slēgt komentārus" title="Slēgt komentārus"/></a>';
}
//raksta labošanas poga
$buttons['4'] = '<a class="button1 icon" href="/article/' . $id . '/edit"><img src="/internal/img/icons/edit.png" alt="Labot" title="Labot ierakstu"/></a>';
if ($current_class == '1' or $current_class == '2') {
//raksta dzēšanas poga
$buttons['5'] = '<a class="button1 icon" href="/article/' . $id . '/delete"><img src="/internal/img/icons/delete.png" alt="Dzēst" title="Dzēst ierakstu"/></a>';
}
}
//plusiņa poga
$buttons['1'] = '<a class="button1 icon" href="/article/' . $id . '/plus"><img src="/internal/img/icons/plus.png" alt="Man patīk!" title="Man patīk. :)"/></a>';
//mīnusiņa poga
$buttons['2'] = '<a class="button1 icon" href="/article/' . $id . '/minus"><img src="/internal/img/icons/minus.png" alt="Man nepatīk!" title="Man nepatīk. :("/></a>';
//raksta info poga
$buttons['3'] = '<a class="button1 icon" href="/article/' . $id . '/info"><img src="/internal/img/icons/info.png" alt="Papildu info" title="Papildu info"/></a>';
$a = 1;
while ($a < 7) {
$button_bar = $button_bar . $buttons[$a];
$a = $a + 1;
}
return '<div class="tools">' . $button_bar . '</div>';
}
article.php
echo article_buttons($id, $query->author_id, 'unlocked', $auth->class);
[/code]
:)
S J miniblogs
- 0
S J 27.03.2013. 14:42
- 0
While ciklu tu mierīgi vari izmest ārā (un pat ja izmanto, tad tur labāk iederētos foreach), un vienkārši rakstīt:
return '<div class="tools">' . implode('', $buttons) . '</div>';
Bet šā vai tā izskatās pēc baigā koda blāķa, un tādas lietas vajadzētu rakstīt kaut kādā skatā/templeitā, nevis php funkcijā.$a = $a + 1; ir tas pats, kas $a++; (tas tā, zināšanai).
Ielogojies vai izveido profilu, lai komentētu!