Ejemplo n.º 1
0
	function onContentAfterSave($context, &$article, $isNew)
	{
		// Check we are handling the frontend edit form.
		if ($context == 'com_content.form') {
			require_once(JCOMMENTS_HELPERS . '/content.php');
			if (JCommentsContentPluginHelper::checkCategory($article->catid)) {
				require_once(JCOMMENTS_HELPERS . '/object.php');
				JCommentsObjectHelper::storeObjectInfo($article->id, 'com_content');
			}
		}
	}
Ejemplo n.º 2
0
 public static function refreshObjectsAjax()
 {
     $app = JFactory::getApplication();
     $hash = $app->input->post->get('hash', '');
     $step = $app->input->post->getInt('step');
     $lang = $app->input->post->get('lang', '');
     $count = 50;
     if ($hash === md5($app->getCfg('secret'))) {
         $db = JFactory::getDBO();
         if ($step == 0) {
             if ($app->getCfg('caching') != 0) {
                 // clean cache for all object groups
                 $db->setQuery('SELECT DISTINCT object_group FROM #__jcomments_objects');
                 $rows = $db->loadColumn();
                 foreach ($rows as $row) {
                     $cache = JFactory::getCache('com_jcomments_objects_' . strtolower($row));
                     $cache->clean();
                 }
             }
             $db->setQuery('TRUNCATE TABLE #__jcomments_objects');
             $db->execute();
         }
         $where = array();
         $where[] = 'IFNULL(c.lang, "") <> ""';
         // count objects without information
         $query = "SELECT COUNT(DISTINCT c.object_id, c.object_group, c.lang)" . " FROM #__jcomments AS c" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : "");
         $db->setQuery($query);
         $total = (int) $db->loadResult();
         $count = 0;
         if ($total > 0) {
             $where[] = 'NOT EXISTS (SELECT o.id FROM #__jcomments_objects AS o WHERE o.object_id = c.object_id AND o.object_group = c.object_group AND o.lang = c.lang)';
             // get list of first objects without information
             $query = "SELECT DISTINCT c.object_id, c.object_group, c.lang" . " FROM #__jcomments AS c" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : "") . " ORDER BY c.object_group, c.lang";
             $db->setQuery($query, 0, $count);
             $rows = $db->loadObjectList();
             $i = 0;
             $multilanguage = JCommentsMultilingual::isEnabled();
             $nextLanguage = $lang;
             if (count($rows)) {
                 foreach ($rows as $row) {
                     if ($nextLanguage != $row->lang && $multilanguage) {
                         $nextLanguage = $row->lang;
                         break;
                     }
                     // retrieve and store object information
                     JCommentsObjectHelper::storeObjectInfo($row->object_id, $row->object_group, $row->lang, false, true);
                     $i++;
                 }
             }
             if ($i > 0) {
                 $db->setQuery("SELECT COUNT(*) FROM #__jcomments_objects");
                 $count = (int) $db->loadResult();
             }
             $percent = ceil($count / $total * 100);
             $percent = min($percent, 100);
         } else {
             $percent = 100;
         }
         $step++;
         $lang_codes = JLanguageHelper::getLanguages('lang_code');
         $language_sef = isset($lang_codes[$nextLanguage]) ? $lang_codes[$nextLanguage]->sef : $nextLanguage;
         $data = array('count' => $count, 'total' => $total, 'percent' => $percent, 'step' => $step, 'hash' => $hash, 'object_group' => null, 'lang' => $nextLanguage, 'lang_sef' => $language_sef);
         echo json_encode($data);
     }
     $app->close();
 }
Ejemplo n.º 3
0
 public static function RefreshObjects($hash, $step = 0, $object_group = '', $lang = '')
 {
     if (JCommentsSecurity::badRequest() == 1) {
         JCommentsSecurity::notAuth();
     }
     $response = JCommentsFactory::getAjaxResponse();
     $app = JCommentsFactory::getApplication();
     $count = 50;
     if ($hash === md5($app->getCfg('secret'))) {
         $db = JCommentsFactory::getDBO();
         if ($step == 0) {
             $db->setQuery('DELETE FROM #__jcomments_objects WHERE 1=1');
             $db->query();
         }
         $where = array();
         $where[] = 'IFNULL(c.lang, "") <> ""';
         if (!empty($object_group)) {
             $where[] = 'c.object_group = ' . $db->Quote($object_group);
         }
         // count objects without information
         $query = "SELECT COUNT(DISTINCT c.object_id, c.object_group, c.lang)" . " FROM #__jcomments AS c" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : "");
         $db->setQuery($query);
         $objectsCount = (int) $db->loadResult();
         $where[] = 'NOT EXISTS (SELECT o.id FROM #__jcomments_objects AS o WHERE o.object_id = c.object_id AND o.object_group = c.object_group AND o.lang = c.lang)';
         // get list of first objects without information
         $query = "SELECT DISTINCT c.object_id, c.object_group, c.lang" . " FROM #__jcomments AS c" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : "") . " ORDER BY c.object_group, c.lang";
         $db->setQuery($query, 0, $count);
         $rows = $db->loadObjectList();
         $i = 0;
         $multilanguage = JCommentsMultilingual::isEnabled();
         $nextLanguage = $lang;
         if (count($rows)) {
             foreach ($rows as $row) {
                 if ($nextLanguage != $row->lang && $multilanguage) {
                     $nextLanguage = $row->lang;
                     break;
                 }
                 // retrieve and store object information
                 JCommentsObjectHelper::storeObjectInfo($row->object_id, $row->object_group, $row->lang, false, true);
                 $i++;
             }
         }
         $objectsRefreshed = 0;
         if ($i > 0) {
             $db->setQuery("SELECT COUNT(*) FROM #__jcomments_objects");
             $objectsRefreshed = (int) $db->loadResult();
             $response->addScript("JCommentsRefreshObjectsProgress({$objectsRefreshed}, {$objectsCount});");
         }
         if ($objectsCount > $objectsRefreshed && ($i > 0 || $lang != $nextLanguage)) {
             // we need continue refresh
             $step++;
             $response->addScript("JCommentsRefreshObjectsAJAX('{$hash}', '{$step}', '', '{$nextLanguage}');");
         } else {
             $response->addScript("JCommentsRefreshObjectsProgress({$objectsCount}, {$objectsCount});");
             if ($app->getCfg('caching')) {
                 // clean cache for all object groups
                 $db->setQuery('SELECT DISTINCT object_group FROM #__jcomments_objects');
                 $rows = $db->loadResultArray();
                 foreach ($rows as $row) {
                     $cache = JCommentsFactory::getCache('com_jcomments_objects_' . strtolower($row));
                     $cache->clean();
                 }
             }
         }
     }
     return $response;
 }
Ejemplo n.º 4
0
 function onContentAfterSave($context, $article, $isNew)
 {
     // Check we are handling the frontend edit form.
     if ($context == 'com_content.form' && !$isNew) {
         require_once JPATH_ROOT . '/components/com_jcomments/helpers/content.php';
         if (JCommentsContentPluginHelper::checkCategory($article->catid)) {
             require_once JPATH_ROOT . '/components/com_jcomments/helpers/object.php';
             JCommentsObjectHelper::storeObjectInfo($article->id, 'com_content');
         }
     }
 }