Forum Replies Created

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter ben.IT

    (@benit)

    Don’t know why either. Thanks for your answer.
    Ben

    Thread Starter ben.IT

    (@benit)

    Hi, I find a solution which works using the fine polylang API :

    //Original : does not manage language. display all comments. doesn't care about the comment language
    		//$comments = get_comments( array( 'number' => $number, 'status' => 'approve' ) );
    		/************************************************************/
    
    		$current_lng= pll_current_language(); //retrieve current language
    		$lng_objects = get_posts(array(
    		'post_type' => 'post',
    		'lang' => $current_lng, // use language slug in the query
    		'showposts' => 150 //remove if problem. here for perf. this prevents loading all posts.
    ));
    $lng_ids=array() ;
    foreach ($lng_objects as $objects)
    	array_push($lng_ids, $objects->ID) ;
    $string_lng_ids=implode(",", $lng_ids); //build ID string for sql query
    
    global $wpdb;
    $query_lng_comments="
    select wp3_comments.*
    from wp3_comments
    inner join wp3_posts on wp3_posts.ID=wp3_comments.comment_post_ID
    where comment_approved=1
    and wp3_posts.ID in ($string_lng_ids)
    order by comment_date desc
    limit 0,$number
    ";
    $comments=$wpdb->get_results($query_lng_comments);
    /*********************************************************/

    Hope this could help.
    greetings,
    ben

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum’s parser.]

    Thread Starter ben.IT

    (@benit)

    Hi chouby . Thanks for your answer. I wrote this yesterday to manage translation import when setting up the site.
    I my case I need french and english translation :

    <?php
    require_once( ABSPATH.'wp-content/plugins/polylang/include/admin-base.php');
    require_once( ABSPATH.'wp-content/plugins/polylang/include/admin.php');
    
    /**
     * Manage translation object for initial import. Need the string reference, the french translation and the english translation
     *
     *
    */
    class Translation
    {
    	public $termReference ;
    	public $termTranslationFr ;
    	public $termTranslationEn ;
    
    	public function __construct($termReference, $termTranslationFr, $termTranslationEn)
    	{
    		$this->termReference=$termReference ;
    		$this->termTranslationFr=$termTranslationFr;
    		$this->termTranslationEn=$termTranslationEn ;
    	}
    }//end of class Translation
    
    /**
     * Manage translation import. Imports Translation objects.
     * This class allows to import translation to polylang backoffice. polylang sets options in wp3_options.
     * Query to see how polylang options : select * from wp3_options where option_name like 'polylang_mo%'
     * This import mechanism his largely inspired by the 2 followings methods of polylang located in wp-content/plugins/polylang/include/base.php :
     * function mo_export($mo, $lang)
     * function mo_import($lang)
     */
    class TranslationImporter
    {
    	private $tableTranslations ; //contain all Translation objects to import
    	private $moFr ; //MO object for french translation
    	private $moEn ; //MO object for english translation
    
    	private $polylang_mo_fr_code='polylang_mo251' ;
    	private $polylang_mo_en_code='polylang_mo253' ;
    
    	public function __construct()
    	{
    		$this->moEn = new MO();
    		$this->moFr = new MO();
    		$this->tableTranslations = array();
    	}
    
    	/**
    	 * adds a Translation object to
    	 * @param unknown $translation the array tableTranslations
    	 */
    	public function addTranslationToImport($translation)
    	{
    		array_push($this->tableTranslations,$translation);
    	}
    
    	/**
    	 * import translations from tableTranslations attribute to the french MO and english MO attributes.
    	 */
    	public function importTranslationToMo()
    	{
    		foreach ($this->tableTranslations as $row)
    		{
    			//make_entry('reference string ', 'translation')
    			$this->moFr->add_entry($this->moFr->make_entry($row->termReference, $row->termTranslationFr));
    			$this->moEn->add_entry($this->moEn->make_entry($row->termReference, $row->termTranslationEn));
    		}
    	}
    
    	/**
    	 * Update polylang options from the mo attributes which has been fill in with the importTranslationToMo method
    	 */
    	public function updateOptionsFromMO()
    	{
    		$stringsFr = array();
    		foreach ($this->moFr->entries as $entry)
    			$strings[] = array($entry->singular, $this->moFr->translate($entry->singular));
    		update_option('polylang_mo'.'251', $strings);
    
    		$stringsEn = array();
    		foreach ($this->moEn->entries as $entry)
    			$strings[] = array($entry->singular, $this->moEn->translate($entry->singular));
    		update_option('polylang_mo'.'253', $strings);
    
    	}
    }//end of class TranslationImporter
    /**
     * This main script imports translation into polylang.
    */
    require_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php') ; //use $_SERVER['DOCUMENT_ROOT'] to refer to WP root while ABSPATH isnt yet set.
    require_once(ABSPATH.'wp-content/plugins/international-int/classes/InternationalIntTranslationImporter.class.php');
    $start_time = microtime(true); //calcul exec time for fun 
    
    $TranslationImporter = new TranslationImporter();
    //add the translations to the importer
    $TranslationImporter->addTranslationToImport(new Translation('annuaire', 'annuaire', 'adress book'));
    $TranslationImporter->addTranslationToImport(new Translation('vos commentaires', 'c fr ', 'c en'));
    $TranslationImporter->addTranslationToImport(new Translation('INTRANET INTERNATIONAL', 'fr ', 'en'));
    $TranslationImporter->addTranslationToImport(new Translation('Evénements clients', 'Evénements clients', 'customers event'));
    $TranslationImporter->addTranslationToImport(new Translation('ref', 'fr ', 'en'));
    
    $TranslationImporter->importTranslationToMo(); //generate MOs in the importer
    $TranslationImporter->updateOptionsFromMO(); //update WP options from MOs importers
    
    echo 'end of translation import. execution took : '.(microtime(true) - $start_time).' seconds.';

    greetings,
    ben

    Thread Starter ben.IT

    (@benit)

    hi kevinB,
    Those methods help me :

    $role_scoper_group_id = ScoperAdminLib::get_group_by_name(‘my group ‘)->ID;
    $group_member = ScoperAdminLib::get_group_members($role_scoper_group_id ) ;

    enjoy 😉
    greetings,
    ben

    Thread Starter ben.IT

    (@benit)

    Hi, I found what I want in rolescoper core source.
    Those methods help me :

    $role_scoper_group_id = ScoperAdminLib::get_group_by_name(‘my group ‘)->ID;
    $group_member = ScoperAdminLib::get_group_members($role_scoper_group_id ) ;

    enjoy 😉
    greetings,
    ben

    Thread Starter ben.IT

    (@benit)

    Hi, thanks for your answer.
    I’ll try to be more precise.

    I have already read this resource and know how to write my own (very basic) plugin.

    I have developed a script which instantiate an XML RPC client to synchronise content between 2 wordpress instances.

    I perform HTTP requests to run this script : http://mywpinstance.com/myscript.php

    now I would like to package it as a plugin.

    To perform this, I think I’m gonna try adding a rewrite rule,
    I will call : http://mywpinstance.com/myscript.php which will execute the code of http://mywpinstance.com/wp-content/plugins/myplugin/myplugin.php

    Hope this will work !

    Hi,
    I am also concerned by his issue.
    Does anybody get an idea/snippet ?

    Thread Starter ben.IT

    (@benit)

    Thanks for your answer Chouby.
    Inspecting Polylang code, I found what I want to set the default language of my posts sended via XML-RPC.
    I wrote the following function which is a snippet of polylang sources :

    <?php
    require('../wp-load.php');
    require_once('../wp-content/plugins/polylang/include/admin-base.php');
    require_once('../wp-content/plugins/polylang/include/admin.php');
    
    /*
    This is a hack from /wp-content/plugins/polylang/include/admin.php line 243 to 262
    * */
    function setDefaultLanguage ($defaultLanguage='fr') {
    	$polylang = new Polylang_Admin();
    	global $wpdb ;
    
    	$untranslated = $polylang->get_untranslated(); var_dump($untranslated);
    	$lang = $polylang->get_language($defaultLanguage); var_dump($lang);
    
    	$values = array();
    	foreach ($untranslated['posts'] as $post_id)
    	{$values[] = $wpdb->prepare("(%d, %d)", $post_id, $lang->term_taxonomy_id); }
    	echo 'values='; var_dump($values);
    
    	if ($values) {
    		echo 'ipmlode values : '.implode(',', $values) ;
    		$wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES " . implode(',', $values));
    		wp_update_term_count($lang->term_taxonomy_id, 'language'); // updating term count is mandatory (thanks to AndyDeGroo)
    	}
    
    	$values = array();
    	foreach ($untranslated['terms'] as $term_id)
    	{$values[] = $wpdb->prepare("(%d, %s, %d)", $term_id, '_language', $lang->term_id);}
    	echo 'values='; var_dump($values);
    
    	if ($values)
    	$wpdb->query("INSERT INTO $wpdb->termmeta (term_id, meta_key, meta_value) VALUES " . implode(',', $values));
    
    }
    
    setDefaultLanguage('fr');

    Ben

    Thread Starter ben.IT

    (@benit)

    thanks for your reply, but this doesn’t fix the bug, still the same id returned.

    any idea ?
    ben

Viewing 9 replies - 1 through 9 (of 9 total)