public function testSave() { $params = array('title' => 'My post with data attributes', 'content_type' => 'post', 'attribute_something' => 'hello there', 'attribute_something_else' => 'hello there 2', 'is_active' => 1); $id = save_content($params); $attributes = content_attributes($id); $this->assertEquals(intval($id) > 0, true); $this->assertEquals($attributes['something'], 'hello there'); $this->assertEquals($attributes['something_else'], 'hello there 2'); }
public function testSaveDataFields() { mw()->database_manager->extended_save_set_permission(true); $val = 'hello there custom 1-' . rand(); $val2 = 'hello there custom 2-' . rand(); $params = array('title' => 'My post with data attributes 1', 'content_type' => 'post', 'data_fields_something_custom' => $val, 'data_fields_something_else_custom' => $val2, 'is_active' => 1); $id = save_content($params); $attributes = content_data($id); $this->assertEquals(intval($id) > 0, true); $this->assertEquals($attributes['something_custom'], $val); $this->assertEquals($attributes['something_else_custom'], $val2); }
public function testSave() { mw()->database_manager->extended_save_set_permission(true); $has_permission = mw()->database_manager->extended_save_has_permission(); $params = array('title' => 'My post with data fields', 'content_type' => 'post', 'data_hi_there' => 'hello world', 'is_active' => 1); //saving $id = save_content($params); $data_fields = content_data($id); $this->assertEquals(intval($id) > 0, true); $this->assertEquals($data_fields['hi_there'], "hello world"); $this->assertEquals(true, $has_permission); }
public function testNextPrev() { $params = array('title' => 'this is my test next prev post', 'content_type' => 'post', 'is_active' => 1); //saving $save_post1 = save_content($params); $save_post2 = save_content($params); $save_post3 = save_content($params); //getting $next = next_content($save_post1); $prev = prev_content($save_post2); $this->assertEquals($save_post2, $next['id']); $this->assertEquals($save_post1, $prev['id']); $next = next_content($save_post2); $prev = prev_content($save_post3); $this->assertEquals($save_post3, $next['id']); $this->assertEquals($save_post2, $prev['id']); $del1 = delete_content($save_post1); $del2 = delete_content($save_post2); $del3 = delete_content($save_post3); //PHPUnit $this->assertEquals(true, is_array($del1)); $this->assertEquals(true, is_array($del2)); $this->assertEquals(true, is_array($del3)); $this->assertEquals(true, is_array($next)); }
function batch_process($content_items = false) { $chunks_folder = $this->get_import_location() . '_process_import' . DS; $index_file = $chunks_folder . 'index.php'; if (!is_dir($chunks_folder)) { mkdir_recursive($chunks_folder); } $total = 0; $remaining = 0; $batch_file = false; if (!is_array($content_items) or empty($content_items)) { $content_items = array(); if (is_file($index_file)) { $total = file_get_contents($index_file); } if ($total == 0) { $total = 0; $dir = $chunks_folder; if ($handle = opendir($dir)) { while (($file = readdir($handle)) !== false) { if (!in_array($file, array('.', '..')) && !is_dir($dir . $file) and strstr($file, 'import_chunk_')) { $total++; } } } file_put_contents($index_file, $total); } $i = 0; $dir = $chunks_folder; $rem_counter = 0; $process_xml_files = array(); $chunk_size = $this->batch_size; if ($handle = opendir($dir)) { while (($file = readdir($handle)) !== false) { if (!in_array($file, array('.', '..')) && !is_dir($dir . $file) and strstr($file, 'import_chunk_')) { //if (!is_array($content_items)) { if ($i < $chunk_size) { $batch_file = $chunks_folder . $file; $batch_file_content = file_get_contents($batch_file); if (strstr($file, 'import_chunk_xml')) { // for ($x=0; $x<=10; $x++){ $content_from_xml = $this->parse_content_from_xml_string($batch_file_content); if (is_array($content_from_xml)) { foreach ($content_from_xml as $content_from_x) { $content_items[] = $content_from_x; } // $rem_counter--; } //} } else { $content_items_from_file = @unserialize($batch_file_content); if (!empty($content_items_from_file)) { foreach ($content_items_from_file as $content_from_x) { $content_items[] = $content_from_x; } } } if ($batch_file != false and is_file($batch_file)) { @unlink($batch_file); } } $i++; } } $remaining = $i; } } else { $total = count($content_items); } // dd($content_items); if ($content_items != false and is_array($content_items)) { if (!empty($content_items)) { $parent = get_content('one=true&subtype=dynamic&is_deleted=0&is_active=1'); if ($parent == false) { $parent = get_content('one=true&content_type=page&is_deleted=0&is_active=1'); } if ($parent == false) { $parent = 0; } $content_items = $this->map_array($content_items); $parent_id = $parent['id']; $restored_items = array(); foreach ($content_items as $content) { if (isset($content['title'])) { $is_saved = get_content('one=true&title=' . $content['title']); if (isset($content['description']) and (!isset($content['content']) or $content['content'] == false)) { //$content['content'] = $content['description']; } if (!isset($content['parent'])) { $content['parent'] = $parent_id; } if (isset($content['parent'])) { $par = get_content_by_id($content['parent']); if ($par != false) { if (isset($par['is_shop']) and $par['is_shop'] == 1) { $content['content_type'] = 'product'; $content['subtype'] = 'product'; } } } if (!isset($content['content_type'])) { $content['content_type'] = 'post'; } if (!isset($content['subtype'])) { $content['subtype'] = 'post'; } // $content['subtype'] = 'post'; $content['is_active'] = 1; if (isset($content['debug'])) { unset($content['debug']); } // $content['debug'] = 'y'; // $content['download_remote_images'] = true; if ($is_saved != false) { $content['id'] = $is_saved['id']; if (!isset($content['content_type'])) { $content['content_type'] = $is_saved['content_type']; $content['subtype'] = $is_saved['subtype']; } } $import = save_content($content); $restored_items[] = $import; } } cache_clear('categories'); cache_clear('content'); $remaining = $remaining - 1; if ($remaining <= 0) { file_put_contents($index_file, '0'); } if ($total < $remaining) { $total = 0; $dir = $chunks_folder; if ($handle = opendir($dir)) { while (($file = readdir($handle)) !== false) { if (!in_array($file, array('.', '..')) && !is_dir($dir . $file) and strstr($file, 'import_chunk_')) { $total++; } } } file_put_contents($index_file, $total); } $ret = array('success' => count($restored_items) . " items restored", 'total' => $total, 'remaining' => $remaining); return $ret; } } return false; }
page_close(); exit; } else { echo "<form name=EditorForm id=EditorForm method=post>\n"; echo "<textarea cols=105 rows=30 name=content>"; echo $csstext; echo "</textarea>\n"; echo "<input type=submit value='Save'>\n"; echo "</form>\n"; } } else { if ($content = $_REQUEST['content']) { check_edit_perms(); $ok = true; if (!save_content($preferred_method, $template, $content)) { if (!save_content($alternate_method, $template, $content)) { echo "<p class=error>Save Failed</p>"; $ok = false; } } if ($ok) { echo "<META HTTP-EQUIV=REFRESH CONTENT=\"2; URL=" . $template . ".html\">"; } echo " <a href=\"" . $template . ".html\">Back to page.</a><br>\n"; page_close(); exit; } } if ($text) { echo "<form name='EditorForm' id='EditorForm' method='post'>\n"; if ($_ENV["SubFolder"]) {
public function save_content_item($content) { if (!isset($content['title']) or $content['title'] == false) { return; } $orig = $content; $this->app->media_manager->download_remote_images = true; if (isset($content['content_type']) and $content['content_type'] == 'category') { unset($content['content_type']); if (isset($content['title']) and is_string($content['title'])) { $category_set_item = $content['title']; $category_set_item = trim($category_set_item); $possible_slug = $this->app->url_manager->slug($category_set_item); $cat_item = $this->app->category_manager->get('no_cache=true&single=true&rel_type=content&url=' . $possible_slug); if (!isset($cat_item['id'])) { $cat_item = $this->app->category_manager->get('no_cache=true&single=true&rel_type=content&title=' . $category_set_item); } if (!isset($cat_item['id'])) { $new = $content; $new['rel_type'] = 'content'; $new['title'] = $category_set_item; // parent_category_title $new_cat = $this->app->category_manager->save($new); $cat_item = $this->app->category_manager->get_by_id($new_cat); } if (isset($cat_item['id'])) { if (isset($content['parent'])) { unset($content['parent']); } $new = $content; $new['id'] = $cat_item['id']; // \Log::info(print_r($new, true)); // dd($new); return $this->app->category_manager->save($new); } } //return save_category($content); } else { // make categories if (isset($content['categories']) and is_string($content['categories'])) { $category_sets = explode(',', $content['categories']); $cats_ids = array(); foreach ($category_sets as $category_set) { if (is_string($category_set)) { $category_set_items = explode('/', $category_set); $nest_level = 0; $prev_parent_cat = 0; foreach ($category_set_items as $category_set_item) { $category_set_item = trim($category_set_item); if ($category_set_item == false) { // dd($category_set_items,$category_set,$content); } if ($category_set_item != false) { $possible_slug = $this->app->url_manager->slug($category_set_item); // \Log::info('------'.print_r($category_set_item, true)); $cat_item = $this->app->category_manager->get('no_cache=true&single=true&rel_type=content&url=' . $possible_slug); // \Log::info('000000----'.print_r($cat_item, true)); if (!isset($cat_item['id'])) { // \Log::info('111000000----'.print_r($cat_item, true)); $cat_item = $this->app->category_manager->get('no_cache=true&single=true&rel_type=content&title=' . $category_set_item); } // $cat_item = $this->app->category_manager->get('no_cache=true&single=true&rel_type=content&title=' . $category_set_item); // dd($category_set_items,$category_set_item); //if (!isset($cat_item['id'])) { $new = array(); if (isset($cat_item['id'])) { $new['id'] = $cat_item['id']; } $new['rel_type'] = 'content'; $new['title'] = $category_set_item; if (isset($content['parent']) and $nest_level == 0) { $new['parent_page'] = $content['parent']; } if ($nest_level > 0 and $prev_parent_cat) { $new['parent_id'] = $prev_parent_cat; } // d($category_set_items); // \Log::info(print_r($new, true)); $new_cat = $this->app->category_manager->save($new); // \Log::info(print_r($new_cat, true)); $cat_item = $this->app->category_manager->get_by_id($new_cat); // } if (isset($cat_item['id'])) { $prev_parent_cat = $cat_item['id']; $cats_ids[] = $cat_item['id']; } ++$nest_level; } } } } if (!empty($cats_ids)) { // \Log::info(print_r($orig, true)); $content['categories'] = $cats_ids; } } // dd($content); if (isset($content['images']) and is_string($content['images'])) { $content['images'] = explode(',', $content['images']); $content['images'] = array_unique($content['images']); } $is_saved = get_content('no_cache=true&one=true&title=' . $content['title']); if (isset($content['description']) and (!isset($content['content']) or $content['content'] == false)) { //$content['content'] = $content['description']; } if (isset($content['parent'])) { $par = get_content_by_id($content['parent']); if ($par != false) { if (isset($par['is_shop']) and $par['is_shop'] == 1) { $content['content_type'] = 'product'; $content['subtype'] = 'product'; } } } if (!isset($content['content_type'])) { $content['content_type'] = 'post'; } if (!isset($content['subtype'])) { $content['subtype'] = 'post'; } // $content['subtype'] = 'post'; $content['is_active'] = 1; if (isset($content['debug'])) { unset($content['debug']); } // $content['debug'] = 'y'; $content['download_remote_images'] = true; if ($is_saved != false) { $content['id'] = $is_saved['id']; if (!isset($content['content_type'])) { $content['content_type'] = $is_saved['content_type']; $content['subtype'] = $is_saved['subtype']; } } // \Log::info('---------------- ================ ----------------'); // \Log::info('---------------- SAVING CONTENT ----------------'); // \Log::info('---------------- ================ ----------------'); // // // // // \Log::info(print_r($content, true)); return save_content($content); } }