phpBB versie:3.1.5
Wat is het probleem?[/list]
Ik ben bezig met een extensie waar je nieuws berichten mee kan maken. Daarbij wil ik ook gebruik maken van rubriek afbeeldingen.
Alles zit in elkaar alleen zodra ik een afbeelding wil kiezen kan dat niet. Select optie blijft leeg.
Als ik een bericht maak zonder afbeelding kan ik het bericht aanpassen maar dan kan ik wel kiezen uit afbeeldingen. Dit is ook als ik nog een bericht wil toevoegen.
Mijn vraag is waarom het in het begin niks laat zien maar zodra ik een bericht heb gemaakt weer wel.
Wat mis ik of wat doe ik verkeerd?
Webadres + login acp via pb
Code: Selecteer alles
<?php
/**
*
* @package news Pages
* @copyright (c) 2015 ForumHulp.com
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace forumhulp\news\acp;
class news_module
{
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\log\log */
protected $log;
/** @var \phpbb\request\request */
protected $request;
/** @var \phpbb\template\template */
protected $template;
/** @var ContainerInterface */
protected $phpbb_container;
/** @var string */
protected $phpbb_root_path;
/** @var string */
protected $php_ext;
/** @var string */
public $u_action;
public function main($id, $mode)
{
global $config, $db, $request, $template, $user, $phpbb_root_path, $phpEx, $phpbb_container, $phpbb_extension_manager;
$this->config = $config;
$this->db = $db;
$this->log = $phpbb_container->get('log');
$this->request = $request;
$this->template = $template;
$this->user = $user;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
$table_news = $phpbb_container->getParameter('forumhulp.news.tables.news');
// Load a template from adm/style for our ACP page
$this->tpl_name = 'news';
$id = $this->request->variable('id', 0);
$submit = ($this->request->is_set_post('submit')) ? true : false;
$action = $this->request->variable('action', '');
switch ($action)
{
case 'details':
$user->add_lang(array('install', 'acp/extensions', 'migrator'));
$ext_name = 'forumhulp/news';
$md_manager = new \phpbb\extension\metadata_manager($ext_name, $config, $phpbb_extension_manager, $template, $user, $phpbb_root_path);
try
{
$this->metadata = $md_manager->get_metadata('all');
}
catch(\phpbb\extension\exception $e)
{
trigger_error($e, E_USER_WARNING);
}
$md_manager->output_template_data();
try
{
$updates_available = $this->version_check($md_manager, $request->variable('versioncheck_force', false));
$template->assign_vars(array(
'S_UP_TO_DATE' => empty($updates_available),
'S_VERSIONCHECK' => true,
'UP_TO_DATE_MSG' => $user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name')),
));
foreach ($updates_available as $branch => $version_data)
{
$template->assign_block_vars('updates_available', $version_data);
}
}
catch (\RuntimeException $e)
{
$template->assign_vars(array(
'S_VERSIONCHECK_STATUS' => $e->getCode(),
'VERSIONCHECK_FAIL_REASON' => ($e->getMessage() !== $user->lang('VERSIONCHECK_FAIL')) ? $e->getMessage() : '',
));
}
if ($request->is_ajax())
{
$template->assign_vars(array(
'IS_AJAX' => true,
));
} else
{
$template->assign_vars(array(
'U_BACK' => $this->u_action,
));
}
$this->tpl_name = 'acp_ext_details';
break;
default:
if ($id && $action == 'dell')
{
if (confirm_box(true))
{
$sql = 'DELETE FROM ' . $table_news . ' WHERE id = ' . $id;
$this->db->sql_query($sql);
$id = 0;
}
else
{
confirm_box(false, $this->user->lang['CONFIRM_OPERATION']);
}
}
if ($id && $submit)
{
$error = array();
$sql_ary = array(
'news_image' => $this->request->variable('news_image', ''),
'title' => utf8_normalize_nfc($this->request->variable('title', ''), true),
'route' => $this->Slug(utf8_normalize_nfc($this->request->variable('title', ''), true)),
'bodytext' => utf8_normalize_nfc($this->request->variable('bodytext', ''), true)
);
if ($news_image != '' && !preg_match('#(\.gif|\.png|\.jpg|\.jpeg)$#i', $news_image))
{
$news_image = '';
}
if (strlen(trim($sql_ary['title'])) < 3)
{
$error[] = 'Titel te kort';
}
if (strlen(trim($sql_ary['bodytext'])) == 0)
{
$error[] = 'Geen tekst ingevuld';
}
if (!sizeof($error))
{
if ($id == -1)
{
$sql_ary += array(
'news_image' => htmlspecialchars_decode($news_image),
'hits' => 0,
'user_id' => $this->user->data['user_id'],
'timestamp' => time()
);
$sql = 'INSERT INTO ' . $table_news . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
} else
{
$sql = 'UPDATE ' . $table_news . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE id = ' . $id;
}
$this->db->sql_query($sql);
$this->template->assign_vars(array(
'WARNING' => true,
'URL' => $this->u_action
));
} else
{
$this->template->assign_vars(array(
'ERRORS' => (sizeof($error)) ? implode('<br />', $error) : '',
'URL' => $this->u_action
));
}
} else if ($id && !$submit)
{
$data = $news = $existing_imgs = array();
$sql = 'SELECT id, news_image, title, bodytext, timestamp FROM ' . $table_news . ' WHERE id = ' . $id;
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$existing_imgs[] = $row['news_image'];
if ($id == $row['id'])
{
$news = $row;
}
$imglist = filelist($phpbb_root_path . $config['news_path'], '');
$edit_img = $filename_list = '';
foreach ($imglist as $path => $img_ary)
{
sort($img_ary);
foreach ($img_ary as $img)
{
$img = $path . $img;
if ($news && $img == $news['news_image'])
{
$selected = ' selected="selected"';
$edit_img = $img;
}
else
{
$selected = '';
}
if (strlen($img) > 255)
{
continue;
}
$filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . $img . ((in_array($img, $existing_imgs)) ? ' ' . $user->lang['NEWS_IMAGE_IN_USE'] : '') . '</option>';
}
}
$filename_list = '<option value=""' . (($edit_img == '') ? ' selected="selected"' : '') . '>----------</option>' . $filename_list;
unset($existing_imgs, $imglist);
// Edit&Add
$this->template->assign_vars(array(
'ID' => ($id == -1) ? -1 : $row['id'],
'NEWS_IMAGE' => $phpbb_root_path . $config['news_path'] . '/' . $row['news_image'],
'NEWS_PATH' => $phpbb_root_path . $config['news_path'],
'TITLE' => $row['title'],
'BODYTXT' => $row['bodytext'],
'DATUM' => ($id == -1) ? $this->user->format_date(time()) : $this->user->format_date($row['timestamp']),
'S_EDIT' => true,
'S_FILENAME_LIST' => $filename_list,
));
} else
{
$sql = 'SELECT n.id, n.news_image, n.title, u.username, n.hits, n.timestamp FROM ' . $table_news . ' n
LEFT JOIN ' . USERS_TABLE . ' u ON u.user_id = n.user_id
ORDER BY timestamp DESC';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$this->template->assign_block_vars('articles', array(
'ID' => $row['id'],
'NEWS_IMAGE' => $phpbb_root_path . $config['news_path'] . '/' . $row['news_image'],
'TITLE' => $row['title'],
'AUTHOR' => $row['username'],
'HITS' => $row['hits'],
'DATUM' => $this->user->format_date($row['timestamp']),
'U_EDIT' => $this->u_action . '&action-edit&id=' . $row['id'],
'U_DELETE' => $this->u_action . '&action=dell&id=' . $row['id'],
'S_NEWS_IMAGE' => ($row['news_image']) ? true : false,
));
}
$this->template->assign_vars(array('U_ADD' => $this->u_action . '&id=-1'));
}
break;
}
$this->template->assign_vars(array('U_ACTION' => $this->u_action));
// Set the page title for our ACP page
$this->page_title = 'ACP_NEWS_SETTINGS';
}
protected function Slug($string)
{
return strtolower(trim(preg_replace('~[^0-9a-z]+~i', '-', html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', htmlentities($string, ENT_QUOTES, 'UTF-8')), ENT_QUOTES, 'UTF-8')), '-'));
}
/**
* Check the version and return the available updates.
*
* @param \phpbb\extension\metadata_manager $md_manager The metadata manager for the version to check.
* @param bool $force_update Ignores cached data. Defaults to false.
* @param bool $force_cache Force the use of the cache. Override $force_update.
* @return string
* @throws RuntimeException
*/
protected function version_check(\phpbb\extension\metadata_manager $md_manager, $force_update = false, $force_cache = false)
{
global $cache, $config, $user;
$meta = $md_manager->get_metadata('all');
if (!isset($meta['extra']['version-check']))
{
throw new \RuntimeException($this->user->lang('NO_VERSIONCHECK'), 1);
}
$version_check = $meta['extra']['version-check'];
if (version_compare($config['version'], '3.1.1', '>'))
{
$version_helper = new \phpbb\version_helper($cache, $config, new \phpbb\file_downloader(), $user);
}
else
{
$version_helper = new \phpbb\version_helper($cache, $config, $user);
}
$version_helper->set_current_version($meta['version']);
$version_helper->set_file_location($version_check['host'], $version_check['directory'], $version_check['filename']);
$version_helper->force_stability($config['extension_force_unstable'] ? 'unstable' : null);
return $updates = $version_helper->get_suggested_updates($force_update, $force_cache);
}
}
Code: Selecteer alles
<!-- IF S_ALLOW_CDN -->
<!-- INCLUDECSS //maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css -->
<!-- ELSE -->
<!-- INCLUDECSS ./../../ext/forumhulp/news/vendor/font-awesome/css/font-awesome.min.css -->
<!-- ENDIF -->
<!-- INCLUDECSS css/news.css -->
<!-- INCLUDECSS css/jquery.simpledialog.css -->
<!-- INCLUDE overall_header.html -->
<a id="maincontent"></a>
<h1>{L_ACP_NEWS_SETTINGS} <a href="{U_ACTION}&action=details" class="simpledialog" data-ajax="true"><i class="fa fa-info-circle"></i></a></h1>
<p>{L_ACP_NEWS_SETTINGS_EXPLAIN}</p>
<!-- IF ERRORS -->
<div class="errorbox">
<h3>{L_WARNING}</h3>
<p>{ERRORS}</p>
<meta http-equiv="refresh" content="3;URL={URL}" />
</div>
<!-- ELSE -->
<!-- IF WARNING -->
<div class="successbox">
<h3>{L_INFORMATION}</h3>
<p>Artikel opgeslagen</p>
<meta http-equiv="refresh" content="3;URL={URL}" />
</div>
<!-- ENDIF -->
<!-- IF .articles and not WARNING -->
<table class="table1 zebra-table">
<thead>
<tr>
<th>Rubriek Afbeelding</th>
<th>Title</th>
<th>Author</th>
<th>Hits</th>
<th>Datum</th>
<th colspan="2">{L_OPTIONS}</th>
</tr>
</thead>
<tbody>
<!-- BEGIN articles -->
<tr>
<td style="width: 40%;"><!-- IF articles.S_NEWS_IMAGE --><img src="{articles.NEWS_IMAGE}" alt="" title="" /><!-- ELSE --> - <!-- ENDIF --></td>
<td style="width: 20%;">{articles.TITLE}</td>
<td style="width: 15%; white-space: nowrap;" align="center"> {articles.AUTHOR} </td>
<td style="width: 15%; white-space: nowrap;" align="center"> {articles.HITS} </td>
<td style="width: 15%; white-space: nowrap;" align="center"> {articles.DATUM} </td>
<td style="text-align: center;"> <a href="{articles.U_EDIT}">{L_EDIT}</a> </td>
<td style="text-align: center;"> <a href="{articles.U_DELETE}">{L_DELETE}</a> </td>
</tr>
<!-- END articles -->
<tr>
<td style="width: 50%;"></td>
<td style="width: 15%; white-space: nowrap;" align="center"></td>
<td style="width: 15%; white-space: nowrap;" align="center"></td>
<td style="width: 15%; white-space: nowrap;" align="center"></td>
<td style="text-align: center;"> <a href="{U_ADD}">{L_ADD}</a> </td>
<td style="text-align: center;"></td>
</tr>
</tbody>
</table>
<!-- ELSE IF not .articles and not WARNING -->
<script type="text/javascript">
// <![CDATA[
var form_name = 'news_module';
function update_image(newimage)
{
document.getElementById('image').src = (newimage) ? "{NEWS_PATH}/" + encodeURI(newimage) : "./images/spacer.gif";
}
// ]]>
</script>
<form id="acp_portal" method="post" action="{U_ACTION}">
<fieldset>
<dl class="responsive-columns">
<dt><label for="news_image">{L_NEWS_IMAGE}:</label></dt>
<dd style="margin-{S_CONTENT_FLOW_BEGIN}:">
<select name="news_image" id="news_image" onchange="update_image(this.options[selectedIndex].value);">{S_FILENAME_LIST}</select>
</dd>
<dd style="margin-{S_CONTENT_FLOW_BEGIN}: -5px;border-color:#fff;">
<img src="{NEWS_IMAGE}" id="image" alt="" />
</dd>
</dl>
<dl class="responsive-columns">
<dd style="margin-{S_CONTENT_FLOW_BEGIN}: -5px;border-color:#fff;">
<input type="text" name="title" style="width: 50%;" value="{TITLE}" title="Title" />
<span style="float:right;">{DATUM}</span>
</dd>
</dl>
<!-- INCLUDEJS @forumhulp_news/tiny_mce/tinymce.min.js -->
<dl class="responsive-columns">
<dd style="margin-{S_CONTENT_FLOW_BEGIN}: -5px;border-color:#fff;">
<textarea class="mceEditor" name="bodytext" rows="25" cols="60" style="width: 95%;">{BODYTXT}</textarea>
</dd>
</dl>
<!-- INCLUDEJS @forumhulp_news/tiny_mce/scripts.js -->
</fieldset>
<fieldset class="submit-buttons">
<input type="hidden" name="id" value="<!-- IF not S_EDIT -->-1<!-- ELSE -->{ID}<!-- ENDIF -->" />
<input class="button1" type="submit" id="submit" name="submit" value="{L_SUBMIT}" />
{S_FORM_TOKEN}
</fieldset>
</form>
<!-- ENDIF -->
<!-- ENDIF -->
<!-- INCLUDEJS js/jquery.simpledialog.js -->
<!-- INCLUDEJS js/news.js -->
<!-- INCLUDE overall_footer.html -->