예제 #1
0
 public static function get_components_synchro_data($app_id)
 {
     $components = array();
     $components_data = array();
     WpakAddons::require_app_addons_php_files($app_id);
     $components_raw = WpakComponentsStorage::get_components($app_id);
     if (!empty($components_raw)) {
         $globals = array();
         foreach ($components_raw as $component) {
             $component_data = WpakComponentsTypes::get_component_data($component, $globals);
             //
             // Don't include null component into the webservice's return
             // Component data could be null if an addon's component has been added to the app and the addon isn't activated anymore
             // An addon could be seen as deactivated either if the corresponding plugin is deactivated, or if the corresponding checkbox is unchecked for the given app
             //
             if (null === $component_data) {
                 continue;
             }
             $globals = $component_data['globals'];
             $components[$component->slug] = $component_data['specific'];
         }
         $navigation_items = WpakNavigationItemsStorage::get_navigation_indexed_by_components_slugs($app_id, true);
         $navigation_items = apply_filters('wpak_navigation_items', $navigation_items, WpakApps::get_app_slug($app_id));
         $components_data['navigation'] = $navigation_items;
         $components_data['components'] = $components;
         $components_data['globals'] = $globals;
         $components_data['addons'] = WpakAddons::get_app_addons_dynamic_data($app_id);
     }
     return $components_data;
 }
    private static function echo_item_form($post_id)
    {
        $components = WpakComponentsStorage::get_components($post_id);
        $no_components = empty($components);
        foreach (array_keys($components) as $component_id) {
            if (WpakNavigationItemsStorage::component_in_navigation($post_id, $component_id)) {
                unset($components[$component_id]);
            }
        }
        $navigation_item_id = 0;
        if (!$no_components) {
            $navigation_item = new WpakNavigationItem(0, 0);
        }
        ?>
		<?php 
        if (!$no_components) {
            ?>
			<div id="navigation-item-form-<?php 
            echo $navigation_item_id;
            ?>
" class="navigation-item-form">
				<table class="form-table">
					<tr valign="top">
						<?php 
            if (!empty($components)) {
                ?>
							<th scope="row"><?php 
                _e('Component', WpAppKit::i18n_domain);
                ?>
</th>
					        <td>
					        	<select name="component_id">
					        		<?php 
                foreach ($components as $component_id => $component) {
                    ?>
					        			<option value="<?php 
                    echo $component_id;
                    ?>
"><?php 
                    echo $component->label;
                    ?>
</option>
					        		<?php 
                }
                ?>
					        	</select>
					        </td>
					     <?php 
            } else {
                ?>
					     	<td>
				        		<?php 
                _e('All components are already in navigation!', WpAppKit::i18n_domain);
                ?>
				        	</td>
				        <?php 
            }
            ?>
				    </tr>
				</table>
				<input type="hidden" name="position" value="0" />
				<input type="hidden" name="navigation_post_id" value="<?php 
            echo $post_id;
            ?>
" />
				<p class="submit">
					<a class="button-secondary alignleft cancel" title="<?php 
            _e('Cancel', WpAppKit::i18n_domain);
            ?>
" href="#" id="cancel-new-item"><?php 
            _e('Cancel', WpAppKit::i18n_domain);
            ?>
</a>&nbsp;
					<?php 
            if (!empty($components)) {
                ?>
						<a class="button button-primary navigation-form-submit" data-id="<?php 
                echo $navigation_item_id;
                ?>
"><?php 
                _e('Add component to navigation', WpAppKit::i18n_domain);
                ?>
</a>
					<?php 
            }
            ?>
				</p>
			</div>
		<?php 
        } else {
            ?>
			<div>
				<?php 
            _e('No component found!', WpAppKit::i18n_domain);
            ?>
 : <?php 
            _e('Please create a component!', WpAppKit::i18n_domain);
            ?>
			</div>
		<?php 
        }
        ?>
		<?php 
    }
    public static function inner_components_box($post, $current_box)
    {
        $components = WpakComponentsStorage::get_components($post->ID);
        ?>

		<div id="components-wrapper">

			<a href="#" class="add-new-h2" id="add-new-component">Add New</a>

			<div id="components-feedback" style="display:none"></div>

			<div id="new-component-form" style="display:none">
				<h4><?php 
        _e('New Component', WpAppKit::i18n_domain);
        ?>
</h4>
				<?php 
        self::echo_component_form($post->ID);
        ?>
			</div>

			<table id="components-table" class="wp-list-table widefat fixed" >
				<thead>
					<tr>
						<th><?php 
        _e('Name', WpAppKit::i18n_domain);
        ?>
</th>
						<th><?php 
        _e('Slug', WpAppKit::i18n_domain);
        ?>
</th>
						<th><?php 
        _e('Type', WpAppKit::i18n_domain);
        ?>
</th>
						<th><?php 
        _e('Options', WpAppKit::i18n_domain);
        ?>
</th>
					</tr>
				</thead>
				<tbody>
					<?php 
        if (!empty($components)) {
            ?>
						<?php 
            $i = 0;
            ?>
						<?php 
            foreach ($components as $id => $component) {
                ?>
							<?php 
                echo self::get_component_row($post->ID, $i++, $id, $component);
                ?>
						<?php 
            }
            ?>
					<?php 
        } else {
            ?>
						<tr class="no-component-yet"><td colspan="4"><?php 
            _e('No Component yet!', WpAppKit::i18n_domain);
            ?>
</td></tr>
					<?php 
        }
        ?>
				</tbody>
			</table>

			<?php 
        WpakComponentsTypes::echo_components_javascript();
        ?>

		</div>

		<style>
			#components-wrapper{ margin-top:1em }
			#components-table{ margin-top:5px }
			#new-component-form{ margin-bottom: 4em }
			#components-wrapper #components-feedback{ margin-top:15px; margin-bottom:17px; padding-top:12px; padding-bottom:12px; }
		</style>

		<?php 
    }