function makeArticle($class, $text)
{
    global $unique;
    $unique++;
    $i = strpos($text, '</a>');
    $j = strpos($text, '</h4>');
    $h4 = substr($text, $i + 4, $j - $i - 4);
    $text = substr($text, $j + 5);
    $text = str_replace('<hr />', '', $text);
    $text = str_replace('<hr/>', '', $text);
    $ts_news = new ZenpageNews(seoFriendly($class . '_' . trim(truncate_string(strip_tags($h4), 30, '')) . '_' . $unique), true);
    $ts_news->setShow(0);
    $ts_news->setDateTime(date('Y-m-d H:i:s'));
    $ts_news->setAuthor('TSGenerator');
    $ts_news->setTitle($h4);
    $ts_news->setContent($text);
    $ts_news->setCategories(array());
    $ts_news->setCategories(array('troubleshooting', 'troubleshooting-' . $class));
    $ts_news->save();
}
Beispiel #2
0
function processPlugins()
{
    global $_zp_current_admin_obj;
    $curdir = getcwd();
    $basepath = SERVERPATH . "/" . ZENFOLDER . '/' . PLUGIN_FOLDER . '/';
    chdir($basepath);
    $filelist = safe_glob('*.php');
    foreach ($filelist as $file) {
        $titlelink = stripSuffix(filesystemToInternal($file));
        $author = stripSuffix(basename(__FILE__));
        $sql = 'SELECT `id` FROM ' . prefix('news') . ' WHERE `titlelink`=' . db_quote($titlelink);
        $result = query_single_row($sql);
        if (empty($result)) {
            $plugin_news = new ZenpageNews($titlelink);
            $fp = fopen($basepath . $file, 'r');
            $empty = true;
            $desc = '<p>';
            $tags = array($titlelink);
            $incomment = false;
            while ($line = fgets($fp)) {
                if (strpos($line, '/*') !== false) {
                    $incomment = true;
                }
                if ($incomment) {
                    if (strpos($line, '*/') !== false) {
                        break;
                    }
                    $i = strpos($line, '*');
                    $line = trim(trim(substr($line, $i + 1), '*'));
                    if (empty($line)) {
                        if (!$empty) {
                            $desc .= '<p>';
                        }
                        $empty = true;
                    } else {
                        if (strpos($line, '@') === 0) {
                            $line = trim($line, '@');
                            $i = strpos($line, ' ');
                            $mod = substr($line, 0, $i);
                            $line = trim(substr($line, $i + 1));
                            switch ($mod) {
                                case 'author':
                                    $desc .= 'Author: ' . html_encode($line) . ' ';
                                    $empty = false;
                                    preg_match_all('|\\((.+?)\\)|', $line, $matches);
                                    $tags = array_merge($tags, $matches[1]);
                                    $author = array_shift($matches[1]);
                                    break;
                                case 'package':
                                case 'subpackage':
                                    $tags[] = $line;
                                    break;
                                case 'tags':
                                    $pluginTags = explode(',', $line);
                                    foreach ($pluginTags as $tag) {
                                        $tags[] = trim(unQuote($tag));
                                    }
                                    break;
                            }
                        } else {
                            $desc .= html_encode($line) . ' ';
                            $empty = false;
                        }
                    }
                }
            }
            $desc .= '</p>';
            fclose($fp);
            $plugin_news->setShow(0);
            $plugin_news->setDateTime(date('Y-m-d H:i:s'), filemtime($file));
            $plugin_news->setAuthor($author);
            $plugin_news->setTitle($titlelink);
            $plugin_news->setContent($desc);
            $plugin_news->setTags($tags);
            $plugin_news->setCategories(array('officially-supported', 'extensions'));
            $plugin_news->setCustomData("http://www.zenphoto.org/documentation/plugins/_" . PLUGIN_FOLDER . "---" . $titlelink . ".html");
            $plugin_news->save();
        }
    }
    chdir($curdir);
}
/**
 * Updates a news article and returns the object of that article
 *
 * @return object
 */
function updateArticle(&$reports)
{
    $date = date('Y-m-d_H-i-s');
    $title = process_language_string_save("title", 2);
    $author = sanitize($_POST['author']);
    $content = process_language_string_save("content", 0);
    // TinyMCE already clears unallowed code
    $extracontent = process_language_string_save("extracontent", 0);
    // TinyMCE already clears unallowed code
    $custom = process_language_string_save("custom_data", 1);
    $show = getcheckboxState('show');
    $date = sanitize($_POST['date']);
    $expiredate = getExpiryDatePost();
    $permalink = getcheckboxState('permalink');
    $lastchange = sanitize($_POST['lastchange']);
    $lastchangeauthor = sanitize($_POST['lastchangeauthor']);
    $commentson = getcheckboxState('commentson');
    $codeblock1 = sanitize($_POST['codeblock1'], 0);
    $codeblock2 = sanitize($_POST['codeblock2'], 0);
    $codeblock3 = sanitize($_POST['codeblock3'], 0);
    $codeblock = serialize(array("1" => $codeblock1, "2" => $codeblock2, "3" => $codeblock3));
    $locked = getcheckboxState('locked');
    $titlelink = $oldtitlelink = sanitize($_POST['titlelink-old'], 3);
    if (getcheckboxState('edittitlelink')) {
        $titlelink = sanitize($_POST['titlelink'], 3);
        if (empty($titlelink)) {
            $titlelink = seoFriendly(get_language_string($title));
            if (empty($titlelink)) {
                $titlelink = seoFriendly($date);
            }
        }
    } else {
        if (!$permalink) {
            //	allow the title link to change.
            $link = seoFriendly(get_language_string($title));
            if (!empty($link)) {
                $titlelink = $link;
            }
        }
    }
    $id = sanitize($_POST['id']);
    $rslt = true;
    if ($titlelink != $oldtitlelink) {
        // title link change must be reflected in DB before any other updates
        $rslt = query('UPDATE ' . prefix('news') . ' SET `titlelink`=' . db_quote($titlelink) . ' WHERE `id`=' . $id, false);
        if (!$rslt) {
            $titlelink = $oldtitlelink;
            // force old link so data gets saved
        }
    }
    // update article
    $article = new ZenpageNews($titlelink, true);
    $article->setTitle($title);
    $article->setContent($content);
    $article->setExtracontent($extracontent);
    $article->setCustomData(zp_apply_filter('save_article_custom_data', $custom, $article));
    $article->setShow($show);
    $article->setDateTime($date);
    $article->setCommentsAllowed($commentson);
    $article->setCodeblock($codeblock);
    $article->setAuthor($author);
    $article->setLastchange($lastchange);
    $article->setLastchangeauthor($lastchangeauthor);
    $article->setPermalink($permalink);
    $article->setLocked($locked);
    $article->setExpiredate($expiredate);
    $article->setSticky(sanitize_numeric($_POST['sticky']));
    if (getcheckboxState('resethitcounter')) {
        $article->set('hitcounter', 0);
    }
    processTags($article);
    $categories = array();
    $result2 = query_full_array("SELECT * FROM " . prefix('news_categories') . " ORDER BY titlelink");
    foreach ($result2 as $cat) {
        if (isset($_POST["cat" . $cat['id']])) {
            $categories[] = $cat['titlelink'];
        }
    }
    $article->setCategories($categories);
    $msg = zp_apply_filter('update_article', '', $article, $oldtitlelink);
    $article->save();
    if (!$rslt) {
        $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("An article with the title/titlelink <em>%s</em> already exists!"), $titlelink) . '</p>';
    } else {
        if (empty($title)) {
            $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("Article <em>%s</em> updated but you need to give it a <strong>title</strong> before publishing!"), get_language_string($titlelink)) . '</p>';
        } else {
            $reports[] = "<p class='messagebox fade-message'>" . sprintf(gettext("Article <em>%s</em> updated"), $titlelink) . '</p>';
        }
    }
    if ($msg) {
        $reports[] = $msg;
    }
    return $article;
}
/**
 * Updates or adds a news article and returns the object of that article
 *
 * @param array $reports display
 * @param bool $newarticle true if a new article
 *
 * @return object
 */
function updateArticle(&$reports, $newarticle = false)
{
    $date = date('Y-m-d_H-i-s');
    $title = process_language_string_save("title", 2);
    $author = sanitize($_POST['author']);
    $content = zpFunctions::updateImageProcessorLink(process_language_string_save("content", EDITOR_SANITIZE_LEVEL));
    $extracontent = zpFunctions::updateImageProcessorLink(process_language_string_save("extracontent", EDITOR_SANITIZE_LEVEL));
    $custom = process_language_string_save("custom_data", 1);
    $show = getcheckboxState('show');
    $date = sanitize($_POST['date']);
    $expiredate = getExpiryDatePost();
    $permalink = getcheckboxState('permalink');
    $lastchange = sanitize($_POST['lastchange']);
    $lastchangeauthor = sanitize($_POST['lastchangeauthor']);
    $commentson = getcheckboxState('commentson');
    if (zp_loggedin(CODEBLOCK_RIGHTS)) {
        $codeblock = processCodeblockSave(0);
    }
    $locked = getcheckboxState('locked');
    if ($newarticle) {
        $titlelink = seoFriendly(get_language_string($title));
        if (empty($titlelink)) {
            $titlelink = seoFriendly($date);
        }
        $sql = 'SELECT `id` FROM ' . prefix('news') . ' WHERE `titlelink`=' . db_quote($titlelink);
        $rslt = query_single_row($sql, false);
        if ($rslt) {
            //already exists
            $time = explode(' ', microtime());
            $titlelink = $titlelink . '_' . ($time[1] + $time[0]);
            $reports[] = "<p class='warningbox fade-message'>" . gettext('Duplicate article title') . '</p>';
        }
        $oldtitlelink = $titlelink;
        $id = 0;
    } else {
        $titlelink = $oldtitlelink = sanitize($_POST['titlelink-old'], 3);
        $id = sanitize($_POST['id']);
    }
    if (getcheckboxState('edittitlelink')) {
        $titlelink = sanitize($_POST['titlelink'], 3);
        if (empty($titlelink)) {
            $titlelink = seoFriendly(get_language_string($title));
            if (empty($titlelink)) {
                $titlelink = seoFriendly($date);
            }
        }
    } else {
        if (!$permalink) {
            //	allow the title link to change.
            $link = seoFriendly(get_language_string($title));
            if (!empty($link)) {
                $titlelink = $link;
            }
        }
    }
    $rslt = true;
    if ($titlelink != $oldtitlelink) {
        // title link change must be reflected in DB before any other updates
        $rslt = query('UPDATE ' . prefix('news') . ' SET `titlelink`=' . db_quote($titlelink) . ' WHERE `id`=' . $id, false);
        if (!$rslt) {
            $titlelink = $oldtitlelink;
            // force old link so data gets saved
        } else {
            SearchEngine::clearSearchCache();
        }
    }
    // update article
    $article = new ZenpageNews($titlelink, true);
    $article->setTitle($title);
    $article->setContent($content);
    $article->setExtracontent($extracontent);
    $article->setCustomData(zp_apply_filter('save_article_custom_data', $custom, $article));
    $article->setShow($show);
    $article->setDateTime($date);
    $article->setCommentsAllowed($commentson);
    if (zp_loggedin(CODEBLOCK_RIGHTS)) {
        $article->setCodeblock($codeblock);
    }
    $article->setAuthor($author);
    $article->setLastchange($lastchange);
    $article->setLastchangeauthor($lastchangeauthor);
    $article->setPermalink($permalink);
    $article->setLocked($locked);
    $article->setExpiredate($expiredate);
    $article->setSticky(sanitize_numeric($_POST['sticky']));
    if (getcheckboxState('resethitcounter')) {
        $article->set('hitcounter', 0);
    }
    if (getcheckboxState('reset_rating')) {
        $article->set('total_value', 0);
        $article->set('total_votes', 0);
        $article->set('used_ips', 0);
    }
    $article->setTruncation(getcheckboxState('truncation'));
    processTags($article);
    $categories = array();
    $result2 = query_full_array("SELECT * FROM " . prefix('news_categories') . " ORDER BY titlelink");
    foreach ($result2 as $cat) {
        if (isset($_POST["cat" . $cat['id']])) {
            $categories[] = $cat['titlelink'];
        }
    }
    $article->setCategories($categories);
    if ($newarticle) {
        $msg = zp_apply_filter('new_article', '', $article);
        if (empty($title)) {
            $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("Article <em>%s</em> added but you need to give it a <strong>title</strong> before publishing!"), get_language_string($titlelink)) . '</p>';
        } else {
            $reports[] = "<p class='messagebox fade-message'>" . sprintf(gettext("Article <em>%s</em> added"), $titlelink) . '</p>';
        }
    } else {
        $msg = zp_apply_filter('update_article', '', $article, $oldtitlelink);
        if (!$rslt) {
            $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("An article with the title/titlelink <em>%s</em> already exists!"), $titlelink) . '</p>';
        } else {
            if (empty($title)) {
                $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("Article <em>%s</em> updated but you need to give it a <strong>title</strong> before publishing!"), get_language_string($titlelink)) . '</p>';
            } else {
                $reports[] = "<p class='messagebox fade-message'>" . sprintf(gettext("Article <em>%s</em> updated"), $titlelink) . '</p>';
            }
        }
    }
    $article->save();
    if ($msg) {
        $reports[] = $msg;
    }
    return $article;
}
 /**
  *
  * Formats the message and calls sendTweet() on an object
  * @param object $obj
  */
 private static function publishArticle($obj, $override = NULL)
 {
     global $_zp_zenpage;
     $galleryitem_text = array();
     switch ($type = $obj->table) {
         case 'albums':
             if (getOption('multi_lingual')) {
                 $option_text = unserialize(getOption('galleryArticles_album_text'));
                 foreach ($option_text as $key => $val) {
                     $galleryitem_text[$key] = sprintf($option_text[$key], $obj->getTitle($key));
                 }
                 $text = serialize($galleryitem_text);
             } else {
                 $text = sprintf(get_language_string(getOption('galleryArticles_album_text')), $obj->getTitle());
             }
             $title = $folder = $obj->name;
             $img = $obj->getAlbumThumbImage();
             $class = 'galleryarticles-newalbum';
             break;
         case 'images':
             if (getOption('multi_lingual')) {
                 $option_text = unserialize(getOption('galleryArticles_image_text'));
                 foreach ($option_text as $key => $val) {
                     $galleryitem_text[$key] = sprintf($option_text[$key], $obj->getTitle($key), $obj->album->getTitle($key));
                 }
                 $text = serialize($galleryitem_text);
             } else {
                 $text = sprintf(get_language_string(getOption('galleryArticles_image_text')), $obj->getTitle(), $obj->album->getTitle());
             }
             $folder = $obj->imagefolder;
             $title = $folder . '-' . $obj->filename;
             $img = $obj;
             $class = 'galleryarticles-newimage';
             break;
     }
     $article = new ZenpageNews(seoFriendly('galleryArticles-' . $title));
     $article->setTitle($text);
     $imglink = $img->getCustomImage(getOption('galleryArticles_size'), NULL, NULL, NULL, NULL, NULL, NULL, -1);
     if (getOption('multi_lingual')) {
         $desc = '';
         foreach ($option_text as $key => $val) {
             $desc[$key] = '<p><a class="' . $class . '" href="' . $obj->getLink() . '"><img src="' . $imglink . '"></a></p><p>' . $obj->getDesc($key) . '</p>';
         }
         $desc = serialize($desc);
     } else {
         $desc = '<p><a class="' . $class . '" href="' . $obj->getLink() . '"><img src="' . $imglink . '"></a></p><p>' . $obj->getDesc() . '</p>';
     }
     $article->setContent($desc);
     $article->setShow(true);
     $date = $obj->getPublishDate();
     if (!$date) {
         $date = date('Y-m-d H:i:s');
     }
     $article->setDateTime($date);
     $article->setAuthor('galleryArticles');
     $article->save();
     if ($override) {
         $cat = $override;
     } else {
         $cat = getOption('galleryArticles_category');
         if (getOption('galleryArticles_albumCategory')) {
             $catlist = $_zp_zenpage->getAllCategories();
             foreach ($catlist as $category) {
                 if ($category['titlelink'] == $folder) {
                     $cat = $category['titlelink'];
                     break;
                 }
             }
         }
     }
     $article->setCategories(array($cat));
 }