function buildCaches(array $files)
{
    $cache = array();
    $cache_icons = array();
    $zip = new ZipArchive();
    foreach ($files as $f) {
        if (substr($f, -4) == '.zip') {
            $name = substr($f, 0, -4);
            $filename = FOLDER . '/' . $f;
            $filedateEpoc = filemtime($filename);
            $filedate = date('c', $filedateEpoc);
            if ($res = $zip->open($filename)) {
                if ($infoFile = searchInfosFile($zip)) {
                    $infos = $zip->getFromName($infoFile);
                    try {
                        @($doc = new SimpleXMLElement($infos));
                        $title = $doc->title->__toString();
                        $author = $doc->author->__toString();
                        $version = $doc->version->__toString();
                        $versionOrder = intval(floatval($version) * 1000.0);
                        $site = $doc->site->__toString();
                        $repository = $doc->repository->__toString();
                        $description = $doc->description->__toString();
                        $requirements = $doc->requirements->__toString();
                        $values = array($filename, $filedate, $version, $repository, $author, $site, $description, $requirements);
                        $keyName = getPluginName($zip);
                        // on vérifie si le plugin existe déjà dans le cache
                        if (!array_key_exists($keyName, $cache)) {
                            $cache[$keyName] = array();
                        }
                        $cache[$keyName][$versionOrder] = $values;
                        // look for an icon
                        for ($i = 0; $i < $zip->numFiles; $i++) {
                            $filenameIcon = $zip->getNameIndex($i);
                            if (preg_match('#/icon\\.(jpg|png|gif)$#', $filenameIcon, $matches)) {
                                if (!array_key_exists($keyName, $cache_icons) or $cache_icons[$keyName][1] < $filedateEpoc) {
                                    // on garde l'icone de la dernière version
                                    $icon = $zip->getFromIndex($i);
                                    $stats = $zip->StatIndex($i);
                                    // keys in array('name', 'index', 'crc', 'size', 'mtime', 'comp_size', ' comp_methohd');
                                    $cache_icons[$keyName] = array($filedateEpoc, $matches[1], $stats['size'], $icon);
                                }
                                break;
                            }
                        }
                    } catch (Exception $e) {
                        error_log(date('Y-m-d H:i') . ' - fichier infos.xml incorrect pour le plugin ' . $f . ' - Ligne n°' . $e->getLine() . ': ' . $e->getMessage() . "\n", 3, dirname(__FILE__) . '/errors.log');
                    }
                }
                $zip->close();
            }
        }
    }
    return array($cache, $cache_icons);
}
Exemple #2
0
    /**
     * displayNavigationForm 
     * 
     * @return void
     */
    function displayNavigationForm()
    {
        $this->displayHeader();
        // Get Plugin Data
        $communicateNav = array();
        $shareNav = array();
        $sql = "SELECT `id`, `link`, `col`, `order`, `req`\n                FROM `fcms_navigation` \n                WHERE `col` = 3 \n                OR `col` = 4\n                AND `order` > 0\n                ORDER BY `order`";
        $rows = $this->fcmsDatabase->getRows($sql);
        if ($rows === false) {
            $this->fcmsError->displayError();
            $this->displayFooter();
            return;
        }
        foreach ($rows as $r) {
            if ($r['col'] == 3) {
                $communicateNav[] = $r;
            } else {
                $shareNav[] = $r;
            }
        }
        $message = '';
        if (isset($_SESSION['success'])) {
            $message = '<div class="alert-message success">';
            $message .= '<a class="close" href="#" onclick="$(this).up(\'div\').hide(); return false;">&times;</a>';
            $message .= T_('Changes Updated Successfully') . '</div>';
            unset($_SESSION['success']);
        }
        echo '
            <h2 id="navigation-heading">' . T_('Navigation') . '</h2>
            ' . $message . '
            <form action="config.php?view=navigation" method="post">

                <div class="row">

                    <div class="span8">
                        <h3>' . T_('Communicate') . '</h3>
                        <ol id="com_order" class="unstyled">';
        $communicateTotal = count($communicateNav);
        $i = 1;
        foreach ($communicateNav as $r) {
            echo '
                            <li id="com_' . $r['id'] . '">
                                <span class="order">' . $this->getOrderSelectBox('com', $r['id'], $communicateTotal, $r['order'], $i) . '</span>
                                <b>' . getPluginName($r['link']) . '</b>
                            </li>';
            $i++;
        }
        echo '
                        </ol>
                    </div><!-- /span8 -->

                    <div class="span8">
                        <h3>' . T_('Share') . '</h3>
                        <ol id="share_order" class="unstyled">';
        $shareTotal = count($shareNav);
        $i = 1;
        foreach ($shareNav as $r) {
            echo '
                            <li id="share_' . $r['id'] . '">
                                <span class="order">' . $this->getOrderSelectBox('share', $r['id'], $shareTotal, $r['order'], $i) . '</span>
                                <b>' . getPluginName($r['link']) . '</b>
                            </li>';
            $i++;
        }
        echo '
                        </ol>
                    </div><!-- /span8 -->

                </div><!-- /row -->

                <p><input type="submit" class="btn primary" id="submit-navigation" name="submit-navigation" value="' . T_('Save') . '"/></p>
            </form>
            <script type="text/javascript">
            $("#submit-navigation").hide();
            $(".order").each(function() {
                $(this).before(\'<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>\');
                $(this).hide();
            });

            $("#com_order").sortable({
                stop: function(event, ui) {
                    var arr = $("#com_order").sortable("toArray");
                    $.ajax({
                        url  : "config.php",
                        type : "POST",
                        data : {
                            "submit-ajax-navigation" : 1,
                            data                     : arr,
                            com_order                : 1
                        }
                    }).done(function(data) {
                        insertAlertMessage("success inline-alert", "navigation-heading", "' . T_('Changes Saved') . '");
                    }).fail(function() {
                        insertAlertMessage("error", "navigation-heading", "' . T_('An error occurred. Changes could not be saved.') . '");
                    });
                },
            });
            $("#share_order").sortable({
                stop: function(event, ui) {
                    var arr = $("#share_order").sortable("toArray");
                    $.ajax({
                        url  : "config.php",
                        type : "POST",
                        data : {
                            "submit-ajax-navigation" : 1,
                            data                     : arr,
                            share_order              : 1
                        }
                    }).done(function(data) {
                        insertAlertMessage("success inline-alert", "navigation-heading", "' . T_('Changes Saved') . '");
                    }).fail(function() {
                        insertAlertMessage("error", "navigation-heading", "' . T_('An error occurred. Changes could not be saved.') . '");
                    });
                },
            });
            </script>';
        $this->displayFooter();
    }
Exemple #3
0
/**
 * getAdminNavLinks 
 * 
 * @return void
 */
function getAdminNavLinks()
{
    $fcmsError = FCMS_Error::getInstance();
    $fcmsDatabase = Database::getInstance($fcmsError);
    $ret = array();
    $sql = "SELECT `link`, `col`\n            FROM `fcms_navigation` \n            WHERE `col` = 6\n            ORDER BY `order`";
    $rows = $fcmsDatabase->getRows($sql);
    if ($rows === false) {
        return $ret;
    }
    foreach ($rows as $r) {
        $ret[$r['link']] = array('url' => getPluginUrl($r['link']), 'text' => getPluginName($r['link']));
    }
    return $ret;
}