Esempio n. 1
0
 /**
  * write() should return string if $format is valid
  */
 public function test_write_returnsString_ifFormatIsValid()
 {
     $string = '\\cxds ing';
     $snippet = new Snippet();
     $snippet->read($string);
     return $this->assertEquals($string, $snippet->write());
 }
Esempio n. 2
0
 public function install($id)
 {
     $dir = FROG_ROOT . '/public/themes/' . $id . '/';
     $files = $this->scan_directory_recursively($dir, 'php');
     $data = array();
     $data['name'] = $id;
     // Layouts
     $layouts = array();
     $l = array();
     // Snippets
     $snippets = array();
     $s = array();
     foreach ($files as $file) {
         switch ($file['name']) {
             case 'layouts':
                 foreach ($file['content'] as $layout) {
                     $layouts[] = $layout['name'];
                     $l['name'] = Themr::theme_name($layout['name']);
                     $l['content_type'] = 'text/html';
                     $l['content'] = file_get_contents($layout['path']);
                     $layout = new Layout($l);
                     if (!$layout->save()) {
                         Flash::set('error', __('Layout has not been added. Name must be unique!'));
                     }
                 }
                 break;
             case 'snippets':
                 foreach ($file['content'] as $snippet) {
                     $snippets[] = $snippet['name'];
                     $s['name'] = $snippet['name'];
                     $s['filter_id'] = '';
                     $s['content'] = file_get_contents($snippet['path']);
                     $snippet = new Snippet($s);
                     if (!$snippet->save()) {
                         Flash::set('error', __('Snippet has not been added. Name must be unique!'));
                     }
                 }
                 break;
         }
     }
     // Serialize Layout and Snippet names
     $data['layout'] = serialize($layouts);
     $data['snippet'] = serialize($snippets);
     // Get Current Theme Info
     $theme_info = Themr::findTheme($id);
     // Save into Themr database table
     $theme = new Themr($data);
     if (!$theme->save()) {
         Flash::set('error', __('Theme has not been added. Name must be unique!'));
         redirect(get_url('plugin/themr'));
     } else {
         Flash::set('success', __('Theme <b>:name</b> has been added!', array(':name' => $theme_info['name'])));
         redirect(get_url('plugin/themr'));
     }
 }
Esempio n. 3
0
    public function testGeneratedHtml()
    {
        $settings = new SnippetSettings(array("app_id" => "foo", "name" => "Nikola Tesla"), NULL, NULL, array());
        $snippet = new Snippet($settings);
        $expectedHtml = <<<HTML
<script data-cfasync="false">
  window.intercomSettings = {"app_id":"foo","name":"Nikola Tesla"};
</script>
<script data-cfasync="false">(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/foo';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()</script>
HTML;
        $this->assertEquals($expectedHtml, $snippet->html());
    }
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 10) as $index) {
         Snippet::create([]);
     }
 }
Esempio n. 5
0
 public static function process($object, $strip = TRUE)
 {
     $object->documents = Snippet::documents($object->id);
     $object->votes = Snippet::votes($object->id);
     $object->syntax = Snippet::get_primary_syntax($object);
     return parent::process($object, $strip);
 }
 /**
  * Parses the snippet short code
  * @example [snippet id=123]
  * @example [snippet id=123 version=456]
  */
 public static function parse($arguments, $content = null, $parser = null)
 {
     //Ensure ID is pressent in the arguments
     if (!array_key_exists('id', $arguments)) {
         return '<p><b><i>' . _t('CodeBankShortCode.MISSING_ID_ATTRIBUTE', '_Short Code missing the id attribute') . '</i></b></p>';
     }
     //Fetch Snippet
     $snippet = Snippet::get()->byID(intval($arguments['id']));
     if (empty($snippet) || $snippet === false || $snippet->ID == 0) {
         return '<p><b><i>' . _t('CodeBankShortCode.SNIPPET_NOT_FOUND', '_Snippet not found') . '</i></b></p>';
     }
     //Fetch Text
     $snippetText = $snippet->SnippetText;
     //If the version exists fetch it, and replace the text with that of the version
     if (array_key_exists('version', $arguments)) {
         $version = $snippet->Version(intval($arguments['version']));
         if (empty($version) || $version === false || $version->ID == 0) {
             $snippetText = $version->Text;
         }
     }
     //Load CSS Requirements
     Requirements::css(CB_DIR . '/javascript/external/syntaxhighlighter/themes/shCore.css');
     Requirements::css(CB_DIR . '/javascript/external/syntaxhighlighter/themes/shCoreDefault.css');
     Requirements::css(CB_DIR . '/javascript/external/syntaxhighlighter/themes/shThemeDefault.css');
     //Load JS Requirements
     Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
     Requirements::javascript(CB_DIR . '/javascript/external/syntaxhighlighter/brushes/shCore.js');
     Requirements::javascript(CB_DIR . '/javascript/external/syntaxhighlighter/brushes/' . self::getBrushName($snippet->Language()->HighlightCode) . '.js');
     Requirements::javascriptTemplate(CB_DIR . '/javascript/CodeBankShortCode.template.js', array('ID' => $snippet->ID), 'snippet-highlightinit-' . $snippet->ID);
     //Render the snippet
     $obj = new ViewableData();
     return $obj->renderWith('CodeBankShortCode', array('ID' => $snippet->ID, 'Title' => $snippet->getField('Title'), 'Description' => $snippet->getField('Description'), 'SnippetText' => DBField::create_field('Text', $snippetText), 'HighlightCode' => strtolower($snippet->Language()->HighlightCode)));
 }
Esempio n. 7
0
 /**
  * Register the shortcode using WP's add_shortcode function
  *
  * @param string $fullpath /full/path/to/file.php
  * @param string $ext file extension. This is stripped to calculate the shortcode
  * @return void
  */
 public static function add_shortcode($fullpath, $ext)
 {
     $tag = self::get_shortname($fullpath, $ext);
     Snippet::map($tag, $fullpath);
     // success
     add_shortcode($tag, 'Phpsnippets\\Snippet::' . $tag);
 }
Esempio n. 8
0
 public function view($pathtotpl)
 {
     ob_start();
     Files::load($pathtotpl);
     $html = ob_get_contents();
     ob_clean();
     echo Snippet::parseSnippet($html, MODE);
 }
 public function fork($id)
 {
     $snippet = Snippet::find($id);
     if (!$snippet) {
         return Redirect::to("/");
     }
     return $this->create($snippet->snippet);
 }
Esempio n. 10
0
 /**
  * Constructs a new view with a particular name. The view name is the same as the HTML template file's name.
  * @param Controller $controller Associated controller
  * @param string     $name       of the view
  * @param string     $type       Render type of the view. Defaults to html.
  */
 public function __construct($controller, $name, $type = 'html')
 {
     parent::__construct('');
     if (!$controller instanceof Controller) {
         throw new InvalidArgumentException('Expected parameter 1 (controller) to be a Controller');
     }
     $this->controller = $controller;
     $this->name = $name;
     $this->type = $type;
 }
Esempio n. 11
0
function grouped_snippets()
{
    $snippets = Snippet::find(array('select' => "*", 'order' => "name ASC"));
    if ($snippets) {
        foreach ($snippets as $key => $snippet) {
            $new_array = $snippet->name[0];
            $new_sel_array[$new_array][] = array('id' => $snippet->id, 'name' => $snippet->name);
        }
        return json_decode(json_encode($new_sel_array));
    } else {
        return false;
    }
}
Esempio n. 12
0
function jksnippets_display_snippet($atts)
{
    $a = shortcode_atts(array('id' => false, 'slug' => false), $atts);
    $output = array();
    $snippet = false;
    if (!empty($a['id'])) {
        $snippet = new Snippet($a['id']);
    } else {
        if (!empty($a['slug'])) {
            $snippet = new Snippet();
            $snippet->getBySlug($a['slug']);
            if (!$snippet->post) {
                $output[] = 'snippet: "' . $a['slug'] . '" Not found';
            }
        }
    }
    if ($snippet) {
        $output[] = $snippet->snippet;
    }
    $output = implode("\n", $output);
    return $output;
}
Esempio n. 13
0
 public static function show($name, $default = '')
 {
     if (!isset(self::$cache)) {
         self::$cache = ci()->cache->get('cms_snippet_cache');
         if (self::$cache === false) {
             $cache = ci()->c_snippet_model->get_many();
             foreach ($cache as $idx => $record) {
                 self::$cache[$record->name] = $record->value;
             }
             ci()->cache->set('cms_snippet_cache', self::$cache);
         }
     }
     return isset(self::$cache[$name]) ? self::$cache[$name] : $default;
 }
 public function actionEdit($id)
 {
     $model = Snippet::model()->findByPk($id);
     if (!$model) {
         throw new CHttpException(404);
     }
     $data = Yii::app()->request->getPost('Snippet');
     if ($data) {
         $model->setAttributes($data);
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('edit', array('model' => $model));
 }
Esempio n. 15
0
 /**
  * 
  * @param string $snippet_name
  * @param array $vars
  * @param integer $cache_lifetime
  * @param boolean $cache_by_uri
  * @param array $tags
  * @param boolean $i18n
  * @return void
  */
 public static function render($snippet_name, $vars = NULL, $cache_lifetime = NULL, $cache_by_uri = FALSE, array $tags = array(), $i18n = NULL)
 {
     $view = Snippet::get($snippet_name, $vars);
     if ($view === NULL) {
         return NULL;
     }
     $cache_key = self::_cache_key($snippet_name, $cache_by_uri);
     if (!in_array($snippet_name, $tags)) {
         $tags[] = $snippet_name;
     }
     if (Kohana::$caching === TRUE and $cache_lifetime !== NULL and !Fragment::load($cache_key, (int) $cache_lifetime, $i18n)) {
         echo $view;
         Fragment::save_with_tags((int) $cache_lifetime, $tags);
     } else {
         if ($cache_lifetime === NULL) {
             echo $view;
         }
     }
 }
 /**
  * Performs the search against the snippets in the system
  *
  * @param {string} $keywords Keywords to search for
  * @param {int} $languageID Language to filter to
  * @param {int} $folderID Folder to filter to
  * @return {DataList} Data list pointing to the snippets in the results
  */
 public function doSnippetSearch($keywords, $languageID = false, $folderID = false)
 {
     $list = Snippet::get();
     if (isset($languageID) && !empty($languageID)) {
         $list = $list->filter('LanguageID', intval($languageID));
     }
     if (isset($folderID) && !empty($folderID)) {
         $list = $list->filter('FolderID', intval($folderID));
     }
     if (isset($keywords) && !empty($keywords)) {
         $SQL_val = Convert::raw2sql($keywords);
         if (DB::getConn() instanceof MySQLDatabase) {
             $list = $list->where("MATCH(\"Title\", \"Description\", \"Tags\") AGAINST('" . $SQL_val . "' IN BOOLEAN MODE)");
         } else {
             $list = $list->filterAny(array('Title:PartialMatch' => $SQL_val, 'Description:PartialMatch' => $SQL_val, 'Tags:PartialMatch' => $SQL_val));
         }
     }
     return $list;
 }
 /**
  * Deletes a folder
  * @param {stdClass} $data Data passed from ActionScript
  * @return {array} Standard response base
  */
 public function moveSnippet($data)
 {
     $response = CodeBank_ClientAPI::responseBase();
     //Ensure logged in
     if (!Permission::check('CODE_BANK_ACCESS')) {
         $response['status'] = 'EROR';
         $response['message'] = _t('CodeBankAPI.PERMISSION_DENINED', '_Permission Denied');
         return $response;
     }
     $snippet = Snippet::get()->byID(intval($data->id));
     if (empty($snippet) || $snippet === false || $snippet->ID == 0) {
         $response['status'] = "EROR";
         $response['message'] = _t('CodeBankAPI.SNIPPET_NOT_FOUND', '_Snippet not found');
         return $response;
     }
     if ($data->folderID != 0) {
         $snippetFolder = SnippetFolder::get()->byID(intval($data->folderID));
         if (empty($snippetFolder) || $snippetFolder === false || $snippetFolder->ID == 0) {
             $response['status'] = "EROR";
             $response['message'] = _t('CodeBankAPI.FOLDER_DOES_NOT_EXIST', '_Folder does not exist');
             return $response;
         }
         if ($snippetFolder->LanguageID != $snippet->LanguageID) {
             $response['status'] = "EROR";
             $response['message'] = _t('CodeBankAPI.LANGUAGE_NOT_SAME', '_Folder is not in the same language as the snippet');
             return $response;
         }
     }
     try {
         $snippet->FolderID = $data->folderID;
         $snippet->write();
         $response['status'] = "HELO";
     } catch (Exception $e) {
         $response['status'] = "EROR";
         $response['message'] = "Internal Server error occured";
     }
     return $response;
 }
Esempio n. 18
0
<?php

session_start();
if (isset($_SESSION["us"])) {
    include_once 'definition.php';
    $Snippet = new Snippet();
    if (isset($_POST['saveTitle'])) {
        // Update color
        $Snippet->updateTitle($_POST['id'], $_POST['title']);
        echo 'ok';
    }
    if (isset($_POST['saveDescription'])) {
        // Update color
        $Snippet->updateDescription($_POST['id'], $_POST['description']);
        echo 'ok';
    }
    if (isset($_POST['addSnippet'])) {
        // Update color
        $id = $Snippet->add($_POST['title'], $_POST['description']);
        echo $id;
    }
    if (isset($_POST['deleteSnippet'])) {
        // deleteSnippet
        $Snippet->deleteSnippet($_POST['id']);
        echo 'ok';
    }
    exit;
} else {
    echo 'logout';
}
Esempio n. 19
0
function add_intercom_snippet()
{
    $options = get_option('intercom');
    $raw_data = array("app_id" => WordPressEscaper::escJS($options['app_id']));
    if ($options['enableChat'] === 'true') {
        $raw_data['widget']['activator'] = '#IntercomDefaultWidget';
    }
    $snippet_settings = new SnippetSettings((array) apply_filters('intercom_snippet_rawdata', $raw_data), WordPressEscaper::escJS($options['secret']), wp_get_current_user());
    $snippet = new Snippet($snippet_settings);
    echo $snippet->html();
}
function add_intercom_snippet()
{
    $options = get_option('intercom');
    $snippet_settings = new SnippetSettings(array("app_id" => WordpressEscaper::escJS($options['app_id'])), WordpressEscaper::escJS($options['secret']), wp_get_current_user());
    $snippet = new Snippet($snippet_settings);
    echo $snippet->html();
}
Esempio n. 21
0
<?php

$snippet = Snippet::findByName('ru-login');
if (false !== $snippet) {
    eval('?' . '>' . $snippet->content_html);
    return true;
} else {
    ?>

    <p><label for="login-username"><?php 
    echo __('Username');
    ?>
</label> <input id="login-username" type="text" name="login[username]" value="" /></p>
    <p><label for="login-password"><?php 
    echo __('Password');
    ?>
</label> <input id="login-password" type="password" name="login[password]" value="" /></p>
    <input id="login-redirect" type="hidden" name="login[redirect]" value="<?php 
    echo BASE_URL . CURRENT_URI . URL_SUFFIX;
    ?>
" />
    <p><label class="checkbox" for="login-remember-me"><?php 
    echo __('Stay logged in');
    ?>
</label> <input id="login-remember-me" type="checkbox" class="checkbox" name="login[remember]" value="checked" /></p>
    <p><label for="submit"> </label><input id="submit_btn" class="btn submit" type="submit" accesskey="s" value="<?php 
    echo __('Log in');
    ?>
" /></p>

<?php 
Esempio n. 22
0
<?php

Route::get('snippets/search/(:any)', function ($term) {
    $field = Input::get('field', 'title');
    $key = implode('-', array('title', 'search', $field, $term));
    if (!($results = Cache::get($key))) {
        $results = Snippet::search($field, $term);
        Cache::put($key, $results, 10);
    }
    $count = Input::get('count', 20);
    $page = Input::get('page', 0);
    return array_slice($results, $page * $count, $count);
});
 /**
  * Handles moving of a snippet when the tree is reordered
  * @param {SS_HTTPRequest} $request HTTP Request
  */
 public function moveSnippet(SS_HTTPRequest $request)
 {
     $snippet = Snippet::get()->byID(intval($request->getVar('ID')));
     if (empty($snippet) || $snippet === false || $snippet->ID == 0) {
         $this->response->setStatusCode(403, _t('CodeBank.SNIPPIT_NOT_EXIST', '_Snippit does not exist'));
         return;
     }
     $parentID = $request->getVar('ParentID');
     if (strpos($parentID, 'language-') !== false) {
         $lang = SnippetLanguage::get()->byID(intval(str_replace('language-', '', $parentID)));
         if (empty($lang) || $lang === false || $lang->ID == 0) {
             $this->response->setStatusCode(403, _t('CodeBank.LANGUAGE_NOT_EXIST', '_Language does not exist'));
             return;
         }
         if ($lang->ID != $snippet->LanguageID) {
             $this->response->setStatusCode(403, _t('CodeBank.CANNOT_MOVE_TO_LANGUAGE', '_You cannot move a snippet to another language'));
             return;
         }
         //Move out of folder
         DB::query('UPDATE "Snippet" SET "FolderID"=0 WHERE "ID"=' . $snippet->ID);
         $this->response->addHeader('X-Status', rawurlencode(_t('CodeBank.SNIPPET_MOVED', '_Snippet moved successfully')));
         return;
     } else {
         if (strpos($parentID, 'folder-') !== false) {
             $folder = SnippetFolder::get()->byID(intval(str_replace('folder-', '', $parentID)));
             if (empty($folder) || $folder === false || $folder->ID == 0) {
                 $this->response->setStatusCode(403, _t('CodeBank.FOLDER_NOT_EXIST', '_Folder does not exist'));
                 return;
             }
             if ($folder->LanguageID != $snippet->LanguageID) {
                 $this->response->setStatusCode(403, _t('CodeBank.CANNOT_MOVE_TO_FOLDER', '_You cannot move a snippet to a folder in another language'));
                 return;
             }
             //Move to folder
             DB::query('UPDATE "Snippet" SET "FolderID"=' . $folder->ID . ' WHERE "ID"=' . $snippet->ID);
             $this->response->addHeader('X-Status', rawurlencode(_t('CodeBank.SNIPPET_MOVED', '_Snippet moved successfully')));
             return;
         }
     }
     $this->response->setStatusCode(403, _t('CodeBank.UNKNOWN_PARENT', '_Unknown Parent'));
 }
</div>
<div class="row">
<div class="col-md-6">
<p class="description"></p>
</div>
<div class="col-md-6">
<a href="" target="_blank" class="btn green_btn preview_btn">Go to Site</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php 
echo Snippet::get('google-analytics');
Javascript::add('public/assets/js/vendor.js', 'frontend', 1);
Javascript::add('public/assets/js/app.js', 'frontend', 2);
Javascript::load();
/*
<div class="loading"></div>
<style rel="stylesheet">
.loading{
background: url('https://dl.dropbox.com/u/23834858/fotos/loading.gif') no-repeat center center rgba(51, 51, 51, 0.82);
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
margin: 0 auto;
display: block;
Esempio n. 25
0
 public function includeSnippet($name)
 {
     $snippet = Snippet::findByName($name);
     if (false !== $snippet) {
         eval('?>' . $snippet->content_html);
         return true;
     }
     return false;
 }
Esempio n. 26
0
function end_snippet()
{
    Snippet::end();
}
Esempio n. 27
0
 /**
  * Saves the edited Snippet.
  *
  * @todo Merge _edit() and edit()
  *
  * @param string $id Snippet id.
  */
 private function _edit($id)
 {
     $data = $_POST['snippet'];
     $data['id'] = $id;
     // CSRF checks
     if (isset($_POST['csrf_token'])) {
         $csrf_token = $_POST['csrf_token'];
         if (!SecureToken::validateToken($csrf_token, BASE_URL . 'snippet/edit')) {
             Flash::set('post_data', (object) $data);
             Flash::set('error', __('Invalid CSRF token found!'));
             Observer::notify('csrf_token_invalid', AuthUser::getUserName());
             redirect(get_url('snippet/edit/' . $id));
         }
     } else {
         Flash::set('post_data', (object) $data);
         Flash::set('error', __('No CSRF token found!'));
         Observer::notify('csrf_token_not_found', AuthUser::getUserName());
         redirect(get_url('snippet/edit/' . $id));
     }
     $snippet = new Snippet($data);
     if (!$snippet->save()) {
         Flash::set('post_data', (object) $data);
         Flash::set('error', __('Snippet :name has not been saved. Name must be unique!', array(':name' => $snippet->name)));
         redirect(get_url('snippet/edit/' . $id));
     } else {
         Flash::set('success', __('Snippet :name has been saved!', array(':name' => $snippet->name)));
         Observer::notify('snippet_after_edit', $snippet);
     }
     // save and quit or save and continue editing?
     if (isset($_POST['commit'])) {
         redirect(get_url('snippet'));
     } else {
         redirect(get_url('snippet/edit/' . $id));
     }
 }
Esempio n. 28
0
<?php

session_start();
if (isset($_SESSION["us"])) {
    include_once 'definition.php';
    $Snippet = new Snippet();
    $jsondata = array();
    if (isset($_GET['all'])) {
        $jsondata = $Snippet->getAll();
    }
    if (isset($_GET['list'])) {
        $jsondata = $Snippet->getList($_GET['listIds']);
    }
    if (isset($_GET['numTotal'])) {
        $jsondata = $Snippet->getNumTotal();
    }
    header('Content-type: application/json; charset=utf-8');
    echo json_encode($jsondata);
    exit;
} else {
    echo 'logout';
}
Esempio n. 29
0
<?php

$snippet = Snippet::findByName('ru-confirmation');
if (false !== $snippet) {
    eval('?' . '>' . $snippet->content_html);
    return true;
} else {
    ?>

<p><label for="email">Email :</label> <input id="email" type="text" name="email" value="" /></p>
<p><label for="rand_key">Authorisation Code :</label> <input id="rand_key" type="text" name="rand_key" value="" /></p>
<p><label for="submit"></label><input id="submit_btn" class="btn submit" type="submit" accesskey="s" value="Activate your account" /></p>

<?php 
}
Esempio n. 30
0
 public function read()
 {
     $this->file = DIAMONDMVC_ROOT . '/templates/' . $this->name . '/index.php';
     return parent::read();
 }