[44] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | /*
|
---|
| 4 | * odl_functions.php
|
---|
| 5 | * wordpress plugin open directory project
|
---|
| 6 | * @author Mohammad Forgani
|
---|
| 7 | * @copyright Copyright 2008, Oh Jung-Su
|
---|
| 8 | * @version 1.0
|
---|
| 9 | * @link http://www.forgani.com
|
---|
| 10 | */
|
---|
| 11 |
|
---|
| 12 | if (!$_SESSION) session_start();
|
---|
| 13 | require(ABSPATH . ODLSMARTY . '/Smarty.class.php');
|
---|
| 14 |
|
---|
| 15 | class ODLTemplate extends Smarty {
|
---|
| 16 | function ODLTemplate($cache = true, $cache_lifetime = 0){
|
---|
| 17 | global $smarty_template_dir, $smarty_compile_dir, $smarty_cache_dir, $smarty_config_dir;
|
---|
| 18 | $this->Smarty();
|
---|
| 19 | $this->template_dir = $smarty_template_dir;
|
---|
| 20 | $this->compile_dir = $smarty_compile_dir;
|
---|
| 21 | $this->config_dir = $smarty_config_dir;
|
---|
| 22 | $this->cache_dir = $smarty_cache_dir;
|
---|
| 23 | $this->caching = $cache;
|
---|
| 24 | $this->cache_lifetime = $cache_lifetime;
|
---|
| 25 | }
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | function odlinksget_wp_mainversion(){
|
---|
| 29 | global $odlinkswp_mainversion;
|
---|
| 30 | if ($odlinkswp_mainversion==false){
|
---|
| 31 | odlinksget_namefield();
|
---|
| 32 | }
|
---|
| 33 | return $odlinkswp_mainversion;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | function odlinksget_pageinfo(){
|
---|
| 37 | global $wpdb, $odlinkswp_pageinfo, $table_prefix;
|
---|
| 38 |
|
---|
| 39 | if ($odlinkswp_pageinfo==false){
|
---|
| 40 | $odlinkswp_pageinfo = $wpdb->get_row("SELECT * FROM {$table_prefix}posts WHERE post_title = '[[ODLINKS]]'", ARRAY_A);
|
---|
| 41 | }
|
---|
| 42 | return $odlinkswp_pageinfo;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | function odlinkscreate_page(){
|
---|
| 46 | global $wpdb, $table_prefix, $wp_version;
|
---|
| 47 | $dt = date("Y-m-d");
|
---|
| 48 | $wpdb->query("INSERT INTO {$table_prefix}posts (post_author, post_date, post_date_gmt, post_content, post_title, post_category, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_content_filtered, post_parent, guid, menu_order, post_type) VALUES ('1', '$dt', '$dt', '[[ODLINKS]]', '[[ODLINKS]]', '0', '[[ODLINKS]]', 'publish', 'closed', 'closed', '', 'odlinks', '', '', '$dt', '$dt', '[[ODLINKS]]', '0', '', '0', 'page')");
|
---|
| 49 | return $wpdb->get_row("SELECT * FROM {$table_prefix}posts WHERE post_title = '[[ODLINKS]]'", ARRAY_A);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | function odlinks_admin_page(){
|
---|
| 53 | global $odlinksadmin_links, $odlinks_name, $odlinksadmin_page_name, $odlinksuser_level;
|
---|
| 54 | add_menu_page($odlinksadmin_page_name,$odlinksadmin_page_name,$odlinksuser_level,__FILE__,'process_odlinkssettings','../wp-content/plugins/odlinks/images/odl.gif');
|
---|
| 55 | for ($i=0; $i<count($odlinksadmin_links); $i++){
|
---|
| 56 | $tlink = $odlinksadmin_links[$i];
|
---|
| 57 | add_submenu_page(__FILE__,$tlink['name'],$tlink['name'],$odlinksuser_level,$tlink['arg'],$tlink['prg']);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | add_management_page($odlinksadmin_page_name, $odlinksadmin_page_name, $odlinksuser_level, $odlinks_name, 'odlinksadmin_page');
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | function odlinksrewrite_rules_wp($wp_rewrite){
|
---|
| 64 | global $wp_rewrite;
|
---|
| 65 | $odlinkssettings = get_option('odlinksdata');
|
---|
| 66 | $odlinksslug = $odlinkssettings['odlinksslug'];
|
---|
| 67 | $odlinksrules = array(
|
---|
| 68 | $odlinksslug.'/([^/\(\)]*)/?([^/\(\)]*)/?([^/\(\)]*)/?' => '/'.$odlinksslug.'/index.php?pagename='.$odlinksslug.'&_action=$matches[1]&id=$matches[2]&parent=$matches[3]');
|
---|
| 69 | $wp_rewrite->rules = $odlinksrules + $wp_rewrite->rules;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | function odlinksquery_vars($vars){
|
---|
| 73 | $vars[] = '_action';
|
---|
| 74 | $vars[] = 'id';
|
---|
| 75 | $vars[] = 'orderby';
|
---|
| 76 | $vars[] = 'who';
|
---|
| 77 | return $vars;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | function odlinks_excerpt_text($length, $text){
|
---|
| 81 | $text = strip_tags(odlinkscreate_post_html($text));
|
---|
| 82 | if(strlen($text)>$length){
|
---|
| 83 | $ret_strpos = strpos($text, ' ', $length);
|
---|
| 84 | $ret = substr($text, 0, $ret_strpos)." ...";
|
---|
| 85 | }else{
|
---|
| 86 | $ret = $text;
|
---|
| 87 | }
|
---|
| 88 | return $ret;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | function odlinkspage_handle_title($title){
|
---|
| 92 | global $odl_breadcrumbs;
|
---|
| 93 | if ($odl_breadcrumbs==""){
|
---|
| 94 | $sidebar = 0;
|
---|
| 95 | $odl_breadcrumbs = odlinksget_breadcrumbs($sidebar);
|
---|
| 96 | }
|
---|
| 97 | return str_replace("[[ODLINKS]]", $odl_breadcrumbs, $title);
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | function odlinkspage_handle_pagetitle($title){
|
---|
| 101 | global $odl_pagetitle;
|
---|
| 102 | return str_replace("[[ODLINKS]]", "ODLinks » ", $title);
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | function odlinkspage_handle_content($content){
|
---|
| 106 | if (eregi("\[\[ODLINKS\]\]", $content)){
|
---|
| 107 | odlinksprocess();
|
---|
| 108 | return "";
|
---|
| 109 | } else {
|
---|
| 110 | return $content;
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | function odlinkspage_handle_titlechange($title){
|
---|
| 115 | global $odl_breadcrumbs;
|
---|
| 116 | $sidebar = 0;
|
---|
| 117 | $odl_breadcrumbs = odlinksget_breadcrumbs($sidebar);
|
---|
| 118 | $odlinkssettings = get_option('odlinksdata');
|
---|
| 119 | $title = str_replace($odl_breadcrumbs, $odlinkssettings["page_link_title"], $title);
|
---|
| 120 | $title = str_replace("[[ODLINKS]]", $odlinkssettings["page_link_title"], $title);
|
---|
| 121 | return $title;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | function odlinksget_breadcrumbs($sidebar){
|
---|
| 125 | global $_GET, $_POST, $table_prefix, $wpdb, $_SERVER, $wp_version;
|
---|
| 126 | $g__action = get_query_var("_action");
|
---|
| 127 | $id = get_query_var("id");
|
---|
| 128 | $parent = get_query_var("parent");
|
---|
| 129 | if (basename($_SERVER['PHP_SELF'])!='index.php'){
|
---|
| 130 | return "[[ODLINKS]]";
|
---|
| 131 | } else {
|
---|
| 132 | $odlinkssettings = get_option('odlinksdata');
|
---|
| 133 | if (!$_POST['search_terms'] && $sidebar=0) {
|
---|
| 134 | $g__action = "sidebar";
|
---|
| 135 | } elseif (!$_POST['search_terms']) {
|
---|
| 136 | $g__action = $g__action;
|
---|
| 137 | } else {
|
---|
| 138 | $g__action = "search";
|
---|
| 139 | }
|
---|
| 140 | switch ($g__action){
|
---|
| 141 | default:
|
---|
| 142 | case "index":
|
---|
| 143 | return '<strong class="odl_breadcrumb">'.$odlinkssettings['page_link_title'].'</strong>';
|
---|
| 144 | break;
|
---|
| 145 | }
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | function odlinkscreate_link($action, $vars){
|
---|
| 150 | global $wpdb, $table_prefix, $wp_rewrite;
|
---|
| 151 | $pageinfo = odlinksget_pageinfo();
|
---|
| 152 | $odlinkssettings = get_option('odlinksdata');
|
---|
| 153 | $rewrite = ($wp_rewrite->get_page_permastruct()=="")?false:true;
|
---|
| 154 | $odl_vars_name = $vars["name"];
|
---|
| 155 | $odl_vars_name = preg_replace('/[^A-Za-z0-9\s\.]/', "", $odl_vars_name);
|
---|
| 156 | $odl_vars_name = preg_replace('/\s/', '-', $odl_vars_name);
|
---|
| 157 | $odl_vars_name = preg_replace('/\./', '-', $odl_vars_name);
|
---|
| 158 |
|
---|
| 159 | $name = trim($vars["name"]);
|
---|
| 160 | switch ($action){
|
---|
| 161 | case "index":
|
---|
| 162 | return ($rewrite)?"<a href=\"".get_bloginfo('url')."/".$pageinfo["post_name"]."/".$vars["parent"]."/\">".$name."</a>":"<a href=\"".get_bloginfo('url')."/?page_id=".$pageinfo["ID"]."&_action=index\">".$name."</a>";
|
---|
| 163 | break;
|
---|
| 164 | case "category":
|
---|
| 165 | return ($rewrite)?"<a href=\"".get_bloginfo('url')."/".$pageinfo["post_name"]."/main/".$vars["id"]."\">".$name."</a>":"<a href=\"".get_bloginfo('url')."/?page_id=".$pageinfo["ID"]."&_action=main&id=".$vars["id"]."&parent=".$vars['parent']."\">".$name."</a>";
|
---|
| 166 | break;
|
---|
| 167 | case "postlink":
|
---|
| 168 | return ($rewrite)?"<a
|
---|
| 169 | href=\"".get_bloginfo('url')."/".$pageinfo["post_name"]."/postlink/".$vars['id']."/".$vars['parent']."\">".$name."</a>":"<a href=\"".get_bloginfo('url')."/?page_id=".$pageinfo["ID"]."&_action=postlink&id=".$vars["id"]."&parent=".$vars['parent'] ."\">".$name."</a>";
|
---|
| 170 | break;
|
---|
| 171 |
|
---|
| 172 | case "searchlink":
|
---|
| 173 | return ($rewrite)?"<a href=\"".get_bloginfo('url')."/".$pageinfo["post_name"]."/searchlink/"."\">".$name."</a>":"<a href=\"".get_bloginfo('url')."/?page_id=".$pageinfo["ID"]."&_action=searchlink" ."\">".$name."</a>";
|
---|
| 174 | break;
|
---|
| 175 |
|
---|
| 176 | case "searchform":
|
---|
| 177 | return ($rewrite)?get_bloginfo('wpurl')."/".$pageinfo["post_name"]."/searchlink/":get_bloginfo('wpurl')."/?page_id=".$pageinfo["ID"]."&_action=searchlink";
|
---|
| 178 | break;
|
---|
| 179 |
|
---|
| 180 | case "sendlink":
|
---|
| 181 | return ($rewrite)?"<a style=\"color:green\" href=\"".get_bloginfo('url')."/".$pageinfo["post_name"]."/sendlink/".$vars['id']."\">".$name."</a>":"<a style=\"color:green\" href=\"".get_bloginfo('url')."/?page_id=".$pageinfo["ID"]."&_action=sendlink&id=".$vars["id"]."\">".$name."</a>";
|
---|
| 182 | break;
|
---|
| 183 |
|
---|
| 184 | case "sendform":
|
---|
| 185 | return ($rewrite)?get_bloginfo('wpurl')."/".$pageinfo["post_name"]."/sendlink/":get_bloginfo('wpurl')."/?page_id=".$pageinfo["ID"]."&_action=sendlink";
|
---|
| 186 | break;
|
---|
| 187 | }
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 |
|
---|
| 192 | function odlinksprocess(){
|
---|
| 193 | global $_GET, $_POST, $table_prefix, $wpdb, $wp_version;
|
---|
| 194 |
|
---|
| 195 |
|
---|
| 196 | $action = get_query_var("_action");
|
---|
| 197 | $odlinkssettings = get_option('odlinksdata');
|
---|
| 198 | switch ($action){
|
---|
| 199 | default:
|
---|
| 200 | case "main":
|
---|
| 201 | odlinksdisplay_index($msg);
|
---|
| 202 | break;
|
---|
| 203 |
|
---|
| 204 | case "searchlink":
|
---|
| 205 | odlinksdisplay_search();
|
---|
| 206 | break;
|
---|
| 207 |
|
---|
| 208 | case "postlink":
|
---|
| 209 | odlinkspost_link($confirm);
|
---|
| 210 | break;
|
---|
| 211 |
|
---|
| 212 | case "sendlink":
|
---|
| 213 | odlinkssend_link($confirm);
|
---|
| 214 | break;
|
---|
| 215 |
|
---|
| 216 | case "install";
|
---|
| 217 | echo "Please install ODLinks by saving the Settings in the ODLinks Admin area.";
|
---|
| 218 | break;
|
---|
| 219 | }
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | function odlinks_footer($tpl){
|
---|
| 223 | $odlinkssettings = get_option('odlinksdata');
|
---|
| 224 | if ($odlinkssettings['odlinksshow_credits']=='y'){
|
---|
| 225 | $tpl->assign('odlinksshow_credits', str_replace("[VERSION]", $odlinkssettings['odlinksversion'], stripslashes($odlinkssettings['odlinks_credit_line'])));
|
---|
| 226 | }
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 |
|
---|
| 230 | ?>
|
---|