summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/wordpress-mobile-pack/export')
-rwxr-xr-xplugins/wordpress-mobile-pack/export/class-export.php170
1 files changed, 131 insertions, 39 deletions
diff --git a/plugins/wordpress-mobile-pack/export/class-export.php b/plugins/wordpress-mobile-pack/export/class-export.php
index b1537d21..09ec0da1 100755
--- a/plugins/wordpress-mobile-pack/export/class-export.php
+++ b/plugins/wordpress-mobile-pack/export/class-export.php
@@ -13,6 +13,8 @@ if ( ! class_exists( 'WMobilePack_Export' ) ) {
*
* @improvement - Move this class to the frontend folder (similar to the PRO version)?
*
+ * @todo (Future releases) Remove category_id and category_name from the exports after apps have been modified to use multiple categories per post
+ *
*/
class WMobilePack_Export
{
@@ -45,6 +47,19 @@ if ( ! class_exists( 'WMobilePack_Export' ) ) {
/**
*
+ * Create an uploads management object and return it
+ *
+ * @return object
+ *
+ */
+ protected function get_uploads_manager()
+ {
+ return new WMobilePack_Uploads();
+ }
+
+
+ /**
+ *
* Verify if a post has a featured image and return it
*
* @param $post_id
@@ -116,7 +131,8 @@ if ( ! class_exists( 'WMobilePack_Export' ) ) {
"date" => WMobilePack_Formatter::format_date(strtotime($post->post_date)),
"timestamp" => strtotime($post->post_date),
"description" => $description,
- "content" => $content
+ "content" => $content,
+ "categories" => $this->get_visible_categories_ids($post)
);
} else {
@@ -130,7 +146,8 @@ if ( ! class_exists( 'WMobilePack_Export' ) ) {
"date" => WMobilePack_Formatter::format_date(strtotime($post->post_date)),
"timestamp" => strtotime($post->post_date),
"description" => $description,
- "content" => ''
+ "content" => '',
+ "categories" => $this->get_visible_categories_ids($post)
);
}
@@ -278,6 +295,76 @@ if ( ! class_exists( 'WMobilePack_Export' ) ) {
return $visible_category;
}
+
+ /**
+ * Parse the 'categories_details' array and return an array with icon paths, indexed by category id.
+ * The method checks if an icon exists before adding it in the array.
+ *
+ * @return array
+ */
+ protected function get_categories_images(){
+
+ $categories_images = array();
+
+ $categories_details = WMobilePack_Options::get_setting('categories_details');
+
+ // create an uploads manager object
+ $WMP_Uploads = $this->get_uploads_manager();
+
+ if (is_array($categories_details) && !empty($categories_details)) {
+
+ foreach ($categories_details as $category_id => $category_details){
+
+ if (is_array($category_details) && array_key_exists('icon', $category_details)) {
+
+ $icon_path = $category_details['icon'];
+
+ if ($icon_path != ''){
+ $icon_path = $WMP_Uploads->get_file_url($icon_path);
+ }
+
+ if ($icon_path != ''){
+
+ // categories icons are used as backgrounds,
+ // so we can use the default width / height in the exports
+ $categories_images[$category_id] = array(
+ 'src' => $icon_path,
+ 'width' => WMobilePack_Uploads::$allowed_files['category_icon']['max_width'],
+ 'height' => WMobilePack_Uploads::$allowed_files['category_icon']['max_height']
+ );
+ }
+ }
+ }
+ }
+
+ return $categories_images;
+ }
+
+
+ /**
+ * Returns a post's visible categories ids.
+ *
+ * @param $post
+ * @return array
+ */
+ protected function get_visible_categories_ids($post)
+ {
+ // get post categories
+ $categories = get_the_category($post->ID);
+
+ // check if at least one of the categories is visible
+ $arr_categories_ids = array();
+
+ foreach ($categories as $category) {
+
+ if (!in_array($category->cat_ID, $this->inactive_categories)) {
+ $arr_categories_ids[] = $category->cat_ID;
+ }
+ }
+
+ return $arr_categories_ids;
+ }
+
/**
*
* The comment_closed method is used to determine the comment status for an article.
@@ -398,6 +485,8 @@ if ( ! class_exists( 'WMobilePack_Export' ) ) {
if (count($active_categories_ids) > 0) {
+ $categories_images = $this->get_categories_images();
+
foreach ($categories as $key => $category) {
if (in_array($category->cat_ID, $active_categories_ids)) {
@@ -410,7 +499,7 @@ if ( ! class_exists( 'WMobilePack_Export' ) ) {
'name' => $category->name,
'name_slug' => $category->slug,
'link' => get_category_link($category->term_id),
- 'image' => ""
+ 'image' => array_key_exists($category->cat_ID, $categories_images) ? $categories_images[$category->cat_ID] : ''
);
// Reset query & search posts from this category
@@ -949,6 +1038,7 @@ if ( ! class_exists( 'WMobilePack_Export' ) ) {
* - comment_parent
* - code = Access token for saving comments
*
+ * @todo Translate error messages
*/
public function save_comment()
{
@@ -1109,13 +1199,12 @@ if ( ! class_exists( 'WMobilePack_Export' ) ) {
/**
*
- * Return array with the pages keys, ordered by hierarchy
+ * Return array with the pages keys, ordered by hierarchy.
+ * Child pages will be excluded if their parents are hidden.
*
* @param int $limit
* @return array
*
- * @todo Delete this method after subpages support is added to themes 1 and 4
- *
*/
protected function get_pages_order($limit = 100){
@@ -1159,8 +1248,6 @@ if ( ! class_exists( 'WMobilePack_Export' ) ) {
* - callback = The JavaScript callback method
* - content = 'exportpages'
*
- * @todo Remove the order_pages array after subpages support is added to themes 1 and 4
- *
*/
public function export_pages()
{
@@ -1213,27 +1300,28 @@ if ( ! class_exists( 'WMobilePack_Export' ) ) {
else
$content = apply_filters("the_content", get_option(WMobilePack_Options::$prefix.'page_' . $page->ID));
- $last_key = count($arr_pages);
- $current_key = $last_key + 1;
-
// if we have a pages hierarchy, use the order from that array
if (!empty($order_pages)) {
+ // if the page and its parent are visible, they should exist in the order array
$index_order = array_search($page->ID, $order_pages);
- if (is_numeric($index_order))
+ if (is_numeric($index_order)) {
+
$current_key = $index_order + 1;
- }
- $arr_pages[] = array(
- 'id' => $page->ID,
- 'parent_id' => intval($page->post_parent),
- 'order' => $current_key,
- 'title' => strip_tags(trim(get_the_title())),
- 'image' => !empty($image_details) ? $image_details : "",
- 'content' => '',
- 'has_content' => $content != '' ? 1 : 0
- );
+ $arr_pages[] = array(
+ 'id' => $page->ID,
+ 'parent_id' => intval($page->post_parent),
+ 'order' => $current_key,
+ 'title' => strip_tags(trim(get_the_title())),
+ 'link' => get_permalink(),
+ 'image' => !empty($image_details) ? $image_details : "",
+ 'content' => '',
+ 'has_content' => $content != '' ? 1 : 0
+ );
+ }
+ }
}
}
}
@@ -1266,6 +1354,8 @@ if ( ! class_exists( 'WMobilePack_Export' ) ) {
* - content = 'exportpage'
* - pageId = The page's id
*
+ * @todo (Improvement) Don't export page if its parent is hidden
+ *
*/
public function export_page()
{
@@ -1368,14 +1458,14 @@ if ( ! class_exists( 'WMobilePack_Export' ) ) {
// load icon from the local settings and folder
$icon_path = WMobilePack_Options::get_setting('icon');
- if ($icon_path == '' || !file_exists(WMP_FILES_UPLOADS_DIR . $icon_path)) {
- $icon_path = false;
- } else {
- $icon_path = WMP_FILES_UPLOADS_URL . $icon_path;
+ if ($icon_path != '') {
+
+ $WMP_Uploads = $this->get_uploads_manager();
+ $icon_path = $WMP_Uploads->get_file_url($icon_path);
}
// set icon depending on the manifest file type
- if ($icon_path != false) {
+ if ($icon_path != '') {
if ($_GET['content'] == 'androidmanifest') {
@@ -1548,25 +1638,27 @@ if ( ! class_exists( 'WMobilePack_Export' ) ) {
if (WMobilePack_Options::get_setting('premium_active') == 0) {
// check if logo exists
+ $WMP_Uploads = $this->get_uploads_manager();
+
$logo_path = WMobilePack_Options::get_setting('logo');
- if ($logo_path == '' || !file_exists(WMP_FILES_UPLOADS_DIR.$logo_path))
- $logo_path = '';
- else
- $logo_path = WMP_FILES_UPLOADS_URL.$logo_path;
+
+ if ($logo_path != ''){
+ $logo_path = $WMP_Uploads->get_file_url($logo_path);
+ }
// check if icon exists
$icon_path = WMobilePack_Options::get_setting('icon');
- if ($icon_path == '' || !file_exists(WMP_FILES_UPLOADS_DIR.$icon_path))
- $icon_path = '';
- else
- $icon_path = WMP_FILES_UPLOADS_URL.$icon_path;
+
+ if ($icon_path != ''){
+ $icon_path = $WMP_Uploads->get_file_url($icon_path);
+ }
// check if cover exists
$cover_path = WMobilePack_Options::get_setting('cover');
- if ($cover_path == '' || !file_exists(WMP_FILES_UPLOADS_DIR.$cover_path))
- $cover_path = '';
- else
- $cover_path = WMP_FILES_UPLOADS_URL.$cover_path;
+
+ if ($cover_path != ''){
+ $cover_path = $WMP_Uploads->get_file_url($cover_path);
+ }
// check if google analytics id is set
$google_analytics_id = WMobilePack_Options::get_setting('google_analytics_id');