Skip to content

Commit

Permalink
update to v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Krytic committed Feb 26, 2016
1 parent 066b80d commit 11e8041
Show file tree
Hide file tree
Showing 18 changed files with 396 additions and 96 deletions.
7 changes: 0 additions & 7 deletions Upload/admin/modules/wiki/articles.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<?php

// wiki.php
// /inc/plugins/wiki.php
// /admin/modules/wiki/module_meta.php
// /admin/modules/wiki/home.php
// /admin/modules/wiki/articles.php
// /inc/languages/english/admin/wiki.lang.php

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
Expand Down
61 changes: 57 additions & 4 deletions Upload/admin/modules/wiki/categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,34 @@
'title' => $lang->wiki_categories,
'link' => 'index.php?module=wiki-categories',
'description' => $lang->wiki_categories_description
);
);

$sub_tabs['wiki_categories_add'] = array(
'title' => $lang->wiki_categories_add,
'link' => 'index.php?module=wiki-categories&action=add',
'description' => $lang->wiki_categories_add_description
);
);

$table = new Table;

if(!$mybb->input['action'])
{
$page->output_nav_tabs($sub_tabs, 'wiki_categories');

$table->construct_header($lang->wiki_category_name, array('width' => '50%', 'class' => 'align_center'));
$table->construct_header($lang->wiki_category_options, array('width' => '50%', 'class' => 'align_center'));
$table->construct_header($lang->wiki_category_name, array('width' => '70%', 'class' => 'align_center'));
$table->construct_header($lang->wiki_category_options, array('width' => '30%', 'class' => 'align_center', 'colspan' => 2));

$categories = $db->write_query("SELECT * FROM `" . TABLE_PREFIX . "wiki_categories`");

if($db->num_rows($categories) > 0)
{
while($category = $db->fetch_array($categories))
{
$options_construct_edit = "<a href=\"index.php?module=wiki-categories&amp;action=edit&amp;id={$category['cid']}&amp;my_post_key={$mybb->post_code}&amp;name={$category['title']}\">{$lang->wiki_cat_edit}</a>";
$options_construct = "<a href=\"index.php?module=wiki-categories&amp;action=delete&amp;id={$category['cid']}&amp;my_post_key={$mybb->post_code}&amp;name={$category['title']}\">{$lang->wiki_cat_delete}</a>";

$table->construct_cell($category['title'], array('class' => 'align_center'));
$table->construct_cell($options_construct_edit, array('class' => 'align_center'));
$table->construct_cell($options_construct, array('class' => 'align_center'));
$table->construct_row();
}
Expand Down Expand Up @@ -113,6 +115,57 @@
}
}
}
elseif($mybb->input['action'] == 'edit')
{
if(!isset($mybb->input['id'])) {
$mybb->request_method = "get";
flash_message($lang->wiki_no_id, 'error');
admin_redirect("index.php?module=wiki-categories");
}

$id = intval($mybb->input['id']);

if($mybb->request_method != 'post')
{
$query = $db->write_query(sprintf("SELECT * FROM `%swiki_categories` WHERE `cid`='" . $id . "'", TABLE_PREFIX));
$category = $db->fetch_array($query);

$form = new Form('', 'POST', '', 0, '', false, '');
$form_container = new FormContainer($lang->wiki_categories_edit);
$form_container->output_row($lang->wiki_cat_title, $lang->wiki_cat_title_desc, $form->generate_text_box('cat_title', $category['title'], array('id' => 'title')), 'title');
$form_container->end();
$buttons = array();
$buttons[] = $form->generate_submit_button($lang->wiki_commit);
$form->output_submit_wrapper($buttons);
$form->end();
}
else
{
if(!isset($mybb->input['my_post_key']) || $mybb->post_code != $mybb->input['my_post_key'])
{
$mybb->request_method = "get";
flash_message($lang->wiki_error_pc, 'error');
admin_redirect("index.php?module=wiki-categories");
}
else
{
$title = $db->escape_string($mybb->input['cat_title']);

$query = $db->write_query(sprintf("UPDATE `%swiki_categories` SET `title`='{$title}' WHERE `cid`='" . $id . "'", TABLE_PREFIX));
if(!$query)
{
flash_message($lang->wiki_error, 'error');
admin_redirect("index.php?module=wiki-categories");
}
else
{
log_admin_action($mybb->input['name']);
flash_message($lang->wiki_cat_edited_success, 'success');
admin_redirect("index.php?module=wiki-categories");
}
}
}
}

$page->output_footer();

Expand Down
129 changes: 97 additions & 32 deletions Upload/admin/modules/wiki/docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,75 @@
'title' => $lang->wiki_docs,
'link' => 'index.php?module=wiki-docs',
'description' => $lang->wiki_docs_description
);
);

$sub_tabs['wiki_docs_2'] = array(
'title' => $lang->wiki_docs_2,
'link' => 'index.php?module=wiki-docs&amp;page=2',
'description' => $lang->wiki_ext_desc
);
$inc = 3;

$sub_tabs['wiki_docs_3'] = array(
'title' => $lang->wiki_credits,
'link' => 'index.php?module=wiki-docs&amp;page=3',
'description' => $lang->wiki_credits_desc
);
$dir = new DirectoryIterator(MYBB_ROOT . 'inc/plugins/wiki/docs');
require_once MYBB_ROOT.'inc/plugins/wiki/markdown/markdown.php';

$table = new Table;
if(!$mybb->input['page'])
foreach($dir as $file)
{
// Main page
$page->output_nav_tabs($sub_tabs, 'wiki_docs');
$table->construct_cell($lang->wiki_intro_body, array('colspan' => 2, 'class' => 'align_center'));
$table->construct_row();
$table->construct_cell($lang->wiki_intro_par1, array('class' => 'align_center', 'width' => '50%'));
$table->construct_cell($lang->sprintf($lang->wiki_intro_par2, WIKI_VERSION), array('class' => 'align_center', 'width' => '50%'));
$table->construct_row();
$table->output($lang->wiki_docs);
if(!$file->isDot() && !$file->isDir() && pathinfo($file->getFilename(), PATHINFO_EXTENSION) == 'md')
{
$content = file_get_contents($file->getPathname());

$regex = '#<meta>(.*?)</meta>#';
preg_match_all($regex, $content, $matches);

$cfg = explode('|', $matches[1][0]);
$config = array();

foreach($cfg as $key => $val)
{
$arr = explode(':', $val);
$config[$arr[0]] = $arr[1];
}

if($config['title'] == 'Home') {
continue; // this is the home page
}

$inc++;
$sub_tabs['wiki_docs_' . $config['code']] = array(
'title' => $config['title'],
'link' => 'index.php?module=wiki-docs&amp;page=' . $config['code'],
'description' => $config['desc']
);
}
}
elseif($mybb->input['page'] == 2)
{
// Extensibility page
$page->output_nav_tabs($sub_tabs, 'wiki_docs_2');
$table->construct_cell($lang->wiki_ext_head, array('class' => 'align_center'));
$table->construct_row();
$table->construct_cell($lang->wiki_ext_par1 . "<br /><br />" . $lang->wiki_ext_par2 . "<br /><br />" . $lang->wiki_ext_par3);

$table = new Table;

if(isset($mybb->input['page']) && $mybb->input['page'] != 'credits') {
$code = strval($mybb->input['page']);
$suffix = '_' . $code;

$content = file_get_contents(MYBB_ROOT . 'inc/plugins/wiki/docs/' . $code . ".md");

$regex = '#<meta>(.*?)</meta>#';
preg_match_all($regex, $content, $matches);

$content = str_replace($matches[1][0], '', $content);

$cfg = explode('|', $matches[1][0]);
$config = array();

foreach($cfg as $key => $val)
{
$arr = explode(':', $val);
$config[$arr[0]] = $arr[1];
}

$table->construct_cell(Markdown($content));
$table->construct_row();
$table->output($lang->wiki_docs);

$tableTitle = $config['title'];
}
elseif($mybb->input['page'] == 3)
else if(isset($mybb->input['page']) && $mybb->input['page'] == 'credits')
{
// Credits page
$page->output_nav_tabs($sub_tabs, 'wiki_docs_3');
$suffix = '_3';

$credits = array(
"euantor" => array(
Expand All @@ -82,7 +111,43 @@
$table->construct_row();
}

$table->output($lang->wiki_docs);
$tableTitle = $lang->wiki_docs;
}
else {
$suffix = '';

$content = file_get_contents(MYBB_ROOT . 'inc/plugins/wiki/docs/home.md');

$regex = '#<meta>(.*?)</meta>#';
preg_match_all($regex, $content, $matches);

$content = str_replace($matches[1][0], '', $content);

$cfg = explode('|', $matches[1][0]);
$config = array();

foreach($cfg as $key => $val)
{
$arr = explode(':', $val);
$config[$arr[0]] = $arr[1];
}

$table->construct_cell(Markdown($content));
$table->construct_row();

$tableTitle = $lang->wiki_docs;
}

$sub_tabs['wiki_docs_3'] = array(
'title' => $lang->wiki_credits,
'link' => 'index.php?module=wiki-docs&amp;page=credits',
'description' => $lang->wiki_credits_desc
);

$page->output_nav_tabs($sub_tabs, 'wiki_docs' . $suffix);

if(isset($tableTitle)) {
$table->output($tableTitle);
}

$page->output_footer();
Expand Down
22 changes: 17 additions & 5 deletions Upload/admin/modules/wiki/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Not ideal in the least but we're not passing sensitive data. See: http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/
curl_setopt($ch, CURLOPT_USERAGENT, 'MyBBWiki by Krytic Update Checker. https://github.com/Krytic');
curl_setopt($ch, CURLOPT_USERAGENT, 'MyBBWiki by Krytic Update Checker. Project URL: https://github.com/Krytic Sender URL: ' . $mybb->settings['bb_url']);
curl_setopt($ch, CURLOPT_URL, $updateurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
Expand All @@ -76,13 +76,25 @@
$table->construct_header($lang->sprintf($lang->wiki_new_version, $latest_release['tag_name']), array("colspan" => 2));
$table->construct_row();

$table->construct_cell($latest_release['body']);
$table->construct_cell("<a href=\"{$latest_release['html_url']}\">" . $lang->new_release_download . "</a>", array('class' => 'align_center'));
require_once MYBB_ROOT.'inc/plugins/wiki/markdown/markdown.php';
$upgrading_instructions = Markdown(file_get_contents(MYBB_ROOT . 'inc/plugins/wiki/upgrading.md'));

$table->construct_cell(nl2br($latest_release['body']));
$table->construct_cell($upgrading_instructions, array('width' => '50%'));
$table->construct_row();

if(strpos($latest_release['body'], 'Upgrader: Yes') !== false) {
$table->construct_cell($lang->wiki_updater_required, array('class' => 'align_center', 'style' => 'font-weight: bold; font-size: 16pt; color: red;'));
}
else {
$table->construct_cell($lang->wiki_updater_not_required, array('class' => 'align_center', 'style' => 'font-weight: bold; font-size: 16pt; color: green;'));
}
$table->construct_cell("<a href=\"{$latest_release['html_url']}\">" . $lang->new_release_download . "</a>", array('class' => 'align_center', 'style' => 'font-size: 16pt; font-weight: bold;', 'rowspan' => 4));
$table->construct_row();
}
else {
$table->construct_cell($lang->wiki_updates, array("class" => "align_center"));
$table->construct_row();
flash_message($lang->wiki_updates, 'success');
admin_redirect("index.php?module=wiki");
}

$table->output($lang->wiki_updates_header);
Expand Down
9 changes: 6 additions & 3 deletions Upload/admin/modules/wiki/module_meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ function wiki_meta()
$sub_menu['20'] = array("id" => "import", "title" => $lang->nav_import, "link" => "index.php?module=wiki-import");
$sub_menu['25'] = array("id" => "perms", "title" => $lang->nav_perms, "link" => "index.php?module=wiki-perms");
$sub_menu['30'] = array("id" => "settings", "title" => $lang->nav_settings, "link" => "index.php?module=wiki-settings");
$sub_menu['40'] = array("id" => "templates", "title" => $lang->nav_templates, "link" => "index.php?module=wiki-templates");
$sub_menu['35'] = array("id" => "plugin", "title" => $lang->nav_plugin_pane, "link" => "index.php?module=config-plugins#mybbwiki");
$sub_menu['40'] = array("id" => "templates", "title" => $lang->nav_templates, "link" => "index.php?module=wiki-templates");
$sub_menu['45'] = array("id" => "upgrades", "title" => $lang->nav_upgrades, "link" => "index.php?module=wiki-upgrades");
$sub_menu['150'] = array("id" => "docs", "title" => $lang->nav_docs, "link" => "index.php?module=wiki-docs");

$sub_menu = $plugins->run_hooks("admin_wiki_menu", $sub_menu);
Expand All @@ -45,7 +46,8 @@ function wiki_action_handler($action)
'perms' => array('active' => 'perms', 'file' => 'perms.php'),
'settings' => array('active' => 'settings', 'file' => 'settings.php'),
'docs' => array('active' => 'docs', 'file' => 'docs.php'),
'templates' => array('active' => 'templates', 'file' => 'templates.php')
'templates' => array('active' => 'templates', 'file' => 'templates.php'),
'upgrades' => array('active' => 'upgrades', 'file' => 'upgrades.php')
);

$actions = $plugins->run_hooks("admin_wiki_action_handler", $actions);
Expand All @@ -72,7 +74,8 @@ function wiki_admin_permissions()
"import" => $lang->wiki_can_manage_imports,
"permissions" => $lang->wiki_can_manage_perms,
"settings" => $lang->wiki_can_manage_settings,
"docs" => $lang->wiki_can_manage_docs
"docs" => $lang->wiki_can_manage_docs,
"upgrades" => $lang->wiki_can_upgrade
);

$admin_permissions = $plugins->run_hooks("admin_wiki_permissions", $admin_permissions);
Expand Down
48 changes: 34 additions & 14 deletions Upload/admin/modules/wiki/perms.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,50 @@

if($mybb->request_method == "post")
{
$db->write_query('TRUNCATE TABLE '.TABLE_PREFIX.'wiki_perms');

$cache_array = array();

$query = $db->write_query("SELECT * FROM `" . TABLE_PREFIX . "usergroups`");
$cache_arr = array();

while($group = $db->fetch_array($query))
{
if(!isset($mybb->input['perm'][$group['gid']]))
{
$mybb->input['perm'][$group['gid']] = array(
'can_view' => 1, // I don't know why it's expecting 1 instead of zero to indicate no permission
'can_create' => 1, // but it works, so let's go with it.
'can_edit' => 1,
'can_protect' => 1,
'can_export' => 1
);
}
}

foreach($mybb->input['perm'] as $gid => $perms)
{
$row = array(
"gid" => (int)$gid,
"can_view" => in_array('can_view', $perms),
"can_create" => in_array('can_create', $perms),
"can_edit" => in_array('can_edit', $perms),
"can_protect" => in_array('can_protect', $perms),
"can_export" => in_array('can_export', $perms)
"can_view" => (in_array('can_view', $perms) ? 1 : 0),
"can_create" => (in_array('can_create', $perms) ? 1 : 0),
"can_edit" => (in_array('can_edit', $perms) ? 1 : 0),
"can_protect" => (in_array('can_protect', $perms) ? 1 : 0),
"can_export" => (in_array('can_export', $perms) ? 1 : 0)
);

$cache_array["gid_{$gid}"] = array(
"can_view" => in_array('can_view', $perms),
"can_create" => in_array('can_create', $perms),
"can_edit" => in_array('can_edit', $perms),
"can_protect" => in_array('can_protect', $perms),
"can_export" => in_array('can_export', $perms)
"can_view" => (in_array('can_view', $perms) ? 1 : 0),
"can_create" => (in_array('can_create', $perms) ? 1 : 0),
"can_edit" => (in_array('can_edit', $perms) ? 1 : 0),
"can_protect" => (in_array('can_protect', $perms) ? 1 : 0),
"can_export" => (in_array('can_export', $perms) ? 1 : 0)
);

$db->insert_query('wiki_perms', $row);
$gid = (int) $gid;
$setstr = "";
foreach($row as $k => $v) {
$setstr .= "`{$k}`='{$v}', ";
}
$setstr = rtrim($setstr, ', ');
$db->write_query(sprintf("UPDATE `%swiki_perms` SET {$setstr} WHERE `gid`='{$gid}'", TABLE_PREFIX));
}

$cache->update('wiki_permissions', $cache_array);
Expand Down
Loading

0 comments on commit 11e8041

Please sign in to comment.