/**
  * 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>');
 }
 /**
  *
  */
 public function init()
 {
     parent::init();
     Yii::app()->clientScript->registerCssFile(YiiEmbed::assetsUrl() . '/css/detail-view.css');
 }
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
// do not allow direct entry here
if (!function_exists('wp')) {
    echo 'Yii Embed cannot be called directly.';
    exit;
}
// yii embed constants
define('YII_EMBED_VERSION', '1.1.0');
define('YII_EMBED_URL', plugin_dir_url(__FILE__));
define('YII_EMBED_PATH', __DIR__ . '/');
// yii constants
defined('YII_DEBUG') or define('YII_DEBUG', WP_DEBUG);
// load debug
if (YII_DEBUG) {
    require_once YII_EMBED_PATH . 'includes/debug.php';
    require_once YII_EMBED_PATH . 'includes/kint/Kint.class.php';
}
// load YiiEmbed and Yii
require_once YII_EMBED_PATH . 'includes/YiiEmbed.php';
define('YII_EMBED_YII_VERSION', YiiEmbed::yiiVersion());
YiiEmbed::init();
    /**
     *
     */
    public function registerClientScript()
    {
        parent::registerClientScript();
        Yii::app()->clientScript->registerCssFile(YiiEmbed::assetsUrl() . '/css/grid-view.css');
        if ($this->multiActions || $this->gridActions || $this->gridButtons) {
            Yii::app()->clientScript->registerScriptFile(YiiEmbed::assetsUrl() . '/js/jquery.form.js');
            // put the url from the button into the form action
            // handle submit form to capture the response into a modal
            Yii::app()->controller->beginWidget('YiiEmbedJavaScriptWidget', array('position' => CClientScript::POS_END));
            ?>
            <script type="text/javascript">
                var modalRemote = $('#modal-remote');

                // handle multiActions
                $('#<?php 
            echo $this->id;
            ?>
-form').on('change', '.multi-actions', function () {
                    var checked = false;
                    var action = $('#<?php 
            echo $this->id;
            ?>
-form').attr('action');
                    var url = $(this).val();
                    $(this).val('');
                    if (url) {
                        $('.select-on-check').each(function () {
                            if ($(this).is(':checked'))
                                checked = true;
                        });
                        if (checked) {
                            setupGridViewAjaxForm();
                            $('#<?php 
            echo $this->id;
            ?>
-form').attr('action', url).submit();
                        }
                        else {
                            alert('<?php 
            echo Yii::t('dressing', 'No rows selected.');
            ?>
');
                        }
                    }
                });

                // handle gridActions
                $('#<?php 
            echo $this->id;
            ?>
-form').on('change', '.grid-actions', function () {
                    var action = $('#<?php 
            echo $this->id;
            ?>
-form').attr('action');
                    var url = $(this).val();
                    $(this).val('');
                    if (url) {
                        setupGridViewAjaxForm();
                        $('#<?php 
            echo $this->id;
            ?>
-form').attr('action', url).submit();
                    }
                });

                // handle gridButtons
                $('#<?php 
            echo $this->id;
            ?>
-form').on('click', '.gridButton', function () {
                    var action = $('#<?php 
            echo $this->id;
            ?>
-form').attr('action');
                    var url = $(this).val();
                    $(this).val('');
                    if (url) {
                        $('#<?php 
            echo $this->id;
            ?>
-form').attr('action', url).submit();
                    }
                });

                // handle form submission
                function setupGridViewAjaxForm() {
                    $('#<?php 
            echo $this->id;
            ?>
-form').ajaxForm({
                        beforeSubmit: function (response) {
                            if (!modalRemote.length) modalRemote = $('<div class="modal hide fade" id="modal-remote"></div>');
                            modalRemote.modalResponsiveFix();
                            modalRemote.touchScroll();
                            modalRemote.html('<div class="modal-header"><h3><?php 
            echo Yii::t('dressing', 'Loading...');
            ?>
</h3></div><div class="modal-body"><div class="modal-remote-indicator"></div>').modal();
                        },
                        success: function (response) {
                            modalRemote.html(response);
                            $(window).resize();
                            $('#modal-remote input:text:visible:first').focus();
                        },
                        error: function (response) {
                            modalRemote.children('.modal-header').html('<button type="button" class="close" data-dismiss="modal"><i class="icon-remove"></i></button><h3><?php 
            echo Yii::t('dressing', 'Error!');
            ?>
</h3>');
                            modalRemote.children('.modal-body').html(response);
                        }
                    });
                }
            </script>
            <?php 
            Yii::app()->controller->endWidget();
        }
    }
 /**
  * Callback to add the yii_path setting field
  */
 public function settings_field_yii_path()
 {
     echo strtr('<input type="text" id="yii_embed_yii_path" name="yii_embed[yii_path]" class="regular-text" value=":value" /><p class="description">:description :default_path</p>', array(':value' => !empty($this->options['yii_path']) ? esc_attr($this->options['yii_path']) : '', ':description' => __('Full path the the folder that contains Yii\'s "framework" folder.'), ':default_path' => empty($this->options['yii_path']) ? '<br/>' . __('Default:') . ' ' . YiiEmbed::yiiPath() : ''));
 }