Ejemplo n.º 1
0
 /**
  *
  *
  */
 public function testShortcodeGeneration()
 {
     $info = array('shortcode' => '[myshortcode x="1"]');
     $result = Phpsnippets\Base::get_shortcode($info, 'myshortcode');
     $this->assertTrue($result == $info['shortcode'], 'The shortcode was not generated properly.');
     $info = array('content' => '');
     $result = Phpsnippets\Base::get_shortcode($info, 'myshortcode');
     $this->assertTrue($result == '[myshortcode][/myshortcode]', 'The shortcode was not generated properly.');
     $info = array('params' => array('x' => '', 'y' => '456'));
     $result = Phpsnippets\Base::get_shortcode($info, 'myshortcode');
     $this->assertTrue($result == '[myshortcode x="" y="456"]', 'The shortcode was not generated properly.');
 }
Ejemplo n.º 2
0
        // A little cleanup before we handoff to save_definition_filter
        $snippet_dirs = Phpsnippets\Base::get_value($_POST, 'snippet_dirs', array());
        $snippet_suffix = Phpsnippets\Base::get_value($_POST, 'snippet_suffix');
        $show_builtin_snippets = Phpsnippets\Base::get_value($_POST, 'show_builtin_snippets');
        $show_tmce_button = Phpsnippets\Base::get_value($_POST, 'show_tmce_button');
        $snippet_suffix = !empty($snippet_suffix) ? trim(strip_tags($snippet_suffix)) : '.snippet.php';
        foreach ($snippet_dirs as $i => $dir) {
            // remove empty val
            if (trim($dir) == '') {
                unset($snippet_dirs[$i]);
            }
            if (!PhpSnippets\Base::dir_exists($dir)) {
                $warns = PhpSnippets\Base::$warnings;
            }
        }
        $data['msg'] .= sprintf('<div class="updated"><p>%s</p></div>', 'Your settings have been updated!');
        $ps_data['snippet_dirs'] = $snippet_dirs;
        $ps_data['snippet_suffix'] = $snippet_suffix;
        $ps_data['show_builtin_snippets'] = $show_builtin_snippets;
        $ps_data['show_tmce_button'] = $show_tmce_button;
        update_option(Phpsnippets\Base::db_key, $ps_data);
        $data['snippet_dirs'] = $snippet_dirs;
        $data['warnings'] = $warns;
        $data['snippet_suffix'] = $snippet_suffix;
        $data['show_builtin_snippets'] = $show_builtin_snippets;
        $data['show_tmce_button'] = $show_tmce_button;
    }
}
$data['content'] .= Phpsnippets\Base::load_view('settings.php', $data);
print Phpsnippets\Base::load_view('default.php', $data);
/*EOF*/
Ejemplo n.º 3
0
    $existing_shortcodes = array_keys($shortcode_tags);
    // Load up data
    $ps_data = get_option(Phpsnippets\Base::db_key, array());
    $defined_dirs = Phpsnippets\Base::get_value($ps_data, 'snippet_dirs', array());
    $ext = Phpsnippets\Base::get_value($ps_data, 'snippet_suffix', '.php');
    $include_built_in = Phpsnippets\Base::get_value($ps_data, 'show_builtin_snippets', true);
    // Set any placeholders we want to support in directory names
    Phpsnippets\Base::set_placeholder('ABSPATH', ABSPATH);
    // Get all snippets in all dirs
    $dirs = Phpsnippets\Base::get_dirs($defined_dirs, $include_built_in);
    PhpSnippets\Widget::setDirs($dirs);
    PhpSnippets\Widget::setExt($ext);
    // Loop thru each dir
    foreach ($dirs as $d => $d_exists) {
        $snippets = (array) Phpsnippets\Base::get_snippets($d, $ext);
        // Loop thru each file
        foreach ($snippets as $s) {
            Phpsnippets\Base::add_shortcode($s, $ext);
        }
    }
    // Register Ajax Calls
    Phpsnippets\Ajax::$controllers['dir_snippets'] = PHP_SNIPPETS_PATH . '/ajax-controllers/dir_snippets.php';
    Phpsnippets\Ajax::$controllers['get_snippet_shortcode'] = PHP_SNIPPETS_PATH . '/ajax-controllers/get_snippet_shortcode.php';
    Phpsnippets\Ajax::$controllers['list_snippets'] = PHP_SNIPPETS_PATH . '/ajax-controllers/list_snippets.php';
    Phpsnippets\Ajax::$controllers['list_directory'] = PHP_SNIPPETS_PATH . '/ajax-controllers/list_directory.php';
    foreach (Phpsnippets\Ajax::$controllers as $shortname => $path) {
        add_action('wp_ajax_' . $shortname, 'Phpsnippets\\Ajax::' . $shortname);
    }
});
add_action('widgets_init', 'PhpSnippets\\Widget::register_this_widget');
/*EOF*/
<?php

/*------------------------------------------------------------------------------
Fires when a user chooses a snippet in the dropdown in the PHP Snippets widget:
Given a filepath, this returns the sample shortcode for that snippet.
------------------------------------------------------------------------------*/
if (!defined('PHP_SNIPPETS_PATH')) {
    exit('No direct script access allowed');
}
if (!current_user_can('edit_posts')) {
    die('You do not have permission to do that.');
}
if (!isset($_POST['snippet_path']) || empty($_POST['snippet_path'])) {
    print 'Missing snippet_path.';
    return;
}
$ps_data = get_option(Phpsnippets\Base::db_key, array());
$ext = Phpsnippets\Base::get_value($ps_data, 'snippet_suffix', '.php');
$shortname = Phpsnippets\Base::get_shortname($_POST['snippet_path'], $ext);
$info = PhpSnippets\Base::get_snippet_info($_POST['snippet_path']);
print PhpSnippets\Base::get_shortcode($info, $shortname);
return;
/*EOF*/