2017-05-29 23:56:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class pluginLinks extends Plugin {
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
2017-06-19 23:14:38 +02:00
|
|
|
// JSON database
|
2017-05-29 23:56:07 +02:00
|
|
|
$jsondb = json_encode(array(
|
2017-07-15 21:28:54 +02:00
|
|
|
'Bludit'=>'https://www.bludit.com',
|
2017-10-08 20:33:21 +02:00
|
|
|
'Bludit PRO'=>'https://pro.bludit.com'
|
2017-05-29 23:56:07 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
// Fields and default values for the database of this plugin
|
|
|
|
$this->dbFields = array(
|
|
|
|
'label'=>'Links',
|
|
|
|
'jsondb'=>$jsondb
|
|
|
|
);
|
2017-06-19 23:14:38 +02:00
|
|
|
|
2017-06-20 23:56:22 +02:00
|
|
|
// Disable default Save and Cancel button
|
2017-06-19 23:14:38 +02:00
|
|
|
$this->formButtons = false;
|
2017-05-29 23:56:07 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 23:14:38 +02:00
|
|
|
// Method called when a POST request is sent
|
2017-06-18 22:44:07 +02:00
|
|
|
public function post()
|
|
|
|
{
|
2017-06-19 23:14:38 +02:00
|
|
|
// Get current jsondb value from database
|
2017-06-20 23:56:22 +02:00
|
|
|
// All data stored in the database is html encoded
|
|
|
|
$jsondb = $this->db['jsondb'];
|
|
|
|
$jsondb = Sanitize::htmlDecode($jsondb);
|
2017-06-19 23:14:38 +02:00
|
|
|
|
|
|
|
// Convert JSON to Array
|
2017-06-18 22:44:07 +02:00
|
|
|
$links = json_decode($jsondb, true);
|
|
|
|
|
2017-06-20 23:56:22 +02:00
|
|
|
// Check if the user click on the button delete or add
|
2017-06-19 23:14:38 +02:00
|
|
|
if( isset($_POST['deleteLink']) ) {
|
|
|
|
// Values from $_POST
|
|
|
|
$name = $_POST['deleteLink'];
|
|
|
|
|
2017-06-20 23:56:22 +02:00
|
|
|
// Delete the link from the array
|
2017-06-19 23:14:38 +02:00
|
|
|
unset($links[$name]);
|
|
|
|
}
|
|
|
|
elseif( isset($_POST['addLink']) ) {
|
|
|
|
// Values from $_POST
|
|
|
|
$name = $_POST['linkName'];
|
|
|
|
$url = $_POST['linkURL'];
|
|
|
|
|
|
|
|
// Check empty string
|
|
|
|
if( empty($name) ) { return false; }
|
|
|
|
|
|
|
|
// Add the link
|
|
|
|
$links[$name] = $url;
|
|
|
|
}
|
2017-06-18 22:44:07 +02:00
|
|
|
|
2017-06-20 23:56:22 +02:00
|
|
|
// Encode html to store the values on the database
|
2017-06-19 23:14:38 +02:00
|
|
|
$this->db['label'] = Sanitize::html($_POST['label']);
|
|
|
|
$this->db['jsondb'] = Sanitize::html(json_encode($links));
|
2017-06-18 22:44:07 +02:00
|
|
|
|
2017-06-19 23:14:38 +02:00
|
|
|
// Save the database
|
|
|
|
return $this->save();
|
2017-06-18 22:44:07 +02:00
|
|
|
}
|
|
|
|
|
2017-05-29 23:56:07 +02:00
|
|
|
// Method called on plugin settings on the admin area
|
|
|
|
public function form()
|
|
|
|
{
|
2018-08-03 19:03:09 +02:00
|
|
|
global $language;
|
2017-05-29 23:56:07 +02:00
|
|
|
|
|
|
|
$html = '<div>';
|
2018-08-03 19:03:09 +02:00
|
|
|
$html .= '<label>'.$language->get('Label').'</label>';
|
2017-06-19 23:14:38 +02:00
|
|
|
$html .= '<input name="label" type="text" value="'.$this->getValue('label').'">';
|
2018-08-03 19:03:09 +02:00
|
|
|
$html .= '<span class="tip">'.$language->get('This title is almost always used in the sidebar of the site').'</span>';
|
2017-06-19 23:14:38 +02:00
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
$html .= '<div>';
|
2018-08-03 19:03:09 +02:00
|
|
|
$html .= '<button name="save" class="btn btn-primary" type="submit">'.$language->get('Save').'</button>';
|
2017-06-19 23:14:38 +02:00
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
// New link, when the user click on save button this call the method post()
|
|
|
|
// and the new link is added to the database
|
2018-08-03 19:03:09 +02:00
|
|
|
$html .= '<legend>'.$language->get('Add a new link').'</legend>';
|
2017-06-19 23:14:38 +02:00
|
|
|
|
|
|
|
$html .= '<div>';
|
2018-08-03 19:03:09 +02:00
|
|
|
$html .= '<label>'.$language->get('Name').'</label>';
|
2017-06-19 23:14:38 +02:00
|
|
|
$html .= '<input name="linkName" type="text" value="">';
|
2017-05-29 23:56:07 +02:00
|
|
|
$html .= '</div>';
|
|
|
|
|
2017-06-19 23:14:38 +02:00
|
|
|
$html .= '<div>';
|
2018-08-03 19:03:09 +02:00
|
|
|
$html .= '<label>'.$language->get('Url').'</label>';
|
2017-06-19 23:14:38 +02:00
|
|
|
$html .= '<input name="linkURL" type="text" value="">';
|
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
$html .= '<div>';
|
2018-08-03 19:03:09 +02:00
|
|
|
$html .= '<button name="addLink" class="blue" type="submit">'.$language->get('Add').'</button>';
|
2017-06-19 23:14:38 +02:00
|
|
|
$html .= '</div>';
|
|
|
|
|
2018-08-03 19:03:09 +02:00
|
|
|
$html .= '<legend>'.$language->get('Links').'</legend>';
|
2017-06-19 23:14:38 +02:00
|
|
|
|
2017-06-18 22:44:07 +02:00
|
|
|
// Get the JSON DB, getValue() with the option unsanitized HTML code
|
|
|
|
$jsondb = $this->getValue('jsondb', $unsanitized=false);
|
|
|
|
$links = json_decode($jsondb, true);
|
|
|
|
foreach($links as $name=>$url) {
|
|
|
|
$html .= '<div>';
|
2018-08-03 19:03:09 +02:00
|
|
|
$html .= '<label>'.$language->get('Name').'</label>';
|
2017-06-19 23:14:38 +02:00
|
|
|
$html .= '<input type="text" value="'.$name.'" disabled>';
|
2017-06-18 22:44:07 +02:00
|
|
|
$html .= '</div>';
|
|
|
|
|
2017-06-19 23:14:38 +02:00
|
|
|
$html .= '<div>';
|
2018-08-03 19:03:09 +02:00
|
|
|
$html .= '<label>'.$language->get('Url').'</label>';
|
2017-06-19 23:14:38 +02:00
|
|
|
$html .= '<input type="text" value="'.$url.'" disabled>';
|
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
$html .= '<div>';
|
2018-08-03 19:03:09 +02:00
|
|
|
$html .= '<button name="deleteLink" type="submit" value="'.$name.'">'.$language->get('Delete').'</button>';
|
2017-06-19 23:14:38 +02:00
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
$html .= '</br>';
|
|
|
|
}
|
2017-06-18 22:44:07 +02:00
|
|
|
|
2017-05-29 23:56:07 +02:00
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Method called on the sidebar of the website
|
|
|
|
public function siteSidebar()
|
|
|
|
{
|
2018-08-03 19:03:09 +02:00
|
|
|
global $language;
|
2017-05-29 23:56:07 +02:00
|
|
|
|
|
|
|
// HTML for sidebar
|
|
|
|
$html = '<div class="plugin plugin-pages">';
|
2017-07-28 20:52:04 +02:00
|
|
|
if ($this->getValue('label')) {
|
|
|
|
$html .= '<h2 class="plugin-label">'.$this->getValue('label').'</h2>';
|
|
|
|
}
|
2017-05-29 23:56:07 +02:00
|
|
|
$html .= '<div class="plugin-content">';
|
|
|
|
$html .= '<ul>';
|
|
|
|
|
|
|
|
// Get the JSON DB, getValue() with the option unsanitized HTML code
|
|
|
|
$jsondb = $this->getValue('jsondb', false);
|
|
|
|
$links = json_decode($jsondb);
|
|
|
|
|
|
|
|
// By default the database of categories are alphanumeric sorted
|
|
|
|
foreach( $links as $name=>$url ) {
|
|
|
|
$html .= '<li>';
|
|
|
|
$html .= '<a href="'.$url.'">';
|
|
|
|
$html .= $name;
|
|
|
|
$html .= '</a>';
|
|
|
|
$html .= '</li>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$html .= '</ul>';
|
|
|
|
$html .= '</div>';
|
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
}
|