コード例 #1
0
ファイル: ajax.php プロジェクト: datracka/datalook.io
function nl_box_builder()
{
    require_once NB_DIR . '/functions.php';
    if (!isset($_POST['box_id'])) {
        die('data is missing');
    }
    $box_id = addslashes($_POST['box_id']);
    // get term and unserialize contents
    $box = get_term($box_id, 'nb_boxes');
    $data = empty($box->description) ? '' : unserialize(nb_fix_serialization($box->description));
    // eventually fix serialization errors
    if (!is_array($data)) {
        $data = array('src' => array(), 'settings' => array());
    }
    ?>
    <form class="form-wrap" id="nb_box_opts">  
		<div class="postbox">
          <h3 class="hndle"><?php 
    _e('News Sources', 'nb_ml');
    ?>
</h3>
          <div class="inside">
        
            <div class="lcwp_mainbox_meta">
				<div class="nb_add_src">
                	<?php 
    _e('Add new source', 'nb_ml');
    ?>
 
                    <select class="lcweb-chosen" data-placeholder="Select a source" tabindex="2">
                    	<?php 
    foreach (nb_news_sources() as $k => $v) {
        echo '<option value="' . $k . '">' . $v . '</option>';
    }
    ?>
                    </select>
                    <input type="button" class="button-secondary" value="<?php 
    _e('Add', 'nb_ml');
    ?>
" /><span></span>
                </div>
                <div class="nb_sources">
                	<?php 
    // saved sources
    foreach ($data['src'] as $src) {
        $cpt_src = strpos($src['src_type'], '|||') !== false ? 'nb_cpt_src' : '';
        echo '
						<div class="nb_type_block nb_' . $src['src_type'] . '_src ' . $cpt_src . '">
						<h4>
							' . nb_news_sources($src['src_type']) . ' 
							<div class="nb_cmd"><span class="lcwp_del_row"></span></div>
						</h4>';
        echo nb_src_form_block($src) . '<div class="mgom_btm_border_fix"></div></div>';
    }
    ?>
                </div>
            </div>  
          </div>
        </div>
        
        <br/>
        
        <div class="postbox" id="nb_box_settings">
          <h3 class="hndle"><?php 
    _e('Settings', 'nb_ml');
    ?>
</h3>
          <div class="inside">
            <div class="lcwp_mainbox_meta">
            	
                <div class="nb_type_block">
                    <h4><?php 
    _e('Initial mode', 'nb_ml');
    ?>
</h4>
                    
                    <?php 
    $fields = array('max_news', 'news_per_time', 'height', 'layout', 'boxed_news', 'horiz_img_mode', 'buttons_position', 'btn_over_img', 'show_src_logo', 'hide_elements', 'horiz_img_h', 'vert_img_w', 'title_behavior', 'img_behavior', 'date_format', 'elapsed_time', 'read_more_btn', 'read_more_btn_txt');
    foreach ($fields as $field) {
        $val = isset($data['settings'][$field]) ? $data['settings'][$field] : '';
        echo nb_fields_builder($field, $val);
    }
    ?>
                
                	<div class="mgom_btm_border_fix"></div>
            	</div>
                
                <div class="nb_type_block">
                    <h4><?php 
    _e('Expanded mode', 'nb_ml');
    ?>
</h4>
                    
                    <?php 
    //$fields = array('expandable_news', 'scroll_exp_elem', 'exp_main_img_pos', 'manage_exp_images', 'exp_img_w', 'exp_img_h');
    $fields = array('expandable_news', 'scroll_exp_elem', 'manage_exp_images');
    foreach ($fields as $field) {
        $val = isset($data['settings'][$field]) ? $data['settings'][$field] : '';
        echo nb_fields_builder($field, $val);
    }
    ?>
                
                	<div class="mgom_btm_border_fix"></div>
            	</div>
                
                <div class="nb_type_block">
                    <h4><?php 
    _e('Navigation / slideshow', 'nb_ml');
    ?>
</h4>
                    
                    <?php 
    $fields = array('nav_arrows', 'carousel', 'autoplay', 'animation_time', 'slideshow_time', 'pause_on_hover', 'slide_all', 'autop_after_exp');
    foreach ($fields as $field) {
        $val = isset($data['settings'][$field]) ? $data['settings'][$field] : '';
        echo nb_fields_builder($field, $val);
    }
    ?>
                
                	<div class="mgom_btm_border_fix"></div>
            	</div>
                
            </div>  
          </div>
        </div>
    </form>    
	<?php 
    die;
}
コード例 #2
0
ファイル: shortcodes.php プロジェクト: datracka/datalook.io
function nb_shortcode($atts, $content = null)
{
    include_once NB_DIR . '/functions.php';
    extract(shortcode_atts(array('id' => ''), $atts));
    if ($id == '') {
        return '';
    }
    // get newsbox data
    $box = get_term($id, 'nb_boxes');
    $data = empty($box->description) ? '' : $box->description;
    if (empty($data)) {
        return '';
    }
    $data = unserialize(nb_fix_serialization($data));
    $opt = $data['settings'];
    // remote sources
    $rm_src = array();
    foreach ($data['src'] as $src) {
        if ($src['src_type'] != 'wp_cat' && $src['src_type'] != 'qn_cat' && $src['src_type'] != 'woo_cat' && strpos($src['src_type'], '|||') === false) {
            $rm_src[] = $src;
        }
    }
    /************************/
    // wrapper
    $nb = '<div id="lcnb_' . $id . '" class="lcnb_wp_wrap">%INLINE%</div>';
    // check if inline news are needed
    if (count($rm_src) != count($data['src'])) {
        $inl_code = '';
        foreach ($data['src'] as $src) {
            if ($src['src_type'] == 'wp_cat' || $src['src_type'] == 'qn_cat' || $src['src_type'] == 'woo_cat' || strpos($src['src_type'], '|||') !== false) {
                $inl_code .= nb_inline_code($src, $opt['max_news'], $opt['manage_exp_images']);
            }
        }
        $nb = str_replace('%INLINE%', $inl_code, $nb);
    } else {
        $nb = str_replace('%INLINE%', '', $nb);
    }
    //// javascript
    $nb .= '
	<script type="text/javascript">
	jQuery(document).ready(function() {
		jQuery("#lcnb_' . $id . '").lc_swift_box({
	';
    // sources
    if (count($rm_src) > 0) {
        $nb .= 'src:[';
        $sc = 1;
        foreach ($rm_src as $src) {
            $nb .= '{';
            // image size check
            if (get_option('nb_img_check')) {
                $nb .= 'max_img_size:{w : ' . get_option('nb_max_img_w', 800) . ', h : ' . get_option('nb_max_img_h', 600) . '},
		';
            }
            // expanded images management
            $nb .= 'exp_img_manag:{pos : "' . $src['exp_img_pos'] . '", w : "' . $src['exp_img_w'] . '", h : "' . $src['exp_img_h'] . '"},
		';
            $a = 1;
            foreach ($src as $i => $v) {
                if ($i != 'src_val' && $i != 'exp_img_pos' && $i != 'exp_img_w' && $i != 'exp_img_h' && $i != 'news_offset') {
                    if ($i == 'src_type') {
                        $nb .= 'type:"' . $v . '",';
                        $nb .= nb_src_opt_index($v) . ': "' . $src['src_val'] . '",
		';
                    } else {
                        if ($i == 'src_hide_elements') {
                            $i = 'hide_elements';
                        }
                        if ($i == 'author') {
                            $v = str_replace(array('&apos;', '&quot;', '&lt;', '&gt;'), array('\'', '"', '<', '>'), $v);
                        }
                        $ending_comma = $a == count($src) ? '
	' : ',
	';
                        $val = nb_php_to_js_datatype($i, $v);
                        $nb .= $i . ':' . $val . $ending_comma;
                    }
                }
                $a++;
            }
            $src_comma = $sc == count($rm_src) ? '
	' : ',
	';
            $nb .= '}' . $src_comma;
            $sc++;
        }
        $nb .= '],
	';
    }
    // global options
    $theme = get_option('nb_custom_style') ? 'wpdt' : get_option('nb_main_style', 'minimal');
    $nb .= 'theme:"' . $theme . '",
				lightbox:nb_lightbox,
				touchswipe:nb_touchswipe,
				min_news_h:nb_min_news_h,
				min_news_w:nb_min_news_w,
				min_horiz_w:nb_min_horiz_w,
				read_more_txt:nb_read_more_txt,
				fb_share_fix:nb_fb_share_fix,
				script_basepath:nb_script_basepath,
				short_d_names:nb_short_d_names,
				full_d_names:nb_full_d_names,
				short_m_names:nb_short_m_names,
				full_m_names:nb_full_m_names,
				elapsed_names:nb_elapsed_names,
		';
    // options
    $b = 1;
    foreach ($opt as $i => $v) {
        if ($i != 'box_id') {
            $ending_comma = $b == count($opt) ? '
	' : ',
	';
            $val = nb_php_to_js_datatype($i, $v);
            $nb .= $i . ':' . $val . $ending_comma;
            // if hide elements - check for socials
            if ($i == 'hide_elements' && is_array($v) && in_array('socials', $v)) {
                $nb .= 'social_share:false,';
            }
        }
        $b++;
    }
    $nb .= '
		});
	});
	</script>';
    return str_replace(array("\r", "\n", "\t", "\v"), '', $nb);
}