Datumsformat setzen

  • PHP

Es gibt 5 Antworten in diesem Thema. Der letzte Beitrag () ist von Orion.

    Datumsformat setzen

    Guten Tag Zusammen,
    Ich habe leider praktisch keine Ahnung von PHP. Okay einzelne Teile versteh ich aber das wird auch nur sehr wenig sein.
    Nun wollte ich euch fragen wie ich diese Zeile Code hier so ändere das er mir unser Format speichert statt in den Settings des Boards nach zu schauen.

    PHP-Quellcode

    1. $lastpostdate = my_date($mybb->settings['dateformat'], $row['lastpost']);
    2. $lastposttime = my_date($mybb->settings['timeformat'], $row['lastpost']);

    Kann mir das jemand schnell umschreiben?
    Bin nicht so der PHP Coder, bin ein Forum am Aufbauen und kann da gerade mal CSS Anpassungen machen, Bilder designen und Plugins übersetzen/konvertieren.
    mfg

    Orion
    Metal-Schweiz wurde nun offiziell veröffentlich nach all den Jahren :)

    Eventuell habe ich die Frage falsch gestellt. In diesem Fall Post ich mal den ganzen Code in einem Spoiler:
    Spoiler anzeigen

    PHP-Quellcode

    1. <?php
    2. //Latest Posts Board Index Mod by Borbole
    3. //Trying to access directly the file, are we :D
    4. if(!defined("IN_MYBB"))
    5. {
    6. die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
    7. }
    8. //Hooking into index_start with our function
    9. $plugins->add_hook("index_start", "recentposts_box");
    10. //Show some info about our mod
    11. function recentpostsindex_info()
    12. {
    13. return array(
    14. "name" => "Recent Posts Forum Index",
    15. "description" => "It shows the recent posts on your board index.",
    16. "website" => "http://www.forumservices.eu/mybb",
    17. "version" => "1.0",
    18. "author" => "borbole",
    19. "authorsite" => "http://www.forumservices.eu/mybb",
    20. "compatibility" => "16*,18*",
    21. 'guid' => 'f8cd8d11a353a4f58a29fbc0d72ec9c3'
    22. );
    23. }
    24. //Activate it
    25. function recentpostsindex_activate()
    26. {
    27. global $db;
    28. //Insert the mod settings in the forumhome settinggroup. It looks beter there :D
    29. $query = $db->simple_select("settinggroups", "gid", "name='forumhome'");
    30. $gid = $db->fetch_field($query, "gid");
    31. $setting = array(
    32. 'name' => 'enable',
    33. 'title' => 'Recent Posts Forum Index',
    34. 'description' => 'Would you like to display the Recent Posts Box at your board index?',
    35. 'optionscode' => 'yesno',
    36. 'value' => '1',
    37. 'disporder' => '90',
    38. 'gid' => intval($gid)
    39. );
    40. $db->insert_query('settings',$setting);
    41. $setting = array(
    42. "name" => "limit_posts_nr",
    43. "title" => "Recent Posts!",
    44. "description" => "Enter here the number of the recent posts that you would like to show at the forum index. By default it set to show 5 posts.",
    45. "optionscode" => "text",
    46. "value" => "5",
    47. "disporder" => "91",
    48. "gid" => intval($gid),
    49. );
    50. $db->insert_query("settings", $setting);
    51. rebuild_settings();
    52. //Add our custom var in the index template to display the latest posts box
    53. require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    54. find_replace_templatesets("index", "#".preg_quote('{$header}') . "#i", '{$header}' . "\n" . '{$recentposts}');
    55. }
    56. //Don't want to use it anymore? Let 's deactivate it then and drop the settings and the custom var as well
    57. function recentpostsindex_deactivate()
    58. {
    59. global $db;
    60. $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='enable'");
    61. $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='limit_posts_nr'");
    62. rebuild_settings();
    63. require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    64. find_replace_templatesets("index", "#".preg_quote('{$header}' . "\n" . '{$recentposts}') . "#i", '{$header}',0);
    65. }
    66. //Insert our function
    67. function recentposts_box()
    68. {
    69. global $db, $mybb, $lang, $theme, $recentposts;
    70. //Enable it
    71. if($mybb->settings['enable'] == 1 )
    72. {
    73. //Load the language files and set up the table for the recent posts box
    74. $lang->load('recentpostsindex');
    75. $recentposts .= '
    76. <table border="0" cellspacing="' . $theme['borderwidth'] . '" cellpadding="' . $theme['tablespace'] . '" class="tborder">
    77. <tbody>
    78. <tr>
    79. <td class="thead" colspan="4" align="center">
    80. <strong>' . $lang->recentpostname . '</strong>
    81. </td>
    82. </tr>
    83. <tr>
    84. <td class="tcat" width="45%"><span class="smalltext"><strong>' . $lang->recentpoststitle . '</strong></span></td>
    85. <td class="tcat" align="center" width="15%"><span class="smalltext"><strong>' . $lang->poster . '</strong></span></td>
    86. <td class="tcat" align="center" width="15%"><span class="smalltext"><strong>' . $lang->lastposttime . '</strong></span></td>
    87. <td class="tcat" align="center" width="20%"><span class="smalltext"><strong>' . $lang->postforum . '</strong></span></td>
    88. </tr>
    89. ';
    90. //Preserve the forum viewing permissions intact
    91. $fids = "";
    92. $unviewablefids = get_unviewable_forums();
    93. if($unviewablefids)
    94. {
    95. $fids = "WHERE t.fid NOT IN ({$unviewablefids})";
    96. }
    97. //Exclude inactive forums from showing up
    98. $inactivefids = get_inactive_forums();
    99. if ($inactivefids)
    100. {
    101. $fids .= " WHERE t.fid NOT IN ($inactivefids)";
    102. }
    103. //Run the query to get the most recent posts along with their posters, time and forums
    104. $query = $db->query("
    105. SELECT t.tid, t.fid, t.subject, t.lastpost,
    106. t.lastposter, t.lastposteruid, f.name,
    107. u.usergroup, u.displaygroup
    108. FROM ".TABLE_PREFIX."threads AS t
    109. INNER JOIN ".TABLE_PREFIX."forums as f
    110. ON (f.fid = t.fid)
    111. LEFT JOIN " . TABLE_PREFIX . "users AS u
    112. ON (t.lastposteruid = u.uid)
    113. {$fids}
    114. AND t.visible = '1'
    115. GROUP BY t.tid
    116. ORDER BY t.lastpost DESC
    117. LIMIT " . $mybb->settings['limit_posts_nr']);
    118. while($row = $db->fetch_array($query))
    119. {
    120. $recentposts .= '
    121. <tr>';
    122. //Trim the thread titles if they are over 49 characters
    123. $subject = htmlspecialchars_uni($row['subject']);
    124. if (strlen($subject) > 49)
    125. {
    126. $subject = substr($subject, 0, 49) . "...";
    127. }
    128. //Trim the usernames if they are over 9 characters
    129. if (strlen($row['lastposter']) > 9)
    130. {
    131. $row['lastposter'] = substr($row['lastposter'], 0, 9) . "...";
    132. }
    133. //Trim the forum names if they are over 19 characters so everything will be in porpotion
    134. if (strlen($row['name']) > 19)
    135. {
    136. $row['name'] = substr($row['name'], 0, 19) . "...";
    137. }
    138. //Get the date and time of the most recent posts
    139. $lastpostdate = my_date($mybb->settings['dateformat'], $row['lastpost']);
    140. $lastposttime = my_date($mybb->settings['timeformat'], $row['lastpost']);
    141. //Get the usernames and make them pretty too with the group styling
    142. $username = build_profile_link(format_name($row['lastposter'],$row['usergroup'],$row['displaygroup']), $row['lastposteruid']);
    143. //Display them all trimmed up and pretty :D
    144. $recentposts .= '
    145. <td class="trow1" width="45%">
    146. <a href="showthread.php?tid=' . $row['tid'] . '&amp;action=lastpost">' . $subject .'</a>
    147. </td>
    148. <td class="trow1" align="center" width="15%">
    149. ' . $username . '
    150. </td>
    151. <td class="trow1" align="center" width="15%">
    152. ' .$lastpostdate . ' ' . $lastposttime . '
    153. </td>
    154. <td class="trow1" align="center" width="20%">
    155. <a href="forumdisplay.php?&amp;fid=' . $row['fid'] . '">' . $row['name'] . '</a>
    156. </td>
    157. </tr>';
    158. }
    159. //End of mod. I hope you enjoy it as much as I did coding it :)
    160. $recentposts .= "</tbody></table><br /><br />";
    161. }
    162. }
    163. ?>
    Metal-Schweiz wurde nun offiziell veröffentlich nach all den Jahren :)

    Oh, Sorry hat sich erledigt. Lag an meinen eigenen Profilsettings das mir das Datum falsch angezeigt wurde. Danke aber für wenigstens jemanden der sich meldet ^^
    Metal-Schweiz wurde nun offiziell veröffentlich nach all den Jahren :)

    Hi,

    also um der Sache auf den Grund zu gehen müsstest du dir die Funktion "my_date(arg2, arg2)" anschauen. Außerdem noch in der Klasse "mybb" die public Variable $settings (offensichtlich ein Array). Eventuell hättest du es auch so machen können dass du die Ausgabe von my_date() vorher durch date() jagst um das Format zu beeinflussen:

    PHP-Quellcode

    1. $lastpostdate = date("d.m.Y H:i", my_date($mybb->settings['dateformat'], $row['lastpost']));


    Immerhin gut dass du dich bemühst. Trotzdem leg ich dir Nahe dich erst in PHP einzuarbeiten, ein Gespür für die Sprache zu entwickeln. Geht bei PHP relativ schnell.

    Link :thumbup:
    Hello World
    Ja, ich arbeite mich bei Codeacademy durch. Da noch grosse Änderungen an der Website bevorstehen und ich die nicht alle dem Programmierer überlassen will muss ich mich da definitiv einarbeiten.
    Metal-Schweiz wurde nun offiziell veröffentlich nach all den Jahren :)