Esempio n. 1
0
 public function paint($page, $data = NULL)
 {
     $this->data['css'] = add_css($this->css);
     $this->data['meta'] = add_meta($this->meta);
     $this->data['js'] = add_js($this->js);
     $this->data['title'] = $this->title;
     $this->data['body_class'] = $this->CI->router->fetch_class();
     if (!is_null($data)) {
         foreach ($data as $key => $value) {
             $this->data[$key] = $value;
         }
     }
     foreach ($this->slice as $key => $value) {
         if (is_array($value)) {
             foreach ($value as $k => $v) {
                 if (method_exists($this->CI->slices, $v)) {
                     $result = call_user_func_array(array($this->CI->slices, $v), array());
                     foreach ($result as $restult_k => $result_v) {
                         if (!isset($this->data[$restult_k])) {
                             $this->data[$restult_k] = $result_v;
                         }
                     }
                 }
                 $this->data[$k] = $this->CI->load->view('slices/' . $v, $this->data, TRUE) . "\n";
             }
         } elseif (!is_numeric($key)) {
             if (method_exists($this->CI->slices, $key)) {
                 $result = call_user_func_array(array($this->CI->slices, $key), array());
                 foreach ($result as $k => $v) {
                     if (!isset($this->data[$k])) {
                         $this->data[$k] = $v;
                     }
                 }
             }
             $this->data[$key] = $this->CI->load->view('slices/' . $value, $this->data, TRUE) . "\n";
         } else {
             if (method_exists($this->CI->slices, $value)) {
                 $result = call_user_func_array(array($this->CI->slices, $value), array());
                 foreach ($result as $restult_k => $result_v) {
                     if (!isset($this->data[$restult_k])) {
                         $this->data[$restult_k] = $result_v;
                     }
                 }
             }
             $this->data[$value] = $this->CI->load->view('slices/' . $value, $this->data, TRUE) . "\n";
         }
     }
     $this->data['content'] = $this->CI->load->view('pages/' . $page, $this->data, TRUE) . "\n";
     $this->CI->load->view('layouts/' . $this->layout, $this->data);
 }
Esempio n. 2
0
 public function paint($page, $data = NULL)
 {
     $this->data['css'] = add_css($this->css);
     $this->data['meta'] = add_meta($this->meta);
     $this->data['js'] = add_js($this->js);
     $this->data['title'] = $this->title;
     if (!is_null($data)) {
         foreach ($data as $key => $value) {
             $this->data[$key] = $value;
         }
     }
     foreach ($this->slice as $slice) {
         $this->data[$slice] = $this->CI->load->view('slices/' . $slice, $this->data, TRUE) . "\n";
     }
     $this->data['content'] = $this->CI->load->view('pages/' . $page, $this->data, TRUE) . "\n";
     $this->CI->load->view('layouts/' . $this->layout, $this->data);
 }
function edit_post()
{
    global $user_ID;
    $post_ID = (int) $_POST['post_ID'];
    if (!current_user_can('edit_post', $post_ID)) {
        die(__('You are not allowed to edit this post.'));
    }
    // Rename.
    $_POST['ID'] = (int) $_POST['post_ID'];
    $_POST['post_content'] = $_POST['content'];
    $_POST['post_excerpt'] = $_POST['excerpt'];
    $_POST['post_parent'] = $_POST['parent_id'];
    $_POST['to_ping'] = $_POST['trackback_url'];
    if (!empty($_POST['post_author_override'])) {
        $_POST['post_author'] = (int) $_POST['post_author_override'];
    } else {
        if (!empty($_POST['post_author'])) {
            $_POST['post_author'] = (int) $_POST['post_author'];
        } else {
            $_POST['post_author'] = (int) $_POST['user_ID'];
        }
    }
    if ($_POST['post_author'] != $_POST['user_ID'] && !current_user_can('edit_others_posts')) {
        die(__('You cannot post as this user.'));
    }
    // What to do based on which button they pressed
    if ('' != $_POST['saveasdraft']) {
        $_POST['post_status'] = 'draft';
    }
    if ('' != $_POST['saveasprivate']) {
        $_POST['post_status'] = 'private';
    }
    if ('' != $_POST['publish']) {
        $_POST['post_status'] = 'publish';
    }
    if ('' != $_POST['advanced']) {
        $_POST['post_status'] = 'draft';
    }
    if ('' != $_POST['savepage']) {
        $_POST['post_status'] = 'static';
    }
    if ('publish' == $_POST['post_status'] && !current_user_can('publish_posts')) {
        $_POST['post_status'] = 'draft';
    }
    if ('static' == $_POST['post_status'] && !current_user_can('edit_pages')) {
        die(__('This user cannot edit pages.'));
    }
    if (!isset($_POST['comment_status'])) {
        $_POST['comment_status'] = 'closed';
    }
    if (!isset($_POST['ping_status'])) {
        $_POST['ping_status'] = 'closed';
    }
    if (!empty($_POST['edit_date'])) {
        $aa = $_POST['aa'];
        $mm = $_POST['mm'];
        $jj = $_POST['jj'];
        $hh = $_POST['hh'];
        $mn = $_POST['mn'];
        $ss = $_POST['ss'];
        $jj = $jj > 31 ? 31 : $jj;
        $hh = $hh > 23 ? $hh - 24 : $hh;
        $mn = $mn > 59 ? $mn - 60 : $mn;
        $ss = $ss > 59 ? $ss - 60 : $ss;
        $_POST['post_date'] = "{$aa}-{$mm}-{$jj} {$hh}:{$mn}:{$ss}";
        $_POST['post_date_gmt'] = get_gmt_from_date("{$aa}-{$mm}-{$jj} {$hh}:{$mn}:{$ss}");
    }
    // Meta Stuff
    if ($_POST['meta']) {
        foreach ($_POST['meta'] as $key => $value) {
            update_meta($key, $value['key'], $value['value']);
        }
    }
    if ($_POST['deletemeta']) {
        foreach ($_POST['deletemeta'] as $key => $value) {
            delete_meta($key);
        }
    }
    add_meta($post_ID);
    wp_update_post($_POST);
    // Now that we have an ID we can fix any attachment anchor hrefs
    fix_attachment_links($post_ID);
    return $post_ID;
}
Esempio n. 4
0
/**
 * Creates a new post from the "Write Post" form using $_POST information.
 *
 * @since unknown
 *
 * @return unknown
 */
function wp_write_post()
{
    global $user_ID;
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_pages')) {
            return new WP_Error('edit_pages', __('You are not allowed to create pages on this blog.'));
        }
    } else {
        if (!current_user_can('edit_posts')) {
            return new WP_Error('edit_posts', __('You are not allowed to create posts or drafts on this blog.'));
        }
    }
    // Check for autosave collisions
    $temp_id = false;
    if (isset($_POST['temp_ID'])) {
        $temp_id = (int) $_POST['temp_ID'];
        if (!($draft_ids = get_user_option('autosave_draft_ids'))) {
            $draft_ids = array();
        }
        foreach ($draft_ids as $temp => $real) {
            if (time() + $temp > 86400) {
                // 1 day: $temp is equal to -1 * time( then )
                unset($draft_ids[$temp]);
            }
        }
        if (isset($draft_ids[$temp_id])) {
            // Edit, don't write
            $_POST['post_ID'] = $draft_ids[$temp_id];
            unset($_POST['temp_ID']);
            update_user_option($user_ID, 'autosave_draft_ids', $draft_ids);
            return edit_post();
        }
    }
    $translated = _wp_translate_postdata(false);
    if (is_wp_error($translated)) {
        return $translated;
    }
    if (isset($_POST['visibility'])) {
        switch ($_POST['visibility']) {
            case 'public':
                $_POST['post_password'] = '';
                break;
            case 'password':
                unset($_POST['sticky']);
                break;
            case 'private':
                $_POST['post_status'] = 'private';
                $_POST['post_password'] = '';
                unset($_POST['sticky']);
                break;
        }
    }
    // Create the post.
    $post_ID = wp_insert_post($_POST);
    if (is_wp_error($post_ID)) {
        return $post_ID;
    }
    if (empty($post_ID)) {
        return 0;
    }
    add_meta($post_ID);
    // Reunite any orphaned attachments with their parent
    if (!($draft_ids = get_user_option('autosave_draft_ids'))) {
        $draft_ids = array();
    }
    if ($draft_temp_id = (int) array_search($post_ID, $draft_ids)) {
        _relocate_children($draft_temp_id, $post_ID);
    }
    if ($temp_id && $temp_id != $draft_temp_id) {
        _relocate_children($temp_id, $post_ID);
    }
    // Update autosave collision detection
    if ($temp_id) {
        $draft_ids[$temp_id] = $post_ID;
        update_user_option($user_ID, 'autosave_draft_ids', $draft_ids);
    }
    // Now that we have an ID we can fix any attachment anchor hrefs
    _fix_attachment_links($post_ID);
    wp_set_post_lock($post_ID, $GLOBALS['current_user']->ID);
    return $post_ID;
}
function edit_post() {
	global $user_ID;

	$post_ID = (int) $_POST['post_ID'];

	if ( 'page' == $_POST['post_type'] ) {
		if ( !current_user_can( 'edit_page', $post_ID ) )
			wp_die( __('You are not allowed to edit this page.' ));
	} else {
		if ( !current_user_can( 'edit_post', $post_ID ) )
			wp_die( __('You are not allowed to edit this post.' ));
	}

	// Autosave shouldn't save too soon after a real save
	if ( 'autosave' == $_POST['action'] ) {
		$post =& get_post( $post_ID );
		$now = time();
		$then = strtotime($post->post_date_gmt . ' +0000');
		// Keep autosave_interval in sync with autosave-js.php.
		$delta = apply_filters( 'autosave_interval', 120 ) / 2;
		if ( ($now - $then) < $delta )
			return $post_ID;
	}

	// Rename.
	$_POST['ID'] = (int) $_POST['post_ID'];
	$_POST['post_content'] = $_POST['content'];
	$_POST['post_excerpt'] = $_POST['excerpt'];
	$_POST['post_parent'] = $_POST['parent_id'];
	$_POST['to_ping'] = $_POST['trackback_url'];

	if (!empty ( $_POST['post_author_override'] ) ) {
		$_POST['post_author'] = (int) $_POST['post_author_override'];
	} else
		if (!empty ( $_POST['post_author'] ) ) {
			$_POST['post_author'] = (int) $_POST['post_author'];
		} else {
			$_POST['post_author'] = (int) $_POST['user_ID'];
		}

	if ( $_POST['post_author'] != $_POST['user_ID'] ) {
		if ( 'page' == $_POST['post_type'] ) {
			if ( !current_user_can( 'edit_others_pages' ) )
				wp_die( __('You are not allowed to edit pages as this user.' ));
		} else {
			if ( !current_user_can( 'edit_others_posts' ) )
				wp_die( __('You are not allowed to edit posts as this user.' ));

		}
	}

	// What to do based on which button they pressed
	if ('' != $_POST['saveasdraft'] )
		$_POST['post_status'] = 'draft';
	if ('' != $_POST['saveasprivate'] )
		$_POST['post_status'] = 'private';
	if ('' != $_POST['publish'] )
		$_POST['post_status'] = 'publish';
	if ('' != $_POST['advanced'] )
		$_POST['post_status'] = 'draft';

	if ( 'page' == $_POST['post_type'] ) {
		if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_pages' ))
			$_POST['post_status'] = 'draft';
	} else {
		if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_posts' ))
			$_POST['post_status'] = 'draft';
	}

	if (!isset( $_POST['comment_status'] ))
		$_POST['comment_status'] = 'closed';

	if (!isset( $_POST['ping_status'] ))
		$_POST['ping_status'] = 'closed';

	if (!empty ( $_POST['edit_date'] ) ) {
		$aa = $_POST['aa'];
		$mm = $_POST['mm'];
		$jj = $_POST['jj'];
		$hh = $_POST['hh'];
		$mn = $_POST['mn'];
		$ss = $_POST['ss'];
		$jj = ($jj > 31 ) ? 31 : $jj;
		$hh = ($hh > 23 ) ? $hh -24 : $hh;
		$mn = ($mn > 59 ) ? $mn -60 : $mn;
		$ss = ($ss > 59 ) ? $ss -60 : $ss;
		$_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
		$_POST['post_date_gmt'] = get_gmt_from_date( "$aa-$mm-$jj $hh:$mn:$ss" );
	}

	// Meta Stuff
	if ( $_POST['meta'] ) {
		foreach ( $_POST['meta'] as $key => $value )
			update_meta( $key, $value['key'], $value['value'] );
	}

	if ( $_POST['deletemeta'] ) {
		foreach ( $_POST['deletemeta'] as $key => $value )
			delete_meta( $key );
	}

	add_meta( $post_ID );

	wp_update_post( $_POST );

	// Reunite any orphaned attachments with their parent
	if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
		$draft_ids = array();
	if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) )
		relocate_children( $draft_temp_id, $post_ID );

	// Now that we have an ID we can fix any attachment anchor hrefs
	fix_attachment_links( $post_ID );

	return $post_ID;
}
Esempio n. 6
0
     }
     if ($pid < 0) {
         $now = current_time('timestamp', 1);
         if ($pid = wp_insert_post(array('post_title' => sprintf('Draft created on %s at %s', date(get_option('date_format'), $now), date(get_option('time_format'), $now))))) {
             if (is_wp_error($pid)) {
                 $x = new WP_Ajax_Response(array('what' => 'meta', 'data' => $pid));
                 $x->send();
             }
             if (!($mid = add_meta($pid))) {
                 die(__('Please provide a custom field value.'));
             }
         } else {
             die('0');
         }
     } else {
         if (!($mid = add_meta($pid))) {
             die(__('Please provide a custom field value.'));
         }
     }
     $meta = get_post_meta_by_id($mid);
     $pid = (int) $meta->post_id;
     $meta = get_object_vars($meta);
     $x = new WP_Ajax_Response(array('what' => 'meta', 'id' => $mid, 'data' => _list_meta_row($meta, $c), 'position' => 1, 'supplemental' => array('postid' => $pid)));
 } else {
     $mid = (int) array_pop(array_keys($_POST['meta']));
     $key = $_POST['meta'][$mid]['key'];
     $value = $_POST['meta'][$mid]['value'];
     if (!($meta = get_post_meta_by_id($mid))) {
         die('0');
     }
     // if meta doesn't exist
         }
         do_action('publish_post', $post_ID);
         do_trackback($postObject, $useutf8);
     }
     // Meta Stuff
     if ($meta) {
         foreach ($meta as $key => $value) {
             update_meta($key, $value['key'], $value['value']);
         }
     }
     if ($deletemeta) {
         foreach ($deletemeta as $key => $value) {
             delete_meta($key);
         }
     }
     add_meta($post_ID);
     do_action('edit_post', $post_ID);
     exit;
     break;
     //Show Delete Cofirmation Screen
 //Show Delete Cofirmation Screen
 case 'confirmdelete':
     //Check User_Level
     user_level_check();
     //Rendering Admin Screen header
     $parent_file = 'edit.php';
     $title = 'Delete Post';
     $standalone = 0;
     require_once 'admin-header.php';
     //Check Paramaters
     init_param('GET', 'post', 'integer', NO_DEFAULT_PARAM, true);
 /**
  * Set custom fields for post.
  *
  * @since 2.5.0
  *
  * @param int $post_id Post ID.
  * @param array $fields Custom fields.
  */
 function set_custom_fields($post_id, $fields)
 {
     $post_id = (int) $post_id;
     foreach ((array) $fields as $meta) {
         if (isset($meta['id'])) {
             $meta['id'] = (int) $meta['id'];
             if (isset($meta['key'])) {
                 update_meta($meta['id'], $meta['key'], $meta['value']);
             } else {
                 delete_meta($meta['id']);
             }
         } else {
             $_POST['metakeyinput'] = $meta['key'];
             $_POST['metavalue'] = $meta['value'];
             add_meta($post_id);
         }
     }
 }
Esempio n. 9
0
    }
    if (get_array_value(CMS::$cache[$module_name]['config'], 'disabled' === true)) {
        continue;
    }
    logthis('applying template processor at module: ' . $module_name);
    $template = CMS::$cache[$module_name]['object']->ContentGenerator($template);
    logthis('template processor finished at module: ' . $module_name);
    if (get_array_value(CMS::$cache[$module_name]['config'], 'break_after', false)) {
        break;
    }
}
// remove unused templates
$template = preg_replace('~</?macro.*?>~', '', $template);
$template = preg_replace('~\\[/?macro.*?\\]~', '', $template);
// back-replace protected templates
$template = str_replace('<protected-macro', '<macro', $template);
$template = str_replace('[protected-macro', '[macro', $template);
$template = str_replace('</protected-macro', '</macro', $template);
$template = str_replace('[/protected-macro', '[/macro', $template);
logthis('unused templates removed');
$template = popup_messages_to_template($template);
logthis('popups added');
// flush CSS and JS storages
$template = flush_CSS($template);
$template = flush_JS($template);
// sign it!
$template = add_meta($template, 'name', 'generator', 'JuliaCMS Valenok Edition');
// yeah we did it!
logthis('completed, adding log results and flushing!');
echo $template;
terminate();
Esempio n. 10
0
function wp_write_post() {
	global $user_ID;

	if ( 'page' == $_POST['post_type'] ) {
		if ( !current_user_can( 'edit_pages' ) )
			return new WP_Error( 'edit_pages', __( 'You are not allowed to create pages on this blog.' ) );
	} else {
		if ( !current_user_can( 'edit_posts' ) )
			return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this blog.' ) );
	}


	// Check for autosave collisions
	$temp_id = false;
	if ( isset($_POST['temp_ID']) ) {
		$temp_id = (int) $_POST['temp_ID'];
		if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
			$draft_ids = array();
		foreach ( $draft_ids as $temp => $real )
			if ( time() + $temp > 86400 ) // 1 day: $temp is equal to -1 * time( then )
				unset($draft_ids[$temp]);

		if ( isset($draft_ids[$temp_id]) ) { // Edit, don't write
			$_POST['post_ID'] = $draft_ids[$temp_id];
			unset($_POST['temp_ID']);
			update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids );
			return edit_post();
		}
	}

	// Rename.
	$_POST['post_content'] = $_POST['content'];
	$_POST['post_excerpt'] = $_POST['excerpt'];
	$_POST['post_parent'] = isset($_POST['parent_id'])? $_POST['parent_id'] : '';
	$_POST['to_ping'] = $_POST['trackback_url'];

	if (!empty ( $_POST['post_author_override'] ) ) {
		$_POST['post_author'] = (int) $_POST['post_author_override'];
	} else {
		if (!empty ( $_POST['post_author'] ) ) {
			$_POST['post_author'] = (int) $_POST['post_author'];
		} else {
			$_POST['post_author'] = (int) $_POST['user_ID'];
		}

	}

	if ( $_POST['post_author'] != $_POST['user_ID'] ) {
		if ( 'page' == $_POST['post_type'] ) {
			if ( !current_user_can( 'edit_others_pages' ) )
				return new WP_Error( 'edit_others_pages', __( 'You are not allowed to create pages as this user.' ) );
		} else {
			if ( !current_user_can( 'edit_others_posts' ) )
				return new WP_Error( 'edit_others_posts', __( 'You are not allowed to post as this user.' ) );

		}
	}

	// What to do based on which button they pressed
	if ( isset($_POST['saveasdraft']) && '' != $_POST['saveasdraft'] )
		$_POST['post_status'] = 'draft';
	if ( isset($_POST['saveasprivate']) && '' != $_POST['saveasprivate'] )
		$_POST['post_status'] = 'private';
	if ( isset($_POST['publish']) && ( '' != $_POST['publish'] ) && ( $_POST['post_status'] != 'private' ) )
		$_POST['post_status'] = 'publish';
	if ( isset($_POST['advanced']) && '' != $_POST['advanced'] )
		$_POST['post_status'] = 'draft';

	if ( 'page' == $_POST['post_type'] ) {
		if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_pages' ) )
			$_POST['post_status'] = 'pending';
	} else {
		if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_posts' ) )
			$_POST['post_status'] = 'pending';
	}

	if (!isset( $_POST['comment_status'] ))
		$_POST['comment_status'] = 'closed';

	if (!isset( $_POST['ping_status'] ))
		$_POST['ping_status'] = 'closed';

	foreach ( array ('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) {
		if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) {
			$_POST['edit_date'] = '1';
			break;
		}
	}

	if (!empty ( $_POST['edit_date'] ) ) {
		$aa = $_POST['aa'];
		$mm = $_POST['mm'];
		$jj = $_POST['jj'];
		$hh = $_POST['hh'];
		$mn = $_POST['mn'];
		$ss = $_POST['ss'];
		$jj = ($jj > 31 ) ? 31 : $jj;
		$hh = ($hh > 23 ) ? $hh -24 : $hh;
		$mn = ($mn > 59 ) ? $mn -60 : $mn;
		$ss = ($ss > 59 ) ? $ss -60 : $ss;
		$_POST['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
		$_POST['post_date_gmt'] = get_gmt_from_date( $_POST['post_date'] );
	}

	// Create the post.
	$post_ID = wp_insert_post( $_POST );
	if ( is_wp_error( $post_ID ) )
		return $post_ID;

	if ( empty($post_ID) )
		return 0;

	add_meta( $post_ID );

	// Reunite any orphaned attachments with their parent
	if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
		$draft_ids = array();
	if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) )
		_relocate_children( $draft_temp_id, $post_ID );
	if ( $temp_id && $temp_id != $draft_temp_id )
		_relocate_children( $temp_id, $post_ID );

	// Update autosave collision detection
	if ( $temp_id ) {
		$draft_ids[$temp_id] = $post_ID;
		update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids );
	}

	// Now that we have an ID we can fix any attachment anchor hrefs
	_fix_attachment_links( $post_ID );

	wp_set_post_lock( $post_ID, $GLOBALS['current_user']->ID );

	return $post_ID;
}
Esempio n. 11
0
    } else {
        return false;
    }
}
function print_metas()
{
    global $yg_metas;
    foreach ($yg_metas as $metakey => $metacontent) {
        $metakey = preg_replace('|[^A-Za-z0-9-]+|', '', $metakey);
        $metatype = $metacontent[1] === true ? 'http-equiv' : 'name';
        $metacontent = htmlspecialchars($metacontent[0]);
        echo '<meta ' . $metatype . '="' . $metakey . '" content="' . $metacontent . '">' . "\n";
    }
}
add_action('yg_meta', 'print_metas');
add_meta('generator', 'Yogo ' . YG_VERSION_FULL);
function get_header()
{
    $template = get_query_template('header');
    if (!empty($template)) {
        load_template($template, true);
    } else {
        Core::log('Header file missing for theme', YG_WARNING);
    }
}
function get_footer()
{
    $template = get_query_template('footer');
    if (!empty($template)) {
        load_template($template, true);
    } else {
                    $proceed = TRUE;
                }
            }
        }
    }
}
if (!$validpage) {
    header("Location: 404");
} else {
    if ($proceed) {
        ob_start();
        $pagetitle = ucfirst($page);
        if ($page == "404") {
            $pagetitle = "HTTP Error " . $page;
        }
        add_meta($pagetitle);
        ?>
			<div id="header">
				<a id="logo" href="<?php 
        if ($_SESSION['loginuserid'] == "") {
            print "login";
        } else {
            if ($user_details->admin == 1) {
                print "admin";
            } else {
                if (isset($user_bookings)) {
                    print "checkout";
                } else {
                    print "browse";
                }
            }
Esempio n. 13
0
 function contentGenerator($template)
 {
     $USERFILES_DIRS = CMS::$R['USERFILES_DIRS'];
     // если этот флажок есть, будет вызван редактор вместо отображения контента
     $edit_mode = isset($_GET['edit']);
     // идентификатор странички, которую надо вставить в шаблон. валидация не нужна - делается поиск в массиве
     // собираем список имеющихся страниц
     $pages = array();
     $query = CMS::$DB->query("select * from `{$this->CONFIG['table']}`");
     while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
         $pages[$row['alias']] = $row;
     }
     $page_id = isset($_GET['p_id']) ? $_GET['p_id'] : DEFAULT_PAGE_ALIAS;
     // ок, берем стандартную страницу, если таковая есть
     $page_found = false;
     if (isset($pages[$page_id])) {
         $page_found = true;
         $page_info = $pages[$page_id];
     } else {
         // если нужного идентификатора нет в страницах, посмотрим в меню, если там найдется - пускай сами разбираются
         if (module_get_config('menu', $menu_module_config) === true) {
             $query = CMS::$DB->query("select alias from `{$menu_module_config['config']['table_menu']}` where alias > ''");
             while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
                 if ($page_id == $row['alias']) {
                     $page_found = true;
                     return $template;
                 }
             }
         }
     }
     // если страница не найдена, попробуем использовать то, что указано в настройках для страницы 404,
     // если и там нету - тупо заменяем макрос на строку и вываливаемся
     if (!$page_found) {
         header('HTTP/1.1 404 Not found');
         if (isset($pages[$this->CONFIG['page_404']])) {
             $page_info = $pages[$this->CONFIG['page_404']];
         } else {
             $template = preg_replace(macro_regexp('content'), 'Страница не найдена', $template);
             return $template;
         }
     }
     // имя файла с контентом
     $content_filename = isset($page_info['filename']) && file_exists($USERFILES_DIRS['pages']['dir'] . $page_info['filename']) ? $USERFILES_DIRS['pages']['dir'] . $page_info['filename'] : $this->CONFIG['page_404'];
     // в режиме редактирования текст/xml не генерируем, а показываем в редакторе (textarea)
     if ($edit_mode && user_allowed_to('edit pages')) {
         switch (pathinfo($page_info['filename'], PATHINFO_EXTENSION)) {
             case 'php':
             case 'xml':
                 $pagehtml = sprintf(MODULE_CONTENT_TEXTAREA_WRAPPER_PHP, $page_id, @file_get_contents($content_filename));
                 break;
             default:
                 $pagecontent = @file_get_contents($content_filename);
                 // при редактировании заменим макросы на защищенную версию, иначе следующие модули на них среагируют
                 // и заменят на свой контент, что наи не нужно. ядро само заменит их обратно потом
                 $pagecontent = str_replace('<macro', '<protected-macro', $pagecontent);
                 $pagecontent = str_replace('[macro', '[protected-macro', $pagecontent);
                 $pagecontent = str_replace('</macro', '</protected-macro', $pagecontent);
                 $pagecontent = str_replace('[/macro', '[/protected-macro', $pagecontent);
                 $pagehtml = sprintf(MODULE_CONTENT_TEXTAREA_WRAPPER, $page_id, $pagecontent);
                 break;
         }
     } else {
         // если html, тащим как есть, иначе формируем с помошью генератора или XSLT
         switch ($ext = pathinfo($content_filename, PATHINFO_EXTENSION)) {
             case 'php':
                 include_once $content_filename;
                 $pagehtml = call_user_func($page_info['generator']);
                 break;
             case 'xml':
                 $pagehtml = XSLTransform($content_filename, $USERFILES_DIRS['xsl']['dir'] . $page_info['xsl'], false, false);
                 break;
             default:
                 ($pagehtml = file_get_contents($content_filename)) !== false or $pagehtml = 'error reading page content (code CONTENT/001)';
                 break;
         }
     }
     // если есть BODY, берем его внутреннее содержимое, иначе весь файл целиком
     if (preg_match(self::REGEXP_HTML_BODY, $pagehtml, $page_body) > 0) {
         $replace = $page_body[1];
     } else {
         $replace = $pagehtml;
     }
     if (isset($_GET['print'])) {
         $template = str_replace('%content%', $replace, MODULE_CONTENT_PRINT_FORM);
     } else {
         $template = preg_replace(macro_regexp('content'), $replace, $template);
     }
     // мета в заголовке. если только буквы-цифры, делаем мету keywords
     if (preg_match('~^[a-zA-Zа-яА-Я0-9,.\\-\\s]+$~ui', $page_info['meta'], $match)) {
         $template = add_meta($template, 'name', 'keywords', $match[0]);
     } elseif (preg_match_all('~(\\(([a-zA-Z\\-]*)\\|([a-zA-Z\\-0-9]+)\\|([a-zA-Z\\-0-9а-яА-Я.,;:\\s+=!@#$%^&*\\(\\)]*)\\))~smui', $page_info['meta'], $matches)) {
         // не прокатило, попробуем структуру со скобками и пайпами
         for ($i = 0; $i < count($matches[0]); $i++) {
             $template = add_meta($template, $matches[2][$i], $matches[3][$i], $matches[4][$i]);
         }
     } elseif (preg_match_all('~<meta\\s[^>]+>~smui', $page_info['meta'], $matches)) {
         // проверим, возможно вписали сырые теги
         for ($i = 0; $i < count($matches[0]); $i++) {
             $template = str_insert_before('</head>', $matches[0][$i] . PHP_EOL, $template);
         }
     }
     // заменяем залоговок страницы, если определен
     if (isset($page_info['title']) && ($replace = $page_info['title']) > '') {
         $template = preg_replace(macro_regexp('page_title'), $replace, $template, 1);
     }
     // кастомный CSS, если указан
     if (isset($page_info['custom_css']) && ($css = $page_info['custom_css']) > '') {
         add_CSS(CMS::$R['USERFILES_DIRS']['css']['dir'] . $css);
     }
     // кастомный JS, если указан
     if (isset($page_info['custom_js']) && ($js = $page_info['custom_js']) > '') {
         add_JS(CMS::$R['USERFILES_DIRS']['js']['dir'] . $js);
     }
     return $template;
 }
Esempio n. 14
0
 /**
  *
  */
 function contentGenerator($template)
 {
     // catalog mode: intercept _GET page alias, look in self elements, display child items list if exists
     $input_filter = array('p_id' => array('filter' => FILTER_VALIDATE_REGEXP, 'options' => array('regexp' => REGEXP_ALIAS)));
     $_INPUT = get_filtered_input($input_filter, array(FILTER_GET_BY_LIST));
     if ($_INPUT['p_id'] > '') {
         // this will mean that nothing was found
         $id = -1;
         $query = CMS::$DB->query("select * from `{$this->CONFIG['table_menu']}` where alias = '{$_INPUT['p_id']}'");
         if ($row = $query->fetch(PDO::FETCH_ASSOC)) {
             $id = $row['id'];
             $css_content = $row['style_content'];
             $caption = $row['caption'];
             $title = $row['title'] ? $row['title'] : $row['caption'];
             $meta = $row['meta'];
         }
         // if we found something, insert it instead content
         if ($id >= 0) {
             while (preg_match(macro_regexp('content'), $template, $match) > 0) {
                 $params = parse_plugin_template($match[0]);
                 $html = $this->generateCatalogPageHTML($_INPUT['p_id'], $params);
                 // possibly we will need navigator from the current page
                 if (get_array_value($params, 'show-navigator', 'yes') == 'yes') {
                     $html = $this->generateNavigatorHTML($_INPUT['p_id'], $params) . $html;
                 }
                 $template = preg_replace(macro_regexp('content'), $html, $template);
                 $template = preg_replace(macro_regexp('page_title'), $title, $template);
                 // add meta. if only letter and digits, make "keywords" meta (!copy-paste detected!)
                 if (preg_match('~^[a-zA-Zа-яА-Я0-9,.\\-\\s]+$~ui', $meta, $match)) {
                     $template = add_meta($template, 'name', 'keywords', $match[0]);
                 } elseif (preg_match_all('~(\\(([a-zA-Z\\-]*)\\|([a-zA-Z\\-0-9]+)\\|([a-zA-Z\\-0-9а-яА-Я.,;:\\s+=!@#$%^&*\\(\\)]*)\\))~smui', $meta, $matches)) {
                     // не прокатило, попробуем структуру со скобками и пайпами
                     for ($i = 0; $i < count($matches[0]); $i++) {
                         $template = add_meta($template, $matches[2][$i], $matches[3][$i], $matches[4][$i]);
                     }
                 } elseif (preg_match_all('~<[a-zA-Z]+\\s[^<>]+>~smui', $meta, $matches)) {
                     // check if raw tags there
                     for ($i = 0; $i < count($matches[0]); $i++) {
                         $template = str_insert_before('</head>', $matches[0][$i] . PHP_EOL, $template);
                     }
                 }
                 // yeah, nice stylesheets
                 add_CSS($css_content, CMS::$R['USERFILES_DIRS']['css']['dir']);
             }
         }
     }
     // standard behavior - menu by macro
     while (preg_match(macro_regexp('menu'), $template, $match) > 0) {
         // parse template parameters into array
         $params = parse_plugin_template($match[0]);
         // generate menu HTML
         $xml = $this->generateMenuAsXML(get_array_value($params, 'start-from', ''));
         $xsl = get_array_value($params, 'menu-template', 'default');
         // now test with path
         $xsl_filename = __DIR__ . '/../../userfiles/_data_modules/menu/templates/menu/' . $xsl . '.xsl';
         if (!file_exists($xsl_filename)) {
             $xsl_filename = __DIR__ . '/templates/' . $catalog_dir . '/' . $xsl . '.xsl';
         }
         $html = XSLTransform($xml->saveXML($xml->documentElement), $xsl_filename);
         // replace it
         $template = str_replace($match[0], $html, $template);
     }
     // navigator mode
     while (preg_match(macro_regexp('menu-navigator'), $template, $match) > 0) {
         // parse template parameters into array
         $params = parse_plugin_template($match[0]);
         // generate navigator HTML
         $html = $this->generateNavigatorHTML(get_array_value($params, 'start-from', ''), $params);
         // replace it
         $template = str_replace($match[0], $html, $template);
     }
     // yeah we are ready
     return $template;
 }
Esempio n. 15
0
/**
 * Creates a new post from the "Write Post" form using $_POST information.
 *
 * @since 2.1.0
 *
 * @global WP_User $current_user
 *
 * @return int|WP_Error
 */
function wp_write_post()
{
    if (isset($_POST['post_type'])) {
        $ptype = get_post_type_object($_POST['post_type']);
    } else {
        $ptype = get_post_type_object('post');
    }
    if (!current_user_can($ptype->cap->edit_posts)) {
        if ('page' == $ptype->name) {
            return new WP_Error('edit_pages', __('Sorry, you are not allowed to create pages on this site.'));
        } else {
            return new WP_Error('edit_posts', __('Sorry, you are not allowed to create posts or drafts on this site.'));
        }
    }
    $_POST['post_mime_type'] = '';
    // Clear out any data in internal vars.
    unset($_POST['filter']);
    // Edit don't write if we have a post id.
    if (isset($_POST['post_ID'])) {
        return edit_post();
    }
    if (isset($_POST['visibility'])) {
        switch ($_POST['visibility']) {
            case 'public':
                $_POST['post_password'] = '';
                break;
            case 'password':
                unset($_POST['sticky']);
                break;
            case 'private':
                $_POST['post_status'] = 'private';
                $_POST['post_password'] = '';
                unset($_POST['sticky']);
                break;
        }
    }
    $translated = _wp_translate_postdata(false);
    if (is_wp_error($translated)) {
        return $translated;
    }
    // Create the post.
    $post_ID = wp_insert_post($_POST);
    if (is_wp_error($post_ID)) {
        return $post_ID;
    }
    if (empty($post_ID)) {
        return 0;
    }
    add_meta($post_ID);
    add_post_meta($post_ID, '_edit_last', $GLOBALS['current_user']->ID);
    // Now that we have an ID we can fix any attachment anchor hrefs
    _fix_attachment_links($post_ID);
    wp_set_post_lock($post_ID);
    return $post_ID;
}
		) );
	}
	$x->send();
	break;
case 'add-meta' :
	if ( !current_user_can( 'edit_post', $id ) )
		die('-1');
	if ( $id < 0 ) {
		$now = current_time('timestamp', 1);
		if ( $pid = wp_insert_post( array(
			'post_title' => sprintf('Draft created on %s at %s', date(get_option('date_format'), $now), date(get_option('time_format'), $now))
		) ) )
			$mid = add_meta( $pid );
		else
			die('0');
	} else if ( !$mid = add_meta( $id ) ) {
		die('0');
	}

	$meta = get_post_meta_by_id( $mid );
	$key = $meta->meta_key;
	$value = $meta->meta_value;
	$pid = (int) $meta->post_id;

	$x = new WP_Ajax_Response( array(
		'what' => 'meta',
		'id' => $mid,
		'data' => wp_ajax_meta_row( $pid, $mid, $key, $value ),
		'supplemental' => array('postid' => $pid)
	) );
	$x->send();
Esempio n. 17
0
/**
 * Ajax handler for adding meta.
 *
 * @since 3.1.0
 */
function wp_ajax_add_meta()
{
    check_ajax_referer('add-meta', '_ajax_nonce-add-meta');
    $c = 0;
    $pid = (int) $_POST['post_id'];
    $post = get_post($pid);
    if (isset($_POST['metakeyselect']) || isset($_POST['metakeyinput'])) {
        if (!current_user_can('edit_post', $pid)) {
            wp_die(-1);
        }
        if (isset($_POST['metakeyselect']) && '#NONE#' == $_POST['metakeyselect'] && empty($_POST['metakeyinput'])) {
            wp_die(1);
        }
        // If the post is an autodraft, save the post as a draft and then attempt to save the meta.
        if ($post->post_status == 'auto-draft') {
            $post_data = array();
            $post_data['action'] = 'draft';
            // Warning fix
            $post_data['post_ID'] = $pid;
            $post_data['post_type'] = $post->post_type;
            $post_data['post_status'] = 'draft';
            $now = current_time('timestamp', 1);
            $post_data['post_title'] = sprintf(__('Draft created on %1$s at %2$s'), date(get_option('date_format'), $now), date(get_option('time_format'), $now));
            $pid = edit_post($post_data);
            if ($pid) {
                if (is_wp_error($pid)) {
                    $x = new WP_Ajax_Response(array('what' => 'meta', 'data' => $pid));
                    $x->send();
                }
                if (!($mid = add_meta($pid))) {
                    wp_die(__('Please provide a custom field value.'));
                }
            } else {
                wp_die(0);
            }
        } elseif (!($mid = add_meta($pid))) {
            wp_die(__('Please provide a custom field value.'));
        }
        $meta = get_metadata_by_mid('post', $mid);
        $pid = (int) $meta->post_id;
        $meta = get_object_vars($meta);
        $x = new WP_Ajax_Response(array('what' => 'meta', 'id' => $mid, 'data' => _list_meta_row($meta, $c), 'position' => 1, 'supplemental' => array('postid' => $pid)));
    } else {
        // Update?
        $mid = (int) key($_POST['meta']);
        $key = wp_unslash($_POST['meta'][$mid]['key']);
        $value = wp_unslash($_POST['meta'][$mid]['value']);
        if ('' == trim($key)) {
            wp_die(__('Please provide a custom field name.'));
        }
        if ('' == trim($value)) {
            wp_die(__('Please provide a custom field value.'));
        }
        if (!($meta = get_metadata_by_mid('post', $mid))) {
            wp_die(0);
        }
        // if meta doesn't exist
        if (is_protected_meta($meta->meta_key, 'post') || is_protected_meta($key, 'post') || !current_user_can('edit_post_meta', $meta->post_id, $meta->meta_key) || !current_user_can('edit_post_meta', $meta->post_id, $key)) {
            wp_die(-1);
        }
        if ($meta->meta_value != $value || $meta->meta_key != $key) {
            if (!($u = update_metadata_by_mid('post', $mid, $value, $key))) {
                wp_die(0);
            }
            // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems).
        }
        $x = new WP_Ajax_Response(array('what' => 'meta', 'id' => $mid, 'old_id' => $mid, 'data' => _list_meta_row(array('meta_key' => $key, 'meta_value' => $value, 'meta_id' => $mid), $c), 'position' => 0, 'supplemental' => array('postid' => $meta->post_id)));
    }
    $x->send();
}
Esempio n. 18
0
    $_SESSION['user_pass'] = $user_pass_true;
    //$this->success('登陆成功',U('user/index/edit?id='.getUserId()));
    header("Location:/user-index-edit-id-" . getUserId() . ".html");
} else {
    do {
        $user_name_test = $oid . rand(1000, 9999);
    } while (mc_check_user_name($user_name_test));
    $user = array();
    $user['title'] = $uinfo["nickname"];
    $user['content'] = '';
    $user['type'] = 'user';
    $user['date'] = time();
    //$result = M("page")->data($user)->add();
    $sql = "insert into mc_page(title,content,type,date) values('" . $user['title'] . "','" . $user['content'] . "','" . $user['type'] . "','" . $user['date'] . "')";
    $res = mysql_query($sql, $link);
    if ($res) {
        $id = mysql_insert_id();
        add_meta($id, 'user_name', $user_name_test, 'user');
        $user_pass = md5($oid . get_option('site_key'));
        add_meta($id, 'user_pass', $user_pass, 'user');
        add_meta($id, 'user_qqoid', $oid, 'user');
        add_meta($id, 'user_level', '1', 'user');
        //session('user_name',$user_name_test);
        $_SESSION['user_name'] = $user_name_test;
        $_SESSION['user_pass'] = $user_pass;
        header("Location:/user-index-edit-id-" . getUserId() . ".html");
    } else {
        echo "登陆失败!";
        header("Location:/");
    }
}