/**
  * Initialize the Admin callbacks and messages.
  */
 public static function init()
 {
     // add action for notices
     add_action('yii_embed_admin_notice', 'YiiEmbedAdmin::notice', 10, 2);
     // message if yii is not found
     if (!YII_EMBED_YII_VERSION) {
         $message = strtr(__('<p><b>Could not find Yii Framework.</b><br/>Visit <a href=":settings_href"><strong>Settings &gt; Yii Embed</strong></a> to configure the path or download the framework using one of the following methods:</p><p class="submit">:automatic_download :manual_download</p>'), array(':settings_href' => get_admin_url() . 'admin.php?page=yii_embed_settings', ':automatic_download' => '<a href="' . YII_EMBED_URL . '/yii/download.php" class="button-primary" onclick="return confirm(\'Do you want to download and install Yii Framework to:\\n' . YiiEmbed::yiiPath() . '\')">' . __('Automatic Download') . '</a>', ':manual_download' => '<a href="' . YiiEmbed::yiiDownloadUrl() . '" onclick="return confirm(\'After downloading, please unzip the Yii &quot;framework/&quot; folder into:\\n' . YiiEmbed::yiiPath() . '\');" class="button">' . __('Manual Download') . '</a>'));
         do_action('yii_embed_admin_notice', $message, 'error');
     }
     // register settings page
     require_once YII_EMBED_PATH . 'includes/YiiEmbedSettings.php';
     new YiiEmbedSettings();
 }
 /**
  * Download and unzip the Yii Framework.
  *
  * @throws Exception
  */
 public function download()
 {
     // header
     $this->output('<style>body{ font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; }</style>');
     $this->output('<h1>' . __('Yii Framework Downloader') . '</h1>');
     // do the download
     if (!empty($_GET['force']) || !YiiEmbed::yiiVersion()) {
         // setup variables
         $yiiPath = YiiEmbed::yiiPath();
         $yiiDownloadUrl = YiiEmbed::yiiDownloadUrl();
         $pathinfo = pathinfo($yiiDownloadUrl);
         $yiiFrameworkPath = $yiiPath . '/framework/';
         $yiiFrameworkUnzipPath = $yiiPath . '/' . $pathinfo['filename'];
         $yiiZipFile = $yiiPath . '/' . $pathinfo['basename'];
         $yiiZipPath = $pathinfo['filename'] . '/framework/';
         // pre cleanup
         $this->delete($yiiFrameworkPath);
         $this->delete($yiiFrameworkUnzipPath);
         $this->delete($yiiZipFile);
         // download
         $this->output('<h2>' . __('Downloading') . '</h2><b>' . $yiiDownloadUrl . '</b> - ');
         $downloaded = $this->downloadChunked($yiiDownloadUrl, $yiiZipFile);
         if (!$downloaded) {
             throw new Exception(__('Failed to download.'));
         }
         // unzip
         $this->output('<h2>' . __('Unzipping') . '</h2><b>' . $yiiZipFile . '</b> - ');
         $files = $this->unzipEntryPath($yiiZipFile, $yiiPath, $yiiZipPath);
         if (!$files) {
             throw new Exception(__('Failed to unzip.'));
         }
         $this->output(count($files) . ' ' . __('files'), true);
         // post cleanup
         rename($yiiFrameworkUnzipPath . '/framework/', $yiiFrameworkPath);
         $this->delete($yiiFrameworkUnzipPath);
         $this->delete($yiiZipFile);
         // output yii version
         $this->output('<h2>' . __('Success!') . '</h2>');
         $this->output(strtr(__('Yii Framework version :version is installed, Yii-Haw!'), array(':version' => YiiEmbed::yiiVersion(true))));
     } else {
         $this->output('<h2>' . strtr(__('Yii Framework :version is already installed'), array(':version' => YiiEmbed::yiiVersion())) . '</h2>');
         $this->output('<a href="download.php?force=true">' . __('Force Download') . '</a> | ');
     }
     // link back to admin
     $this->output('<a href="' . get_admin_url() . 'options-general.php?page=yii_embed_settings">' . __('Return to WordPress') . '</a>');
 }