"; } /** * Returns plugin's path. * * @param string str Path to append * @return string * @access public */ function lexi_plugin_url($str = '') { $dir_name = '/wp-content/plugins/lexi'; $url=get_bloginfo('wpurl'); return $url . $dir_name . $str; } /** * Function to create the database and to add options into WordPress * * @access public */ function lexi_activate() { global $wpdb; global $db_version; $table_name = $wpdb->prefix . "lexi"; if($wpdb->get_var("show tables like '$table_name'") != $table_name) { $sql = "CREATE TABLE $table_name( id bigint(1) NOT NULL AUTO_INCREMENT, name tinytext NOT NULL, position int, rss text NOT NULL, items int NOT NULL, showcontent tinyint NOT NULL, cached tinyint NOT NULL, PRIMARY KEY (id) );"; require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); dbDelta($sql); add_option('lexi_db_version', 1); } } /** * Function to edit feed's data. * * @param int id Feed's id * @param string name Feed's name * @param string rss Feed's URL * @param int items Items to show * @param bool showcontent Show contents in Widget? * @param bool cache Record Rss content in cache? * @access public */ function lexi_editfeed($id, $name, $rss, $items=5, $showcontent=false, $cached=true) { global $wpdb; if($showcontent) { $showcontent=1; } else { $showcontent=0; } if($cached) { $cached=1; } else { $cached=0; } $table_name = $wpdb->prefix . "lexi"; $query="UPDATE " . $table_name ." SET name='".$name."', rss='".$rss."', items='".$items."', showcontent='".$showcontent."', cached='".$cached."' WHERE id=".$id; $wpdb->query($query); } /** * Function to add a feed. * * @param string name Feed's name * @param string rss Feed's URL * @param int items Items to show * @param bool showcontent Show contents in Widget? * @param bool cache Record Rss content in cache? * @return bool * @access public */ function lexi_addfeed($name, $rss, $items=5, $showcontent=false, $cached=true) { global $wpdb; if($showcontent) { $showcontent=1; } else { $showcontent=0; } if($cached) { $cached=1; } else { $cached=0; } $table_name = $wpdb->prefix . "lexi"; $insert = "INSERT INTO " . $table_name . " (name, rss, items, showcontent, cached) " . "VALUES ('" . $wpdb->escape($name) . "', '" . $wpdb->escape($rss) . "', '$items', '$showcontent', '$cached')"; $results = $wpdb->query( $insert ); $id = $wpdb->get_var("select last_insert_id()"); $position = $wpdb->get_var("SELECT MAX(position) FROM $table_name"); $position++; $wpdb->query("UPDATE " . $table_name ." SET position='$position' WHERE id=".$id); return true; } /** * Function to delete a feed. * * @param int id Feed to delete * @return bool * @access public */ function lexi_deletefeed($id) { global $wpdb; $table_name = $wpdb->prefix . "lexi"; $position = $wpdb->get_var("SELECT position FROM $table_name WHERE id=$id"); $query = "DELETE FROM " . $table_name ." WHERE id=" . $id; $answer1=$wpdb->query( $query ); $wpdb->query("UPDATE " . $table_name ." SET position=position-1 WHERE position > $position"); return $answer1; } /** * Move feed one row up * * @param int id Feed to move * @return bool * @access public */ function lexi_upfeed($id) { global $wpdb; $table_name = $wpdb->prefix . "lexi"; $position = $wpdb->get_var("SELECT position FROM $table_name WHERE id=$id"); if($position>1) { $position_aux=$position-1; $answer1 = $wpdb->query("UPDATE " . $table_name ." SET position = $position WHERE position = $position_aux"); $answer2 = $wpdb->query("UPDATE " . $table_name ." SET position = $position_aux WHERE id = $id"); } return $answer1 && $answer2; } /** * Move feed one row down * * @param int id Feed to move * @return bool * @access public */ function lexi_downfeed($id) { global $wpdb; $table_name = $wpdb->prefix . "lexi"; $position = $wpdb->get_var("SELECT position FROM $table_name WHERE id=$id"); $max_position = $wpdb->get_var("SELECT MAX(position) FROM $table_name"); if($position<$max_position) { $position_aux=$position+1; $answer1 = $wpdb->query("UPDATE " . $table_name ." SET position = $position WHERE position = $position_aux"); $answer2 = $wpdb->query("UPDATE " . $table_name ." SET position = $position_aux WHERE id = $id"); } return $answer1 && $answer2; } /** * Returns the html code with 'minimax' script and div. * Add this code into the html page to create the RSS reader. * * @param string link The RSS URL * @param string title The title to put at the beginning of the list * @param string items Max number of feeds to show * @param string sc Show feed contents? * @param string cache Save feeds in cache? * @return string * @access public */ function lexi_postRss($link, $title, $items, $conf) { $answer=""; if(function_exists('minimax') && minimax_version()==0.2) { $num = mt_rand(); $url=lexi_plugin_url('/content.php'); if($sc) $sc=1; else $sc=0; if($cache) $cache=1; else $cache=0; $post="url=".urlencode(str_replace("&", "&", $link))."&title=".urlencode(str_replace("&", "&", $title))."&num=$items&conf=$conf"; $answer.="\n
".__('Loading Feed...','lexi')." |
)*\s*\[lexi\s*(:\s*\d+)?\]\s*(?:
)*@i"; if (preg_match_all($search, $content, $matches)) { if (is_array($matches)) { foreach ($matches[1] as $key =>$v0) { $v1=$matches[1][$key]; $id=false; if($v1) { $v1=substr($v1,1); $id=$v1*1; } $search = $matches[0][$key]; $replace=lexi_postId($id); $content = str_replace ($search, $replace, $content); } } } //RSS $search = "@(?:)*\s*\[lexi\s*:([^,]+),(\d+),(true|false),(true|false)?\]\s*(?:
)*@i"; if (preg_match_all($search, $content, $matches)) { if (is_array($matches)) { foreach ($matches[1] as $key =>$rss) { $items=$matches[2][$key]; $sc=$matches[3][$key]; if($sc=='true') $sc=1; else $sc=0; $cache=$matches[4][$key]; if($cache=='true') $cache=1; else $cache=0; $conf = CONF_SHOWHEADER + CONF_TARGETBLANK; if($sc) $conf += CONF_SHOWCONTENT; if($cache) $conf += CONF_CACHE; $search = $matches[0][$key]; $replace=lexi_postRss($rss,"",$items,$conf); $content = str_replace ($search, $replace, $content); } } } //Lexi 2 w/ title $search = "@(?:)*\s*\[lexi\s*:(\d+),([^,]+),([^,]+),(\d+)?\]\s*(?:
)*@i"; if (preg_match_all($search, $content, $matches)) { if (is_array($matches)) { foreach ($matches[1] as $key =>$conf) { $rss=$matches[2][$key]; $title=$matches[3][$key]; $items=$matches[4][$key]; $search = $matches[0][$key]; $replace=lexi_postRss($rss, $title, $items, $conf); $content = str_replace ($search, $replace, $content); } } } //Lexi 2 w/out title $search = "@(?:)*\s*\[lexi\s*:(\d+),([^,]+),(\d+)?\]\s*(?:
)*@i"; if (preg_match_all($search, $content, $matches)) { if (is_array($matches)) { foreach ($matches[1] as $key =>$conf) { $url=$matches[2][$key]; $items=$matches[3][$key]; $search = $matches[0][$key]; $replace=lexi_postRss($rss, "", $items, $conf); $content = str_replace ($search, $replace, $content); } } } return $content; } /** * Function to be called in templates. Returns the html code * with 'minimax' script and div. Add this function into the html * page to create the RSS reader. * If the id is numeric, the function returns the code for the * corresponding feed in the lexi list, and forget the other * parameters. If its a string, the function would use it as the URL, * and would use the other parameters. * If you call the function without parameters, it returns the code * for the entire lexi list. * * @param string id Would be the URL or the lexi id. See function description. * @param string num Max number of feeds to show * @param string sc Show feed contents? * @param string cached Save feeds in cache? * @access public */ function lexi($id=0, $num=0, $sc=false, $cached=false, $sh=true) { if(is_numeric($id)) { echo lexi_postId($id); } else { echo lexi_postRss($id, "", $num, $sc, $cached, $sh); } } /** * Function to be called in templates. Returns the html code * with 'minimax' script and div. Add this function into the html * page to create the RSS reader. * If the id is numeric, the function returns the code for the * corresponding feed in the lexi list, and forget the other * parameters. If its a string, the function would use it as the URL, * and would use the other parameters. * If you call the function without parameters, it returns the code * for the entire lexi list. * * @param string id Would be the URL or the lexi id. See function description. * @param string num Max number of feeds to show * @param string sc Show feed contents? * @param string cached Save feeds in cache? * @access public */ function lexiRSS($conf, $rss, $title, $max_items) { if(!$title) $title=""; echo lexi_postRss($rss, $title, $max_items, $conf); } /** * Returns the HTML list for an RSS feed. * * @param string link The URL of the rss. * @param string name Name to be shown at the top of the list. If empty would use * the name in the rss. * @param string num Max number of feeds to show. * @param string sc Show feed contents? * @param string cached Save feeds in cache? * @return string * @access public */ function lexi_readfeed($link, $name, $num, $config) { include_once(ABSPATH . WPINC . '/rss.php'); @include_once(ABSPATH . WPINC . '/class-simplepie.php'); $name=str_replace("\\\"","\"",$name); if(($config & CONF_TARGETBLANK)) { $target = " target='_blank'"; } if(class_exists('SimplePie')) { $rss = new SimplePie($link); if(!($config & CONF_CACHE)) { $rss->enable_cache(false); $rss->init(); } $channel_link = $rss->get_permalink(); if($name=="") { $name=htmlspecialchars($rss->get_title()); } $items = $rss->get_items(0, $num); if($items) { foreach ($items as $item) { $answer.="