Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php class JElementLicense extends JElement {
- function fetchTooltip($label, $description, &$node, $control_name, $name) {
- return;
- }
- function fetchElement($name, $value, &$node, $control_name) {
- $extension = $node->attributes('extension');
- if (!$extension) {
- return;
- }
- return '<div class="panel">' . NoNumber_License_outputState($extension) . '</div>';
- }
- }
- if (!function_exists('NoNumber_License_outputState')) {
- function NoNumber_License_outputState($extension) {
- $ext = '';
- $ext->alias = preg_replace('#[^a-z\-]#', '', str_replace('?', '-', strtolower($extension)));
- $ext->host = parse_url(JURI::root(false));
- $ext->host = strtolower($ext->host['host']);
- $ext->state = 0;
- $ext->codes = array('', '');
- $db = & JFactory::getDBO();
- $sql = 'show tables like "' . $db->_table_prefix . 'nonumber_licenses"';
- $db->setQuery($sql);
- $exists = $db->loadResult();
- if ($exists) {
- $sql = 'SELECT code FROM #__nonumber_licenses' . ' WHERE extension = \'' . $ext->alias . '\'' . ' LIMIT 1';
- $db->setQuery($sql);
- $ext->codes[0] = $db->loadResult();
- $sql = 'SELECT code FROM #__nonumber_licenses' . ' WHERE extension = \'all\'' . ' LIMIT 1';
- $db->setQuery($sql);
- $ext->codes[1] = $db->loadResult();
- }
- if ($ext->codes[0] || $ext->codes[1]) {
- NoNumber_License_getState($ext);
- }
- $text = '';
- switch ($ext->state) {
- case 1:
- // commercial but not valid
- $text = JText::sprintf('-The License code is not valid', $extension, $ext->host);
- break;
- case 2:
- // commercial but local
- $text = JText::sprintf('-Cannot check if License code is valid because you are working on a local server', $extension);
- break;
- case 3:
- // commercial
- $text = JText::sprintf('-This is a commercial version', $extension, $ext->host);
- break;
- default:
- // non-commercial
- $text = JText::sprintf('-This is a non-commercial version', $extension);
- break;
- }
- if ($ext->state == 3) {
- $bgcolor = '#F6F6F6';
- $color = '#009900';
- $formcolor = '#999999';
- $bordercolor = '#EEEEEE';
- } else {
- $bgcolor = '#FFCCCC';
- $color = '#000000';
- $formcolor = '#996666';
- $bordercolor = '#EEBBBB';
- }
- $html = array();
- $html[] = '<div style="padding: 2px 5px;background-color:' . $bgcolor . ';">';
- $html[] = '<strong style="color:' . $color . ';">' . $text . '</strong>';
- if ($ext->state != 3) {
- $html[] = '<br />' . JText::_('-There are no limitations in functionality');
- $html[] = ' <span style="white-space:nowrap;"><em>(<a href="http://www.nonumber.nl/' . $ext->alias . '/license" target="_blank">' . JText::_('-Purchase License code') . '</a>';
- if ($ext->host && $ext->host != 'localhost' && $ext->host != '127.0.0.1') {
- $html[] = ' ' . JText::sprintf('-for your domain', $ext->host);
- }
- $html[] = ')</em></span>';
- }
- $html[] = '</div>';
- return implode('', $html);
- }
- }
- if (!function_exists('NoNumber_License_getState')) {
- function NoNumber_License_getState(&$ext) {
- if (isset($ext->code)) {
- $ext->codes = array($ext->code, '');
- }
- $ext->codes[0] = preg_replace('#[^a-z0-9]#i', '', $ext->codes[0]);
- $ext->codes[1] = preg_replace('#[^a-z0-9]#i', '', $ext->codes[1]);
- if (isset($ext->code)) {
- $ext->code = $ext->codes[0];
- }
- $state = 0;
- if ($ext->codes[0] || $ext->codes[1]) {
- $state = 1;
- if ($ext->host == 'localhost' || $ext->host == '127.0.0.1') {
- $state = 2;
- } else {
- if (!(strpos($ext->host, '.') === false)) {
- $host_array = explode('.', $ext->host);
- if (count($host_array) > 1) {
- $slds = 'ac city co edu gov law ltd me med mil mod net nhs nic nom org parliament plc police pub sch school';
- $host = array();
- $host[] = array_pop($host_array);
- $host[] = array_pop($host_array);
- if (in_array($host['1'], explode(' ', $slds))) {
- $host[] = array_pop($host_array);
- }
- $ext->host = implode('.', array_reverse($host));
- }
- }
- $keys = array();
- $keys[0] = sprintf("%u", crc32(md5($ext->host . '::' . $ext->alias)));
- $keys[1] = sprintf("%u", crc32(md5($ext->host . '::all')));
- if ($ext->codes[0] == $keys[0] || $ext->codes[1] == $keys[1]) {
- $state = 3;
- }
- }
- }
- $ext->state = $state;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement