initActions(); } /** * function called on init in the theme */ function themeInitHook() { add_action('wp_print_styles', array($this, 'addTemplateCSS')); add_shortcode('arlima', array($this, 'arlimaListShortCode')); if ( is_page() ) { add_filter('the_content', array($this, 'displayArlimaList')); } } /** */ function displayArlimaList($content) { if( has_arlima_list() ) { global $post; $connector = new Arlima_ListConnector(); $relation = $connector->getRelationData($post->ID); if( isset($relation['attr']['position']) && $relation['attr']['position'] == 'after') { $relation['attr']['echo'] = false; $content .= arlima_render_list(get_arlima_list(), $relation['attr']); } else { arlima_render_list(get_arlima_list(), $relation['attr']); } } return $content; } /** * Short code for arlima * @param array $attr * @return string */ public function arlimaListShortCode($attr) { $factory = new Arlima_ListFactory(); $attr = shortcode_atts( array( 'offset' => 0, 'limit' => 0, 'width' => 560, 'list' => null, 'filter_suffix' => '' ), $attr ); $attr['echo'] = false; $error_html = '
%s
>
> : [getVersionDisplayName($version) ?>]
post_mime_type), $img_content_types); } /** * @var null|bool */ private static $is_wp_support_img_editor = null; /** * @return bool */ public static function supportsImageEditor() { if( self::$is_wp_support_img_editor === null ) { global $wp_version; self::$is_wp_support_img_editor = version_compare( $wp_version, '3.5', '>=' ); } return self::$is_wp_support_img_editor; } /** * Adds arlima export feed to Wordpress */ function addExportFeeds() { add_feed(self::EXPORT_FEED_NAME, array($this, 'loadExportFeed')); } /** * Install procedure for this plugin * - Adds database tables * - Adds version number in db * - Adds arlima export feed and flushed wp_rewrite * @static */ public static function install() { $factory = new Arlima_ListFactory(); $factory->install(); global $wp_rewrite; $plugin = new self(); $plugin->addExportFeeds(); $wp_rewrite->flush_rules(); $plugin = new self(); $settings = $plugin->loadSettings(); $settings['install_version'] = self::VERSION; $plugin->saveSettings($settings); } /** * Uninstall procedure for this plugin * - Removes plugin settings * - Removes database tables * @static */ public static function uninstall() { $factory = new Arlima_ListFactory(); $factory->uninstall(); delete_option('arlima_plugin_settings'); } /** * Deactivation procedure for this plugin * - Removes feed from wp_rewrite * @static */ public static function deactivate() { global $wp_rewrite; $feed_index = array_search('arlima', $wp_rewrite->feeds); if ( $feed_index ) { array_splice($wp_rewrite->feeds, $feed_index, 1); $wp_rewrite->flush_rules(); } } /** * Update procedure for this plugin. Since wordpress is lacking this feature we * should call this function on a regular basis. */ public static function update() { $plugin = new self(); $settings = $plugin->loadSettings(); $current_version = isset($settings['install_version']) ? $settings['install_version'] : 0; // Time for an update if ( $current_version != self::VERSION ) { // Update to v 2.0 if ( $current_version < 2 ) { global $wp_rewrite; $plugin->addExportFeeds(); $wp_rewrite->flush_rules(); } // Update to version 2.2 if ( $current_version < 2.2 ) { Arlima_ListFactory::databaseUpdates($current_version); } // Update to version 2.4 if ( $current_version < self::VERSION ) { Arlima_ListFactory::databaseUpdates($current_version); $pages = get_pages( array( 'meta_key' => '_wp_page_template', 'meta_value' => 'page-arlima.php', 'hierarchical' => 0 ) ); // Include arlima template to get width $list_width = false; $page_template = get_stylesheet_directory() . '/page-arlima.php'; if ( file_exists($page_template) ) { $page_content = explode('TMPL_ARTICLE_WIDTH', file_get_contents($page_template)); if( count($page_content) > 1 ) { $definition = explode(';', $page_content[1]); $list_width = (int)preg_replace('([^0-9]*)', '', current($definition)); } } if( !$list_width ) $list_width = 468; $connector = new Arlima_ListConnector(); $factory = new Arlima_ListFactory(); $list_attr = array( 'width' => $list_width, 'offset' => 0, 'limit' => 0 ); foreach ($pages as $page) { $arlima_slug = get_post_meta($page->ID, 'arlima', true); if ( $arlima_slug ) { $list = $factory->loadListBySlug($arlima_slug); if( $list->exists() ) { $connector->setList($list); $connector->relate($page->ID, $list_attr); } } } } $settings['install_version'] = self::VERSION; $plugin->saveSettings($settings); } } /** * Will try to export arlima list from currently visited page */ function loadExportFeed() { global $wp_query; $format = isset($_REQUEST['format']) ? $_REQUEST['format'] : Arlima_ExportManager::DEFAULT_FORMAT; $page_slug = !empty($wp_query->query_vars['pagename']) ? $wp_query->query_vars['pagename'] : ''; $export_manager = new Arlima_ExportManager($this); $export_manager->export($page_slug, $format); die; } /** * Settings of any kind related to this plugin * @return array */ function loadSettings() { return get_option('arlima_plugin_settings', array()); } /** * @param array $setting */ function saveSettings($setting) { update_option('arlima_plugin_settings', $setting); } /** * Adds meta box to post edit/create page */ function addMetaBox() { add_meta_box( 'arlima-meta-box', 'Arlima', array($this, 'postMetaBox'), 'post', 'side', 'low' ); add_meta_box( 'arlima-page-meta-box', 'Arlima', array($this, 'pageMetaBox'), 'page', 'side', 'low' ); } /** * Content of meta box used to send a wordpress post immediately from post * edit page in wp-admin to an arlima list */ function postMetaBox() { global $post; wp_nonce_field(plugin_basename(__FILE__), 'vkuc_nonce'); if ( $post->post_status == 'publish' ) { $factory = new Arlima_ListFactory(); ?> ' . __('Post needs to be published', 'arlima') . ''; } } function pageMetaBox() { global $post; wp_nonce_field(__FILE__, 'arlima_nonce'); $factory = new Arlima_ListFactory(); $connector = new Arlima_ListConnector(); $lists = $factory->loadListSlugs(); $relation_data = false; if ( $post ) { $relation_data = $connector->getRelationData($post->ID); } if( !$relation_data ) $relation_data = array('id' => '', 'attr'=>$connector->getDefaultListAttributes()); ?> removeRelation($post_id); } else { $list_factory = new Arlima_ListFactory(); $connector->setList($list_factory->loadList($_POST['arlima_list'])); $connector->relate($post_id, array( 'width' => (int)$_POST['arlima_width'], 'offset' => (int)$_POST['arlima_offset'], 'limit' => (int)$_POST['arlima_limit'], 'position' => $_POST['arlima_position'] )); } } else { Arlima_ListFactory::updateArlimaArticleData(get_post($post_id)); } } } /** * Creates the menu in wp-admin for this plugin and then call Arlima_Plugin::addAdminPageScriptsAndStylesheets * that will add all javascript and stylesheets needed by this plugin in wp-admin */ function adminMenu() { $arlima_mainpage = add_menu_page( __('Article List Manager', 'arlima'), __('Article lists', 'arlima'), 'edit_posts', 'arlima', 'Arlima_Plugin::loadAdminMainPage', ARLIMA_PLUGIN_URL . '/images/arlima-icon.png' ); add_submenu_page( 'arlima', __('Article lists', 'arlima'), __('Manage lists', 'arlima'), 'edit_posts', 'arlima', 'Arlima_Plugin::loadAdminMainPage' ); $arlima_editpage = add_submenu_page( 'arlima', __('Edit lists', 'arlima'), __('Edit lists', 'arlima'), 'edit_posts', 'arlima-editpage', 'Arlima_Plugin::loadAdminEditPage' ); $arlima_webservicepage = add_submenu_page( 'arlima', __('Web Service', 'arlima'), __('Web Service', 'arlima'), 'edit_posts', 'arlima-webservicepage', 'Arlima_Plugin::loadAdminWebServicePage' ); $this->addAdminPageScriptsAndStylesheets($arlima_mainpage, $arlima_editpage, $arlima_webservicepage); if ( function_exists('poll_footer_admin') ) { add_action('admin_footer', 'poll_footer_admin'); } } /** * @param string $main_page_slug * @param string $edit_page_slug * @param string $service_page_slug */ function addAdminPageScriptsAndStylesheets($main_page_slug, $edit_page_slug, $service_page_slug) { add_action('admin_print_scripts-' . $main_page_slug, array($this, 'addAdminMainPageScripts')); add_action('admin_print_styles-' . $main_page_slug, array($this, 'addAdminStyleSheets')); add_action('admin_print_styles-' . $main_page_slug, array($this, 'addTemplateCSS')); add_action('admin_print_scripts-' . $main_page_slug, array($this, 'addTinyMCEFilters')); add_action('admin_footer-' . $main_page_slug, array($this, 'addTemplateLoadingJS')); add_action('admin_print_scripts-' . $edit_page_slug, array($this, 'addAdminEditPageScripts')); add_action('admin_print_styles-' . $edit_page_slug, array($this, 'addAdminStyleSheets')); add_action('admin_print_styles-' . $service_page_slug, array($this, 'addAdminStyleSheets')); add_action('admin_print_scripts-' . $service_page_slug, array($this, 'addAdminServicePageScripts')); // Javascript used in meta-box on wp-admin page where blog posts is created $php_file = basename($_SERVER['PHP_SELF']); if ( $php_file == 'post-new.php' || $php_file = 'post.php' ) { wp_enqueue_script( 'arlima_js_admin', ARLIMA_PLUGIN_URL . '/js/admin-post.js', array('jquery'), self::STATIC_VERSION ); wp_localize_script( 'arlima_js_admin', 'ArlimaJSAdmin', array( 'ajaxurl' => admin_url('admin-ajax.php'), 'arlimaNonce' => wp_create_nonce('arlima-nonce'), 'imageurl' => ARLIMA_PLUGIN_URL . '/images/', 'lang' => array( 'notice' => __( 'Are you sure you want to insert this post in the top of selected article list?', 'arlima' ), 'wasSentTo' => __('The post is inserted in article list', 'arlima') ) ) ); } } /** * Add javascripts used on list edit page in wp-admin */ function addAdminEditPageScripts() { wp_enqueue_script('arlima_js', ARLIMA_PLUGIN_URL . 'js/page-edit.js', array('jquery'), self::STATIC_VERSION); wp_enqueue_script( 'arlima_js_jquery', ARLIMA_PLUGIN_URL . 'js/arlima/arlima-jquery-plugins.js', array('jquery'), self::STATIC_VERSION ); } /** * Add javascripts used on list edit page in wp-admin */ function addAdminServicePageScripts() { wp_enqueue_script('arlima_js', ARLIMA_PLUGIN_URL . 'js/page-service.js', array('jquery'), self::STATIC_VERSION); } /** * Adds all javascript files needed in the list editor in wp-admin */ function addAdminMainPageScripts() { // Enqueue scissors scripts if installed if ( Arlima_Plugin::isScissorsInstalled() ) { $scissors_url = WP_PLUGIN_URL . '/scissors-continued'; wp_enqueue_script('scissors_crop', $scissors_url . '/js/jquery.Jcrop.js', array('jquery')); wp_enqueue_script('scissors_js', $scissors_url . '/js/scissors.js'); $scissors_js_obj = array('ajaxUrl' => admin_url('admin-ajax.php')); foreach (array('large', 'medium', 'thumbnail') as $size) { $width = intval(get_option("{$size}_size_w")); $height = intval(get_option("{$size}_size_h")); $ratio = max(1, $width) / max(1, $height); if ( !get_option("{$size}_crop") ) { $ratio = 0; } $scissors_js_obj[$size . 'AspectRatio'] = $ratio; } echo ''; } // Add our template css to tinyMCE if ( !function_exists('tdav_css') ) { function tdav_css($wp) { $wp .= ',' . Arlima_Plugin::getTemplateCSS(); return $wp; } } add_filter('mce_css', 'tdav_css'); // Deregister scripts we need to override wp_deregister_script('jquery-hotkeys'); wp_deregister_script('jquery-ui-sortable'); // Replace jquery.ui.sortable with old version of the same function wp_register_script('jquery-ui-sortable', ARLIMA_PLUGIN_URL . 'js/jquery/jquery.ui.sortable-1.82.js', array('jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-mouse'), 12, true); wp_enqueue_script('jquery-ui-sortable'); // Add an almost astronomical amount of javascript $scripts = array( 'jquery' => false, 'jquery-ui-slider' => false, 'media-upload' => false, 'thickbox' => false, 'qtip' => ARLIMA_PLUGIN_URL . 'js/jquery/jquery.qtip.min.js', 'colourpicker' => ARLIMA_PLUGIN_URL . 'js/jquery/colourpicker/jquery.colourpicker.js', 'fancybox' => ARLIMA_PLUGIN_URL . 'js/jquery/fancybox/jquery.fancybox-1.3.4.pack.js', 'ui-nestedsortable' => ARLIMA_PLUGIN_URL . 'js/jquery/jquery.ui.nestedSortable.js', 'pluploadfull' => ARLIMA_PLUGIN_URL . 'js/misc/plupload.full.js', 'jquery-tmpl' => ARLIMA_PLUGIN_URL . 'js/jquery/jquery.tmpl.min.js', 'arlima-jquery' => ARLIMA_PLUGIN_URL . 'js/arlima/arlima-jquery-plugins.js', 'arlima-tmpl' => ARLIMA_PLUGIN_URL . 'js/arlima/template-loader.js', 'arlima-js' => ARLIMA_PLUGIN_URL . 'js/arlima/arlima.js', 'arlima-plupload' => ARLIMA_PLUGIN_URL . 'js/arlima/plupload-init.js', 'arlima-main-js' => ARLIMA_PLUGIN_URL . 'js/page-main.js', 'new-hotkeys' => ARLIMA_PLUGIN_URL . 'js/jquery/jquery.hotkeys.js' ); if( self::supportsImageEditor() ) { // these files could not be enqueue´d until wp version 3.5 $wp_inc_url = includes_url() .'/js/jquery/ui/'; $scripts['jquery-ui-effects'] = $wp_inc_url .'jquery.ui.effect.min.js'; $scripts['jquery-ui-effects-shake'] = $wp_inc_url .'jquery.ui.effect-shake.min.js'; $scripts['jquery-ui-effects-highlight'] = $wp_inc_url .'jquery.ui.effect-highlight.min.js'; } foreach($scripts as $handle => $js) { if( $js !== false ) { $dependency = array('jquery'); if( $handle == 'ui-nestedsortable' ) $dependency = array('jquery-ui-sortable'); wp_register_script($handle, $js, $dependency, self::STATIC_VERSION, false); } wp_enqueue_script($handle); } wp_localize_script( 'arlima-js', 'ArlimaJS', array( 'ajaxurl' => admin_url('admin-ajax.php'), 'arlimaNonce' => wp_create_nonce('arlima-nonce'), 'imageurl' => ARLIMA_PLUGIN_URL . '/images/', 'baseurl' => get_bloginfo('url'), 'is_admin' => current_user_can('manage_options') ? 1 : 0, 'preview_query_arg' => Arlima_List::QUERY_ARG_PREVIEW, 'lang' => array( // todo: but these args in a separate .js.php file when this array gets to long 'unsaved' => __('You have one, or more, unsaved article lists', 'arlima'), 'laterVersion' => __('It exists an older version of this article list', 'arlima'), 'overWrite' => __('Do you still want to save this version of the list?', 'arlima'), 'severalExtras' => __('This article list has more than one extra-streamer', 'arlima'), 'changesBeforeRemove' => __( 'You have made changes to this list, do you want to remove it anyway?', 'arlima' ), 'wantToRemove' => __('Do you want to remove "', 'arlima'), 'fromList' => __('" from this article list?', 'arlima'), 'chooseImage' => __('Choose image', 'arlima'), 'admin_lock' => __('This article is locked by admin', 'arlima'), 'admin_only' => __('Only administrators can manage article locks', 'arlima'), 'noList' => __('No list is active!', 'arlima'), 'noImages' => __('This article has no related image', 'arlima'), 'noConnection' => __('this article is not connected to any post', 'arlima'), 'listRemoved' => __('This list have been removed!', 'arlima'), 'savePreview' => __('to save article list', 'arlima'), 'isSaved' => __('This list has no unsaved changes', 'arlima'), 'missingPreviewPage' => __('This list is not yet related to any page', 'arlima'), 'hasUnsavedChanges' => __('This list has unsaved changes', 'arlima'), 'dragAndDrop' => __('Drag images to this container', 'arlima'), 'sticky' => __('Sticky', 'arlima'), 'loggedOut' => __('Your login session seems to have expired, pls reload the page!', 'arlima') ) ) ); } /** * Will enqueue the css for the presentation of articles in an arlima list */ function addTemplateCSS() { wp_enqueue_style('arlima_template_css', self::getTemplateCSS(), array(), null); } /** * Get the path to the CSS file that controls the presentation of * articles in an arlima list * @static * @return string */ public static function getTemplateCSS() { return apply_filters('arlima_template_css', ARLIMA_PLUGIN_URL . 'css/template.css?v='.self::STATIC_VERSION); } /** * Will output javascript that loads all jQuery templates from backend */ function addTemplateLoadingJS() { $tmpl_resolver = new Arlima_TemplatePathResolver(); ?>