Пример #1
0
<?php

only_admin_access();
$data = false;
if (isset($params['content-id'])) {
    $data = get_content_by_id($params["content-id"]);
}
$available_content_types = false;
$available_content_subtypes = false;
/* FILLING UP EMPTY CONTENT WITH DATA */
if ($data == false or empty($data)) {
    $is_new_content = true;
    include '_empty_content_data.php';
} else {
    $available_content_types = get_content('group_by=content_type');
    $available_content_subtypes = get_content('group_by=subtype');
}
/* END OF FILLING UP EMPTY CONTENT  */
$show_page_settings = false;
if (isset($params['content-type']) and $params['content-type'] == 'page') {
    $show_page_settings = 1;
}
$template_config = mw()->template->get_config();
$data_fields_conf = false;
$data_fields_values = false;
if (!empty($template_config)) {
    if (isset($params['content-type'])) {
        if (isset($template_config['data-fields-' . $params['content-type']]) and is_array($template_config['data-fields-' . $params['content-type']])) {
            $data_fields_conf = $template_config['data-fields-' . $params['content-type']];
            if (isset($params['content-id'])) {
                $data_fields_values = content_data($params['content-id']);
Пример #2
0
<?php

/*
type: layout
name: Add to cart default
description: Add to cart default
*/
if (isset($params['content-id'])) {
    $product = get_content_by_id($params["content-id"]);
    $title = $product['title'];
} else {
    $title = _e("Product");
}
?>
 
<script>mw.moduleCSS("<?php 
print modules_url();
?>
shop/cart_add/templates.css")</script>



<script type="text/javascript">
   LocalPrice = null;
   SetLocalPrice = window.SetLocalPrice || function(input){
     if(input.checked === true){
         LocalPrice = input.value;
     }
   }

</script>
Пример #3
0
<?php

/*
  type: layout
  content_type: static
  name: Post
  description: Post layout
*/
$id = post_id();
$content = get_content_by_id($id);
?>


  <?php 
include TEMPLATE_DIR . "header.php";
?>
 <div class="container content edit" rel="content<?php 
print PAGE_ID();
?>
" field="content<?php 
print PAGE_ID();
?>
">
	<div class="row blog-page">
		<!-- Left Sidebar -->
		<div class="col-md-9">
			<!--Blog Post-->
			<div class="blog margin-bottom-40">
				<h2 class="headline edit" field="title" rel="content"><?php 
print $content['title'];
?>
Пример #4
0
                                <table width="100%" cellspacing="0" cellpadding="0" class="mw-ui-table mw-ui-table-basic">
                                    <thead>
                                        <tr>
                                          <th>Image </th>
                                          <th>Title</th>
                                          <th>Quantity</th>
                                          <th>Price</th>
                                          <th>Total</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                           <?php 
            foreach ($cart as $product) {
                ?>
                                           <?php 
                $theproduct = get_content_by_id($product['rel_id']);
                ?>
                                             <tr>
                                                <td><img src="<?php 
                print get_picture($theproduct['id']);
                ?>
" width="70" alt="" /> </td>
                                                <td><?php 
                print $theproduct['title'];
                ?>
</td>
                                                <td><?php 
                print $product['qty'];
                ?>
</td>
                                                <td><?php 
Пример #5
0
<?php

only_admin_access();
$data = array('content_id' => $params['content_id']);
$comments = get_comments($data);
$item = get_content_by_id($params['content_id']);
$content_id = $params['content_id'];
$moderation_is_required = get_option('require_moderation', 'comments') == 'y';
?>

<div class="comment-post">
  <div class="comment-info-holder" content-id="<?php 
print $item['id'];
?>
" onclick="mw.adminComments.toggleMaster(this, event)"> <span class="img"> <img src="<?php 
print thumbnail(get_picture($content_id), 67, 67);
?>
" alt="" />
    <?php 
// $new = get_comments('count=1&is_moderated=n&rel=content&rel_id='.$content_id);
$new = get_comments('count=1&is_new=y&rel=content&rel_id=' . $content_id);
?>
    <?php 
if ($new > 0) {
    ?>
    <span class="comments_number"><?php 
    print $new;
    ?>
</span>
    <?php 
}
Пример #6
0
    ?>
" title="<?php 
    echo get_the_title(get_the_ID());
    ?>
">
                                                        <span><?php 
    echo get_the_title(get_the_ID());
    ?>
</span>
                                                    </a>
                                                </h2>


                                            <div class="desc std">
                                                  <p><?php 
    echo wp_trim_words(get_content_by_id(get_the_ID()), 50);
    ?>
    </p>                               
                                                  <a href="<?php 
    echo get_the_permalink(get_the_ID());
    ?>
" title="<?php 
    echo get_the_title(get_the_ID());
    ?>
" class="link-learn">Chi tiết</a>
                                            </div>
                                                                                                    
                                        </div>
                                    </div>
                                </div>
                            </li>
Пример #7
0
 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;
 }
Пример #8
0
if (!is_admin()) {
    return;
}
$cont_id = false;
if (isset($params['post_id']) and intval($params['post_id']) != 0) {
    $cont_id = intval($params['post_id']);
} else {
    if (isset($params['page_id']) and intval($params['page_id']) != 0) {
        $cont_id = intval($params['page_id']);
    }
}
$url = mw()->url_manager->string(true);
$history_files = false;
if ($cont_id != false) {
    $history_files = get_content_field('limit=30&order_by=id desc&fields=id,created_at&is_draft=1&all=1&url=' . $url);
    $last_saved = get_content_by_id($cont_id);
    $last_saved_date = $last_saved['updated_at'];
    $latest_drafs = get_content_field('limit=30&order_by=id desc&fields=id&created_at=[mt]' . $last_saved_date . '&is_draft=1&all=1&url=' . $url . '&rel_id=' . $cont_id);
    $history_files_fields = get_content_field('group_by=field&order_by=id desc&fields=field,id,created_at&is_draft=1&all=1&url=' . $url);
}
if (isset($latest_drafs) and is_array($latest_drafs)) {
    //
    $latest_drafs_vals = array();
    foreach ($latest_drafs as $value) {
        $latest_drafs_vals[] = $value['id'];
    }
    if (!empty($latest_drafs_vals)) {
        ?>
<script  type="text/javascript">

 public function copy($data)
 {
     $new_cont_id = false;
     if (defined('MW_API_CALL')) {
         $to_trash = true;
         $adm = $this->app->user_manager->is_admin();
         if ($adm == false) {
             return array('error' => 'You must be admin to copy content!');
         }
     }
     if (isset($data['id'])) {
         $this->app->event_manager->trigger('content.before.copy', $data);
         $cont = get_content_by_id($data['id']);
         if ($cont != false and isset($cont['id'])) {
             $new_cont = $cont;
             if (isset($new_cont['title'])) {
                 $new_cont['title'] = $new_cont['title'] . ' copy';
             }
             $new_cont['id'] = 0;
             $content_cats = array();
             $cats = content_categories($cont['id']);
             if (!empty($cats)) {
                 foreach ($cats as $cat) {
                     if (isset($cat['id'])) {
                         $content_cats[] = $cat['id'];
                     }
                 }
             }
             if (!empty($content_cats)) {
                 $new_cont['categories'] = $content_cats;
             }
             $new_cont_id = $this->save($new_cont);
             $cust_fields = get_custom_fields('content', $data['id'], true);
             if (!empty($cust_fields)) {
                 foreach ($cust_fields as $cust_field) {
                     $new = $cust_field;
                     $new['id'] = 0;
                     $new['rel_id'] = $new_cont_id;
                     $new_item = save_custom_field($new);
                 }
             }
             $images = get_pictures($data['id']);
             if (!empty($images)) {
                 foreach ($images as $image) {
                     $new = $image;
                     $new['id'] = 0;
                     $new['rel_id'] = $new_cont_id;
                     $new['rel_type'] = 'content';
                     $new_item = save_media($new);
                 }
             }
         }
     }
     return $new_cont_id;
 }
Пример #10
0
        }
        ?>
        </div>
    <?php 
    }
    ?>


<?php 
} else {
    ?>
    <div class="mw-no-posts-foot">
        <?php 
    $page_is_shop = false;
    if (isset($post_params["page-id"])) {
        $page_is_shop_check = get_content_by_id($post_params["page-id"]);
        if (isset($page_is_shop_check['is_shop']) and $page_is_shop_check['is_shop'] == 1) {
            $page_is_shop = true;
        }
    }
    if (isset($post_params['content_type']) and $post_params['content_type'] == 'product' or isset($params['content_type']) and $params['content_type'] == 'product' or $page_is_shop) {
        ?>

            <span class="mw-no-posts-foot-label"><?php 
        _e("No Products Here");
        ?>
</span>

            <?php 
        if (isset($post_params['category-id'])) {
            $url = "#action=new:product&amp;category_id=" . $post_params['category-id'];
Пример #11
0
        $parent_page_active = $data['parent'];
    }
}
?>

<div class="admin-manage-content-wrap">


<div class="admin-manage-toolbar-holder">
    <div class="admin-manage-toolbar">
        <div class="admin-manage-toolbar-content">
            <div class="mw-ui-row-nodrop">
                <div class="mw-ui-col">
                    <?php 
if (isset($data['id']) and intval($data['id']) == 0 and isset($data['parent']) and intval($data['parent']) != 0) {
    $parent_data = get_content_by_id($data['parent']);
    if (is_array($parent_data) and isset($parent_data['is_active']) and $parent_data['is_active'] == 0) {
        $data['is_active'] = 0;
    }
}
if ($edit_page_info['is_shop'] == 1) {
    $type = 'shop';
} elseif ($edit_page_info['subtype'] == 'dynamic') {
    $type = 'dynamicpage';
} elseif ($edit_page_info['subtype'] == 'post') {
    $type = 'post';
} elseif ($edit_page_info['content_type'] == 'product') {
    $type = 'product';
} else {
    $type = 'page';
}
Пример #12
0
            $i++;
        }
    }
    if (!empty($data)) {
        //$more = $data;
    }
    if (!empty($more)) {
        if ($list_preview == false) {
            ?>

<div class="mw-ui-field mw-tag-selector mw-custom-fields-tags" onclick="__smart_field_opener(event)">
  <?php 
            if (isset($params['save_to_content_id']) and isset($params["rel_id"]) and intval($params["rel_id"] > 0)) {
                ?>
  <?php 
                $p = get_content_by_id($params["rel_id"]);
                ?>
  <?php 
                if (isset($p['title'])) {
                    ?>
  <div class="mw-custom-fields-from-page-title"> <span class="mw-custom-fields-from-page-title-text">
    <?php 
                    _e("From");
                    ?>
    <strong><?php 
                    print $p['title'];
                    ?>
</strong></span> </div>
  <?php 
                }
                ?>
Пример #13
0
$selected = 0;
if (isset($params['field-name'])) {
    $field_name = $params['field-name'];
}
if (isset($params['selected-id'])) {
    $selected = intval($params['selected-id']);
}
$rand = uniqid();
$no_parent_title = _e("None", 1);
if (isset($params['no-parent-title'])) {
    $no_parent_title = $params['no-parent-title'];
}
$top_item = false;
if (isset($params['recommended-id']) and $params['recommended-id'] != false) {
    $recommended_parent = $params['recommended-id'];
    $top_item = get_content_by_id(intval($recommended_parent));
}
?>
 

<?php 
if (isset($params['change-field'])) {
    ?>
	

<script  type="text/javascript">

  $(document).ready(function(){
  	mw.$('#content_selector_<?php 
    print $rand;
    ?>
Пример #14
0
    ?>



<div class="<?php 
    print $config['module_class'];
    ?>
 menu_item_edit" id="mw_content/menu_item_save_<?php 
    print $rand;
    ?>
">
  <?php 
    if ((!isset($data['title']) or $data['title'] == '') and isset($data["content_id"]) and intval($data["content_id"]) > 0) {
        ?>
  <?php 
        $cont = get_content_by_id($data["content_id"]);
        if (isset($cont['title'])) {
            $data['title'] = $cont['title'];
            $item_url = content_link($cont['id']);
        }
        ?>
  <?php 
    } else {
        ?>
  <?php 
        if ((!isset($data['title']) or $data['title'] == '') and isset($data["categories_id"]) and intval($data["categories_id"]) > 0) {
            ?>
  <?php 
            $cont = get_category_by_id($data["categories_id"]);
            if (isset($cont['title'])) {
                $data['title'] = $cont['title'];
Пример #15
0
    if (isset($params["inherit_from"]) and (trim($params["inherit_from"]) != '' or trim($params["inherit_from"]) != '0')) {
        //
        $inherit_from_id = get_content_by_id($params["inherit_from"]);
        // $inherit_from_id = false;
        if ($inherit_from_id != false and isset($inherit_from_id['active_site_template']) and trim($inherit_from_id['active_site_template']) != 'inherit') {
            $data['active_site_template'] = $inherit_from_id['active_site_template'];
            $data['layout_file'] = $inherit_from_id['layout_file'];
            $inherit_from = $inherit_from_id;
            $data['layout_file'] = 'inherit';
        } else {
            $inh1 = mw()->content_manager->get_inherited_parent($params["inherit_from"]);
            if ($inh1 == false) {
                $inh1 = intval($params["inherit_from"]);
            }
            if ($inh1 != false) {
                $inherit_from = get_content_by_id($inh1);
                if (is_array($inherit_from) and isset($inherit_from['active_site_template'])) {
                    $data['active_site_template'] = $inherit_from['active_site_template'];
                    $data['layout_file'] = 'inherit';
                }
            }
        }
    }
}
if ((!isset($data['layout_file']) or $data['layout_file'] == NULL) and isset($data['is_home']) and $data['is_home'] == 'y') {
    $data['layout_file'] = 'index.php';
}
if (!isset($params["active_site_template"]) and isset($params["site-template"])) {
    $params["active_site_template"] = $params["site-template"];
}
if (isset($params["active_site_template"])) {
Пример #16
0
                                                        <span class="price" content="<?php 
    echo $price;
    ?>
"><?php 
    echo $price;
    ?>
 VNĐ</span>
                                                    </span>

                                                </div>

                                            </div>
                                        </div>
                                        <div class="descofProduct">
                                            <?php 
    echo wp_trim_words(get_content_by_id($newhome->ID), 50);
    ?>
 
                                        </div>
                                    </div>
                                </div>
                            </li>
                            <?php 
}
?>
                            
                        </ul>
            <div class="paging">
            <?php 
echo wp_pagenavi();
?>
Пример #17
0
 public function save_content_admin($data, $delete_the_cache = true)
 {
     if (is_string($data)) {
         $data = parse_params($data);
     }
     $adm = $this->app->user_manager->is_admin();
     $checks = mw_var('FORCE_SAVE_CONTENT');
     $orig_data = $data;
     $stop = false;
     $data = $this->app->format->strip_unsafe($data);
     if ($adm == false) {
         $stop = true;
         $author_id = user_id();
         if (isset($data['created_at'])) {
             unset($data['created_at']);
         }
         if (isset($data['updated_at'])) {
             unset($data['updated_at']);
         }
         if (isset($data['id']) and $data['id'] != 0 and $author_id != 0) {
             $page_data_to_check_author = $this->get_by_id($data['id']);
             if (!isset($page_data_to_check_author['created_by']) or $page_data_to_check_author['created_by'] != $author_id) {
                 $stop = true;
                 return array('error' => "You don't have permission to edit this content");
             } elseif (isset($page_data_to_check_author['created_by']) and $page_data_to_check_author['created_by'] == $author_id) {
                 $stop = false;
             }
         } elseif ($author_id == false) {
             return array('error' => 'You must be logged to save content');
         }
         if (isset($data['id']) and $data['id'] != 0) {
             if (!is_admin()) {
                 $check = get_content_by_id($data['id']);
                 if ($check['created_by'] != user_id()) {
                     return array('error' => 'Wrong content');
                 }
             }
         }
         if (isset($data['is_home'])) {
             if (!is_admin()) {
                 unset($data['is_home']);
             }
         }
         if ($stop == true) {
             if (defined('MW_API_FUNCTION_CALL') and MW_API_FUNCTION_CALL == __FUNCTION__) {
                 if (!isset($data['captcha'])) {
                     if (isset($data['error_msg'])) {
                         return array('error' => $data['error_msg']);
                     } else {
                         return array('error' => 'Please enter a captcha answer!');
                     }
                 } else {
                     $cap = $this->app->user_manager->session_get('captcha');
                     if ($cap == false) {
                         return array('error' => 'You must load a captcha first!');
                     }
                     if ($data['captcha'] != $cap) {
                         return array('error' => 'Invalid captcha answer!');
                     }
                 }
             }
         }
         if (isset($data['categories'])) {
             $data['category'] = $data['categories'];
         }
         //if (defined('MW_API_FUNCTION_CALL') and MW_API_FUNCTION_CALL == __FUNCTION__) {
         if (isset($data['category'])) {
             $cats_check = array();
             if (is_array($data['category'])) {
                 foreach ($data['category'] as $cat) {
                     $cats_check[] = intval($cat);
                 }
             } else {
                 $cats_check[] = intval($data['category']);
             }
             $check_if_user_can_publish = $this->app->category_manager->get('ids=' . implode(',', $cats_check));
             if (!empty($check_if_user_can_publish)) {
                 $user_cats = array();
                 foreach ($check_if_user_can_publish as $item) {
                     if (isset($item['users_can_create_content']) and $item['users_can_create_content'] == 1) {
                         $user_cats[] = $item['id'];
                         $cont_cat = $this->get('limit=1&content_type=page&subtype_value=' . $item['id']);
                     }
                 }
                 if (!empty($user_cats)) {
                     $stop = false;
                     $data['categories'] = $user_cats;
                 }
             }
         }
     }
     // }
     if ($stop == true) {
         return array('error' => 'You don\'t have permissions to save content here!');
     }
     return $this->save_content($data, $delete_the_cache);
 }
Пример #18
0
 public function testContentCategories()
 {
     $params = array('title' => 'My categories page', 'content_type' => 'page', 'subtype' => 'dynamic', 'is_active' => 1);
     //saving
     $parent_page_id = save_content($params);
     $parent_page_data = get_content_by_id($parent_page_id);
     $params = array('title' => 'Test Category 1', 'parent_page' => $parent_page_id);
     //saving
     $category_id = save_category($params);
     $category_data = get_category_by_id($category_id);
     $category_page = get_page_for_category($category_data['id']);
     $delete_category = delete_category($category_id);
     $delete_page = delete_content($parent_page_id);
     $deleted_page = get_content_by_id($parent_page_id);
     $params = array('title' => 'Test Category with invalid position', 'position' => 'uga buga');
     $category_with_invalid_pos = save_category($params);
     //PHPUnit
     $this->assertEquals(true, intval($parent_page_id) > 0);
     $this->assertEquals(true, intval($category_id) > 0);
     $this->assertEquals(true, is_array($category_data));
     $this->assertEquals(true, is_array($category_page));
     $this->assertEquals($category_page['title'], $parent_page_data['title']);
     $this->assertEquals(true, $delete_category);
     $this->assertEquals(false, $deleted_page);
     $this->assertEquals(true, intval($category_with_invalid_pos) > 0);
     $this->assertEquals(true, is_array($delete_page));
 }
Пример #19
0
        ?>
    <h4>
      <?php 
        _e("Recent comments");
        ?>
    </h4>
    <?php 
    } else {
        ?>
    <h4>
      <?php 
        _e("Comments for");
        ?>
      <strong>
      <?php 
        $post = get_content_by_id($data['rel_id']);
        print $post['title'];
        ?>
      </strong></h4>
    <?php 
    }
    ?>
    <div class="comments" id="comments-list-<?php 
    print $data['id'];
    ?>
">
      <?php 
    foreach ($comments as $comment) {
        ?>
      <?php 
        $required_moderation = get_option('require_moderation', 'comments') == 'y';
Пример #20
0
 public function reset_edit($data)
 {
     if (defined('MW_API_CALL')) {
         $to_trash = true;
         $adm = $this->app->user_manager->is_admin();
         if ($adm == false) {
             return array('error' => 'You must be admin to reset content!');
         }
     }
     if (isset($data['id'])) {
         $cont = get_content_by_id($data['id']);
         if (isset($cont['id']) and $cont['id'] != 0) {
             $id = intval($cont['id']);
             $cont['content'] = false;
             $cont['content_body'] = false;
             $save = $this->save($cont);
             $table_fields = $this->app->database_manager->real_table_name($this->tables['content_fields']);
             $del = "DELETE FROM {$table_fields} WHERE rel_type='content' AND rel_id='{$id}' ";
             $this->app->database_manager->query($del);
             $this->app->cache_manager->delete('content');
             $this->app->cache_manager->delete('content_fields');
             return $save;
         }
     }
 }
Пример #21
0
 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);
     }
 }