Example #1
0
if (!empty($cats)) {
    echo $cats;
}
$containers = elgg_view('input/containers', $vars);
if ($containers) {
    echo $containers;
}
if (elgg_is_active_plugin('pages_tools')) {
    // add support to disable commenting
    echo "<div>";
    echo "<label>" . elgg_echo("pages_tools:allow_comments") . "</label>";
    echo "<br />";
    echo elgg_view("input/dropdown", array("name" => "allow_comments", "value" => $allow_comments, "options_values" => $yesno_options));
    echo "</div>";
    // advanced puplication options
    if (pages_tools_use_advanced_publication_options()) {
        if (!empty($entity)) {
            $publication_date_value = $entity->publication_date;
            $expiration_date_value = $entity->expiration_date;
        }
        if (empty($publication_date_value)) {
            $publication_date_value = "";
        }
        if (empty($expiration_date_value)) {
            $expiration_date_value = "";
        }
        $publication_date = "<div class='mbs'>";
        $publication_date .= "<label for='publication_date'>" . elgg_echo("pages_tools:label:publication_date") . "</label>";
        $publication_date .= elgg_view("input/date", array("name" => "publication_date", "value" => $publication_date_value));
        $publication_date .= "<div class='elgg-subtext'>" . elgg_echo("pages_tools:publication_date:description") . "</div>";
        $publication_date .= "</div>";
Example #2
0
function pages_tools_get_publication_wheres()
{
    static $result;
    if (!isset($result)) {
        $result = array();
        if (pages_tools_use_advanced_publication_options()) {
            $unpublished_id = add_metastring("unpublished");
            $dbprefix = elgg_get_config("dbprefix");
            $query = "(e.guid NOT IN (";
            $query .= "SELECT entity_guid";
            $query .= " FROM " . $dbprefix . "metadata";
            $query .= " WHERE name_id = " . $unpublished_id;
            $query .= "))";
            $result[] = $query;
        }
    }
    return $result;
}
Example #3
0
function pages_tools_daily_cron_hook($hook, $type, $return_value, $params)
{
    if (pages_tools_use_advanced_publication_options()) {
        $publication_id = add_metastring("publication_date");
        $expiration_id = add_metastring("expiration_date");
        $dbprefix = elgg_get_config("dbprefix");
        $time = elgg_extract("time", $params, time());
        $publish_options = array("type" => "object", "subtype" => array("page_top"), "limit" => false, "joins" => array("JOIN " . $dbprefix . "metadata mdtime ON e.guid = mdtime.entity_guid", "JOIN " . $dbprefix . "metastrings mstime ON mdtime.value_id = mstime.id"), "metadata_name_value_pairs" => array("name" => "unpublished", "value" => true), "wheres" => array("((mdtime.name_id = " . $publication_id . ") AND (DATE(mstime.string) = DATE(NOW())))"));
        $expire_options = array("type" => "object", "subtypes" => array("page_top", "page"), "limit" => false, "joins" => array("JOIN " . $dbprefix . "metadata mdtime ON e.guid = mdtime.entity_guid", "JOIN " . $dbprefix . "metastrings mstime ON mdtime.value_id = mstime.id"), "wheres" => pages_tools_get_publication_wheres());
        $expire_options["wheres"][] = "((mdtime.name_id = " . $expiration_id . ") AND (DATE(mstime.string) = DATE(NOW())))";
        // ignore access
        $ia = elgg_set_ignore_access(true);
        // get unpublished pages that need to be published
        if ($entities = elgg_get_entities_from_metadata($publish_options)) {
            foreach ($entities as $entity) {
                // add river event
                add_to_river("river/object/page/create", "create", $entity->getOwner(), $entity->getGUID());
                // set time created
                $entity->time_created = $time;
                // make sure the page is listed
                unset($entity->unpublished);
                // notify the user
                notify_user($entity->getOwnerGUID(), $entity->site_guid, elgg_echo("pages_tools:notify:publish:subject"), elgg_echo("pages_tools:notify:publish:message", array($entity->title, $entity->getURL())));
                // save everything
                $entity->save();
            }
        }
        // get pages that have expired
        if ($entities = elgg_get_entities_from_metadata($expire_options)) {
            foreach ($entities as $entity) {
                // remove river event
                elgg_delete_river(array("object_guid" => $entity->getGUID(), "action_type" => "create"));
                // make sure the page is no longer listed
                $entity->unpublished = true;
                // notify the user
                notify_user($entity->getOwnerGUID(), $entity->site_guid, elgg_echo("pages_tools:notify:expire:subject"), elgg_echo("pages_tools:notify:expire:message", array($entity->title, $entity->getURL())));
                // save everything
                $entity->save();
            }
        }
        // reset access
        elgg_set_ignore_access($ia);
    }
}