public function githubHook($route)
 {
     $github = new Github();
     $http = herbert('http');
     $fd = get_option('gitcontent_settings');
     if ($route != $fd['route']) {
         return;
     }
     $args = ['meta_query' => [['key' => '_gitcontent_file', 'value' => '', 'compare' => '!=']]];
     $posts = get_posts($args);
     foreach ($posts as $post) {
         $file = get_post_meta($post->ID, '_gitcontent_file', true);
         $inputs = get_option('gitcontent_settings');
         $response = $github->checkFile($inputs, $file);
         $markdownFile = Helper::storagePath($post->ID);
         if ($response === false) {
             return;
         }
         if ($github->downloadFile($inputs, $response, $markdownFile) === false) {
             return;
         }
         wp_update_post(['ID' => $post->ID, 'post_content' => (new ParsedownExtra())->text(file_get_contents($markdownFile))], false);
     }
     echo 'Done';
 }
 /**
  * Handles the save of metabox values.
  *
  * @param $postID
  *
  * @return mixed
  */
 public function save($postID)
 {
     $validator = new Validator();
     $http = herbert('http');
     if (!$validator->validateSave($this->nonce, $this->name, $postID)) {
         return $postID;
     }
     update_post_meta($postID, $this->metaKey, $http->get('apiposts_enable_api'));
 }
Exemplo n.º 3
0
 private function __construct()
 {
     $csrfTokenManager = new CsrfTokenManager();
     $validator = Validation::createValidator();
     $localCode = substr(get_locale(), 0, 2);
     $translator = new Translator($localCode);
     $translator->addLoader('xlf', new XliffFileLoader());
     $translator->addResource('xlf', VENDOR_FORM_DIR . '/Resources/translations/validators.en.xlf', $localCode, 'validators');
     $translator->addResource('xlf', VENDOR_VALIDATOR_DIR . '/Resources/translations/validators.en.xlf', $localCode, 'validators');
     $twig = herbert('Twig_Environment');
     $formEngine = new TwigRendererEngine(array(DEFAULT_FORM_THEME));
     $formEngine->setEnvironment($twig);
     $twig->addExtension(new TranslationExtension($translator));
     $twig->addExtension(new FormExtension(new TwigRenderer($formEngine, $csrfTokenManager)));
     $this->formFactory = Forms::createFormFactoryBuilder()->addExtension(new CsrfExtension($csrfTokenManager))->addExtension(new ValidatorExtension($validator))->getFormFactory();
 }
 /**
  * Handles the save of metabox values.
  *
  * @param $postID
  *
  * @return mixed
  */
 public function save($postID)
 {
     $validator = new Validator();
     $github = new Github();
     $http = herbert('http');
     if (!$validator->validateSave($this->nonce, $this->name, $postID)) {
         return $postID;
     }
     $file = trim($http->get('gitcontent_file'));
     if (strlen($file) == 0) {
         Notifier::success('Git Content: Disabled', true);
         update_post_meta($postID, $this->metaKey, '');
         return;
     }
     $inputs = get_option((new AdminController())->optionName);
     $response = $github->checkFile($inputs, $file);
     $markdownFile = Helper::storagePath($postID);
     if ($response === false) {
         Notifier::error('Git Content: Something went wrong, check the name of your file.', true);
         return;
     }
     if ($github->downloadFile($inputs, $response, $markdownFile) === false) {
         Notifier::error('Git Content: Something went wrong, couldn\'t download file', true);
         return;
     }
     /**
      * Should really be using wp_insert_post_data filter
      * but it fires to early, requires double update.
      * Will update later. See app/filters.php
      **/
     remove_action('save_post', [$this, 'save']);
     wp_update_post(['ID' => $postID, 'post_content' => (new ParsedownExtra())->text(file_get_contents($markdownFile))], false);
     add_action('save_post', [$this, 'save']);
     /**
      * End
      **/
     Notifier::success('Git Content: Success using ' . $file, true);
     update_post_meta($postID, $this->metaKey, $file);
 }
 /**
  * Checks to save if its okay to save/update a metabox.
  *
  * @param $nonce
  * @param $name
  * @param $postID
  *
  * @return bool
  */
 public function validateSave($nonce, $name, $postID)
 {
     $http = herbert('http');
     if (!$http->has($nonce)) {
         return false;
     }
     if (!wp_verify_nonce($http->get($nonce), $name)) {
         return false;
     }
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return false;
     }
     if ($http->get('post_type') == 'page') {
         if (!current_user_can('edit_page', $postID)) {
             return false;
         }
     } else {
         if (!current_user_can('edit_post', $postID)) {
             return false;
         }
     }
     return true;
 }
 /**
  * Gets the url to a route.
  *
  * @param  string $name
  * @param  array  $args
  * @param  array  $query
  * @return string
  */
 function route_url($name, $args = [], $query = [])
 {
     return add_query_arg($query, herbert('router')->url($name, $args));
 }
<?php

// Add the twig extensions for playing with WP theme parts...
herbert('Twig_Environment')->addExtension(new TestHerbert\TwigExtension\WordpressTemplateExtension());
// set constants for SymfonyForm
define('DEFAULT_FORM_THEME', 'form_div_layout.html.twig');
define('VENDOR_DIR', realpath(__DIR__ . '/../vendor'));
define('VENDOR_FORM_DIR', VENDOR_DIR . '/symfony/form');
define('VENDOR_VALIDATOR_DIR', VENDOR_DIR . '/symfony/validator');
define('VENDOR_TWIG_BRIDGE_DIR', VENDOR_DIR . '/symfony/twig-bridge');
define('VIEWS_DIR', realpath(__DIR__ . '/../reources/views'));
<?php

herbert()->bind('Socializr\\Repositories\\Set\\SetInterface', 'Socializr\\Repositories\\Set\\SetRepository');
herbert()->bind('Socializr\\Repositories\\Share\\ShareInterface', 'Socializr\\Repositories\\Share\\ShareRepository');