sPluginRootFile = __FILE__; //ensure all relative paths etc. are setup. $this->sPluginFile = plugin_basename( $this->sPluginRootFile ); $this->loadOptions(); if ( strstr( $_SERVER['REQUEST_URI'], 'icwp-adr.php' ) && isset($_GET['ver']) ) { echo $this->artdir_get_version(); } add_action( 'wp_loaded', array( $this, 'onWpLoaded' ) ); add_action( 'admin_init', array( $this, 'artdir_textdomain' ) ); add_filter( 'pre_kses', array( $this, 'artdir_plugin_description' ) ); add_action( 'admin_menu', array( $this, 'artdir_options_page' ) ); if ( $this->aOptions['kinderloss'] == 1 ) { add_filter( 'posts_where', array( $this, 'kinderloss_where' ) ); } if ($this->aOptions['show_article_code'] == 1) { add_filter( 'the_content', array( $this, 'artdir_get_article_code' ) ); } if ($this->aOptions['author_interface'] == 0) { add_action('init', array( $this, 'artdir_restrict_admin_area' ) ); } register_deactivation_hook( __FILE__, array( $this, 'artdir_uninstall' ) ); } protected function loadOptions() { $this->aOptions = get_option( 'article_directory' ); if ( $this->aOptions ) { //make a copy for us in case they deactivate the other and delete their settings. update_option( 'article_directory_redux', $this->aOptions ); } else { $this->aOptions = get_option( 'article_directory_redux', $this->aOptions ); } // if it's still empty, set the defaults if ( empty($this->aOptions) ) { $this->aOptions = $this->artdir_default_options(); } } protected function getAuthorPanelPageId() { return !empty( $this->aOptions['author_panel_id'] )? $this->aOptions['author_panel_id'] : -1; } public function onWpLoaded() { if ( is_page( $this->getAuthorPanelPageId() ) || ( $this->aOptions['show_article_code'] == 1 && is_single() ) ) { add_action( 'wp_head', array( $this, 'artdir_jquery' ), 8 ); } } /** * @return string */ public function artdir_get_version() { return self::PluginVersion; } public function artdir_textdomain() { load_plugin_textdomain( self::PluginTextDomain, false, dirname($this->sPluginFile) . '/languages/' ); register_setting('article_directory', 'article_directory', array( $this, 'artdir_validate' ) ); } public function artdir_plugin_description($string) { if (trim($string) == 'Displays the structured list of categories (like in article directory), which can be easily customized with CSS. Also allows authors to publish articles and change their profile bypassing the admin interface.') $string = __('Displays the structured list of categories (like in article directory), which can be easily customized with CSS. Also allows authors to publish articles and change their profile bypassing the admin interface. See the demo at articlesss.com. Attention! If you deactivate the plugin its settings will be removed from the database.', 'article-directory-redux'); return $string; } public function artdir_validate($input) { $def_options = $this->artdir_default_options(); $input['exclude_cats'] = (preg_match("/^(\d+,)*\d+$/", $input['exclude_cats']) ? $input['exclude_cats'] : $def_options['exclude_cats']); $input['show_parent_count'] = ($input['show_parent_count'] == 1 ? 1 : 0); $input['show_child_count'] = ($input['show_child_count'] == 1 ? 1 : 0); $input['hide_empty'] = ($input['hide_empty'] == 1 ? 1 : 0); $input['desc_for_parent_title'] = ($input['desc_for_parent_title'] == 1 ? 1 : 0); $input['desc_for_child_title'] = ($input['desc_for_child_title'] == 1 ? 1 : 0); $input['child_hierarchical'] = ($input['child_hierarchical'] == 1 ? 1 : 0); $input['column_count'] = (is_numeric($input['column_count']) && $input['column_count'] > 0 ? $input['column_count'] : $def_options['column_count']); $input['sort_by'] = ($input['sort_by'] == 1 ? 1 : 0); $input['sort_direction'] = ($input['sort_direction'] == 1 ? 1 : 0); $input['no_child_alert'] = ($input['no_child_alert'] == 1 ? 1 : 0); $input['show_child'] = ($input['show_child'] == 1 ? 1 : 0); $input['maximum_child'] = (is_numeric($input['maximum_child']) && $input['maximum_child'] > 0 ? $input['maximum_child'] : $def_options['maximum_child']); $input['author_interface'] = ($input['author_interface'] == 1 ? 1 : 0); $input['author_panel_id'] = (!empty($input['author_panel_id']) && $input['author_panel_id'] > 0 && is_numeric($input['author_panel_id']) ? $input['author_panel_id'] : ''); $input['article_status'] = ($input['article_status'] == 1 ? 1 : 0); $input['minimum_symbols'] = (!empty($input['minimum_symbols']) && $input['minimum_symbols'] > 0 && is_numeric($input['minimum_symbols']) ? $input['minimum_symbols'] : $def_options['minimum_symbols']); $input['maximum_links'] = (!empty($input['maximum_links']) && $input['maximum_links'] >= 0 && is_numeric($input['maximum_links']) ? $input['maximum_links'] : $def_options['maximum_links']); $input['show_editor'] = ($input['show_editor'] == 1 ? 1 : 0); $input['default_editor'] = ($input['default_editor'] == 'tinymce' ? 'tinymce' : $def_options['default_editor']); $input['sel_only_one_cat'] = ($input['sel_only_one_cat'] == 1 ? 1 : 0); $input['show_tags'] = ($input['show_tags'] == 1 ? 1 : 0); $input['allow_new_tags'] = ($input['allow_new_tags'] == 1 ? 1 : 0); $input['publish_terms_text'] = (!empty($input['publish_terms_text']) ? $input['publish_terms_text'] : ''); $input['kinderloss'] = ($input['kinderloss'] == 1 ? 1 : 0); $input['show_article_code'] = ($input['show_article_code'] == 1 ? 1 : 0); if (isset($_POST['artdirReset'])) { $input = $this->artdir_default_options(); } return $input; } public function artdir_default_options() { $def_options['exclude_cats'] = 0; $def_options['show_parent_count'] = 1; $def_options['show_child_count'] = 1; $def_options['hide_empty'] = 0; $def_options['desc_for_parent_title'] = 1; $def_options['desc_for_child_title'] = 1; $def_options['child_hierarchical'] = 1; $def_options['column_count'] = 3; $def_options['sort_by'] = 0; $def_options['sort_direction'] = 0; $def_options['no_child_alert'] = 1; $def_options['show_child'] = 1; $def_options['maximum_child'] = 0; $def_options['author_interface'] = 0; $def_options['author_panel_id'] = ''; $def_options['article_status'] = 0; $def_options['minimum_symbols'] = 700; $def_options['maximum_links'] = 3; $def_options['show_editor'] = 1; $def_options['default_editor'] = 'html'; $def_options['sel_only_one_cat'] = 1; $def_options['show_tags'] = 0; $def_options['allow_new_tags'] = 0; $def_options['publish_terms_text'] = ''; $def_options['kinderloss'] = 1; $def_options['show_article_code'] = 0; return $def_options; } public function artdir_options_page() { add_options_page('Article Directory', 'Article Directory Redux', 8, __FILE__, array( $this, 'artdir_options' ) ); } public function artdir_options() { $aOptions = $this->aOptions; $sVersion = $this->artdir_get_version(); include( dirname(__FILE__).'/adr-options-page-view.php' ); } public function printArticleDirectory( $echo = true ) { include( dirname(__FILE__).'/adr-article-directory-page-view.php' ); } public function printAuthorPanel() { $aOptions = $this->aOptions; include( dirname(__FILE__).'/author-panel.php' ); } public function printArticleDirectoryAuthForm() { include( dirname(__FILE__).'/adr-directory-authorization-form-view.php' ); } public function declareDuplicateFunctions() { if ( !function_exists('article_directory') ) { function article_directory( $echo = true ) { $oAD = ICWP_ArticleDirectoryRedux::GetInstance(); $oAD->printArticleDirectory( $echo ); } } if ( !function_exists('article_directory_author_panel') ) { function article_directory_author_panel() { $oAD = ICWP_ArticleDirectoryRedux::GetInstance(); $oAD->printAuthorPanel(); } } if ( !function_exists('article_directory') ) { function article_directory_authorization_form() { $oAD = ICWP_ArticleDirectoryRedux::GetInstance(); $oAD->printArticleDirectoryAuthForm(); } } } //thanks to "Kinderlose" plugin - http://guff.szub.net/kinderlose public function kinderloss_where( $where ) { if ( is_category() ) { global $wp_query; $where = preg_replace('/.term_id IN \(\'(.*)\'\)/', '.term_id IN (\'' . $wp_query->query_vars['cat'] . '\') AND post_type = \'post\' AND post_status = \'publish\'', $where); } return $where; } public function artdir_get_article_code($text) { $rn = "\r\n\r\n"; $get_article_code = '
'.__('Article Source', 'article-directory-redux').'
'; if (is_single()) { return '