Exemple #1
0
 function updateSelectedCategories($changed_cats)
 {
     $selected_cats = $this->getCategories();
     // look for newly checked categories
     foreach ($changed_cats as $changed_cat) {
         $found = false;
         if (is_array($selected_cats)) {
             foreach ($selected_cats as $selected_cat) {
                 if ($selected_cat->id == $changed_cat) {
                     $found = true;
                 }
             }
         }
         if (!$found) {
             $tmp_cat = Categories::FindById($changed_cat);
             $this->attach($tmp_cat);
         }
     }
     // look for deleted/unchecked categories
     foreach ($selected_cats as $selected_cat) {
         if (!in_array($selected_cat->id, $changed_cats)) {
             //the user has removed this area
             $tmp_cat = Categories::FindById($selected_cat->id);
             $this->detach($tmp_cat);
         }
     }
 }
Exemple #2
0
function initialize_page()
{
    // This file does both, so check the parameters first
    if (requestIdParam() == "add") {
        $entry = MyActiveRecord::Create('Blog_Entries');
    } else {
        $entry_id = requestIdParam();
        $entry = Blog_Entries::FindById($entry_id);
    }
    $post_action = "";
    if (isset($_POST['submit'])) {
        $post_action = $_POST['submit'];
    }
    $blog = Blogs::FindById(BLOG_DEFAULT_ID);
    // Check for the delete action
    if (isset($_POST['delete'])) {
        // Delete a photo if there is one
        if (BLOG_ENTRY_IMAGES) {
            $photo = array_shift(MyActiveRecord::FindBySql('Photos', "SELECT * FROM photos WHERE entry_id = {$entry->id}"));
            if (is_object($photo)) {
                $photo->delete(true);
            }
        }
        $entry->delete();
        setFlash("<h3>Entry Deleted</h3>");
        redirect("/admin/list_entries/" . $user->id);
    } else {
        if ($post_action == "Save Entry" || $post_action == "Save and Return to List") {
            /*
             * Columns: id, title, slug, date, content, excerpt, public, template, author_id, blog_id
             */
            $entry->title = getPostValue('title');
            $entry->slug = slug(getPostValue('title'));
            if (getPostValue('date') != "") {
                $entry->setEntryDateAndTime(getPostValue('date'));
            } else {
                $entry->date = date('Y-m-d H:i:s');
            }
            $entry->content = getPostValue('entry_content');
            $entry->excerpt = getPostValue('entry_excerpt');
            $entry->public = checkboxValue($_POST, 'public');
            if (BLOG_ENTRY_TEMPLATES) {
                $entry->template = $_POST['template'];
            }
            $entry->author_id = $_POST['author_id'];
            $entry->blog_id = $blog->id;
            $entry->save();
            $success = "Blog Entry Saved / ";
            // synchronize the users category selections
            $selected_cats = array();
            if (isset($_POST['selected_cats'])) {
                $selected_cats = $_POST['selected_cats'];
                $entry->updateSelectedCategories($selected_cats);
            } else {
                $uncategorized = Categories::FindById(1);
                $entry->attach($uncategorized);
            }
            // Upload the photo if one is allowed
            if (isset($_FILES['entry_image']) && $_FILES['entry_image']['error'] == 0) {
                // delete an old file if there is one
                $oldphoto = array_shift(MyActiveRecord::FindBySql('Photos', "SELECT * FROM photos WHERE entry_id = {$entry->id}"));
                if (is_object($oldphoto)) {
                    $oldphoto->delete(true);
                }
                // user has added a new photo
                $newphoto = MyActiveRecord::Create('Photos', array('caption' => $entry->title, 'entry_id' => $entry->id));
                $newphoto->save();
                $newphoto->save_uploaded_file($_FILES['entry_image']['tmp_name'], $_FILES['entry_image']['name'], '', $isentryimg = true);
                $success .= "New image uploaded / ";
            }
            if (requestIdParam() == "add") {
                setFlash('<h3>' . $success . '<a href="' . get_link('admin/edit_entry/' . $entry->id) . '">Edit it Now</a></h3>');
            } else {
                setFlash("<h3>" . substr($success, 0, -3) . "</h3>");
            }
            if ($post_action == "Save and Return to List") {
                redirect("admin/list_entries/");
            }
        }
    }
}
Exemple #3
0
function display_page_content()
{
    // We use the old way to get all entries, because the FindAll function forces an exclusion date
    $the_blog = Blogs::FindById(BLOG_DEFAULT_ID);
    $entries = $the_blog->getEntries(false, false);
    $categories = Categories::FindAll();
    $year_month = $year = $month = $extraheader = "";
    $default_open = "opened";
    $thiscategory_id = requestIdParam();
    $thiscategory = Categories::FindById($thiscategory_id);
    if (is_object($thiscategory)) {
        $default_open = "";
        $extraheader = "from &ldquo;" . $thiscategory->display_name . "&rdquo;";
        $entries = $thiscategory->getEntries(false, false);
    }
    ?>
	
	<div id="edit-header" class="entrynav">		
		<div class="nav-left column">
			<h1>Edit <?php 
    echo ucwords(BLOG_STATIC_AREA);
    ?>
 Entries <?php 
    echo $extraheader . ' :: <a href="' . get_link(BLOG_STATIC_AREA) . '" title="Click to View All Entries">View Entries</a>';
    ?>
</h1>
		</div>
		<div class="nav-right column">
			<a class="hcd_button" href="<?php 
    echo get_link("/admin/edit_entry/add");
    ?>
">Add an Entry</a>
			<a class="hcd_button" href="<?php 
    echo get_link("/admin/list_categories/");
    ?>
">Edit Categories</a>
			<a class="hcd_button" href="<?php 
    echo get_link("/admin/add_category/");
    ?>
">Add a Category</a>
		</div>
		<div class="clearleft"></div>
	</div>
	
	<ul id="sort-list" class="menu tabs">
		<li><a class="<?php 
    echo $default_open;
    ?>
" href="<?php 
    echo get_link("admin/list_entries/");
    ?>
">All Categories</a></li><?php 
    foreach ($categories as $category) {
        $posts = $category->getEntries(false, false);
        if (count($posts) > 0) {
            $openclass = $category->id == $thiscategory_id ? "opened" : "";
            echo "<li><a class=\"{$openclass}\" href=\"" . get_link("admin/list_entries/" . $category->id) . "\">{$category->display_name}</a></li>";
        }
    }
    ?>
	
	</ul>
	<div class="clearleft"></div>
	
<?php 
    if (count($entries) > 0) {
        ?>
	<div id="table-header" class="entries">
		<strong class="item-link">Entry Name</strong>
		<span class="item-public">Public</span>
		<span class="item-created">Publication Date</span>
		<span class="item-revised">Author</span>
	</div>
	
	<ul id="listitems" class="managelist">
	<?php 
        foreach ($entries as $entry) {
            $blogyear_month = parseDate($entry->date, "Y-m");
            $blogyear = parseDate($entry->date, "Y");
            $blogmonth = parseDate($entry->date, "F");
            if ($blogyear_month != $year_month) {
                echo "\t\t<li class=\"monthname\">{$blogmonth} {$blogyear}</li>";
                $year_month = $blogyear_month;
                $year = $blogyear;
                $month = $blogmonth;
            }
            $public = $entry->public ? "" : "<span class=\"red\">(not public)</span>";
            echo "\t\t<li>\n\t\t\t\t<a class=\"item-link\" href=\"" . get_link("/admin/edit_entry/{$entry->id}") . "\">{$entry->title}</a>\n\t\t\t\t<span class=\"item-public\">{$public}</span>\n\t\t\t\t<span class=\"item-created\">" . formatDateTimeView($entry->date) . "</span>\n\t\t\t\t<span class=\"item-revised\">" . $entry->get_author() . "</span>\n\t\t\t</li>\n";
        }
        ?>

	</ul>
<?php 
    } else {
        echo "\t\t<h3 class=\"empty-list\">There are no " . BLOG_STATIC_AREA . " entries to edit. <a class=\"short\" href=\"" . get_link("admin/add_entry") . "\">Add one if you like</a>.</h3>";
    }
}
function display_page_content()
{
    $category_id = requestIdParam();
    $category = Categories::FindById($category_id);
    ?>

	<script type="text/javascript">
		//<![CDATA[
	    loadTinyMce("category_content");
		
		$().ready(function() {
			
			$("#category").validate({
				rules: {
						display_name: "required",
					},
				messages: {
						display_name: "Please enter a display name for this category",
					}
			});
		});
		//]]>
	</script>
	
	<div id="edit-header" class="categorynav">
		<h1>Add a Category</h1>
	</div>
	
	<form method="POST" id="add_blog">
		<p><span class="hint">If a text box is underlined in red, it is a required field</span></p>
		
		<p class="display_name">
			<label for="display_name">Display Name:</label>
			<span class="hint">This is the display name of the category; how it will display in navigation.</span><br />
			<?php 
    textField("display_name", $category->display_name, "required: true");
    ?>
		</p>
		
		<p>
			<label for="category_content">Content (optional &ndash; not all templates may display this content):</label><br />
			<?php 
    textArea("category_content", $category->content, 98, EDIT_WINDOW_HEIGHT);
    ?>
		</p>
		
<?php 
    require_once snippetPath("admin-insert_configs");
    ?>
					
		
		<div id="edit-footer" class="categorynav clearfix">
			<div class="column half">
		
				<p>
					<input type="submit" class="submitbutton" name="submit" value="Edit Category" /> <br />
					<input type="submit" class="submitbuttonsmall" name="submit" value="Edit and Return to List" />
				</p>
				
			</div>
			<div class="column half last">
			<?php 
    if ($category->id == 1) {
        ?>
			
				<p class="red">Sorry, the default category can not be deleted.</p>
			<?php 
    } else {
        ?>
				
				<p>
					<label for="delete">Delete this category?</label>
					<input name="delete" class="boxes" type="checkbox" value='<?php 
        echo $category->id;
        ?>
' />
					<span class="hint">Check the box and then click &ldquo;Save&rdquo; above to delete this category from the database</span>
				</p>
			<?php 
    }
    ?>
			
			</div>
		</div>
		
	</form>
<?php 
}