plugins/admin/PluginManager.php
changeset 526 b2fb50d572c7
parent 524 26287ae2449d
child 527 21e11f564463
equal deleted inserted replaced
525:3f2dfdb99be4 526:b2fb50d572c7
   253           // not set, skip this plugin
   253           // not set, skip this plugin
   254           continue 2;
   254           continue 2;
   255       }
   255       }
   256       // decide if it's a system plugin
   256       // decide if it's a system plugin
   257       $plugin_meta['system plugin'] = in_array($dh, $plugins->system_plugins);
   257       $plugin_meta['system plugin'] = in_array($dh, $plugins->system_plugins);
       
   258       // reset installed variable
       
   259       $plugin_meta['installed'] = false;
       
   260       $plugin_meta['status'] = 0;
   258       // all checks passed
   261       // all checks passed
   259       $plugin_list[$dh] = $plugin_meta;
   262       $plugin_list[$dh] = $plugin_meta;
   260     }
   263     }
   261   }
   264   }
   262   echo '<pre>' . print_r($plugin_list, true) . '</pre>';
   265   // gather info about installed plugins
       
   266   $q = $db->sql_query('SELECT plugin_filename, plugin_version, plugin_flags FROM ' . table_prefix . 'plugins;');
       
   267   if ( !$q )
       
   268     $db->_die();
       
   269   while ( $row = $db->fetchrow() )
       
   270   {
       
   271     if ( !isset($plugin_list[ $row['plugin_filename'] ]) )
       
   272     {
       
   273       // missing plugin file, don't report (for now)
       
   274       continue;
       
   275     }
       
   276     $filename =& $row['plugin_filename'];
       
   277     $plugin_list[$filename]['installed'] = true;
       
   278     $plugin_list[$filename]['status'] = PLUGIN_INSTALLED;
       
   279     if ( $row['plugin_version'] != $plugin_list[$filename]['version'] )
       
   280     {
       
   281       $plugin_list[$filename]['status'] |= PLUGIN_OUTOFDATE;
       
   282       $plugin_list[$filename]['version installed'] = $row['plugin_version'];
       
   283     }
       
   284     if ( $row['plugin_flags'] & PLUGIN_DISABLED )
       
   285     {
       
   286       $plugin_list[$filename]['status'] |= PLUGIN_DISABLED;
       
   287     }
       
   288   }
       
   289   $db->free_result();
       
   290   
       
   291   // sort it all out by filename
       
   292   ksort($plugin_list);
       
   293   
       
   294   // start printing things out
       
   295   acp_start_form();
       
   296   ?>
       
   297   <div class="tblholder">
       
   298     <table border="0" cellspacing="1" cellpadding="5">
       
   299       <?php
       
   300       $rowid = '2';
       
   301       foreach ( $plugin_list as $filename => $data )
       
   302       {
       
   303         // print out all plugins
       
   304         $rowid = ( $rowid == '1' ) ? '2' : '1';
       
   305         $plugin_name = ( preg_match('/^[a-z0-9_]+$/', $data['plugin name']) ) ? $lang->get($data['plugin name']) : $data['plugin name'];
       
   306         $plugin_basics = $lang->get('acppl_lbl_plugin_name', array(
       
   307             'plugin' => $plugin_name,
       
   308             'author' => $data['author']
       
   309           ));
       
   310         $color = '';
       
   311         $buttons = '';
       
   312         if ( $data['system plugin'] )
       
   313         {
       
   314           $status = $lang->get('acppl_lbl_status_system');
       
   315         }
       
   316         else if ( $data['installed'] && !( $data['status'] & PLUGIN_DISABLED ) && !( $data['status'] & PLUGIN_OUTOFDATE ) )
       
   317         {
       
   318           // this plugin is all good
       
   319           $color = '_green';
       
   320           $status = $lang->get('acppl_lbl_status_installed');
       
   321           $buttons = 'uninstall|disable';
       
   322         }
       
   323         else if ( $data['installed'] && $data['status'] & PLUGIN_OUTOFDATE )
       
   324         {
       
   325           $color = '_red';
       
   326           $status = $lang->get('acppl_lbl_status_need_upgrade');
       
   327           $buttons = 'uninstall|update';
       
   328         }
       
   329         else if ( $data['installed'] && $data['status'] & PLUGIN_DISABLED )
       
   330         {
       
   331           $color = '_red';
       
   332           $status = $lang->get('acppl_lbl_status_disabled');
       
   333           $buttons = 'uninstall|enable';
       
   334         }
       
   335         else
       
   336         {
       
   337           $color = '_red';
       
   338           $status = $lang->get('acppl_lbl_status_uninstalled');
       
   339           $buttons = 'install';
       
   340         }
       
   341         $uuid = md5($data['plugin name'] . $data['version'] . $filename);
       
   342         $desc = ( preg_match('/^[a-z0-9_]+$/', $data['description']) ) ? $lang->get($data['description']) : $data['description'];
       
   343         $desc = sanitize_html($desc);
       
   344         
       
   345         $additional = '';
       
   346         
       
   347         // filename
       
   348         $additional .= '<b>' . $lang->get('acppl_lbl_filename') . '</b> ' . "{$filename}<br />";
       
   349         
       
   350         // plugin's site
       
   351         $data['plugin uri'] = htmlspecialchars($data['plugin uri']);
       
   352         $additional .= '<b>' . $lang->get('acppl_lbl_plugin_site') . '</b> ' . "<a href=\"{$data['plugin uri']}\">{$data['plugin uri']}</a><br />";
       
   353         
       
   354         // author's site
       
   355         $data['author uri'] = htmlspecialchars($data['author uri']);
       
   356         $additional .= '<b>' . $lang->get('acppl_lbl_author_site') . '</b> ' . "<a href=\"{$data['author uri']}\">{$data['author uri']}</a><br />";
       
   357         
       
   358         // version
       
   359         $additional .= '<b>' . $lang->get('acppl_lbl_version') . '</b> ' . "{$data['version']}<br />";
       
   360         
       
   361         // installed version
       
   362         if ( $data['status'] & PLUGIN_OUTOFDATE )
       
   363         {
       
   364           $additional .= '<b>' . $lang->get('acppl_lbl_installed_version') . '</b> ' . "{$data['version installed']}<br />";
       
   365         }
       
   366         
       
   367         // build list of buttons
       
   368         $buttons_html = '';
       
   369         if ( !empty($buttons) )
       
   370         {
       
   371           $filename_js = addslashes($filename);
       
   372           $buttons = explode('|', $buttons);
       
   373           $colors = array(
       
   374               'install' => 'green',
       
   375               'disable' => 'blue',
       
   376               'enable' => 'blue',
       
   377               'upgrade' => 'green',
       
   378               'uninstall' => 'red'
       
   379             );
       
   380           foreach ( $buttons as $button )
       
   381           {
       
   382             $btnface = $lang->get("acppl_btn_$button");
       
   383             $buttons_html .= "<a href=\"#\" onclick=\"ajaxPluginAction('$button', '$filename_js', this); return false;\" class=\"abutton_{$colors[$button]} abutton\">$btnface</a>\n";
       
   384           }
       
   385         }
       
   386         
       
   387         echo "<tr>
       
   388                 <td class=\"row{$rowid}$color\">
       
   389                   <div style=\"float: right;\">
       
   390                     <b>$status</b>
       
   391                   </div>
       
   392                   <div style=\"cursor: pointer;\" onclick=\"if ( !this.fx ) this.fx = new Spry.Effect.Blind('plugininfo_$uuid', { duration: 500, from: '0%', to: '100%', toggle: true }); this.fx.start();\"
       
   393                     $plugin_basics
       
   394                   </div>
       
   395                   <span class=\"menuclear\"></span>
       
   396                   <div id=\"plugininfo_$uuid\" style=\"display: none;\">
       
   397                     $desc
       
   398                     <div style=\"padding: 5px;\">
       
   399                       $additional
       
   400                       <div style=\"float: right; position: relative; top: -10px;\">
       
   401                         $buttons_html
       
   402                       </div>
       
   403                       <span class=\"menuclear\"></span>
       
   404                     </div>
       
   405                   </div>
       
   406                 </td>
       
   407               </tr>";
       
   408       }
       
   409       ?>
       
   410     </table>
       
   411   </div>
       
   412   <?php
       
   413   echo '</form>';
   263 }
   414 }