Advertisement
Guest User

Untitled

a guest
Dec 18th, 2015
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.22 KB | None | 0 0
  1. <?php class JElementLicense extends JElement {
  2.     function fetchTooltip($label, $description, &$node, $control_name, $name) {
  3.         return;
  4.     }
  5.     function fetchElement($name, $value, &$node, $control_name) {
  6.         $extension = $node->attributes('extension');
  7.         if (!$extension) {
  8.             return;
  9.         }
  10.         return '<div class="panel">' . NoNumber_License_outputState($extension) . '</div>';
  11.     }
  12. }
  13. if (!function_exists('NoNumber_License_outputState')) {
  14.     function NoNumber_License_outputState($extension) {
  15.         $ext = '';
  16.         $ext->alias = preg_replace('#[^a-z\-]#', '', str_replace('?', '-', strtolower($extension)));
  17.         $ext->host = parse_url(JURI::root(false));
  18.         $ext->host = strtolower($ext->host['host']);
  19.         $ext->state = 0;
  20.         $ext->codes = array('', '');
  21.         $db = & JFactory::getDBO();
  22.         $sql = 'show tables like "' . $db->_table_prefix . 'nonumber_licenses"';
  23.         $db->setQuery($sql);
  24.         $exists = $db->loadResult();
  25.         if ($exists) {
  26.             $sql = 'SELECT code FROM #__nonumber_licenses' . ' WHERE extension = \'' . $ext->alias . '\'' . ' LIMIT 1';
  27.             $db->setQuery($sql);
  28.             $ext->codes[0] = $db->loadResult();
  29.             $sql = 'SELECT code FROM #__nonumber_licenses' . ' WHERE extension = \'all\'' . ' LIMIT 1';
  30.             $db->setQuery($sql);
  31.             $ext->codes[1] = $db->loadResult();
  32.         }
  33.         if ($ext->codes[0] || $ext->codes[1]) {
  34.             NoNumber_License_getState($ext);
  35.         }
  36.         $text = '';
  37.         switch ($ext->state) {
  38.             case 1:
  39.                 // commercial but not valid
  40.                 $text = JText::sprintf('-The License code is not valid', $extension, $ext->host);
  41.             break;
  42.             case 2:
  43.                 // commercial but local
  44.                 $text = JText::sprintf('-Cannot check if License code is valid because you are working on a local server', $extension);
  45.             break;
  46.             case 3:
  47.                 // commercial
  48.                 $text = JText::sprintf('-This is a commercial version', $extension, $ext->host);
  49.             break;
  50.             default:
  51.                 // non-commercial
  52.                 $text = JText::sprintf('-This is a non-commercial version', $extension);
  53.             break;
  54.         }
  55.         if ($ext->state == 3) {
  56.             $bgcolor = '#F6F6F6';
  57.             $color = '#009900';
  58.             $formcolor = '#999999';
  59.             $bordercolor = '#EEEEEE';
  60.         } else {
  61.             $bgcolor = '#FFCCCC';
  62.             $color = '#000000';
  63.             $formcolor = '#996666';
  64.             $bordercolor = '#EEBBBB';
  65.         }
  66.         $html = array();
  67.         $html[] = '<div style="padding: 2px 5px;background-color:' . $bgcolor . ';">';
  68.         $html[] = '<strong style="color:' . $color . ';">' . $text . '</strong>';
  69.         if ($ext->state != 3) {
  70.             $html[] = '<br />' . JText::_('-There are no limitations in functionality');
  71.             $html[] = ' <span style="white-space:nowrap;"><em>(<a href="http://www.nonumber.nl/' . $ext->alias . '/license" target="_blank">' . JText::_('-Purchase License code') . '</a>';
  72.             if ($ext->host && $ext->host != 'localhost' && $ext->host != '127.0.0.1') {
  73.                 $html[] = ' ' . JText::sprintf('-for your domain', $ext->host);
  74.             }
  75.             $html[] = ')</em></span>';
  76.         }
  77.         $html[] = '</div>';
  78.         return implode('', $html);
  79.     }
  80. }
  81. if (!function_exists('NoNumber_License_getState')) {
  82.     function NoNumber_License_getState(&$ext) {
  83.         if (isset($ext->code)) {
  84.             $ext->codes = array($ext->code, '');
  85.         }
  86.         $ext->codes[0] = preg_replace('#[^a-z0-9]#i', '', $ext->codes[0]);
  87.         $ext->codes[1] = preg_replace('#[^a-z0-9]#i', '', $ext->codes[1]);
  88.         if (isset($ext->code)) {
  89.             $ext->code = $ext->codes[0];
  90.         }
  91.         $state = 0;
  92.         if ($ext->codes[0] || $ext->codes[1]) {
  93.             $state = 1;
  94.             if ($ext->host == 'localhost' || $ext->host == '127.0.0.1') {
  95.                 $state = 2;
  96.             } else {
  97.                 if (!(strpos($ext->host, '.') === false)) {
  98.                     $host_array = explode('.', $ext->host);
  99.                     if (count($host_array) > 1) {
  100.                         $slds = 'ac city co edu gov law ltd me med mil mod net nhs nic nom org parliament plc police pub sch school';
  101.                         $host = array();
  102.                         $host[] = array_pop($host_array);
  103.                         $host[] = array_pop($host_array);
  104.                         if (in_array($host['1'], explode(' ', $slds))) {
  105.                             $host[] = array_pop($host_array);
  106.                         }
  107.                         $ext->host = implode('.', array_reverse($host));
  108.                     }
  109.                 }
  110.                 $keys = array();
  111.                 $keys[0] = sprintf("%u", crc32(md5($ext->host . '::' . $ext->alias)));
  112.                 $keys[1] = sprintf("%u", crc32(md5($ext->host . '::all')));
  113.                 if ($ext->codes[0] == $keys[0] || $ext->codes[1] == $keys[1]) {
  114.                     $state = 3;
  115.                 }
  116.             }
  117.         }
  118.         $ext->state = $state;
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement