コード例 #1
0
ファイル: App.php プロジェクト: noprotocol/plandown
 /**
  * Public methods are accessable as file and must return a View object.
  * "/index.html"
  * @return View
  */
 function index()
 {
     $form = new Form(['method' => 'post', 'fields' => ['subdomain' => new Input(['name' => 'subdomain', 'class' => 'form-control', 'label' => 'JIRA Subdomain']), new Input(['type' => 'submit', 'class' => 'btn btn-primary', 'value' => 'Continue'])]]);
     $values = $form->import($error);
     if ($form->isSent()) {
         redirect($values['subdomain'] . '/');
     }
     return $form;
 }
コード例 #2
0
 public function generateContent()
 {
     Bridge::initialize();
     $value = chunk_split(base64_encode(Json::encode($this->createSnapshot())));
     $form = new Form(['legend' => 'Compare snapshot', 'fields' => ['direction' => new Input(['name' => 'mode', 'type' => 'select', 'options' => ['as source', 'as target'], 'value' => 'as source']), 'btn' => new Input(['name' => 'compare', 'type' => 'submit', 'class' => 'btn btn-primary', 'value' => 'Compare']), 'snapshot' => new Input(['name' => 'snapshot', 'type' => 'textarea', 'rows' => 30, 'class' => 'form-control', 'style' => 'font-family: monospace;', 'value' => $value])]]);
     $data = $form->import();
     if ($form->isSent() === false) {
         return $form;
     }
     $newValues = $this->createSnapshot();
     $newSnapshot = chunk_split(base64_encode(Json::encode($newValues)));
     if ($data['snapshot'] === $newSnapshot) {
         return new Dialog('No changes detected', 'No changes detected in the <b>wp_options</b> table.');
     }
     $oldValues = Json::decode(base64_decode($data['snapshot']), true);
     if ($data['direction'] === 'as target') {
         $diff = $this->compare($newValues, $oldValues);
     } else {
         $diff = $this->compare($oldValues, $newValues);
     }
     return new Template('sledgehammer/wordpress/templates/diff.php', $diff);
 }
コード例 #3
0
 public function generateContent()
 {
     Bridge::initialize();
     $repo = Repository::instance();
     $lastPosts = $repo->allTaxonomies()->orderByDescending('id')->take(25);
     //['AND', 'status !=' => 'auto-draft', 'type !=' => 'revision']
     $options = $lastPosts->select(function ($taxonomy) {
         return $taxonomy->id . ') ' . $taxonomy->taxonomy . ' - ' . $taxonomy->term->name;
     }, 'id')->toArray();
     \Sledgehammer\array_key_unshift($options, 'custom', 'Custom ID');
     $form = new Form(['method' => 'GET', 'fields' => ['taxonomy' => new Input(['name' => 'id', 'class' => 'form-control', 'type' => 'select', 'options' => $options, 'label' => 'Select post', 'value' => $lastPosts[0]->id]), 'id' => new Input(['name' => 'custom', 'class' => 'form-control', 'label' => 'Custom ID']), 'varname' => new Input(['name' => 'varname', 'class' => 'form-control', 'label' => 'Variable name', 'value' => '$taxonomy'])], 'actions' => [new Button('Export', ['class' => 'btn btn-primary'])]]);
     $values = $form->import();
     if ($form->isSent()) {
         if ($values['id'] !== '') {
             $form->setValue(['taxonomy' => $values['id']]);
             $id = $values['id'];
         } else {
             $id = $values['taxonomy'];
         }
         if ($id === 'custom') {
             return $form;
         }
         $taxonomy = $repo->getTaxonomy($id);
         $var = $values['varname'];
         $mustSave = false;
         $php = $var . ' = Sledgehammer\\Wordpress\\Migrate::taxonomy(' . var_export($taxonomy->taxonomy, true) . ', ' . var_export($taxonomy->term->name, true) . ', ' . var_export($taxonomy->term->slug, true) . ');';
         if (count($taxonomy->term->getMeta()) > 0) {
             $php .= $var . '->setMeta(' . var_export($taxonomy->term->getMeta(), true) . ");\n";
             $mustSave = true;
         }
         $php .= "\n\n";
         //            if ($taxonomy->posts->count() > 0) {
         //                $php .= "\$repo->resolveProperty(".$var.", 'posts', ['model' => 'Taxonomy']);\n";
         //                foreach ($taxonomy->posts as $post) {
         //                    $php .= $var."->posts[] = ";
         //                    $phpPost = "\$repo->onePost(['AND', 'type' => ".var_export($post->type, true).", 'slug' => ".var_export($post->slug, true)."])";
         //                    if ($post->order == '0') {
         //                        $php .= $phpPost.";\n";
         //                    } else {
         //                        $php .= "new Sledgehammer\Orm\Junction(".$phpPost.", ['order' => ".var_export($post->order, true)."]);\n";
         //                    }
         //                }
         //                $php .= $var."->count = ".$var."->posts->count();\n";
         //                $mustSave = true;
         //            }
         if ($mustSave) {
             $php .= "\$repo->saveTaxonomy(" . $var . ");\n";
         }
         return new Template('sledgehammer/wordpress/templates/export_post.php', ['form' => $form, 'php' => $php]);
     }
     return $form;
 }
コード例 #4
0
ファイル: FormTest.php プロジェクト: sledgehammer/mvc
 public function test_import()
 {
     $form = new Form(['action' => '/', 'fields' => ['key1' => new Input(['name' => 'field1'])]]);
     $data = $form->import($error, ['field1' => 'value1']);
     $this->assertEquals(['key1' => 'value1'], $data);
 }
コード例 #5
0
ファイル: ExportPost.php プロジェクト: sledgehammer/wordpress
 public function generateContent()
 {
     Bridge::initialize();
     $repo = Repository::instance();
     $lastPosts = $repo->allPosts(['AND', 'status !=' => 'auto-draft', 'type !=' => 'revision'])->orderByDescending('id')->take(25);
     $options = $lastPosts->select(function ($post) {
         return $post->id . ') ' . $post->type . ' - ' . $post->slug;
     }, 'id')->toArray();
     \Sledgehammer\array_key_unshift($options, 'custom', 'Custom ID');
     $form = new Form(['method' => 'GET', 'fields' => ['post' => new Input(['name' => 'id', 'class' => 'form-control', 'type' => 'select', 'options' => $options, 'label' => 'Select post', 'value' => $lastPosts[0]->id]), 'id' => new Input(['name' => 'custom', 'class' => 'form-control', 'label' => 'Custom ID']), 'varname' => new Input(['name' => 'varname', 'class' => 'form-control', 'label' => 'Variable name', 'value' => '$post']), 'export_defaults' => new Input(['name' => 'export_defaults', 'type' => 'checkbox', 'label' => 'Force defaults (verbose export)'])], 'actions' => [new Button('Export', ['class' => 'btn btn-primary'])]]);
     $values = $form->import();
     if ($form->isSent()) {
         if ($values['id'] !== '') {
             $form->setValue(['post' => $values['id']]);
             $id = $values['id'];
         } else {
             $id = $values['post'];
         }
         if ($id === 'custom') {
             return $form;
         }
         $post = $repo->getPost($id);
         $var = $values['varname'];
         $defaults = $repo->createPost();
         $taxonomies = [];
         $php = '';
         foreach ($post->taxonomies as $i => $taxonomy) {
             if ($taxonomy->parent_id !== '0' || $taxonomy->description !== '' || $taxonomy->term->group !== '0' || $taxonomy->order !== '0') {
                 throw new Exception('@todo Implement taxonomy feature');
             }
             if (count($taxonomy->term->getMeta()) === 0) {
                 $taxonomies[] = 'Migrate::taxonomy(' . var_export($taxonomy->taxonomy, true) . ', ' . var_export($taxonomy->term->name, true) . ', ' . var_export($taxonomy->term->slug, true) . ')';
             } else {
                 $php .= '$taxonomy' . $i . ' = Migrate::taxonomy(' . var_export($taxonomy->taxonomy, true) . ', ' . var_export($taxonomy->term->name, true) . ', ' . var_export($taxonomy->term->slug, true) . ");\n";
                 $php .= '$taxonomy' . $i . '->setMeta(' . var_export($taxonomy->term->getMeta(), true) . ");\n";
                 $taxonomies[] = '$taxonomy' . $i;
             }
         }
         $php .= $var . " = Sledgehammer\\Wordpress\\Migrate::post([\n";
         $fields = ['type', 'title', 'slug', 'excerpt', 'status', 'content', 'comment_status', 'ping_status', 'password', 'to_ping', 'pinged', 'content_filtered', 'menu_order', 'mimetype', 'comment_count', 'parent_id', 'author', 'date', 'date_gmt', 'modified', 'modified_gmt'];
         if ($post->type === 'attachment') {
             $fields[] = 'guid';
         }
         foreach ($fields as $property) {
             if ($values['export_defaults'] === false && $defaults->{$property} === $post->{$property}) {
                 continue;
                 // skip default values
             }
             if ($property === 'author') {
                 $value = "\$repo->oneUser(['login' => " . var_export($post->author->login, true) . '])';
             } elseif ($property === 'guid') {
                 $guid = var_export($post->guid, true);
                 $value = str_replace("'" . WP_HOME, 'WP_HOME.\'', $guid);
             } elseif ($property === 'parent_id') {
                 if ($post->parent_id === '0') {
                     $value = "'0'";
                 } else {
                     $parent = $repo->getPost($post->parent_id);
                     $value = "\$repo->onePost(['AND', 'type' => " . var_export($parent->type, true) . ", 'slug' => " . var_export($parent->slug, true) . '])->id';
                 }
             } else {
                 $value = var_export($post->{$property}, true);
             }
             $php .= "    '" . $property . "' => " . $value . ",\n";
         }
         if ($taxonomies) {
             $php .= "    'taxonomies' => [\n        " . implode(",\n        ", $taxonomies) . "\n    ],\n";
         }
         $php .= "],[\n";
         $meta = $post->getMeta();
         foreach ($meta as $key => $value) {
             if (in_array($key, ['_edit_lock', '_edit_last'])) {
                 continue;
             }
             if ($key === '_thumbnail_id') {
                 $attachment = $repo->getPost($value);
                 $guid = var_export($attachment->guid, true);
                 $value = "\$repo->onePost(['AND','type' => 'attachment', 'guid' => " . str_replace("'" . WP_HOME, 'WP_HOME.\'', $guid) . '])';
             } else {
                 $value = var_export($value, true);
             }
             $php .= "    '" . $key . "' => " . $value . ",\n";
         }
         $php .= '], ';
         if ($post->type === 'attachment') {
             $php .= 'false';
         } else {
             $guid = var_export($post->guid, true);
             $guid = str_replace("'" . WP_HOME, 'WP_HOME.\'', $guid);
             $php .= str_replace('=' . $post->id . "'", "='", $guid);
         }
         $php .= ");\n";
         return new Template('sledgehammer/wordpress/templates/export_post.php', ['form' => $form, 'php' => $php]);
     }
     return $form;
 }