예제 #1
0
function nm_save_settings()
{
    global $NMPAGEURL, $NMPRETTYURLS, $NMLANG, $NMSHOWEXCERPT, $NMEXCERPTLENGTH, $NMPOSTSPERPAGE, $NMRECENTPOSTS, $NMSETTING;
    $backup = array('page_url' => $NMPAGEURL, 'pretty_urls' => $NMPRETTYURLS);
    # parse $_POST
    $NMPAGEURL = $_POST['page-url'];
    $NMPRETTYURLS = isset($_POST['pretty-urls']) ? 'Y' : '';
    $NMLANG = $_POST['language'];
    $NMSHOWEXCERPT = $_POST['show-excerpt'] ? 'Y' : '';
    $NMEXCERPTLENGTH = intval($_POST['excerpt-length']);
    $NMPOSTSPERPAGE = intval($_POST['posts-per-page']);
    $NMRECENTPOSTS = intval($_POST['recent-posts']);
    # new settings since 3.0
    $NMSETTING = array();
    $NMSETTING['archivesby'] = $_POST['archivesby'];
    $NMSETTING['readmore'] = $_POST['readmore'];
    $NMSETTING['titlelink'] = $_POST['titlelink'];
    $NMSETTING['gobacklink'] = $_POST['gobacklink'];
    $NMSETTING['images'] = $_POST['images'];
    $NMSETTING['imagewidth'] = $_POST['imagewidth'];
    $NMSETTING['imageheight'] = $_POST['imageheight'];
    $NMSETTING['imagecrop'] = isset($_POST['imagecrop']);
    $NMSETTING['imagealt'] = isset($_POST['imagealt']);
    $NMSETTING['imagelink'] = isset($_POST['imagelink']);
    $NMSETTING['enablecustomsettings'] = isset($_POST['enablecustomsettings']);
    $NMSETTING['customsettings'] = get_magic_quotes_gpc() == 0 ? $_POST['customsettings'] : stripslashes($_POST['customsettings']);
    # write settings to file
    if (nm_settings_to_xml()) {
        nm_generate_sitemap();
        nm_display_message(i18n_r('news_manager/SUCCESS_SAVE'));
    } else {
        nm_display_message(i18n_r('news_manager/ERROR_SAVE'), true);
    }
    # should we update .htaccess?
    if ($NMPRETTYURLS == 'Y') {
        if ($backup['pretty_urls'] != 'Y' || $backup['page_url'] != $NMPAGEURL) {
            nm_display_message(sprintf(i18n_r('news_manager/UPDATE_HTACCESS'), 'load.php?id=news_manager&htaccess'), true);
        }
    }
    # clear registered image sizes for pic.php - since 3.2
    foreach (glob(NMDATAPATH . 'images.*.txt') as $file) {
        unlink($file);
    }
}
예제 #2
0
function nm_admin_panel()
{
    global $NMPAGEURL;
    $posts = nm_get_posts(true);
    if (nm_post_files_differ($posts)) {
        nm_update_cache();
        $posts = nm_get_posts(true);
        if (nm_post_files_differ($posts)) {
            nm_display_message('<b>Warning:</b> Post files/cache mismatch', true);
        } else {
            nm_display_message('Post cache file has been updated', false);
        }
        // not translated
    }
    ?>
  <h3 class="floated"><?php 
    i18n('news_manager/PLUGIN_NAME');
    ?>
</h3>
  <div class="edit-nav clearfix">
    <a href="#" id="filter-button" ><?php 
    i18n('FILTER');
    ?>
</a>
    <a href="load.php?id=news_manager&amp;edit"><?php 
    i18n('news_manager/NEW_POST');
    ?>
</a>
    <a href="load.php?id=news_manager&amp;settings"><?php 
    i18n('news_manager/SETTINGS');
    ?>
</a>
  </div>
  <?php 
    if (!empty($posts)) {
        ?>
    <div id="filter-search">
      <form>
        <input type="text" class="text" id="tokens" placeholder="<?php 
        echo lowercase(strip_tags(i18n_r('FILTER')));
        ?>
..." />
        &nbsp;
        <a href="load.php?id=news_manager" class="cancel"><?php 
        i18n('news_manager/CANCEL');
        ?>
</a>
      </form>
    </div>
    <table id="posts" class="highlight">
    <tr>
      <th><?php 
        i18n('news_manager/POST_TITLE');
        ?>
</th>
      <th style="text-align: right;"><?php 
        i18n('news_manager/DATE');
        ?>
</th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
    <?php 
        foreach ($posts as $post) {
            $title = stripslashes($post->title);
            $date = shtDate($post->date);
            $url = nm_get_url('post') . $post->slug;
            $url = nm_patch_i18n_url($url);
            ?>
      <tr>
        <td class="posttitle">
          <a href="load.php?id=news_manager&amp;edit=<?php 
            echo $post->slug;
            ?>
" title="<?php 
            i18n('news_manager/EDIT_POST');
            ?>
: <?php 
            echo $title;
            ?>
">
            <?php 
            echo $title;
            ?>
          </a>
        </td>
        <td style="text-align: right;">
          <?php 
            if (strtotime($post->date) > time()) {
                echo '<span style="color:#aaa">', $date, '</span>';
            } else {
                echo '<span>', $date, '</span>';
            }
            ?>
        </td>
        <td style="width: 20px;text-align: center;">
          <?php 
            if ($post->private == 'Y') {
                echo '<span style="color: #aaa;">P</span>';
            }
            ?>
        </td>
        <td class="secondarylink">
          <?php 
            if ($NMPAGEURL && $NMPAGEURL != '') {
                ?>
            <a href="<?php 
                echo $url;
                ?>
" target="_blank" title="<?php 
                i18n('news_manager/VIEW_POST');
                ?>
: <?php 
                echo $title;
                ?>
">
              #
            </a>
          <?php 
            }
            ?>
        </td>
        <td class="delete">
          <a href="load.php?id=news_manager&amp;delete=<?php 
            echo $post->slug;
            ?>
" class="nm_delconfirm" title="<?php 
            i18n('news_manager/DELETE_POST');
            ?>
: <?php 
            echo $title;
            ?>
?">
            &times;
          </a>
        </td>
      </tr>
      <?php 
        }
        ?>
    </table>
    <p>
      <b><?php 
        echo count($posts);
        ?>
</b>
      <?php 
        i18n('news_manager/POSTS');
        ?>
    </p>

    <script>
    $(document).ready(function() {
      // filter button opens up filter dialog
      $("#filter-button").on("click", function($e) {
        $e.preventDefault();
        $("#filter-search").slideToggle();
        $(this).toggleClass("current");
        $("#filter-search #tokens").focus();
      });
      // ignore enter key in filter form
      $("#filter-search #tokens").keydown(function($e) {
        if($e.keyCode == 13) {
          $e.preventDefault();
        }
      });
      // close filter dialog on cancel
      $("#filter-search .cancel").on("click", function($e) {
        $e.preventDefault();
        $("#posts tr").show();
        $('#filter-button').toggleClass("current");
        $("#filter-search #tokens").val("");
        $("#filter-search").slideUp();
      });
      // filter table, see:
      // http://kobikobi.wordpress.com/2008/09/15/using-jquery-to-filter-table-rows/
      $("#posts tr:has(td.posttitle)").each(function() {
        var t = $(this).find('td.posttitle').text().toLowerCase();
        $("<td class='indexColumn'></td>")
        .hide().text(t).appendTo(this);
      });
      $("#tokens").keyup(function() {
        var s = $(this).val().toLowerCase().split(" ");
      $("#posts tr:hidden").show();
      $.each(s, function(){
           $("#posts tr:visible .indexColumn:not(:contains('"
              + this + "'))").parent().hide();
        });
      });
      // confirm delete 
      $('.nm_delconfirm').on('click', function () {
        return confirm($(this).attr("title"));
      });
    });
    </script>

    <?php 
    }
}
예제 #3
0
파일: posts.php 프로젝트: hatasu/appdroid
function nm_restore_post($backup)
{
    if (strpos($backup, ':')) {
        # revert to the previous version of a post
        list($current, $backup) = explode(':', $backup);
        $current .= '.xml';
        $backup .= '.xml';
        if (dirname(realpath(NMPOSTPATH . $current)) == realpath(NMPOSTPATH) && dirname(realpath(NMBACKUPPATH . $backup)) == realpath(NMBACKUPPATH)) {
            // no path traversal
            if (file_exists(NMPOSTPATH . $current) && file_exists(NMBACKUPPATH . $backup)) {
                $status = unlink(NMPOSTPATH . $current) && nm_rename_file(NMBACKUPPATH . $backup, NMPOSTPATH . $backup) && nm_update_cache();
            }
        }
    } else {
        # restore the deleted post
        $backup .= '.xml';
        if (dirname(realpath(NMBACKUPPATH . $backup)) == realpath(NMBACKUPPATH)) {
            // no path traversal
            if (file_exists(NMBACKUPPATH . $backup)) {
                $status = nm_rename_file(NMBACKUPPATH . $backup, NMPOSTPATH . $backup) && nm_update_cache();
            }
        }
    }
    if (@$status) {
        nm_generate_sitemap();
        nm_display_message(i18n_r('news_manager/SUCCESS_RESTORE'));
    } else {
        nm_display_message(i18n_r('news_manager/ERROR_RESTORE'), true);
    }
}