function __construct($args) { SimpleBlogCommon::Init(); $search_obj = $args[0]; $blog_label = common::GetLabelIndex('special_blog'); $post_ids = SimpleBlogCommon::AStrToArray('str_index'); foreach ($post_ids as $id) { $post = SimpleBlogCommon::GetPostContent($id); if (!$post) { continue; } $title = $blog_label . ': ' . str_replace('_', ' ', $post['title']); $content = str_replace('_', ' ', $post['title']) . ' ' . $post['content']; SimpleBlogCommon::UrlQuery($id, $url, $query); $search_obj->FindString($content, $title, $url, $query); } }
function WhichCatPosts($start, $len, $include_drafts = false) { $cat_posts = SimpleBlogCommon::AStrToArray('category_posts_' . $this->catindex); //remove drafts $show_posts = array(); if (!$include_drafts) { foreach ($cat_posts as $post_id) { if (!SimpleBlogCommon::AStrValue('drafts', $post_id)) { $show_posts[] = $post_id; } } } else { $show_posts = $cat_posts; } $this->total_posts = count($show_posts); return array_slice($show_posts, $start, $len); }
/** * Get a id for the post that is most similar to the requested title * */ public function SimilarPost($title) { global $config; $titles = SimpleBlogCommon::AStrToArray('titles'); $post_times = SimpleBlogCommon::AStrToArray('post_times'); $similar = array(); $lower = str_replace(' ', '_', strtolower($title)); foreach ($titles as $post_id => $title) { if ($post_times[$post_id] > time()) { continue; } similar_text($lower, strtolower($title), $percent); $similar[$percent] = $post_id; //if similarity is the same for two posts, the newer post will take precedence } krsort($similar); $similarity = key($similar); if ($config['auto_redir'] > 0 && $similarity >= $config['auto_redir']) { return current($similar); } }
function __construct() { global $langmessage, $addonRelativeCode, $addonFolderName, $page; $this->Init(); $this->categories = SimpleBlogCommon::AStrToArray('categories'); $cmd = common::GetCommand(); switch ($cmd) { //category commands case 'save_categories': $this->SaveCategories(); break; case 'new_category': $this->NewCategory(); return; case 'save_new_category': $this->SaveNewCategory(); break; case 'delete_category': $this->DeleteCategory(); break; } $page->css_admin[] = '/include/css/addons.css'; //for hmargin css pre gpEasy 3.6 $page->head_js[] = '/data/_addoncode/' . $addonFolderName . '/admin.js'; $label = gpOutput::SelectText('Blog'); echo '<h2 class="hmargin">'; echo common::Link('Special_Blog', $label); echo ' » '; echo common::Link('Admin_Blog', 'Configuration'); echo ' <span>|</span> '; echo ' Categories '; echo ' <span>|</span> '; $comments = gpOutput::SelectText('Comments'); echo common::Link('Admin_BlogComments', $comments); echo '</h2>'; // print all categories and settings echo '<form name="categories" action="' . common::GetUrl('Admin_BlogCategories') . '" method="post">'; echo '<table class="bordered">'; echo '<tr><th> </th><th>Category</th><th>Number of Posts</th><th>Visible</th><th>Options</th></tr>'; echo '<tbody class="sortable_table">'; foreach ($this->categories as $catindex => $catname) { echo '<tr><td style="vertical-align:middle">'; echo '<img src="' . $addonRelativeCode . '/grip.png" height="15" width="15" style="padding:2px;cursor:pointer;"/>'; echo '</td><td>'; echo '<input type="text" name="cattitle[' . $catindex . ']" value="' . $catname . '" class="gpinput" />'; echo '</td><td>'; $astr =& SimpleBlogCommon::$data['category_posts_' . $catindex]; echo substr_count($astr, '>'); echo '</td><td>'; $checked = ''; if (!SimpleBlogCommon::AStrValue('categories_hidden', $catindex)) { $checked = ' checked="checked"'; } echo ' <input type="checkbox" name="catvis[' . $catindex . ']"' . $checked . '/> '; echo '</td><td>'; echo common::Link('Admin_BlogCategories', $langmessage['delete'], 'cmd=delete_category&index=' . $catindex, ' name="postlink" class="gpconfirm" title="Delete this Category?" '); echo '</td></tr>'; } echo '</tbody>'; echo '</table>'; echo '<p>'; echo '<input type="hidden" name="cmd" value="save_categories" />'; echo '<input type="submit" value="' . $langmessage['save_changes'] . '" class="gpsubmit"/>'; echo ' '; echo common::Link('Admin_BlogCategories', 'Add New Category', 'cmd=new_category', ' name="gpabox" '); echo '</p>'; echo '</form>'; // print all posts /* if( count($this->itlist) ){ echo '<h3 onclick="$(this).next(\'form\').toggle()" style="cursor:pointer">All Blog Posts</h3>'; echo '<form name="allposts" action="'.common::GetUrl('Admin_BlogCategories').'" method="post" style="display:none">'; echo '<table style="width:100%">'; foreach( $this->itlist as $postindex => $postdata ){ echo '<tr><td>'.$postdata['title'].' '; echo common::Link('Special_Blog','»','id='.$postindex,'target="_blank"').'</td><td>'; echo '<select id="post'.$postindex.'" name="post'.$postindex.'[]" multiple="multiple" class="gpselect">'; foreach( $this->categories as $catindex => $catdata){ echo '<option value="'.$catindex.'" '.(isset($catdata[$postindex])? 'selected="selected"':'').'>'.$catdata['ct'].'</option>'; } echo '</select>'; echo '</td></tr>'; } echo '</table>'; echo '<input name="save_posts" type="submit" value="'.$langmessage['save'].'" class="gpsubmit" />'; echo '</form>'; } */ }
/** * Regenerate the static content used to display the archive gadget * */ static function GenArchiveGadget() { global $addonPathData; //get list of posts and times $list = SimpleBlogCommon::AStrToArray('post_times'); if (!count($list)) { return; } //get year counts $archive = array(); foreach ($list as $post_id => $time) { $ym = date('Y-m', $time); //year&month $archive[$ym][] = $post_id; } ob_start(); $prev_year = false; echo '<ul>'; foreach ($archive as $ym => $posts) { $y = substr($ym, 0, 4); $m = substr($ym, -2); if ($y != $prev_year) { if ($prev_year !== false) { echo '</li>'; } echo '<li><div class="simple_blog_gadget_year">' . $y . '</div>'; $prev_year = $y; } $sum = count($posts); if (!$sum) { continue; } echo '<ul>'; echo '<li><a class="blog_gadget_link">'; $time = strtotime($ym . '-01'); echo strftime('%B', $time); echo ' (' . $sum . ')</a>'; echo '<ul class="simple_blog_category_posts nodisplay">'; foreach ($posts as $post_id) { $post_title = SimpleBlogCommon::AStrGet('titles', $post_id); echo '<li>'; echo SimpleBlogCommon::PostLink($post_id, $post_title); echo '</li>'; } echo '</ul>'; echo '</li>'; echo '</ul>'; } echo '</li></ul>'; $content = ob_get_clean(); $gadgetFile = $addonPathData . '/gadget_archive.php'; gpFiles::Save($gadgetFile, $content); }
/** * Show a list of all categories * */ function show_category_list($post_id, $post) { $_POST += array('category' => array()); echo '<tr><td>Category</td><td>'; echo '<select name="category[]" multiple="multiple">'; $categories = SimpleBlogCommon::AStrToArray('categories'); foreach ($categories as $catindex => $catname) { $selected = ''; $label = $catname; if ($post_id && in_array($catindex, $post['categories'])) { $selected = 'selected="selected"'; } elseif (in_array($catindex, $_POST['category'])) { $selected = 'selected="selected"'; } if (SimpleBlogCommon::AStrValue('categories_hidden', $catindex)) { $label .= ' (Hidden)'; } echo '<option value="' . $catindex . '" ' . $selected . '>' . $label . '</option>'; } echo '</select></td></tr>'; }
/** * Remove a blog entry from a category * */ public static function DeletePostFromCategories($post_id) { $categories = SimpleBlogCommon::AStrToArray('categories'); foreach ($categories as $catindex => $catname) { SimpleBlogCommon::AStrRmValue('category_posts_' . $catindex, $post_id); } }
/** * Update a category when a blog entry is edited * */ private static function UpdatePostCategories($post_id) { $_POST += array('category' => array()); //get order of all posts $post_times = SimpleBlogCommon::AStrToArray('post_times'); arsort($post_times); $post_times = array_keys($post_times); //loop through each category $categories = SimpleBlogCommon::AStrToArray('categories'); foreach ($categories as $catindex => $catname) { SimpleBlogCommon::AStrRmValue('category_posts_' . $catindex, $post_id); if (in_array($catindex, $_POST['category'])) { //add and order correctly $category_posts = SimpleBlogCommon::AStrToArray('category_posts_' . $catindex); $category_posts[] = $post_id; $category_posts = array_intersect($post_times, $category_posts); SimpleBlogCommon::$data['category_posts_' . $catindex] = SimpleBlogCommon::AStrFromArray($category_posts); } } }